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 "SkBmpStandardCodec.h" | 8 #include "SkBmpStandardCodec.h" |
9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 uint32_t maxColors = 1 << this->bitsPerPixel(); | 84 uint32_t maxColors = 1 << this->bitsPerPixel(); |
85 if (NULL != numColors) { | 85 if (NULL != numColors) { |
86 // We set the number of colors to maxColors in order to ensure | 86 // We set the number of colors to maxColors in order to ensure |
87 // safe memory accesses. Otherwise, an invalid pixel could | 87 // safe memory accesses. Otherwise, an invalid pixel could |
88 // access memory outside of our color table array. | 88 // access memory outside of our color table array. |
89 *numColors = maxColors; | 89 *numColors = maxColors; |
90 } | 90 } |
91 | 91 |
92 // Read the color table from the stream | 92 // Read the color table from the stream |
93 colorBytes = fNumColors * fBytesPerColor; | 93 colorBytes = fNumColors * fBytesPerColor; |
94 SkAutoTDeleteArray<uint8_t> cBuffer(SkNEW_ARRAY(uint8_t, colorBytes)); | 94 SkAutoTDeleteArray<uint8_t> cBuffer(new uint8_t[colorBytes]); |
95 if (stream()->read(cBuffer.get(), colorBytes) != colorBytes) { | 95 if (stream()->read(cBuffer.get(), colorBytes) != colorBytes) { |
96 SkCodecPrintf("Error: unable to read color table.\n"); | 96 SkCodecPrintf("Error: unable to read color table.\n"); |
97 return false; | 97 return false; |
98 } | 98 } |
99 | 99 |
100 // Choose the proper packing function | 100 // Choose the proper packing function |
101 SkPMColor (*packARGB) (uint32_t, uint32_t, uint32_t, uint32_t); | 101 SkPMColor (*packARGB) (uint32_t, uint32_t, uint32_t, uint32_t); |
102 switch (alphaType) { | 102 switch (alphaType) { |
103 case kOpaque_SkAlphaType: | 103 case kOpaque_SkAlphaType: |
104 case kUnpremul_SkAlphaType: | 104 case kUnpremul_SkAlphaType: |
(...skipping 27 matching lines...) Expand all Loading... |
132 } | 132 } |
133 | 133 |
134 // To avoid segmentation faults on bad pixel data, fill the end of the | 134 // To avoid segmentation faults on bad pixel data, fill the end of the |
135 // color table with black. This is the same the behavior as the | 135 // color table with black. This is the same the behavior as the |
136 // chromium decoder. | 136 // chromium decoder. |
137 for (; i < maxColors; i++) { | 137 for (; i < maxColors; i++) { |
138 colorTable[i] = SkPackARGB32NoCheck(0xFF, 0, 0, 0); | 138 colorTable[i] = SkPackARGB32NoCheck(0xFF, 0, 0, 0); |
139 } | 139 } |
140 | 140 |
141 // Set the color table | 141 // Set the color table |
142 fColorTable.reset(SkNEW_ARGS(SkColorTable, (colorTable, maxColors))); | 142 fColorTable.reset(new SkColorTable(colorTable, maxColors)); |
143 } | 143 } |
144 | 144 |
145 // Bmp-in-Ico files do not use an offset to indicate where the pixel data | 145 // Bmp-in-Ico files do not use an offset to indicate where the pixel data |
146 // begins. Pixel data always begins immediately after the color table. | 146 // begins. Pixel data always begins immediately after the color table. |
147 if (!fInIco) { | 147 if (!fInIco) { |
148 // Check that we have not read past the pixel array offset | 148 // Check that we have not read past the pixel array offset |
149 if(fOffset < colorBytes) { | 149 if(fOffset < colorBytes) { |
150 // This may occur on OS 2.1 and other old versions where the color | 150 // This may occur on OS 2.1 and other old versions where the color |
151 // table defaults to max size, and the bmp tries to use a smaller | 151 // table defaults to max size, and the bmp tries to use a smaller |
152 // color table. This is invalid, and our decision is to indicate | 152 // color table. This is invalid, and our decision is to indicate |
(...skipping 11 matching lines...) Expand all Loading... |
164 } | 164 } |
165 | 165 |
166 // Return true on success | 166 // Return true on success |
167 return true; | 167 return true; |
168 } | 168 } |
169 | 169 |
170 bool SkBmpStandardCodec::initializeSwizzler(const SkImageInfo& dstInfo, | 170 bool SkBmpStandardCodec::initializeSwizzler(const SkImageInfo& dstInfo, |
171 const Options& opts) { | 171 const Options& opts) { |
172 // Allocate space for a row buffer | 172 // Allocate space for a row buffer |
173 const size_t rowBytes = SkAlign4(compute_row_bytes(dstInfo.width(), this->bi
tsPerPixel())); | 173 const size_t rowBytes = SkAlign4(compute_row_bytes(dstInfo.width(), this->bi
tsPerPixel())); |
174 fSrcBuffer.reset(SkNEW_ARRAY(uint8_t, rowBytes)); | 174 fSrcBuffer.reset(new uint8_t[rowBytes]); |
175 | 175 |
176 // Get swizzler configuration | 176 // Get swizzler configuration |
177 SkSwizzler::SrcConfig config; | 177 SkSwizzler::SrcConfig config; |
178 switch (this->bitsPerPixel()) { | 178 switch (this->bitsPerPixel()) { |
179 case 1: | 179 case 1: |
180 config = SkSwizzler::kIndex1; | 180 config = SkSwizzler::kIndex1; |
181 break; | 181 break; |
182 case 2: | 182 case 2: |
183 config = SkSwizzler::kIndex2; | 183 config = SkSwizzler::kIndex2; |
184 break; | 184 break; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 uint32_t alphaBit = | 328 uint32_t alphaBit = |
329 (fSrcBuffer.get()[quotient] >> shift) & 0x1; | 329 (fSrcBuffer.get()[quotient] >> shift) & 0x1; |
330 dstRow[x] &= alphaBit - 1; | 330 dstRow[x] &= alphaBit - 1; |
331 } | 331 } |
332 } | 332 } |
333 } | 333 } |
334 | 334 |
335 // Finished decoding the entire image | 335 // Finished decoding the entire image |
336 return kSuccess; | 336 return kSuccess; |
337 } | 337 } |
OLD | NEW |