michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _MOZILLA_GFX_DATASURFACEHELPERS_H michael@0: #define _MOZILLA_GFX_DATASURFACEHELPERS_H michael@0: michael@0: #include "2D.h" michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: void michael@0: ConvertBGRXToBGRA(uint8_t* aData, const IntSize &aSize, int32_t aStride); michael@0: michael@0: /** michael@0: * Copy the pixel data from aSrc and pack it into aDst. aSrcSize, aSrcStride michael@0: * and aBytesPerPixel give the size, stride and bytes per pixel for aSrc's michael@0: * surface. Callers are responsible for making sure that aDst is big enough to michael@0: * contain |aSrcSize.width * aSrcSize.height * aBytesPerPixel| bytes. michael@0: */ michael@0: void michael@0: CopySurfaceDataToPackedArray(uint8_t* aSrc, uint8_t* aDst, IntSize aSrcSize, michael@0: int32_t aSrcStride, int32_t aBytesPerPixel); michael@0: michael@0: /** michael@0: * Convert aSurface to a packed buffer in BGRA format. The pixel data is michael@0: * returned in a buffer allocated with new uint8_t[]. The caller then has michael@0: * ownership of the buffer and is responsible for delete[]'ing it. michael@0: */ michael@0: uint8_t* michael@0: SurfaceToPackedBGRA(DataSourceSurface *aSurface); michael@0: michael@0: /** michael@0: * Convert aSurface to a packed buffer in BGR format. The pixel data is michael@0: * returned in a buffer allocated with new uint8_t[]. The caller then has michael@0: * ownership of the buffer and is responsible for delete[]'ing it. michael@0: * michael@0: * This function is currently only intended for use with surfaces of format michael@0: * SurfaceFormat::B8G8R8X8 since the X components of the pixel data (if any) michael@0: * are simply dropped (no attempt is made to un-pre-multiply alpha from the michael@0: * color components). michael@0: */ michael@0: uint8_t* michael@0: SurfaceToPackedBGR(DataSourceSurface *aSurface); michael@0: michael@0: /** michael@0: * Multiplies aStride and aHeight and makes sure the result is limited to michael@0: * something sane. To keep things consistent, this should always be used michael@0: * wherever we allocate a buffer based on surface stride and height. michael@0: * michael@0: * @param aExtra Optional argument to specify an additional number of trailing michael@0: * bytes (useful for creating intermediate surfaces for filters, for michael@0: * example). michael@0: * michael@0: * @return The result of the multiplication if it is acceptable, or else zero. michael@0: */ michael@0: size_t michael@0: BufferSizeFromStrideAndHeight(int32_t aStride, michael@0: int32_t aHeight, michael@0: int32_t aExtraBytes = 0); michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif // _MOZILLA_GFX_DATASURFACEHELPERS_H