OLD | NEW |
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 Loading... |
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* rowsDecoded) { |
33 if (opts.fSubset) { | 34 if (opts.fSubset) { |
34 // Subsets are not supported. | 35 // Subsets are not supported. |
35 return kUnimplemented; | 36 return kUnimplemented; |
36 } | 37 } |
37 if (dstInfo.dimensions() != this->getInfo().dimensions()) { | 38 if (dstInfo.dimensions() != this->getInfo().dimensions()) { |
38 SkCodecPrintf("Error: scaling not supported.\n"); | 39 SkCodecPrintf("Error: scaling not supported.\n"); |
39 return kInvalidScale; | 40 return kInvalidScale; |
40 } | 41 } |
41 | 42 |
42 if (!conversion_possible(dstInfo, this->getInfo())) { | 43 if (!conversion_possible(dstInfo, this->getInfo())) { |
43 SkCodecPrintf("Error: cannot convert input type to output type.\n"); | 44 SkCodecPrintf("Error: cannot convert input type to output type.\n"); |
44 return kInvalidConversion; | 45 return kInvalidConversion; |
45 } | 46 } |
46 | 47 |
47 Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputCol
orCount); | 48 Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputCol
orCount); |
48 if (kSuccess != result) { | 49 if (kSuccess != result) { |
49 return result; | 50 return result; |
50 } | 51 } |
51 | 52 |
52 return this->decodeRows(dstInfo, dst, dstRowBytes, opts); | 53 uint32_t rows = this->decodeRows(dstInfo, dst, dstRowBytes, opts); |
| 54 if (rows != dstInfo.height()) { |
| 55 *rowsDecoded = rows; |
| 56 return kIncompleteInput; |
| 57 } |
| 58 return kSuccess; |
53 } | 59 } |
54 | 60 |
55 bool SkBmpMaskCodec::initializeSwizzler(const SkImageInfo& dstInfo) { | 61 bool SkBmpMaskCodec::initializeSwizzler(const SkImageInfo& dstInfo) { |
56 // Create the swizzler | 62 // Create the swizzler |
57 fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler( | 63 fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler( |
58 dstInfo, this->getInfo(), fMasks, this->bitsPerPixel())); | 64 dstInfo, this->getInfo(), fMasks, this->bitsPerPixel())); |
59 | 65 |
60 if (nullptr == fMaskSwizzler.get()) { | 66 if (nullptr == fMaskSwizzler.get()) { |
61 return false; | 67 return false; |
62 } | 68 } |
63 | 69 |
64 return true; | 70 return true; |
65 } | 71 } |
66 | 72 |
67 SkCodec::Result SkBmpMaskCodec::prepareToDecode(const SkImageInfo& dstInfo, | 73 SkCodec::Result SkBmpMaskCodec::prepareToDecode(const SkImageInfo& dstInfo, |
68 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo
lorCount) { | 74 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo
lorCount) { |
69 // Initialize a the mask swizzler | 75 // Initialize a the mask swizzler |
70 if (!this->initializeSwizzler(dstInfo)) { | 76 if (!this->initializeSwizzler(dstInfo)) { |
71 SkCodecPrintf("Error: cannot initialize swizzler.\n"); | 77 SkCodecPrintf("Error: cannot initialize swizzler.\n"); |
72 return SkCodec::kInvalidConversion; | 78 return SkCodec::kInvalidConversion; |
73 } | 79 } |
74 | 80 |
75 return SkCodec::kSuccess; | 81 return SkCodec::kSuccess; |
76 } | 82 } |
77 | 83 |
78 /* | 84 /* |
79 * Performs the decoding | 85 * Performs the decoding |
80 */ | 86 */ |
81 SkCodec::Result SkBmpMaskCodec::decodeRows(const SkImageInfo& dstInfo, | 87 int SkBmpMaskCodec::decodeRows(const SkImageInfo& dstInfo, |
82 void* dst, size_t dstRowBytes, | 88 void* dst, size_t dstRowBytes, |
83 const Options& opts) { | 89 const Options& opts) { |
84 // Iterate over rows of the image | 90 // Iterate over rows of the image |
85 uint8_t* srcRow = fSrcBuffer.get(); | 91 uint8_t* srcRow = fSrcBuffer.get(); |
86 const int height = dstInfo.height(); | 92 const int height = dstInfo.height(); |
87 for (int y = 0; y < height; y++) { | 93 for (int y = 0; y < height; y++) { |
88 // Read a row of the input | 94 // Read a row of the input |
89 if (this->stream()->read(srcRow, fSrcRowBytes) != fSrcRowBytes) { | 95 if (this->stream()->read(srcRow, fSrcRowBytes) != fSrcRowBytes) { |
90 SkCodecPrintf("Warning: incomplete input stream.\n"); | 96 SkCodecPrintf("Warning: incomplete input stream.\n"); |
91 // Fill the destination image on failure | 97 return y; |
92 void* dstStart = this->getDstStartRow(dst, dstRowBytes, y); | |
93 uint32_t fillColor = get_fill_color_or_index(dstInfo.alphaType()); | |
94 SkSwizzler::Fill(dstStart, dstInfo, dstRowBytes, height - y, | |
95 fillColor, nullptr, opts.fZeroInitialized); | |
96 return kIncompleteInput; | |
97 } | 98 } |
98 | 99 |
99 // Decode the row in destination format | 100 // Decode the row in destination format |
100 uint32_t row = this->getDstRow(y, height); | 101 uint32_t row = this->getDstRow(y, height); |
101 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); | 102 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); |
102 fMaskSwizzler->swizzle(dstRow, srcRow); | 103 fMaskSwizzler->swizzle(dstRow, srcRow); |
103 } | 104 } |
104 | 105 |
105 // Finished decoding the entire image | 106 // Finished decoding the entire image |
106 return kSuccess; | 107 return height; |
107 } | 108 } |
OLD | NEW |