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