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

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: Tested bmp and swizzler design Created 5 years, 10 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,
scroggo 2015/02/25 17:22:43 Alternatively, we could make the caller specify ho
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 kIndex8,
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 static int BytesPerPixel(SrcConfig sc) {
30 switch (sc) { 39 switch (sc) {
40 case kIndex1:
41 case kIndex2:
42 case kIndex4:
43 return 0; // Flag used when pixels are less than a byte
scroggo 2015/02/25 17:22:43 I don't like having both BitsPerPixel and BytesPer
31 case kGray: 44 case kGray:
32 case kIndex: 45 case kIndex8:
33 return 1; 46 return 1;
34 case kRGB: 47 case kRGB:
48 case kBGR:
49 case kMask24:
35 return 3; 50 return 3;
36 case kRGBX: 51 case kRGBX:
52 case kBGRX:
37 case kRGBA: 53 case kRGBA:
54 case kBGRA:
55 case kMask32:
38 return 4; 56 return 4;
39 case kRGB_565: 57 case kRGB_565:
58 case kMask16:
40 return 2; 59 return 2;
41 } 60 }
42 } 61 }
62
63 static int BitsPerPixel(SrcConfig sc) {
64 switch (sc) {
65 case kIndex1:
66 return 1;
67 case kIndex2:
68 return 2;
69 case kIndex4:
70 return 4;
71 default:
72 return BytesPerPixel(sc) * 8;
73 }
74 }
43 75
44 /** 76 /**
45 * Create a new SkSwizzler. 77 * Create a new SkSwizzler.
46 * @param sc SrcConfig 78 * @param sc SrcConfig
47 * @param info dimensions() describe both the src and the dst. 79 * @param info dimensions() describe both the src and the dst.
48 * Other fields describe the dst. 80 * Other fields describe the dst.
49 * @param dst Destination to write pixels. Must match info and dstRowBytes 81 * @param dst Destination to write pixels. Must match info and dstRowBytes
50 * @param dstRowBytes rowBytes for dst. 82 * @param dstRowBytes rowBytes for dst.
51 * @param skipZeroes Whether to skip writing zeroes. Useful if dst is 83 * @param skipZeroes Whether to skip writing zeroes. Useful if dst is
52 * zero-initialized. The implementation may or may not respect this. 84 * zero-initialized. The implementation may or may not respect this.
85 * @param bitMasks Custom bit masks used to interpret pixels
scroggo 2015/02/25 17:22:43 What does custom mean?
scroggo 2015/02/25 17:22:43 What does this mean? Does the swizzler always do t
86 * @param fixAlpha Whether to monitor for fully transparent images and set
87 * them as opaque
53 * @return A new SkSwizzler or NULL on failure. 88 * @return A new SkSwizzler or NULL on failure.
54 */ 89 */
55 static SkSwizzler* CreateSwizzler(SrcConfig sc, const SkPMColor* ctable, 90 static SkSwizzler* CreateSwizzler(SrcConfig sc, const SkPMColor* ctable,
56 const SkImageInfo& info, void* dst, 91 const SkImageInfo& info, void* dst,
57 size_t dstRowBytes, bool skipZeroes); 92 size_t dstRowBytes, bool skipZeroes,
93 const uint32_t* bitMasks = NULL,
94 const bool fixAlpha = false,
95 const bool inverted = false);
scroggo 2015/02/25 17:22:43 Can you add a comment explaining "inverted"? I sh
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 bool next(const uint8_t* SK_RESTRICT src);
64 private: 102 private:
65 /** 103 /**
66 * Method for converting raw data to Skia pixels. 104 * Method for converting raw data to Skia pixels.
67 * @param dstRow Row in which to write the resulting pixels. 105 * @param dstRow Row in which to write the resulting pixels.
68 * @param src Row of src data, in format specified by SrcConfig 106 * @param src Row of src data, in format specified by SrcConfig
69 * @param width Width in pixels 107 * @param width Width in pixels
70 * @param bpp bytes per pixel of the source. 108 * @param bpp bytes per pixel of the source.
71 * @param y Line of source. 109 * @param y Line of source.
72 * @param ctable Colors (used for kIndex source). 110 * @param ctable Colors (used for kIndex source).
73 */ 111 */
74 typedef bool (*RowProc)(void* SK_RESTRICT dstRow, 112 typedef bool (*RowProc)(void* SK_RESTRICT dstRow,
75 const uint8_t* SK_RESTRICT src, 113 const uint8_t* SK_RESTRICT src,
76 int width, int bpp, int y, 114 int width, int bpp, int bitsPerPixel, int y,
77 const SkPMColor ctable[]); 115 const SkPMColor ctable[], const uint32_t* masks,
scroggo 2015/02/25 17:22:43 please add comments for all of these.
116 const bool fixAlpha, bool* fSeenNonZeroAlphaPtr,
scroggo 2015/02/25 17:22:43 fCamelCase is reserved for member fields. Paramete
msarett 2015/02/26 23:58:18 I was trying to draw attention to the fact that I
117 bool* fZeroPrevRowsPtr);
78 118
79 const RowProc fRowProc; 119 const RowProc fRowProc;
80 const SkPMColor* fColorTable; // Unowned pointer 120 const SkPMColor* fColorTable; // Unowned pointer
121 const uint32_t* fBitMasks; // Unowned pointer
81 const int fSrcPixelSize; 122 const int fSrcPixelSize;
123 const int fSrcBitsPerPixel;
82 const SkImageInfo fDstInfo; 124 const SkImageInfo fDstInfo;
83 void* fDstRow; 125 void* fDstRow;
84 const size_t fDstRowBytes; 126 const size_t fDstRowBytes;
85 int fCurrY; 127 int fCurrY;
128 const bool fFixAlpha;
129 const bool fInverted;
130 bool fSeenNonZeroAlpha;
131 bool fZeroPrevRows;
86 132
87 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBpp, 133 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBpp, int srcBitsPP,
88 const SkImageInfo& info, void* dst, size_t rowBytes); 134 const SkImageInfo& info, void* dst, size_t rowBytes,
135 const uint32_t* bitMasks, const bool fixAlpha,
136 const bool inverted);
89 137
90 }; 138 };
91 #endif // SkSwizzler_DEFINED 139 #endif // SkSwizzler_DEFINED
92 140
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698