OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2015 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #ifndef SkSwizzler_DEFINED | |
9 #define SkSwizzler_DEFINED | |
10 | |
11 #include "SkTypes.h" | |
12 #include "SkColor.h" | |
13 #include "SkImageInfo.h" | |
14 | |
15 class SkSwizzler : public SkNoncopyable { | |
16 public: | |
17 /** | |
18 * Enum describing the config of the source data. | |
19 */ | |
20 enum SrcConfig { | |
21 kGray, // 1 byte per pixel | |
22 kIndex, // 1 byte per pixel | |
23 kRGB, // 3 bytes per pixel | |
24 kRGBX, // 4 byes per pixel (ignore 4th) | |
25 kRGBA, // 4 bytes per pixel | |
26 kRGB_565 // 2 bytes per pixel | |
27 }; | |
28 | |
29 static int BytesPerPixel(SrcConfig sc) { | |
30 switch (sc) { | |
31 case kGray: | |
32 case kIndex: | |
33 return 1; | |
34 case kRGB: | |
35 return 3; | |
36 case kRGBX: | |
37 case kRGBA: | |
38 return 4; | |
39 case kRGB_565: | |
40 return 2; | |
41 default: | |
42 SkDebugf("invalid source config passed to BytesPerPixel\n"); | |
43 return -1; | |
44 } | |
45 } | |
46 | |
47 /** | |
48 * Create a new SkSwizzler. | |
49 * @param sc SrcConfig | |
50 * @param info dimensions() describe both the src and the dst. | |
51 * Other fields describe the dst. | |
52 * @param dst Destination to write pixels. Must match info and dstRowBytes | |
53 * @param dstRowBytes rowBytes for dst. | |
54 * @param skipZeroes Whether to skip writing zeroes. Useful if dst is | |
55 * zero-initialized. The implementation may or may not respect
this. | |
56 * @return A new SkSwizzler or NULL on failure. | |
57 */ | |
58 static SkSwizzler* CreateSwizzler(SrcConfig sc, const SkPMColor* ctable, | |
59 const SkImageInfo& info, void* dst, | |
60 size_t dstRowBytes, bool skipZeroes); | |
61 /** | |
62 * Swizzle the next line. Call height times, once for each row of source. | |
63 * @param src The next row of the source data. | |
64 * @return Whether the row had non-opaque alpha. | |
65 */ | |
66 bool next(const uint8_t* SK_RESTRICT src); | |
67 private: | |
68 /** | |
69 * Method for converting raw data to Skia pixels. | |
70 * @param dstRow Row in which to write the resulting pixels. | |
71 * @param src Row of src data, in format specified by SrcConfig | |
72 * @param width Width in pixels | |
73 * @param bpp bytes per pixel of the source. | |
74 * @param y Line of source. | |
75 * @param ctable Colors (used for kIndex source). | |
76 */ | |
77 typedef bool (*RowProc)(void* SK_RESTRICT dstRow, | |
78 const uint8_t* SK_RESTRICT src, | |
79 int width, int bpp, int y, | |
80 const SkPMColor ctable[]); | |
81 | |
82 const RowProc fRowProc; | |
83 const SkPMColor* fColorTable; // Unowned pointer | |
84 const int fSrcPixelSize; | |
85 const SkImageInfo fDstInfo; | |
86 void* fDstRow; | |
87 const size_t fDstRowBytes; | |
88 int fCurrY; | |
89 | |
90 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBpp, | |
91 const SkImageInfo& info, void* dst, size_t rowBytes); | |
92 | |
93 }; | |
94 #endif // SkSwizzler_DEFINED | |
OLD | NEW |