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" |
11 | 11 |
12 /* | 12 /* |
13 * Creates an instance of the decoder | 13 * Creates an instance of the decoder |
14 */ | 14 */ |
15 SkBmpMaskCodec::SkBmpMaskCodec(const SkImageInfo& info, SkStream* stream, | 15 SkBmpMaskCodec::SkBmpMaskCodec(const SkImageInfo& info, SkStream* stream, |
16 uint16_t bitsPerPixel, SkMasks* masks, | 16 uint16_t bitsPerPixel, SkMasks* masks, |
17 SkBmpCodec::RowOrder rowOrder) | 17 SkBmpCodec::RowOrder rowOrder) |
18 : INHERITED(info, stream, bitsPerPixel, rowOrder) | 18 : INHERITED(info, stream, bitsPerPixel, rowOrder) |
19 , fMasks(masks) | 19 , fMasks(masks) |
20 , fMaskSwizzler(NULL) | 20 , fMaskSwizzler(nullptr) |
21 , fSrcBuffer(NULL) | 21 , fSrcBuffer(nullptr) |
22 {} | 22 {} |
23 | 23 |
24 /* | 24 /* |
25 * Initiates the bitmap decode | 25 * Initiates the bitmap decode |
26 */ | 26 */ |
27 SkCodec::Result SkBmpMaskCodec::onGetPixels(const SkImageInfo& dstInfo, | 27 SkCodec::Result SkBmpMaskCodec::onGetPixels(const SkImageInfo& dstInfo, |
28 void* dst, size_t dstRowBytes, | 28 void* dst, size_t dstRowBytes, |
29 const Options& opts, | 29 const Options& opts, |
30 SkPMColor* inputColorPtr, | 30 SkPMColor* inputColorPtr, |
31 int* inputColorCount) { | 31 int* inputColorCount) { |
(...skipping 25 matching lines...) Expand all Loading... |
57 | 57 |
58 bool SkBmpMaskCodec::initializeSwizzler(const SkImageInfo& dstInfo) { | 58 bool SkBmpMaskCodec::initializeSwizzler(const SkImageInfo& dstInfo) { |
59 // Allocate space for a row buffer | 59 // Allocate space for a row buffer |
60 const size_t rowBytes = SkAlign4(compute_row_bytes(dstInfo.width(), this->bi
tsPerPixel())); | 60 const size_t rowBytes = SkAlign4(compute_row_bytes(dstInfo.width(), this->bi
tsPerPixel())); |
61 fSrcBuffer.reset(new uint8_t[rowBytes]); | 61 fSrcBuffer.reset(new uint8_t[rowBytes]); |
62 | 62 |
63 // Create the swizzler | 63 // Create the swizzler |
64 fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler( | 64 fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler( |
65 dstInfo, fMasks, this->bitsPerPixel())); | 65 dstInfo, fMasks, this->bitsPerPixel())); |
66 | 66 |
67 if (NULL == fMaskSwizzler.get()) { | 67 if (nullptr == fMaskSwizzler.get()) { |
68 return false; | 68 return false; |
69 } | 69 } |
70 | 70 |
71 return true; | 71 return true; |
72 } | 72 } |
73 | 73 |
74 /* | 74 /* |
75 * Performs the decoding | 75 * Performs the decoding |
76 */ | 76 */ |
77 SkCodec::Result SkBmpMaskCodec::decode(const SkImageInfo& dstInfo, | 77 SkCodec::Result SkBmpMaskCodec::decode(const SkImageInfo& dstInfo, |
78 void* dst, size_t dstRowBytes, | 78 void* dst, size_t dstRowBytes, |
79 const Options& opts) { | 79 const Options& opts) { |
80 // Set constant values | 80 // Set constant values |
81 const int width = dstInfo.width(); | 81 const int width = dstInfo.width(); |
82 const int height = dstInfo.height(); | 82 const int height = dstInfo.height(); |
83 const size_t rowBytes = SkAlign4(compute_row_bytes(width, this->bitsPerPixel
())); | 83 const size_t rowBytes = SkAlign4(compute_row_bytes(width, this->bitsPerPixel
())); |
84 | 84 |
85 // Iterate over rows of the image | 85 // Iterate over rows of the image |
86 uint8_t* srcRow = fSrcBuffer.get(); | 86 uint8_t* srcRow = fSrcBuffer.get(); |
87 for (int y = 0; y < height; y++) { | 87 for (int y = 0; y < height; y++) { |
88 // Read a row of the input | 88 // Read a row of the input |
89 if (this->stream()->read(srcRow, rowBytes) != rowBytes) { | 89 if (this->stream()->read(srcRow, rowBytes) != rowBytes) { |
90 SkCodecPrintf("Warning: incomplete input stream.\n"); | 90 SkCodecPrintf("Warning: incomplete input stream.\n"); |
91 // Fill the destination image on failure | 91 // Fill the destination image on failure |
92 SkPMColor fillColor = dstInfo.alphaType() == kOpaque_SkAlphaType ? | 92 SkPMColor fillColor = dstInfo.alphaType() == kOpaque_SkAlphaType ? |
93 SK_ColorBLACK : SK_ColorTRANSPARENT; | 93 SK_ColorBLACK : SK_ColorTRANSPARENT; |
94 if (kNo_ZeroInitialized == opts.fZeroInitialized || 0 != fillColor)
{ | 94 if (kNo_ZeroInitialized == opts.fZeroInitialized || 0 != fillColor)
{ |
95 void* dstStart = this->getDstStartRow(dst, dstRowBytes, y); | 95 void* dstStart = this->getDstStartRow(dst, dstRowBytes, y); |
96 SkSwizzler::Fill(dstStart, dstInfo, dstRowBytes, dstInfo.height(
) - y, fillColor, | 96 SkSwizzler::Fill(dstStart, dstInfo, dstRowBytes, dstInfo.height(
) - y, fillColor, |
97 NULL); | 97 nullptr); |
98 } | 98 } |
99 return kIncompleteInput; | 99 return kIncompleteInput; |
100 } | 100 } |
101 | 101 |
102 // Decode the row in destination format | 102 // Decode the row in destination format |
103 int row = SkBmpCodec::kBottomUp_RowOrder == this->rowOrder() ? height -
1 - y : y; | 103 int row = SkBmpCodec::kBottomUp_RowOrder == this->rowOrder() ? height -
1 - y : y; |
104 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); | 104 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes); |
105 fMaskSwizzler->swizzle(dstRow, srcRow); | 105 fMaskSwizzler->swizzle(dstRow, srcRow); |
106 } | 106 } |
107 | 107 |
108 // Finished decoding the entire image | 108 // Finished decoding the entire image |
109 return kSuccess; | 109 return kSuccess; |
110 } | 110 } |
OLD | NEW |