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

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: Moved bmp specific code out of the swizzler 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
44 /** 69 /**
45 * Create a new SkSwizzler. 70 * Create a new SkSwizzler.
46 * @param sc SrcConfig 71 * @param sc SrcConfig
47 * @param info dimensions() describe both the src and the dst. 72 * @param info dimensions() describe both the src and the dst.
48 * Other fields describe the dst. 73 * Other fields describe the dst.
49 * @param dst Destination to write pixels. Must match info and dstRowBytes 74 * @param dst Destination to write pixels. Must match info and dstRowBytes
50 * @param dstRowBytes rowBytes for dst. 75 * @param dstRowBytes rowBytes for dst.
51 * @param skipZeroes Whether to skip writing zeroes. Useful if dst is 76 * @param skipZeroes Whether to skip writing zeroes. Useful if dst is
52 * zero-initialized. The implementation may or may not respect this. 77 * zero-initialized. The implementation may or may not respect this.
53 * @return A new SkSwizzler or NULL on failure. 78 * @return A new SkSwizzler or NULL on failure.
54 */ 79 */
55 static SkSwizzler* CreateSwizzler(SrcConfig sc, const SkPMColor* ctable, 80 static SkSwizzler* CreateSwizzler(
56 const SkImageInfo& info, void* dst, 81 SrcConfig sc, const SkPMColor* ctable, const SkImageInfo& info,
57 size_t dstRowBytes, bool skipZeroes); 82 void* dst, size_t dstRowBytes, bool skipZeroes);
83
58 /** 84 /**
59 * Swizzle the next line. Call height times, once for each row of source. 85 * Swizzle the next line. Call height times, once for each row of source.
60 * @param src The next row of the source data. 86 * @param src The next row of the source data.
61 * @return Whether the row had non-opaque alpha. 87 * @return Whether the row had non-opaque alpha.
62 */ 88 */
63 bool next(const uint8_t* SK_RESTRICT src); 89 ResultAlpha next(const uint8_t* SK_RESTRICT src);
scroggo 2015/03/06 18:56:14 I think the PNG decoder needs to update the way it
90
91 /**
92 *
93 * Alternate version of next that allows the caller to specify the offset
94 * bytes to move to the next row.
95 *
96 */
97 ResultAlpha next(const uint8_t* SK_RESTRICT src, int32_t delta);
scroggo 2015/03/06 18:56:14 This interface is going to be hard for our SkGifCo
64 private: 98 private:
65 /** 99 /**
66 * Method for converting raw data to Skia pixels. 100 * Method for converting raw data to Skia pixels.
67 * @param dstRow Row in which to write the resulting pixels. 101 * @param dstRow Row in which to write the resulting pixels.
68 * @param src Row of src data, in format specified by SrcConfig 102 * @param src Row of src data, in format specified by SrcConfig
69 * @param width Width in pixels 103 * @param width Width in pixels
70 * @param bpp bytes per pixel of the source. 104 * @param bpp bytes per pixel of the source.
scroggo 2015/03/06 18:56:14 No longer bytes.
71 * @param y Line of source. 105 * @param y Line of source.
72 * @param ctable Colors (used for kIndex source). 106 * @param ctable Colors (used for kIndex source).
73 */ 107 */
74 typedef bool (*RowProc)(void* SK_RESTRICT dstRow, 108 typedef ResultAlpha (*RowProc)(void* SK_RESTRICT dstRow,
75 const uint8_t* SK_RESTRICT src, 109 const uint8_t* SK_RESTRICT src,
76 int width, int bpp, int y, 110 int width, int bitsPerPixel, int y,
77 const SkPMColor ctable[]); 111 const SkPMColor ctable[]);
78 112
79 const RowProc fRowProc; 113 const RowProc fRowProc;
80 const SkPMColor* fColorTable; // Unowned pointer 114 const SkPMColor* fColorTable; // Unowned pointer
81 const int fSrcPixelSize; 115 const int fSrcBitsPerPixel;
82 const SkImageInfo fDstInfo; 116 const SkImageInfo fDstInfo;
83 void* fDstRow; 117 void* fDstRow;
84 const size_t fDstRowBytes; 118 const size_t fDstRowBytes;
85 int fCurrY; 119 int fCurrY;
86 120
87 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBpp, 121 SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcBPP,
scroggo 2015/03/06 18:56:14 Why did this change?
88 const SkImageInfo& info, void* dst, size_t rowBytes); 122 const SkImageInfo& info, void* dst, size_t rowBytes);
89 123
90 }; 124 };
91 #endif // SkSwizzler_DEFINED 125 #endif // SkSwizzler_DEFINED
92
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698