1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/2d/DataSurfaceHelpers.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef _MOZILLA_GFX_DATASURFACEHELPERS_H 1.10 +#define _MOZILLA_GFX_DATASURFACEHELPERS_H 1.11 + 1.12 +#include "2D.h" 1.13 + 1.14 +namespace mozilla { 1.15 +namespace gfx { 1.16 + 1.17 +void 1.18 +ConvertBGRXToBGRA(uint8_t* aData, const IntSize &aSize, int32_t aStride); 1.19 + 1.20 +/** 1.21 + * Copy the pixel data from aSrc and pack it into aDst. aSrcSize, aSrcStride 1.22 + * and aBytesPerPixel give the size, stride and bytes per pixel for aSrc's 1.23 + * surface. Callers are responsible for making sure that aDst is big enough to 1.24 + * contain |aSrcSize.width * aSrcSize.height * aBytesPerPixel| bytes. 1.25 + */ 1.26 +void 1.27 +CopySurfaceDataToPackedArray(uint8_t* aSrc, uint8_t* aDst, IntSize aSrcSize, 1.28 + int32_t aSrcStride, int32_t aBytesPerPixel); 1.29 + 1.30 +/** 1.31 + * Convert aSurface to a packed buffer in BGRA format. The pixel data is 1.32 + * returned in a buffer allocated with new uint8_t[]. The caller then has 1.33 + * ownership of the buffer and is responsible for delete[]'ing it. 1.34 + */ 1.35 +uint8_t* 1.36 +SurfaceToPackedBGRA(DataSourceSurface *aSurface); 1.37 + 1.38 +/** 1.39 + * Convert aSurface to a packed buffer in BGR format. The pixel data is 1.40 + * returned in a buffer allocated with new uint8_t[]. The caller then has 1.41 + * ownership of the buffer and is responsible for delete[]'ing it. 1.42 + * 1.43 + * This function is currently only intended for use with surfaces of format 1.44 + * SurfaceFormat::B8G8R8X8 since the X components of the pixel data (if any) 1.45 + * are simply dropped (no attempt is made to un-pre-multiply alpha from the 1.46 + * color components). 1.47 + */ 1.48 +uint8_t* 1.49 +SurfaceToPackedBGR(DataSourceSurface *aSurface); 1.50 + 1.51 +/** 1.52 + * Multiplies aStride and aHeight and makes sure the result is limited to 1.53 + * something sane. To keep things consistent, this should always be used 1.54 + * wherever we allocate a buffer based on surface stride and height. 1.55 + * 1.56 + * @param aExtra Optional argument to specify an additional number of trailing 1.57 + * bytes (useful for creating intermediate surfaces for filters, for 1.58 + * example). 1.59 + * 1.60 + * @return The result of the multiplication if it is acceptable, or else zero. 1.61 + */ 1.62 +size_t 1.63 +BufferSizeFromStrideAndHeight(int32_t aStride, 1.64 + int32_t aHeight, 1.65 + int32_t aExtraBytes = 0); 1.66 + 1.67 +} 1.68 +} 1.69 + 1.70 +#endif // _MOZILLA_GFX_DATASURFACEHELPERS_H