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

Side by Side Diff: src/codec/SkBmpStandardCodec.cpp

Issue 1694513002: Support more color types for ICOs (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: inIco Created 4 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
« no previous file with comments | « src/codec/SkBmpStandardCodec.h ('k') | src/codec/SkIcoCodec.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "SkBmpStandardCodec.h" 8 #include "SkBmpStandardCodec.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 #include "SkStream.h" 11 #include "SkStream.h"
12 12
13 /* 13 /*
14 * Creates an instance of the decoder 14 * Creates an instance of the decoder
15 * Called only by NewFromStream 15 * Called only by NewFromStream
16 */ 16 */
17 SkBmpStandardCodec::SkBmpStandardCodec(const SkImageInfo& info, SkStream* stream , 17 SkBmpStandardCodec::SkBmpStandardCodec(const SkImageInfo& info, SkStream* stream ,
18 uint16_t bitsPerPixel, uint32_t numColors , 18 uint16_t bitsPerPixel, uint32_t numColors ,
19 uint32_t bytesPerColor, uint32_t offset, 19 uint32_t bytesPerColor, uint32_t offset,
20 SkCodec::SkScanlineOrder rowOrder, bool i nIco) 20 SkCodec::SkScanlineOrder rowOrder,
21 bool isOpaque, bool inIco)
21 : INHERITED(info, stream, bitsPerPixel, rowOrder) 22 : INHERITED(info, stream, bitsPerPixel, rowOrder)
22 , fColorTable(nullptr) 23 , fColorTable(nullptr)
23 , fNumColors(numColors) 24 , fNumColors(numColors)
24 , fBytesPerColor(bytesPerColor) 25 , fBytesPerColor(bytesPerColor)
25 , fOffset(offset) 26 , fOffset(offset)
26 , fSwizzler(nullptr) 27 , fSwizzler(nullptr)
27 , fSrcRowBytes(SkAlign4(compute_row_bytes(this->getInfo().width(), this->bit sPerPixel()))) 28 , fSrcRowBytes(SkAlign4(compute_row_bytes(this->getInfo().width(), this->bit sPerPixel())))
28 , fSrcBuffer(new uint8_t [fSrcRowBytes]) 29 , fSrcBuffer(new uint8_t [fSrcRowBytes])
30 , fIsOpaque(isOpaque)
29 , fInIco(inIco) 31 , fInIco(inIco)
30 , fAndMaskRowBytes(fInIco ? SkAlign4(compute_row_bytes(this->getInfo().width (), 1)) : 0) 32 , fAndMaskRowBytes(fInIco ? SkAlign4(compute_row_bytes(this->getInfo().width (), 1)) : 0)
31 {} 33 {}
32 34
33 /* 35 /*
34 * Initiates the bitmap decode 36 * Initiates the bitmap decode
35 */ 37 */
36 SkCodec::Result SkBmpStandardCodec::onGetPixels(const SkImageInfo& dstInfo, 38 SkCodec::Result SkBmpStandardCodec::onGetPixels(const SkImageInfo& dstInfo,
37 void* dst, size_t dstRowBytes, 39 void* dst, size_t dstRowBytes,
38 const Options& opts, 40 const Options& opts,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // Read the color table from the stream 89 // Read the color table from the stream
88 colorBytes = numColorsToRead * fBytesPerColor; 90 colorBytes = numColorsToRead * fBytesPerColor;
89 SkAutoTDeleteArray<uint8_t> cBuffer(new uint8_t[colorBytes]); 91 SkAutoTDeleteArray<uint8_t> cBuffer(new uint8_t[colorBytes]);
90 if (stream()->read(cBuffer.get(), colorBytes) != colorBytes) { 92 if (stream()->read(cBuffer.get(), colorBytes) != colorBytes) {
91 SkCodecPrintf("Error: unable to read color table.\n"); 93 SkCodecPrintf("Error: unable to read color table.\n");
92 return false; 94 return false;
93 } 95 }
94 96
95 // Choose the proper packing function 97 // Choose the proper packing function
96 SkPMColor (*packARGB) (uint32_t, uint32_t, uint32_t, uint32_t); 98 SkPMColor (*packARGB) (uint32_t, uint32_t, uint32_t, uint32_t);
97 SkAlphaType encodedAlphaType = this->getInfo().alphaType(); 99 if (fIsOpaque || kUnpremul_SkAlphaType == dstAlphaType) {
98 if (kOpaque_SkAlphaType == encodedAlphaType || kUnpremul_SkAlphaType == dstAlphaType) {
99 packARGB = &SkPackARGB32NoCheck; 100 packARGB = &SkPackARGB32NoCheck;
100 } else { 101 } else {
101 packARGB = &SkPremultiplyARGBInline; 102 packARGB = &SkPremultiplyARGBInline;
102 } 103 }
103 104
104 // Fill in the color table 105 // Fill in the color table
105 uint32_t i = 0; 106 uint32_t i = 0;
106 for (; i < numColorsToRead; i++) { 107 for (; i < numColorsToRead; i++) {
107 uint8_t blue = get_byte(cBuffer.get(), i*fBytesPerColor); 108 uint8_t blue = get_byte(cBuffer.get(), i*fBytesPerColor);
108 uint8_t green = get_byte(cBuffer.get(), i*fBytesPerColor + 1); 109 uint8_t green = get_byte(cBuffer.get(), i*fBytesPerColor + 1);
109 uint8_t red = get_byte(cBuffer.get(), i*fBytesPerColor + 2); 110 uint8_t red = get_byte(cBuffer.get(), i*fBytesPerColor + 2);
110 uint8_t alpha; 111 uint8_t alpha;
111 if (kOpaque_SkAlphaType == encodedAlphaType) { 112 if (fIsOpaque) {
112 alpha = 0xFF; 113 alpha = 0xFF;
113 } else { 114 } else {
114 alpha = get_byte(cBuffer.get(), i*fBytesPerColor + 3); 115 alpha = get_byte(cBuffer.get(), i*fBytesPerColor + 3);
115 } 116 }
116 colorTable[i] = packARGB(alpha, red, green, blue); 117 colorTable[i] = packARGB(alpha, red, green, blue);
117 } 118 }
118 119
119 // To avoid segmentation faults on bad pixel data, fill the end of the 120 // To avoid segmentation faults on bad pixel data, fill the end of the
120 // color table with black. This is the same the behavior as the 121 // color table with black. This is the same the behavior as the
121 // chromium decoder. 122 // chromium decoder.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 case 4: 166 case 4:
166 config = SkSwizzler::kIndex4; 167 config = SkSwizzler::kIndex4;
167 break; 168 break;
168 case 8: 169 case 8:
169 config = SkSwizzler::kIndex; 170 config = SkSwizzler::kIndex;
170 break; 171 break;
171 case 24: 172 case 24:
172 config = SkSwizzler::kBGR; 173 config = SkSwizzler::kBGR;
173 break; 174 break;
174 case 32: 175 case 32:
175 if (kOpaque_SkAlphaType == this->getInfo().alphaType()) { 176 if (fIsOpaque) {
176 config = SkSwizzler::kBGRX; 177 config = SkSwizzler::kBGRX;
177 } else { 178 } else {
178 config = SkSwizzler::kBGRA; 179 config = SkSwizzler::kBGRA;
179 } 180 }
180 break; 181 break;
181 default: 182 default:
182 SkASSERT(false); 183 SkASSERT(false);
183 return false; 184 return false;
184 } 185 }
185 186
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 328 }
328 } 329 }
329 330
330 uint32_t SkBmpStandardCodec::onGetFillValue(SkColorType colorType) const { 331 uint32_t SkBmpStandardCodec::onGetFillValue(SkColorType colorType) const {
331 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); 332 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get());
332 if (colorPtr) { 333 if (colorPtr) {
333 return get_color_table_fill_value(colorType, colorPtr, 0); 334 return get_color_table_fill_value(colorType, colorPtr, 0);
334 } 335 }
335 return INHERITED::onGetFillValue(colorType); 336 return INHERITED::onGetFillValue(colorType);
336 } 337 }
OLDNEW
« no previous file with comments | « src/codec/SkBmpStandardCodec.h ('k') | src/codec/SkIcoCodec.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698