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

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

Issue 1694023002: Revert of Fix colorType/alphaType checks in SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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/SkCodec.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"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 if (stream()->skip(fOffset - colorBytes) != fOffset - colorBytes) { 145 if (stream()->skip(fOffset - colorBytes) != fOffset - colorBytes) {
146 SkCodecPrintf("Error: unable to skip to image data.\n"); 146 SkCodecPrintf("Error: unable to skip to image data.\n");
147 return false; 147 return false;
148 } 148 }
149 } 149 }
150 150
151 // Return true on success 151 // Return true on success
152 return true; 152 return true;
153 } 153 }
154 154
155 void SkBmpStandardCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Op tions& opts) { 155 bool SkBmpStandardCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Op tions& opts) {
156 // Get swizzler configuration 156 // Get swizzler configuration
157 SkSwizzler::SrcConfig config = SkSwizzler::kUnknown; 157 SkSwizzler::SrcConfig config;
158 switch (this->bitsPerPixel()) { 158 switch (this->bitsPerPixel()) {
159 case 1: 159 case 1:
160 config = SkSwizzler::kIndex1; 160 config = SkSwizzler::kIndex1;
161 break; 161 break;
162 case 2: 162 case 2:
163 config = SkSwizzler::kIndex2; 163 config = SkSwizzler::kIndex2;
164 break; 164 break;
165 case 4: 165 case 4:
166 config = SkSwizzler::kIndex4; 166 config = SkSwizzler::kIndex4;
167 break; 167 break;
168 case 8: 168 case 8:
169 config = SkSwizzler::kIndex; 169 config = SkSwizzler::kIndex;
170 break; 170 break;
171 case 24: 171 case 24:
172 config = SkSwizzler::kBGR; 172 config = SkSwizzler::kBGR;
173 break; 173 break;
174 case 32: 174 case 32:
175 if (kOpaque_SkAlphaType == this->getInfo().alphaType()) { 175 if (kOpaque_SkAlphaType == this->getInfo().alphaType()) {
176 config = SkSwizzler::kBGRX; 176 config = SkSwizzler::kBGRX;
177 } else { 177 } else {
178 config = SkSwizzler::kBGRA; 178 config = SkSwizzler::kBGRA;
179 } 179 }
180 break; 180 break;
181 default: 181 default:
182 SkASSERT(false); 182 SkASSERT(false);
183 return false;
183 } 184 }
184 185
185 // Get a pointer to the color table if it exists 186 // Get a pointer to the color table if it exists
186 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); 187 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get());
187 188
188 // Create swizzler 189 // Create swizzler
189 fSwizzler.reset(SkSwizzler::CreateSwizzler(config, colorPtr, dstInfo, opts)) ; 190 fSwizzler.reset(SkSwizzler::CreateSwizzler(config, colorPtr, dstInfo, opts)) ;
190 SkASSERT(fSwizzler); 191
192 if (nullptr == fSwizzler.get()) {
193 return false;
194 }
195 return true;
191 } 196 }
192 197
193 SkCodec::Result SkBmpStandardCodec::prepareToDecode(const SkImageInfo& dstInfo, 198 SkCodec::Result SkBmpStandardCodec::prepareToDecode(const SkImageInfo& dstInfo,
194 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo lorCount) { 199 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo lorCount) {
195 // Create the color table if necessary and prepare the stream for decode 200 // Create the color table if necessary and prepare the stream for decode
196 // Note that if it is non-NULL, inputColorCount will be modified 201 // Note that if it is non-NULL, inputColorCount will be modified
197 if (!this->createColorTable(dstInfo.alphaType(), inputColorCount)) { 202 if (!this->createColorTable(dstInfo.alphaType(), inputColorCount)) {
198 SkCodecPrintf("Error: could not create color table.\n"); 203 SkCodecPrintf("Error: could not create color table.\n");
199 return SkCodec::kInvalidInput; 204 return SkCodec::kInvalidInput;
200 } 205 }
201 206
202 // Copy the color table to the client if necessary 207 // Copy the color table to the client if necessary
203 copy_color_table(dstInfo, this->fColorTable, inputColorPtr, inputColorCount) ; 208 copy_color_table(dstInfo, this->fColorTable, inputColorPtr, inputColorCount) ;
204 209
205 // Initialize a swizzler 210 // Initialize a swizzler if necessary
206 this->initializeSwizzler(dstInfo, options); 211 if (!this->initializeSwizzler(dstInfo, options)) {
212 SkCodecPrintf("Error: cannot initialize swizzler.\n");
213 return SkCodec::kInvalidConversion;
214 }
207 return SkCodec::kSuccess; 215 return SkCodec::kSuccess;
208 } 216 }
209 217
210 /* 218 /*
211 * Performs the bitmap decoding for standard input format 219 * Performs the bitmap decoding for standard input format
212 */ 220 */
213 int SkBmpStandardCodec::decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, 221 int SkBmpStandardCodec::decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes,
214 const Options& opts) { 222 const Options& opts) {
215 // Iterate over rows of the image 223 // Iterate over rows of the image
216 const int height = dstInfo.height(); 224 const int height = dstInfo.height();
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 327 }
320 } 328 }
321 329
322 uint32_t SkBmpStandardCodec::onGetFillValue(SkColorType colorType) const { 330 uint32_t SkBmpStandardCodec::onGetFillValue(SkColorType colorType) const {
323 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get()); 331 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get());
324 if (colorPtr) { 332 if (colorPtr) {
325 return get_color_table_fill_value(colorType, colorPtr, 0); 333 return get_color_table_fill_value(colorType, colorPtr, 0);
326 } 334 }
327 return INHERITED::onGetFillValue(colorType); 335 return INHERITED::onGetFillValue(colorType);
328 } 336 }
OLDNEW
« no previous file with comments | « src/codec/SkBmpStandardCodec.h ('k') | src/codec/SkCodec.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698