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

Side by Side Diff: src/codec/SkBmpMaskCodec.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, 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
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 "SkBmpMaskCodec.h" 8 #include "SkBmpMaskCodec.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 11 matching lines...) Expand all
22 , fSrcBuffer(new uint8_t [fSrcRowBytes]) 22 , fSrcBuffer(new uint8_t [fSrcRowBytes])
23 {} 23 {}
24 24
25 /* 25 /*
26 * Initiates the bitmap decode 26 * Initiates the bitmap decode
27 */ 27 */
28 SkCodec::Result SkBmpMaskCodec::onGetPixels(const SkImageInfo& dstInfo, 28 SkCodec::Result SkBmpMaskCodec::onGetPixels(const SkImageInfo& dstInfo,
29 void* dst, size_t dstRowBytes, 29 void* dst, size_t dstRowBytes,
30 const Options& opts, 30 const Options& opts,
31 SkPMColor* inputColorPtr, 31 SkPMColor* inputColorPtr,
32 int* inputColorCount) { 32 int* inputColorCount,
33 int* incompleteScanlines) {
33 if (!this->rewindIfNeeded()) { 34 if (!this->rewindIfNeeded()) {
34 return kCouldNotRewind; 35 return kCouldNotRewind;
35 } 36 }
36 if (opts.fSubset) { 37 if (opts.fSubset) {
37 // Subsets are not supported. 38 // Subsets are not supported.
38 return kUnimplemented; 39 return kUnimplemented;
39 } 40 }
40 if (dstInfo.dimensions() != this->getInfo().dimensions()) { 41 if (dstInfo.dimensions() != this->getInfo().dimensions()) {
41 SkCodecPrintf("Error: scaling not supported.\n"); 42 SkCodecPrintf("Error: scaling not supported.\n");
42 return kInvalidScale; 43 return kInvalidScale;
43 } 44 }
44 45
45 if (!conversion_possible(dstInfo, this->getInfo())) { 46 if (!conversion_possible(dstInfo, this->getInfo())) {
46 SkCodecPrintf("Error: cannot convert input type to output type.\n"); 47 SkCodecPrintf("Error: cannot convert input type to output type.\n");
47 return kInvalidConversion; 48 return kInvalidConversion;
48 } 49 }
49 50
50 Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputCol orCount); 51 Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputCol orCount);
51 if (kSuccess != result) { 52 if (kSuccess != result) {
52 return result; 53 return result;
53 } 54 }
54 55
55 return this->decodeRows(dstInfo, dst, dstRowBytes, opts); 56 uint32_t rows = this->decodeRows(dstInfo, dst, dstRowBytes, opts);
57 if (rows != dstInfo.height()) {
58 *incompleteScanlines = dstInfo.height() - rows;
scroggo 2015/09/25 15:55:05 It's a little weird to me that onGetScanlines retu
msarett 2015/10/01 12:44:52 Done.
59 return kIncompleteInput;
60 }
61 return kSuccess;
56 } 62 }
57 63
58 bool SkBmpMaskCodec::initializeSwizzler(const SkImageInfo& dstInfo) { 64 bool SkBmpMaskCodec::initializeSwizzler(const SkImageInfo& dstInfo) {
59 // Create the swizzler 65 // Create the swizzler
60 fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler( 66 fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler(
61 dstInfo, this->getInfo(), fMasks, this->bitsPerPixel())); 67 dstInfo, this->getInfo(), fMasks, this->bitsPerPixel()));
62 68
63 if (nullptr == fMaskSwizzler.get()) { 69 if (nullptr == fMaskSwizzler.get()) {
64 return false; 70 return false;
65 } 71 }
66 72
67 return true; 73 return true;
68 } 74 }
69 75
70 SkCodec::Result SkBmpMaskCodec::prepareToDecode(const SkImageInfo& dstInfo, 76 SkCodec::Result SkBmpMaskCodec::prepareToDecode(const SkImageInfo& dstInfo,
71 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo lorCount) { 77 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo lorCount) {
72 // Initialize a the mask swizzler 78 // Initialize a the mask swizzler
73 if (!this->initializeSwizzler(dstInfo)) { 79 if (!this->initializeSwizzler(dstInfo)) {
74 SkCodecPrintf("Error: cannot initialize swizzler.\n"); 80 SkCodecPrintf("Error: cannot initialize swizzler.\n");
75 return SkCodec::kInvalidConversion; 81 return SkCodec::kInvalidConversion;
76 } 82 }
77 83
78 return SkCodec::kSuccess; 84 return SkCodec::kSuccess;
79 } 85 }
80 86
81 /* 87 /*
82 * Performs the decoding 88 * Performs the decoding
83 */ 89 */
84 SkCodec::Result SkBmpMaskCodec::decodeRows(const SkImageInfo& dstInfo, 90 uint32_t SkBmpMaskCodec::decodeRows(const SkImageInfo& dstInfo,
85 void* dst, size_t dstRowBytes, 91 void* dst, size_t dstRowBytes,
86 const Options& opts) { 92 const Options& opts) {
87 // Iterate over rows of the image 93 // Iterate over rows of the image
88 uint8_t* srcRow = fSrcBuffer.get(); 94 uint8_t* srcRow = fSrcBuffer.get();
89 const int height = dstInfo.height(); 95 const int height = dstInfo.height();
90 for (int y = 0; y < height; y++) { 96 for (int y = 0; y < height; y++) {
91 // Read a row of the input 97 // Read a row of the input
92 if (this->stream()->read(srcRow, fSrcRowBytes) != fSrcRowBytes) { 98 if (this->stream()->read(srcRow, fSrcRowBytes) != fSrcRowBytes) {
93 SkCodecPrintf("Warning: incomplete input stream.\n"); 99 SkCodecPrintf("Warning: incomplete input stream.\n");
94 // Fill the destination image on failure 100 return y;
95 void* dstStart = this->getDstStartRow(dst, dstRowBytes, y);
96 uint32_t fillColor = get_fill_color_or_index(dstInfo.alphaType());
97 SkSwizzler::Fill(dstStart, dstInfo, dstRowBytes, height - y,
98 fillColor, nullptr, opts.fZeroInitialized);
99 return kIncompleteInput;
100 } 101 }
101 102
102 // Decode the row in destination format 103 // Decode the row in destination format
103 uint32_t row = this->getDstRow(y, height); 104 uint32_t row = this->getDstRow(y, height);
104 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); 105 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes);
105 fMaskSwizzler->swizzle(dstRow, srcRow); 106 fMaskSwizzler->swizzle(dstRow, srcRow);
106 } 107 }
107 108
108 // Finished decoding the entire image 109 // Finished decoding the entire image
109 return kSuccess; 110 return height;
110 } 111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698