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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } | 50 } |
51 | 51 |
52 int rows = this->decodeRows(dstInfo, dst, dstRowBytes, opts); | 52 int rows = this->decodeRows(dstInfo, dst, dstRowBytes, opts); |
53 if (rows != dstInfo.height()) { | 53 if (rows != dstInfo.height()) { |
54 *rowsDecoded = rows; | 54 *rowsDecoded = rows; |
55 return kIncompleteInput; | 55 return kIncompleteInput; |
56 } | 56 } |
57 return kSuccess; | 57 return kSuccess; |
58 } | 58 } |
59 | 59 |
60 bool SkBmpMaskCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Option
s& options) { | |
61 // Create the swizzler | |
62 fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler(dstInfo, this->getInf
o(), fMasks, | |
63 this->bitsPerPixel(), options)); | |
64 | |
65 if (nullptr == fMaskSwizzler.get()) { | |
66 return false; | |
67 } | |
68 | |
69 return true; | |
70 } | |
71 | |
72 SkCodec::Result SkBmpMaskCodec::prepareToDecode(const SkImageInfo& dstInfo, | 60 SkCodec::Result SkBmpMaskCodec::prepareToDecode(const SkImageInfo& dstInfo, |
73 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo
lorCount) { | 61 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo
lorCount) { |
74 // Initialize a the mask swizzler | 62 // Initialize the mask swizzler |
75 if (!this->initializeSwizzler(dstInfo, options)) { | 63 fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler(dstInfo, this->getInf
o(), fMasks, |
76 SkCodecPrintf("Error: cannot initialize swizzler.\n"); | 64 this->bitsPerPixel(), options)); |
77 return SkCodec::kInvalidConversion; | 65 SkASSERT(fMaskSwizzler); |
78 } | |
79 | 66 |
80 return SkCodec::kSuccess; | 67 return SkCodec::kSuccess; |
81 } | 68 } |
82 | 69 |
83 /* | 70 /* |
84 * Performs the decoding | 71 * Performs the decoding |
85 */ | 72 */ |
86 int SkBmpMaskCodec::decodeRows(const SkImageInfo& dstInfo, | 73 int SkBmpMaskCodec::decodeRows(const SkImageInfo& dstInfo, |
87 void* dst, size_t dstRowBytes, | 74 void* dst, size_t dstRowBytes, |
88 const Options& opts) { | 75 const Options& opts) { |
89 // Iterate over rows of the image | 76 // Iterate over rows of the image |
90 uint8_t* srcRow = fSrcBuffer.get(); | 77 uint8_t* srcRow = fSrcBuffer.get(); |
91 const int height = dstInfo.height(); | 78 const int height = dstInfo.height(); |
92 for (int y = 0; y < height; y++) { | 79 for (int y = 0; y < height; y++) { |
93 // Read a row of the input | 80 // Read a row of the input |
94 if (this->stream()->read(srcRow, this->srcRowBytes()) != this->srcRowByt
es()) { | 81 if (this->stream()->read(srcRow, this->srcRowBytes()) != this->srcRowByt
es()) { |
95 SkCodecPrintf("Warning: incomplete input stream.\n"); | 82 SkCodecPrintf("Warning: incomplete input stream.\n"); |
96 return y; | 83 return y; |
97 } | 84 } |
98 | 85 |
99 // Decode the row in destination format | 86 // Decode the row in destination format |
100 uint32_t row = this->getDstRow(y, height); | 87 uint32_t row = this->getDstRow(y, height); |
101 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); | 88 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); |
102 fMaskSwizzler->swizzle(dstRow, srcRow); | 89 fMaskSwizzler->swizzle(dstRow, srcRow); |
103 } | 90 } |
104 | 91 |
105 // Finished decoding the entire image | 92 // Finished decoding the entire image |
106 return height; | 93 return height; |
107 } | 94 } |
OLD | NEW |