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

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: Improved clarity of swizzler with regard to weird alpha 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,
33 kMask16,
34 kMask24,
35 kMask32
27 }; 36 };
28 37
29 static int BytesPerPixel(SrcConfig sc) { 38 /**
39 * In mask SrcConfigs, used as bit masks for color components.
40 */
41 struct ColorMasks {
42 uint32_t redMask;
43 uint32_t greenMask;
44 uint32_t blueMask;
45 uint32_t alphaMask;
46 };
47
48 /**
49 * Describes if rows of the input start at the top or bottom of the image.
50 */
51 enum RowOrder {
52 kTopDown_RowOrder,
53 kBottomUp_RowOrder
54 };
55
56 /**
57 * Describes if we will render fully transparent images as opaque.
58 * TODO: should we consider merging this SkAlphaType?
scroggo 2015/03/04 17:10:31 I don't think so. (I don't think we'll want to inc
59 * kOpaque_AlphaOption corresponds to kIgnore_SkAlphaType
60 * kNormal_AlphaOption corresponds to kPremul_SkAlphaType
scroggo 2015/03/04 17:10:31 Keep in mind we want to support unpremul as well.
61 * kTransparentAsOpaque_AlphaOption does not correspond to an
62 * existing SkAlphaType
63 */
64 enum AlphaOption {
65 kOpaque_AlphaOption,
66 kNormal_AlphaOption,
67 kTransparentAsOpaque_AlphaOption
68 };
69
70 static int BitsPerPixel(SrcConfig sc) {
30 switch (sc) { 71 switch (sc) {
31 case kGray: 72 case kIndex1:
73 return 1;
74 case kIndex2:
75 return 2;
76 case kIndex4:
77 return 4;
32 case kIndex: 78 case kIndex:
33 return 1; 79 return 8;
80 case kRGB_565:
81 case kMask16:
82 return 16;
34 case kRGB: 83 case kRGB:
35 return 3; 84 case kBGR:
85 case kMask24:
86 return 24;
36 case kRGBX: 87 case kRGBX:
37 case kRGBA: 88 case kRGBA:
38 return 4; 89 case kBGRX:
39 case kRGB_565: 90 case kBGRA:
40 return 2; 91 case kMask32:
92 return 32;
41 } 93 }
42 } 94 }
43 95
44 /** 96 /**
45 * Create a new SkSwizzler. 97 * Create a new SkSwizzler.
46 * @param sc SrcConfig 98 * @param sc SrcConfig
47 * @param info dimensions() describe both the src and the dst. 99 * @param info dimensions() describe both the src and the dst.
48 * Other fields describe the dst. 100 * Other fields describe the dst.
49 * @param dst Destination to write pixels. Must match info and dstRowBytes 101 * @param dst Destination to write pixels. Must match info and dstRowBytes
50 * @param dstRowBytes rowBytes for dst. 102 * @param dstRowBytes rowBytes for dst.
51 * @param skipZeroes Whether to skip writing zeroes. Useful if dst is 103 * @param skipZeroes Whether to skip writing zeroes. Useful if dst is
52 * zero-initialized. The implementation may or may not respect this. 104 * zero-initialized. The implementation may or may not respect this.
105 * @param bitMasks Masks used to separate the color components of a pixel
106 * @param alphaOption Some inputs (bmp) have an alpha channel that is unuse d.
107 * Users of this channel often fill it with zeros, but still
108 * expect the image to be opaque. When alphaOption is
109 * kTransparentAsOpaque, completely transparent images should
110 * be rendered as opaque. Images that are not completely
111 * transparent should be treated normally.
112 * @param rowOrder Order in which input rows are swizzled
53 * @return A new SkSwizzler or NULL on failure. 113 * @return A new SkSwizzler or NULL on failure.
54 */ 114 */
55 static SkSwizzler* CreateSwizzler(SrcConfig sc, const SkPMColor* ctable, 115 static SkSwizzler* CreateSwizzler(
56 const SkImageInfo& info, void* dst, 116 SrcConfig sc, const SkPMColor* ctable, const SkImageInfo& info,
57 size_t dstRowBytes, bool skipZeroes); 117 void* dst, size_t dstRowBytes, bool skipZeroes,
118 const ColorMasks bitMasks = { 0, 0, 0, 0 },
scroggo 2015/03/04 17:10:31 I'm glad you're using the Swizzler, but: A lot of
119 const AlphaOption alphaOption = kNormal_AlphaOption,
120 const RowOrder rowOrder = kTopDown_RowOrder);
58 /** 121 /**
59 * Swizzle the next line. Call height times, once for each row of source. 122 * Swizzle the next line. Call height times, once for each row of source.
60 * @param src The next row of the source data. 123 * @param src The next row of the source data.
61 * @return Whether the row had non-opaque alpha. 124 * @return Whether the row had non-opaque alpha.
62 */ 125 */
63 bool next(const uint8_t* SK_RESTRICT src); 126 bool next(const uint8_t* SK_RESTRICT src);
64 private: 127 private:
65 /** 128 /**
66 * Method for converting raw data to Skia pixels. 129 * Method for converting raw data to Skia pixels.
67 * @param dstRow Row in which to write the resulting pixels. 130 * @param dstRow Row in which to write the resulting pixels.
68 * @param src Row of src data, in format specified by SrcConfig 131 * @param src Row of src data, in format specified by SrcConfig
69 * @param width Width in pixels 132 * @param width Width in pixels
70 * @param bpp bytes per pixel of the source. 133 * @param bpp bytes per pixel of the source.
71 * @param y Line of source. 134 * @param y Line of source.
72 * @param ctable Colors (used for kIndex source). 135 * @param ctable Colors (used for kIndex source).
136 * @param masks Bit masks used to separate the color components of a pixel
137 * @param alphaOption Some inputs (bmp) have an alpha channel that is unuse d.
138 * Users of this channel often fill it with zeros, but still
139 * expect the image to be opaque. When alphaOption is
140 * kTransparentAsOpaque, completely transparent images should
141 * be rendered as opaque. Images that are not completely
142 * transparent should be treated normally.
143 * @param seenNonAlphaOption,
144 kTransparentAsOpaque_AlphaOptionPtr A ptr to the field that indicates if we have
145 * seen a non-zero alpha value in an image. This is used in
146 * conjunction with alphaOption to ensure accidentally fully
147 * transparent images are rendered as opaque.
148 * @param zeroPrevRowsPtr A ptr to the field that indicates if we need
149 * to set all previously decoded rows as transparent. This
150 * occurs when we have decoded transparent rows as opaque
151 * (because alphaOption is true), but then find a pixel that is
152 * not transparent. On this event, we must return to
153 * previously decoded rows and set them as transparent.
73 */ 154 */
74 typedef bool (*RowProc)(void* SK_RESTRICT dstRow, 155 typedef bool (*RowProc)(void* SK_RESTRICT dstRow,
75 const uint8_t* SK_RESTRICT src, 156 const uint8_t* SK_RESTRICT src,
76 int width, int bpp, int y, 157 int width, int bitsPerPixel, int y,
77 const SkPMColor ctable[]); 158 const SkPMColor ctable[], const ColorMasks masks,
159 const AlphaOption alphaOption,
160 bool* seenNonZeroAlpha, bool* zeroPrevRowsPtr);
78 161
79 const RowProc fRowProc; 162 const RowProc fRowProc;
80 const SkPMColor* fColorTable; // Unowned pointer 163 const SkPMColor* fColorTable; // Unowned pointer
81 const int fSrcPixelSize; 164 const ColorMasks fBitMasks;
165 const int fSrcBitsPerPixel;
82 const SkImageInfo fDstInfo; 166 const SkImageInfo fDstInfo;
83 void* fDstRow; 167 void* fDstRow;
84 const size_t fDstRowBytes; 168 const size_t fDstRowBytes;
85 int fCurrY; 169 int fCurrY;
170 const AlphaOption fAlphaOption;
171 const RowOrder fRowOrder;
172 bool fSeenNonZeroAlpha;
173 bool fZeroPrevRows;
86 174
87 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBpp, 175 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBPP,
88 const SkImageInfo& info, void* dst, size_t rowBytes); 176 const SkImageInfo& info, void* dst, size_t rowBytes,
177 const ColorMasks bitMasks, const AlphaOption alphaOption,
178 const RowOrder rowOrder);
89 179
90 }; 180 };
91 #endif // SkSwizzler_DEFINED 181 #endif // SkSwizzler_DEFINED
92 182
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698