Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef _MOZILLA_GFX_DATASURFACEHELPERS_H |
michael@0 | 7 | #define _MOZILLA_GFX_DATASURFACEHELPERS_H |
michael@0 | 8 | |
michael@0 | 9 | #include "2D.h" |
michael@0 | 10 | |
michael@0 | 11 | namespace mozilla { |
michael@0 | 12 | namespace gfx { |
michael@0 | 13 | |
michael@0 | 14 | void |
michael@0 | 15 | ConvertBGRXToBGRA(uint8_t* aData, const IntSize &aSize, int32_t aStride); |
michael@0 | 16 | |
michael@0 | 17 | /** |
michael@0 | 18 | * Copy the pixel data from aSrc and pack it into aDst. aSrcSize, aSrcStride |
michael@0 | 19 | * and aBytesPerPixel give the size, stride and bytes per pixel for aSrc's |
michael@0 | 20 | * surface. Callers are responsible for making sure that aDst is big enough to |
michael@0 | 21 | * contain |aSrcSize.width * aSrcSize.height * aBytesPerPixel| bytes. |
michael@0 | 22 | */ |
michael@0 | 23 | void |
michael@0 | 24 | CopySurfaceDataToPackedArray(uint8_t* aSrc, uint8_t* aDst, IntSize aSrcSize, |
michael@0 | 25 | int32_t aSrcStride, int32_t aBytesPerPixel); |
michael@0 | 26 | |
michael@0 | 27 | /** |
michael@0 | 28 | * Convert aSurface to a packed buffer in BGRA format. The pixel data is |
michael@0 | 29 | * returned in a buffer allocated with new uint8_t[]. The caller then has |
michael@0 | 30 | * ownership of the buffer and is responsible for delete[]'ing it. |
michael@0 | 31 | */ |
michael@0 | 32 | uint8_t* |
michael@0 | 33 | SurfaceToPackedBGRA(DataSourceSurface *aSurface); |
michael@0 | 34 | |
michael@0 | 35 | /** |
michael@0 | 36 | * Convert aSurface to a packed buffer in BGR format. The pixel data is |
michael@0 | 37 | * returned in a buffer allocated with new uint8_t[]. The caller then has |
michael@0 | 38 | * ownership of the buffer and is responsible for delete[]'ing it. |
michael@0 | 39 | * |
michael@0 | 40 | * This function is currently only intended for use with surfaces of format |
michael@0 | 41 | * SurfaceFormat::B8G8R8X8 since the X components of the pixel data (if any) |
michael@0 | 42 | * are simply dropped (no attempt is made to un-pre-multiply alpha from the |
michael@0 | 43 | * color components). |
michael@0 | 44 | */ |
michael@0 | 45 | uint8_t* |
michael@0 | 46 | SurfaceToPackedBGR(DataSourceSurface *aSurface); |
michael@0 | 47 | |
michael@0 | 48 | /** |
michael@0 | 49 | * Multiplies aStride and aHeight and makes sure the result is limited to |
michael@0 | 50 | * something sane. To keep things consistent, this should always be used |
michael@0 | 51 | * wherever we allocate a buffer based on surface stride and height. |
michael@0 | 52 | * |
michael@0 | 53 | * @param aExtra Optional argument to specify an additional number of trailing |
michael@0 | 54 | * bytes (useful for creating intermediate surfaces for filters, for |
michael@0 | 55 | * example). |
michael@0 | 56 | * |
michael@0 | 57 | * @return The result of the multiplication if it is acceptable, or else zero. |
michael@0 | 58 | */ |
michael@0 | 59 | size_t |
michael@0 | 60 | BufferSizeFromStrideAndHeight(int32_t aStride, |
michael@0 | 61 | int32_t aHeight, |
michael@0 | 62 | int32_t aExtraBytes = 0); |
michael@0 | 63 | |
michael@0 | 64 | } |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | #endif // _MOZILLA_GFX_DATASURFACEHELPERS_H |