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

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

Issue 1907593004: Support the non-native (RGBA/BGRA) swizzle (Closed) Base URL: https://skia.googlesource.com/skia.git@tryagain
Patch Set: Rebase Created 4 years, 8 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 #include "SkBmpStandardCodec.h" 8 #include "SkBmpStandardCodec.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 if (rows != dstInfo.height()) { 61 if (rows != dstInfo.height()) {
62 *rowsDecoded = rows; 62 *rowsDecoded = rows;
63 return kIncompleteInput; 63 return kIncompleteInput;
64 } 64 }
65 return kSuccess; 65 return kSuccess;
66 } 66 }
67 67
68 /* 68 /*
69 * Process the color table for the bmp input 69 * Process the color table for the bmp input
70 */ 70 */
71 bool SkBmpStandardCodec::createColorTable(SkAlphaType dstAlphaType, int* numCol ors) { 71 bool SkBmpStandardCodec::createColorTable(SkColorType dstColorType, SkAlphaType dstAlphaType,
72 int* numColors) {
72 // Allocate memory for color table 73 // Allocate memory for color table
73 uint32_t colorBytes = 0; 74 uint32_t colorBytes = 0;
74 SkPMColor colorTable[256]; 75 SkPMColor colorTable[256];
75 if (this->bitsPerPixel() <= 8) { 76 if (this->bitsPerPixel() <= 8) {
76 // Inform the caller of the number of colors 77 // Inform the caller of the number of colors
77 uint32_t maxColors = 1 << this->bitsPerPixel(); 78 uint32_t maxColors = 1 << this->bitsPerPixel();
78 if (nullptr != numColors) { 79 if (nullptr != numColors) {
79 // We set the number of colors to maxColors in order to ensure 80 // We set the number of colors to maxColors in order to ensure
80 // safe memory accesses. Otherwise, an invalid pixel could 81 // safe memory accesses. Otherwise, an invalid pixel could
81 // access memory outside of our color table array. 82 // access memory outside of our color table array.
82 *numColors = maxColors; 83 *numColors = maxColors;
83 } 84 }
84 // Don't bother reading more than maxColors. 85 // Don't bother reading more than maxColors.
85 const uint32_t numColorsToRead = 86 const uint32_t numColorsToRead =
86 fNumColors == 0 ? maxColors : SkTMin(fNumColors, maxColors); 87 fNumColors == 0 ? maxColors : SkTMin(fNumColors, maxColors);
87 88
88 // Read the color table from the stream 89 // Read the color table from the stream
89 colorBytes = numColorsToRead * fBytesPerColor; 90 colorBytes = numColorsToRead * fBytesPerColor;
90 SkAutoTDeleteArray<uint8_t> cBuffer(new uint8_t[colorBytes]); 91 SkAutoTDeleteArray<uint8_t> cBuffer(new uint8_t[colorBytes]);
91 if (stream()->read(cBuffer.get(), colorBytes) != colorBytes) { 92 if (stream()->read(cBuffer.get(), colorBytes) != colorBytes) {
92 SkCodecPrintf("Error: unable to read color table.\n"); 93 SkCodecPrintf("Error: unable to read color table.\n");
93 return false; 94 return false;
94 } 95 }
95 96
96 // Choose the proper packing function 97 // Choose the proper packing function
97 SkPMColor (*packARGB) (uint32_t, uint32_t, uint32_t, uint32_t); 98 bool isPremul = (kPremul_SkAlphaType == dstAlphaType) && !fIsOpaque;
98 if (fIsOpaque || kUnpremul_SkAlphaType == dstAlphaType) { 99 PackColorProc packARGB = choose_pack_color_proc(isPremul, dstColorType);
99 packARGB = &SkPackARGB32NoCheck;
100 } else {
101 packARGB = &SkPremultiplyARGBInline;
102 }
103 100
104 // Fill in the color table 101 // Fill in the color table
105 uint32_t i = 0; 102 uint32_t i = 0;
106 for (; i < numColorsToRead; i++) { 103 for (; i < numColorsToRead; i++) {
107 uint8_t blue = get_byte(cBuffer.get(), i*fBytesPerColor); 104 uint8_t blue = get_byte(cBuffer.get(), i*fBytesPerColor);
108 uint8_t green = get_byte(cBuffer.get(), i*fBytesPerColor + 1); 105 uint8_t green = get_byte(cBuffer.get(), i*fBytesPerColor + 1);
109 uint8_t red = get_byte(cBuffer.get(), i*fBytesPerColor + 2); 106 uint8_t red = get_byte(cBuffer.get(), i*fBytesPerColor + 2);
110 uint8_t alpha; 107 uint8_t alpha;
111 if (fIsOpaque) { 108 if (fIsOpaque) {
112 alpha = 0xFF; 109 alpha = 0xFF;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 155
159 // Create swizzler 156 // Create swizzler
160 fSwizzler.reset(SkSwizzler::CreateSwizzler(this->getEncodedInfo(), colorPtr, dstInfo, opts)); 157 fSwizzler.reset(SkSwizzler::CreateSwizzler(this->getEncodedInfo(), colorPtr, dstInfo, opts));
161 SkASSERT(fSwizzler); 158 SkASSERT(fSwizzler);
162 } 159 }
163 160
164 SkCodec::Result SkBmpStandardCodec::prepareToDecode(const SkImageInfo& dstInfo, 161 SkCodec::Result SkBmpStandardCodec::prepareToDecode(const SkImageInfo& dstInfo,
165 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo lorCount) { 162 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo lorCount) {
166 // Create the color table if necessary and prepare the stream for decode 163 // Create the color table if necessary and prepare the stream for decode
167 // Note that if it is non-NULL, inputColorCount will be modified 164 // Note that if it is non-NULL, inputColorCount will be modified
168 if (!this->createColorTable(dstInfo.alphaType(), inputColorCount)) { 165 if (!this->createColorTable(dstInfo.colorType(), dstInfo.alphaType(), inputC olorCount)) {
169 SkCodecPrintf("Error: could not create color table.\n"); 166 SkCodecPrintf("Error: could not create color table.\n");
170 return SkCodec::kInvalidInput; 167 return SkCodec::kInvalidInput;
171 } 168 }
172 169
173 // Copy the color table to the client if necessary 170 // Copy the color table to the client if necessary
174 copy_color_table(dstInfo, this->fColorTable, inputColorPtr, inputColorCount) ; 171 copy_color_table(dstInfo, this->fColorTable, inputColorPtr, inputColorCount) ;
175 172
176 // Initialize a swizzler 173 // Initialize a swizzler
177 this->initializeSwizzler(dstInfo, options); 174 this->initializeSwizzler(dstInfo, options);
178 return SkCodec::kSuccess; 175 return SkCodec::kSuccess;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 287 }
291 } 288 }
292 289
293 uint32_t SkBmpStandardCodec::onGetFillValue(SkColorType colorType) const { 290 uint32_t SkBmpStandardCodec::onGetFillValue(SkColorType colorType) const {
294 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); 291 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get());
295 if (colorPtr) { 292 if (colorPtr) {
296 return get_color_table_fill_value(colorType, colorPtr, 0); 293 return get_color_table_fill_value(colorType, colorPtr, 0);
297 } 294 }
298 return INHERITED::onGetFillValue(colorType); 295 return INHERITED::onGetFillValue(colorType);
299 } 296 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698