| 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 "SkBmpRLECodec.h" | 8 #include "SkBmpRLECodec.h" |
| 9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 } | 46 } |
| 47 if (dstInfo.dimensions() != this->getInfo().dimensions()) { | 47 if (dstInfo.dimensions() != this->getInfo().dimensions()) { |
| 48 SkCodecPrintf("Error: scaling not supported.\n"); | 48 SkCodecPrintf("Error: scaling not supported.\n"); |
| 49 return kInvalidScale; | 49 return kInvalidScale; |
| 50 } | 50 } |
| 51 if (!conversion_possible(dstInfo, this->getInfo())) { | 51 if (!conversion_possible(dstInfo, this->getInfo())) { |
| 52 SkCodecPrintf("Error: cannot convert input type to output type.\n"); | 52 SkCodecPrintf("Error: cannot convert input type to output type.\n"); |
| 53 return kInvalidConversion; | 53 return kInvalidConversion; |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Create the color table if necessary and prepare the stream for decode | 56 Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputCol
orCount); |
| 57 // Note that if it is non-NULL, inputColorCount will be modified | 57 if (kSuccess != result) { |
| 58 if (!this->createColorTable(inputColorCount)) { | 58 return result; |
| 59 SkCodecPrintf("Error: could not create color table.\n"); | |
| 60 return kInvalidInput; | |
| 61 } | |
| 62 | |
| 63 // Copy the color table to the client if necessary | |
| 64 copy_color_table(dstInfo, fColorTable, inputColorPtr, inputColorCount); | |
| 65 | |
| 66 // Initialize a swizzler if necessary | |
| 67 if (!this->initializeStreamBuffer()) { | |
| 68 SkCodecPrintf("Error: cannot initialize swizzler.\n"); | |
| 69 return kInvalidConversion; | |
| 70 } | 59 } |
| 71 | 60 |
| 72 // Perform the decode | 61 // Perform the decode |
| 73 return decode(dstInfo, dst, dstRowBytes, opts); | 62 return decode(dstInfo, dst, dstRowBytes, opts); |
| 74 } | 63 } |
| 75 | 64 |
| 76 /* | 65 /* |
| 77 * Process the color table for the bmp input | 66 * Process the color table for the bmp input |
| 78 */ | 67 */ |
| 79 bool SkBmpRLECodec::createColorTable(int* numColors) { | 68 bool SkBmpRLECodec::createColorTable(int* numColors) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 } | 178 } |
| 190 | 179 |
| 191 /* | 180 /* |
| 192 * Set an RLE pixel using the color table | 181 * Set an RLE pixel using the color table |
| 193 */ | 182 */ |
| 194 void SkBmpRLECodec::setPixel(void* dst, size_t dstRowBytes, | 183 void SkBmpRLECodec::setPixel(void* dst, size_t dstRowBytes, |
| 195 const SkImageInfo& dstInfo, uint32_t x, uint32_t y, | 184 const SkImageInfo& dstInfo, uint32_t x, uint32_t y, |
| 196 uint8_t index) { | 185 uint8_t index) { |
| 197 // Set the row | 186 // Set the row |
| 198 int height = dstInfo.height(); | 187 int height = dstInfo.height(); |
| 199 int row; | 188 int row = this->getDstRow(y); |
| 200 if (SkBmpCodec::kBottomUp_RowOrder == this->rowOrder()) { | |
| 201 row = height - y - 1; | |
| 202 } else { | |
| 203 row = y; | |
| 204 } | |
| 205 | 189 |
| 206 // Set the pixel based on destination color type | 190 // Set the pixel based on destination color type |
| 207 switch (dstInfo.colorType()) { | 191 switch (dstInfo.colorType()) { |
| 208 case kN32_SkColorType: { | 192 case kN32_SkColorType: { |
| 209 SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst, | 193 SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst, |
| 210 row * (int) dstRowBytes); | 194 row * (int) dstRowBytes); |
| 211 dstRow[x] = fColorTable->operator[](index); | 195 dstRow[x] = fColorTable->operator[](index); |
| 212 break; | 196 break; |
| 213 } | 197 } |
| 214 case kRGB_565_SkColorType: { | 198 case kRGB_565_SkColorType: { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 226 | 210 |
| 227 /* | 211 /* |
| 228 * Set an RLE pixel from R, G, B values | 212 * Set an RLE pixel from R, G, B values |
| 229 */ | 213 */ |
| 230 void SkBmpRLECodec::setRGBPixel(void* dst, size_t dstRowBytes, | 214 void SkBmpRLECodec::setRGBPixel(void* dst, size_t dstRowBytes, |
| 231 const SkImageInfo& dstInfo, uint32_t x, | 215 const SkImageInfo& dstInfo, uint32_t x, |
| 232 uint32_t y, uint8_t red, uint8_t green, | 216 uint32_t y, uint8_t red, uint8_t green, |
| 233 uint8_t blue) { | 217 uint8_t blue) { |
| 234 // Set the row | 218 // Set the row |
| 235 int height = dstInfo.height(); | 219 int height = dstInfo.height(); |
| 236 int row; | 220 uint32_t row = this->getDstRow(y); |
| 237 if (SkBmpCodec::kBottomUp_RowOrder == this->rowOrder()) { | |
| 238 row = height - y - 1; | |
| 239 } else { | |
| 240 row = y; | |
| 241 } | |
| 242 | 221 |
| 243 // Set the pixel based on destination color type | 222 // Set the pixel based on destination color type |
| 244 switch (dstInfo.colorType()) { | 223 switch (dstInfo.colorType()) { |
| 245 case kN32_SkColorType: { | 224 case kN32_SkColorType: { |
| 246 SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst, | 225 SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst, |
| 247 row * (int) dstRowBytes); | 226 row * (int) dstRowBytes); |
| 248 dstRow[x] = SkPackARGB32NoCheck(0xFF, red, green, blue); | 227 dstRow[x] = SkPackARGB32NoCheck(0xFF, red, green, blue); |
| 249 break; | 228 break; |
| 250 } | 229 } |
| 251 case kRGB_565_SkColorType: { | 230 case kRGB_565_SkColorType: { |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 // Set the indicated number of pixels | 428 // Set the indicated number of pixels |
| 450 for (int which = 0; x < endX; x++) { | 429 for (int which = 0; x < endX; x++) { |
| 451 setPixel(dst, dstRowBytes, dstInfo, x, y, | 430 setPixel(dst, dstRowBytes, dstInfo, x, y, |
| 452 indices[which]); | 431 indices[which]); |
| 453 which = !which; | 432 which = !which; |
| 454 } | 433 } |
| 455 } | 434 } |
| 456 } | 435 } |
| 457 } | 436 } |
| 458 } | 437 } |
| 438 |
| 439 SkCodec::Result SkBmpRLECodec::prepareToDecode(const SkImageInfo& dstInfo, |
| 440 const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputCo
lorCount) { |
| 441 // Create the color table if necessary and prepare the stream for decode |
| 442 // Note that if it is non-NULL, inputColorCount will be modified |
| 443 if (!this->createColorTable(inputColorCount)) { |
| 444 SkCodecPrintf("Error: could not create color table.\n"); |
| 445 return SkCodec::kInvalidInput; |
| 446 } |
| 447 |
| 448 // Copy the color table to the client if necessary |
| 449 copy_color_table(dstInfo, this->fColorTable, inputColorPtr, inputColorCount)
; |
| 450 |
| 451 // Initialize a buffer for encoded RLE data |
| 452 if (!this->initializeStreamBuffer()) { |
| 453 SkCodecPrintf("Error: cannot initialize swizzler.\n"); |
| 454 return SkCodec::kInvalidConversion; |
| 455 } |
| 456 |
| 457 return SkCodec::kSuccess; |
| 458 } |
| OLD | NEW |