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

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