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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 } | 163 } |
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(this->getInfo().width(), |
| 174 this->bitsPerPixel())); |
174 fSrcBuffer.reset(SkNEW_ARRAY(uint8_t, rowBytes)); | 175 fSrcBuffer.reset(SkNEW_ARRAY(uint8_t, rowBytes)); |
175 | 176 |
176 // Get swizzler configuration | 177 // Get swizzler configuration |
177 SkSwizzler::SrcConfig config; | 178 SkSwizzler::SrcConfig config; |
178 switch (this->bitsPerPixel()) { | 179 switch (this->bitsPerPixel()) { |
179 case 1: | 180 case 1: |
180 config = SkSwizzler::kIndex1; | 181 config = SkSwizzler::kIndex1; |
181 break; | 182 break; |
182 case 2: | 183 case 2: |
183 config = SkSwizzler::kIndex2; | 184 config = SkSwizzler::kIndex2; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 SkASSERT(false); | 245 SkASSERT(false); |
245 return 0; | 246 return 0; |
246 } | 247 } |
247 return fillColorOrIndex; | 248 return fillColorOrIndex; |
248 } | 249 } |
249 | 250 |
250 /* | 251 /* |
251 * Performs the bitmap decoding for standard input format | 252 * Performs the bitmap decoding for standard input format |
252 */ | 253 */ |
253 SkCodec::Result SkBmpStandardCodec::decode(const SkImageInfo& dstInfo, | 254 SkCodec::Result SkBmpStandardCodec::decode(const SkImageInfo& dstInfo, |
254 void* dst, size_t dstRowBytes, | 255 void* dst, size_t dstRowBytes, |
255 const Options& opts) { | 256 const Options& opts) { |
256 // Set constant values | 257 // Set constant values |
257 const int width = dstInfo.width(); | 258 const int width = this->getInfo().width(); |
258 const int height = dstInfo.height(); | 259 const int height = dstInfo.height(); |
259 const size_t rowBytes = SkAlign4(compute_row_bytes(width, this->bitsPerPixel
())); | 260 const size_t rowBytes = SkAlign4(compute_row_bytes(width, this->bitsPerPixel
())); |
260 | 261 |
261 // Iterate over rows of the image | 262 // Iterate over rows of the image |
262 for (int y = 0; y < height; y++) { | 263 for (int y = 0; y < height; y++) { |
263 // Read a row of the input | 264 // Read a row of the input |
264 if (this->stream()->read(fSrcBuffer.get(), rowBytes) != rowBytes) { | 265 if (this->stream()->read(fSrcBuffer.get(), rowBytes) != rowBytes) { |
265 SkCodecPrintf("Warning: incomplete input stream.\n"); | 266 SkCodecPrintf("Warning: incomplete input stream.\n"); |
266 // Fill the destination image on failure | 267 // Fill the destination image on failure |
267 // Get the fill color/index and check if it is 0 | 268 // Get the fill color/index and check if it is 0 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 uint32_t alphaBit = | 329 uint32_t alphaBit = |
329 (fSrcBuffer.get()[quotient] >> shift) & 0x1; | 330 (fSrcBuffer.get()[quotient] >> shift) & 0x1; |
330 dstRow[x] &= alphaBit - 1; | 331 dstRow[x] &= alphaBit - 1; |
331 } | 332 } |
332 } | 333 } |
333 } | 334 } |
334 | 335 |
335 // Finished decoding the entire image | 336 // Finished decoding the entire image |
336 return kSuccess; | 337 return kSuccess; |
337 } | 338 } |
| 339 |
| 340 SkCodec::Result SkBmpStandardCodec::onStart(const SkImageInfo& dstInfo, |
| 341 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo
lorCount) { |
| 342 // Create the color table if necessary and prepare the stream for decode |
| 343 // Note that if it is non-NULL, inputColorCount will be modified |
| 344 if (!this->createColorTable(dstInfo.alphaType(), inputColorCount)) { |
| 345 SkCodecPrintf("Error: could not create color table.\n"); |
| 346 return SkCodec::kInvalidInput; |
| 347 } |
| 348 |
| 349 // Copy the color table to the client if necessary |
| 350 copy_color_table(dstInfo, this->fColorTable, inputColorPtr, inputColorCount)
; |
| 351 |
| 352 // Initialize a swizzler if necessary |
| 353 if (!this->initializeSwizzler(dstInfo, options)) { |
| 354 SkCodecPrintf("Error: cannot initialize swizzler.\n"); |
| 355 return SkCodec::kInvalidConversion; |
| 356 } |
| 357 return SkCodec::kSuccess; |
| 358 } |
OLD | NEW |