| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 int row; | 202 int row; |
| 203 if (SkBmpCodec::kBottomUp_RowOrder == this->rowOrder()) { | 203 if (SkBmpCodec::kBottomUp_RowOrder == this->rowOrder()) { |
| 204 row = height - y - 1; | 204 row = height - y - 1; |
| 205 } else { | 205 } else { |
| 206 row = y; | 206 row = y; |
| 207 } | 207 } |
| 208 | 208 |
| 209 // Set the pixel based on destination color type | 209 // Set the pixel based on destination color type |
| 210 switch (dstInfo.colorType()) { | 210 switch (dstInfo.colorType()) { |
| 211 case kN32_SkColorType: { | 211 case kN32_SkColorType: { |
| 212 SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst, | 212 SkPMColor* dstRow = SkTAddOffset<SkPMColor>(dst, row * (int) dstRowB
ytes); |
| 213 row * (int) dstRowBytes); | |
| 214 dstRow[x] = fColorTable->operator[](index); | 213 dstRow[x] = fColorTable->operator[](index); |
| 215 break; | 214 break; |
| 216 } | 215 } |
| 217 case kRGB_565_SkColorType: { | 216 case kRGB_565_SkColorType: { |
| 218 uint16_t* dstRow = SkTAddOffset<uint16_t>(dst, row * (int) dstRowByt
es); | 217 uint16_t* dstRow = SkTAddOffset<uint16_t>(dst, row * (int) dstRowByt
es); |
| 219 dstRow[x] = SkPixel32ToPixel16(fColorTable->operator[](index)); | 218 dstRow[x] = SkPixel32ToPixel16(fColorTable->operator[](index)); |
| 220 break; | 219 break; |
| 221 } | 220 } |
| 222 default: | 221 default: |
| 223 // This case should not be reached. We should catch an invalid | 222 // This case should not be reached. We should catch an invalid |
| (...skipping 15 matching lines...) Expand all Loading... |
| 239 int row; | 238 int row; |
| 240 if (SkBmpCodec::kBottomUp_RowOrder == this->rowOrder()) { | 239 if (SkBmpCodec::kBottomUp_RowOrder == this->rowOrder()) { |
| 241 row = height - y - 1; | 240 row = height - y - 1; |
| 242 } else { | 241 } else { |
| 243 row = y; | 242 row = y; |
| 244 } | 243 } |
| 245 | 244 |
| 246 // Set the pixel based on destination color type | 245 // Set the pixel based on destination color type |
| 247 switch (dstInfo.colorType()) { | 246 switch (dstInfo.colorType()) { |
| 248 case kN32_SkColorType: { | 247 case kN32_SkColorType: { |
| 249 SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst, | 248 SkPMColor* dstRow = SkTAddOffset<SkPMColor>(dst, row * (int) dstRowB
ytes); |
| 250 row * (int) dstRowBytes); | |
| 251 dstRow[x] = SkPackARGB32NoCheck(0xFF, red, green, blue); | 249 dstRow[x] = SkPackARGB32NoCheck(0xFF, red, green, blue); |
| 252 break; | 250 break; |
| 253 } | 251 } |
| 254 case kRGB_565_SkColorType: { | 252 case kRGB_565_SkColorType: { |
| 255 uint16_t* dstRow = SkTAddOffset<uint16_t>(dst, row * (int) dstRowByt
es); | 253 uint16_t* dstRow = SkTAddOffset<uint16_t>(dst, row * (int) dstRowByt
es); |
| 256 dstRow[x] = SkPack888ToRGB16(red, green, blue); | 254 dstRow[x] = SkPack888ToRGB16(red, green, blue); |
| 257 break; | 255 break; |
| 258 } | 256 } |
| 259 default: | 257 default: |
| 260 // This case should not be reached. We should catch an invalid | 258 // This case should not be reached. We should catch an invalid |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 if (this->checkForMoreData() < 2) { | 425 if (this->checkForMoreData() < 2) { |
| 428 return kIncompleteInput; | 426 return kIncompleteInput; |
| 429 } | 427 } |
| 430 } | 428 } |
| 431 | 429 |
| 432 // Fill the pixels up to endX with the specified color | 430 // Fill the pixels up to endX with the specified color |
| 433 uint8_t blue = task; | 431 uint8_t blue = task; |
| 434 uint8_t green = fStreamBuffer.get()[fCurrRLEByte++]; | 432 uint8_t green = fStreamBuffer.get()[fCurrRLEByte++]; |
| 435 uint8_t red = fStreamBuffer.get()[fCurrRLEByte++]; | 433 uint8_t red = fStreamBuffer.get()[fCurrRLEByte++]; |
| 436 while (x < endX) { | 434 while (x < endX) { |
| 437 setRGBPixel(dst, dstRowBytes, dstInfo, x++, y, red, | 435 setRGBPixel(dst, dstRowBytes, dstInfo, x++, y, red, green, b
lue); |
| 438 green, blue); | |
| 439 } | 436 } |
| 440 } else { | 437 } else { |
| 441 // In RLE8 or RLE4, the second byte read gives the index in the | 438 // In RLE8 or RLE4, the second byte read gives the index in the |
| 442 // color table to look up the pixel color. | 439 // color table to look up the pixel color. |
| 443 // RLE8 has one color index that gets repeated | 440 // RLE8 has one color index that gets repeated |
| 444 // RLE4 has two color indexes in the upper and lower 4 bits of | 441 // RLE4 has two color indexes in the upper and lower 4 bits of |
| 445 // the bytes, which are alternated | 442 // the bytes, which are alternated |
| 446 uint8_t indices[2] = { task, task }; | 443 uint8_t indices[2] = { task, task }; |
| 447 if (4 == this->bitsPerPixel()) { | 444 if (4 == this->bitsPerPixel()) { |
| 448 indices[0] >>= 4; | 445 indices[0] >>= 4; |
| 449 indices[1] &= 0xf; | 446 indices[1] &= 0xf; |
| 450 } | 447 } |
| 451 | 448 |
| 452 // Set the indicated number of pixels | 449 // Set the indicated number of pixels |
| 453 for (int which = 0; x < endX; x++) { | 450 for (int which = 0; x < endX; x++) { |
| 454 setPixel(dst, dstRowBytes, dstInfo, x, y, | 451 setPixel(dst, dstRowBytes, dstInfo, x, y, indices[which]); |
| 455 indices[which]); | |
| 456 which = !which; | 452 which = !which; |
| 457 } | 453 } |
| 458 } | 454 } |
| 459 } | 455 } |
| 460 } | 456 } |
| 461 } | 457 } |
| OLD | NEW |