Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: src/codec/SkSwizzler.h

Issue 947283002: Bmp Image Decoding (Closed) Base URL: https://skia.googlesource.com/skia.git@decode-leon-3
Patch Set: separate swizzler for masks Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkSwizzler_DEFINED 8 #ifndef SkSwizzler_DEFINED
9 #define SkSwizzler_DEFINED 9 #define SkSwizzler_DEFINED
10 10
11 #include "SkTypes.h" 11 #include "SkTypes.h"
12 #include "SkColor.h" 12 #include "SkColor.h"
13 #include "SkImageInfo.h" 13 #include "SkImageInfo.h"
14 14
15 class SkSwizzler : public SkNoncopyable { 15 class SkSwizzler : public SkNoncopyable {
16 public: 16 public:
17 /** 17 /**
18 * Enum describing the config of the source data. 18 * Enum describing the config of the source data.
19 */ 19 */
20 enum SrcConfig { 20 enum SrcConfig {
21 kGray, // 1 byte per pixel 21 kGray,
22 kIndex, // 1 byte per pixel 22 kIndex1,
23 kRGB, // 3 bytes per pixel 23 kIndex2,
24 kRGBX, // 4 byes per pixel (ignore 4th) 24 kIndex4,
25 kRGBA, // 4 bytes per pixel 25 kIndex,
26 kRGB_565 // 2 bytes per pixel 26 kRGB,
27 kBGR,
28 kRGBX,
29 kBGRX,
30 kRGBA,
31 kBGRA,
32 kRGB_565,
27 }; 33 };
28 34
29 static int BytesPerPixel(SrcConfig sc) { 35 /*
36 *
37 * Result code for the alpha components of a row.
38 *
39 */
40 enum ResultAlpha {
41 kOpaque_ResultAlpha, // All pixels in a row have max alpha
42 kTransparent_ResultAlpha, // All pixels in a row have zero alpha
43 kNeither_ResultAlpha // Alpha is not completely maxed or zeroed
44 };
45
46 static int BitsPerPixel(SrcConfig sc) {
30 switch (sc) { 47 switch (sc) {
31 case kGray: 48 case kIndex1:
49 return 1;
50 case kIndex2:
51 return 2;
52 case kIndex4:
53 return 4;
32 case kIndex: 54 case kIndex:
33 return 1; 55 return 8;
56 case kRGB_565:
57 return 16;
34 case kRGB: 58 case kRGB:
35 return 3; 59 case kBGR:
60 return 24;
36 case kRGBX: 61 case kRGBX:
37 case kRGBA: 62 case kRGBA:
38 return 4; 63 case kBGRX:
39 case kRGB_565: 64 case kBGRA:
40 return 2; 65 return 32;
41 } 66 }
42 } 67 }
43 68
69 static int BytesPerPixel(SrcConfig sc) {
70 SkASSERT(SkIsAlign4(BitsPerPixel(sc)));
71 return (BitsPerPixel(sc)) >> 3;
72 }
73
44 /** 74 /**
45 * Create a new SkSwizzler. 75 * Create a new SkSwizzler.
46 * @param sc SrcConfig 76 * @param sc SrcConfig
47 * @param info dimensions() describe both the src and the dst. 77 * @param info dimensions() describe both the src and the dst.
48 * Other fields describe the dst. 78 * Other fields describe the dst.
49 * @param dst Destination to write pixels. Must match info and dstRowBytes 79 * @param dst Destination to write pixels. Must match info and dstRowBytes
50 * @param dstRowBytes rowBytes for dst. 80 * @param dstRowBytes rowBytes for dst.
51 * @param skipZeroes Whether to skip writing zeroes. Useful if dst is 81 * @param skipZeroes Whether to skip writing zeroes. Useful if dst is
52 * zero-initialized. The implementation may or may not respect this. 82 * zero-initialized. The implementation may or may not respect this.
53 * @return A new SkSwizzler or NULL on failure. 83 * @return A new SkSwizzler or NULL on failure.
54 */ 84 */
55 static SkSwizzler* CreateSwizzler(SrcConfig sc, const SkPMColor* ctable, 85 static SkSwizzler* CreateSwizzler(
56 const SkImageInfo& info, void* dst, 86 SrcConfig sc, const SkPMColor* ctable, const SkImageInfo& info,
57 size_t dstRowBytes, bool skipZeroes); 87 void* dst, size_t dstRowBytes, bool skipZeroes);
88
89 /**
90 *
91 * Chooses the proper result alpha enum based on accumulated alpha masks
92 *
93 */
94 static ResultAlpha GetResult(uint8_t zeroAlpha, uint8_t maxAlpha);
95
58 /** 96 /**
59 * Swizzle the next line. Call height times, once for each row of source. 97 * Swizzle the next line. Call height times, once for each row of source.
60 * @param src The next row of the source data. 98 * @param src The next row of the source data.
61 * @return Whether the row had non-opaque alpha. 99 * @return Whether the row had non-opaque alpha.
62 */ 100 */
63 bool next(const uint8_t* SK_RESTRICT src); 101 ResultAlpha next(const uint8_t* SK_RESTRICT src);
102
103 /**
104 *
105 * Alternate version of next that allows the caller to specify the row.
106 * It is very important to only use one version of next. Since the other
scroggo 2015/03/11 14:23:10 In SkScaledBitmapSampler, we use an enum in debug
msarett 2015/03/11 18:53:05 That seems like a good solution. I added that her
107 * version modifies the dst pointer, it will change the behavior of this
108 * function.
109 *
110 */
111 ResultAlpha next(const uint8_t* SK_RESTRICT src, uint32_t y);
64 private: 112 private:
65 /** 113 /**
66 * Method for converting raw data to Skia pixels. 114 * Method for converting raw data to Skia pixels.
67 * @param dstRow Row in which to write the resulting pixels. 115 * @param dstRow Row in which to write the resulting pixels.
68 * @param src Row of src data, in format specified by SrcConfig 116 * @param src Row of src data, in format specified by SrcConfig
69 * @param width Width in pixels 117 * @param width Width in pixels
70 * @param bpp bytes per pixel of the source. 118 * @param bpp bits per pixel of the source.
71 * @param y Line of source. 119 * @param y Line of source.
72 * @param ctable Colors (used for kIndex source). 120 * @param ctable Colors (used for kIndex source).
73 */ 121 */
74 typedef bool (*RowProc)(void* SK_RESTRICT dstRow, 122 typedef ResultAlpha (*RowProc)(void* SK_RESTRICT dstRow,
75 const uint8_t* SK_RESTRICT src, 123 const uint8_t* SK_RESTRICT src,
76 int width, int bpp, int y, 124 int width, int bitsPerPixel, int y,
77 const SkPMColor ctable[]); 125 const SkPMColor ctable[]);
78 126
79 const RowProc fRowProc; 127 const RowProc fRowProc;
80 const SkPMColor* fColorTable; // Unowned pointer 128 const SkPMColor* fColorTable; // Unowned pointer
81 const int fSrcPixelSize; 129 const int fSrcBitsPerPixel;
82 const SkImageInfo fDstInfo; 130 const SkImageInfo fDstInfo;
83 void* fDstRow; 131 void* fDstRow;
84 const size_t fDstRowBytes; 132 const size_t fDstRowBytes;
85 int fCurrY; 133 int fCurrY;
86 134
87 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBpp, 135 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBPP,
88 const SkImageInfo& info, void* dst, size_t rowBytes); 136 const SkImageInfo& info, void* dst, size_t rowBytes);
89 137
90 }; 138 };
91 #endif // SkSwizzler_DEFINED 139 #endif // SkSwizzler_DEFINED
92
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698