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

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

Issue 1332053002: Fill incomplete images in SkCodec parent class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Response to comments Created 5 years, 3 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 19 matching lines...) Expand all
30 , fInIco(inIco) 30 , fInIco(inIco)
31 {} 31 {}
32 32
33 /* 33 /*
34 * Initiates the bitmap decode 34 * Initiates the bitmap decode
35 */ 35 */
36 SkCodec::Result SkBmpStandardCodec::onGetPixels(const SkImageInfo& dstInfo, 36 SkCodec::Result SkBmpStandardCodec::onGetPixels(const SkImageInfo& dstInfo,
37 void* dst, size_t dstRowBytes, 37 void* dst, size_t dstRowBytes,
38 const Options& opts, 38 const Options& opts,
39 SkPMColor* inputColorPtr, 39 SkPMColor* inputColorPtr,
40 int* inputColorCount) { 40 int* inputColorCount,
41 int* incompleteScanlines) {
41 if (!this->rewindIfNeeded()) { 42 if (!this->rewindIfNeeded()) {
42 return kCouldNotRewind; 43 return kCouldNotRewind;
43 } 44 }
44 if (opts.fSubset) { 45 if (opts.fSubset) {
45 // Subsets are not supported. 46 // Subsets are not supported.
46 return kUnimplemented; 47 return kUnimplemented;
47 } 48 }
48 if (dstInfo.dimensions() != this->getInfo().dimensions()) { 49 if (dstInfo.dimensions() != this->getInfo().dimensions()) {
49 SkCodecPrintf("Error: scaling not supported.\n"); 50 SkCodecPrintf("Error: scaling not supported.\n");
50 return kInvalidScale; 51 return kInvalidScale;
51 } 52 }
52 if (!conversion_possible(dstInfo, this->getInfo())) { 53 if (!conversion_possible(dstInfo, this->getInfo())) {
53 SkCodecPrintf("Error: cannot convert input type to output type.\n"); 54 SkCodecPrintf("Error: cannot convert input type to output type.\n");
54 return kInvalidConversion; 55 return kInvalidConversion;
55 } 56 }
56 57
57 Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputCol orCount); 58 Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputCol orCount);
58 if (kSuccess != result) { 59 if (kSuccess != result) {
59 return result; 60 return result;
60 } 61 }
61 result = this->decodeRows(dstInfo, dst, dstRowBytes, opts); 62 uint32_t rows = this->decodeRows(dstInfo, dst, dstRowBytes, opts);
62 if (kSuccess != result) { 63 if (rows != dstInfo.height()) {
63 return result; 64 *incompleteScanlines = dstInfo.height() - rows;
65 return kIncompleteInput;
64 } 66 }
65 if (fInIco) { 67 if (fInIco) {
66 return this->decodeIcoMask(dstInfo, dst, dstRowBytes); 68 return this->decodeIcoMask(dstInfo, dst, dstRowBytes);
67 } 69 }
68 return kSuccess; 70 return kSuccess;
69 } 71 }
70 72
71 /* 73 /*
72 * Process the color table for the bmp input 74 * Process the color table for the bmp input
73 */ 75 */
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 if (!this->initializeSwizzler(dstInfo, options)) { 226 if (!this->initializeSwizzler(dstInfo, options)) {
225 SkCodecPrintf("Error: cannot initialize swizzler.\n"); 227 SkCodecPrintf("Error: cannot initialize swizzler.\n");
226 return SkCodec::kInvalidConversion; 228 return SkCodec::kInvalidConversion;
227 } 229 }
228 return SkCodec::kSuccess; 230 return SkCodec::kSuccess;
229 } 231 }
230 232
231 /* 233 /*
232 * Performs the bitmap decoding for standard input format 234 * Performs the bitmap decoding for standard input format
233 */ 235 */
234 SkCodec::Result SkBmpStandardCodec::decodeRows(const SkImageInfo& dstInfo, 236 uint32_t SkBmpStandardCodec::decodeRows(const SkImageInfo& dstInfo,
235 void* dst, size_t dstRowBytes, 237 void* dst, size_t dstRowBytes,
236 const Options& opts) { 238 const Options& opts) {
237 // Iterate over rows of the image 239 // Iterate over rows of the image
238 const int height = dstInfo.height(); 240 const int height = dstInfo.height();
239 for (int y = 0; y < height; y++) { 241 for (int y = 0; y < height; y++) {
240 // Read a row of the input 242 // Read a row of the input
241 if (this->stream()->read(fSrcBuffer.get(), fSrcRowBytes) != fSrcRowBytes ) { 243 if (this->stream()->read(fSrcBuffer.get(), fSrcRowBytes) != fSrcRowBytes ) {
242 SkCodecPrintf("Warning: incomplete input stream.\n"); 244 SkCodecPrintf("Warning: incomplete input stream.\n");
243 // Fill the destination image on failure 245 return y;
244 void* dstStart = this->getDstStartRow(dst, dstRowBytes, y);
245 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get());
246 uint32_t fillColorOrIndex = get_fill_color_or_index(dstInfo.alphaTyp e());
247 SkSwizzler::Fill(dstStart, dstInfo, dstRowBytes, dstInfo.height() - y,
248 fillColorOrIndex, colorPtr, opts.fZeroInitialized);
249 return kIncompleteInput;
250 } 246 }
251 247
252 // Decode the row in destination format 248 // Decode the row in destination format
253 uint32_t row = this->getDstRow(y, dstInfo.height()); 249 uint32_t row = this->getDstRow(y, dstInfo.height());
254 250
255 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); 251 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes);
256 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); 252 fSwizzler->swizzle(dstRow, fSrcBuffer.get());
257 } 253 }
258 254
259 // Finished decoding the entire image 255 // Finished decoding the entire image
260 return kSuccess; 256 return height;
261 } 257 }
262 258
263 // TODO (msarett): This function will need to be modified in order to perform ro w by row decodes 259 // TODO (msarett): This function will need to be modified in order to perform ro w by row decodes
264 // when the Ico scanline decoder is implemented. 260 // when the Ico scanline decoder is implemented.
265 SkCodec::Result SkBmpStandardCodec::decodeIcoMask(const SkImageInfo& dstInfo, 261 SkCodec::Result SkBmpStandardCodec::decodeIcoMask(const SkImageInfo& dstInfo,
266 void* dst, size_t dstRowBytes) { 262 void* dst, size_t dstRowBytes) {
267 // BMP in ICO have transparency, so this cannot be 565, and this mask 263 // BMP in ICO have transparency, so this cannot be 565, and this mask
268 // prevents us from using kIndex8. The below code depends on the output 264 // prevents us from using kIndex8. The below code depends on the output
269 // being an SkPMColor. 265 // being an SkPMColor.
270 SkASSERT(dstInfo.colorType() == kN32_SkColorType); 266 SkASSERT(dstInfo.colorType() == kN32_SkColorType);
(...skipping 20 matching lines...) Expand all
291 int modulus; 287 int modulus;
292 SkTDivMod(x, 8, &quotient, &modulus); 288 SkTDivMod(x, 8, &quotient, &modulus);
293 uint32_t shift = 7 - modulus; 289 uint32_t shift = 7 - modulus;
294 uint32_t alphaBit = 290 uint32_t alphaBit =
295 (fSrcBuffer.get()[quotient] >> shift) & 0x1; 291 (fSrcBuffer.get()[quotient] >> shift) & 0x1;
296 dstRow[x] &= alphaBit - 1; 292 dstRow[x] &= alphaBit - 1;
297 } 293 }
298 } 294 }
299 return kSuccess; 295 return kSuccess;
300 } 296 }
297
298 uint32_t SkBmpStandardCodec::onGetFillValue(const SkImageInfo& dstInfo) const {
299 const SkPMColor* colorPtr = get_color_ptr(fColorTable.get());
300 if (colorPtr) {
301 return get_color_table_fill_value(dstInfo.colorType(), colorPtr, 0);
302 }
303 return INHERITED::onGetFillValue(dstInfo);
304 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698