| Index: src/codec/SkBmpRLECodec.cpp
|
| diff --git a/src/codec/SkBmpRLECodec.cpp b/src/codec/SkBmpRLECodec.cpp
|
| index 14a5b01c1f374d520856058aeef61ef9978324d3..e53a9e17f307ebb384d08d325ad04f20f3ad7464 100644
|
| --- a/src/codec/SkBmpRLECodec.cpp
|
| +++ b/src/codec/SkBmpRLECodec.cpp
|
| @@ -8,6 +8,7 @@
|
| #include "SkBmpRLECodec.h"
|
| #include "SkCodecPriv.h"
|
| #include "SkColorPriv.h"
|
| +#include "SkScaledCodec.h"
|
| #include "SkScanlineDecoder.h"
|
| #include "SkStream.h"
|
|
|
| @@ -53,20 +54,9 @@ SkCodec::Result SkBmpRLECodec::onGetPixels(const SkImageInfo& dstInfo,
|
| return kInvalidConversion;
|
| }
|
|
|
| - // Create the color table if necessary and prepare the stream for decode
|
| - // Note that if it is non-NULL, inputColorCount will be modified
|
| - if (!this->createColorTable(inputColorCount)) {
|
| - SkCodecPrintf("Error: could not create color table.\n");
|
| - return kInvalidInput;
|
| - }
|
| -
|
| - // Copy the color table to the client if necessary
|
| - copy_color_table(dstInfo, fColorTable, inputColorPtr, inputColorCount);
|
| -
|
| - // Initialize a swizzler if necessary
|
| - if (!this->initializeStreamBuffer()) {
|
| - SkCodecPrintf("Error: cannot initialize swizzler.\n");
|
| - return kInvalidConversion;
|
| + Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputColorCount);
|
| + if (kSuccess != result) {
|
| + return result;
|
| }
|
|
|
| // Perform the decode
|
| @@ -194,33 +184,31 @@ size_t SkBmpRLECodec::checkForMoreData() {
|
| void SkBmpRLECodec::setPixel(void* dst, size_t dstRowBytes,
|
| const SkImageInfo& dstInfo, uint32_t x, uint32_t y,
|
| uint8_t index) {
|
| - // Set the row
|
| - int height = dstInfo.height();
|
| - int row;
|
| - if (SkBmpCodec::kBottomUp_RowOrder == this->rowOrder()) {
|
| - row = height - y - 1;
|
| - } else {
|
| - row = y;
|
| - }
|
| -
|
| - // Set the pixel based on destination color type
|
| - switch (dstInfo.colorType()) {
|
| - case kN32_SkColorType: {
|
| - SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst,
|
| - row * (int) dstRowBytes);
|
| - dstRow[x] = fColorTable->operator[](index);
|
| - break;
|
| - }
|
| - case kRGB_565_SkColorType: {
|
| - uint16_t* dstRow = SkTAddOffset<uint16_t>(dst, row * (int) dstRowBytes);
|
| - dstRow[x] = SkPixel32ToPixel16(fColorTable->operator[](index));
|
| - break;
|
| + int sampleX;
|
| + SkScaledCodec::ComputeSampleSize(dstInfo, this->getInfo(), &sampleX, NULL);
|
| + if (is_coord_necessary(x, sampleX >> 1, sampleX, dstInfo.width())) {
|
| + // Set the row
|
| + uint32_t row = this->getDstRow(y, dstInfo.height());
|
| +
|
| + // Set the pixel based on destination color type
|
| + switch (dstInfo.colorType()) {
|
| + case kN32_SkColorType: {
|
| + SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst,
|
| + row * (int) dstRowBytes);
|
| + dstRow[x / sampleX] = fColorTable->operator[](index);
|
| + break;
|
| + }
|
| + case kRGB_565_SkColorType: {
|
| + uint16_t* dstRow = SkTAddOffset<uint16_t>(dst, row * (int) dstRowBytes);
|
| + dstRow[x / sampleX] = SkPixel32ToPixel16(fColorTable->operator[](index));
|
| + break;
|
| + }
|
| + default:
|
| + // This case should not be reached. We should catch an invalid
|
| + // color type when we check that the conversion is possible.
|
| + SkASSERT(false);
|
| + break;
|
| }
|
| - default:
|
| - // This case should not be reached. We should catch an invalid
|
| - // color type when we check that the conversion is possible.
|
| - SkASSERT(false);
|
| - break;
|
| }
|
| }
|
|
|
| @@ -231,33 +219,31 @@ void SkBmpRLECodec::setRGBPixel(void* dst, size_t dstRowBytes,
|
| const SkImageInfo& dstInfo, uint32_t x,
|
| uint32_t y, uint8_t red, uint8_t green,
|
| uint8_t blue) {
|
| - // Set the row
|
| - int height = dstInfo.height();
|
| - int row;
|
| - if (SkBmpCodec::kBottomUp_RowOrder == this->rowOrder()) {
|
| - row = height - y - 1;
|
| - } else {
|
| - row = y;
|
| - }
|
| -
|
| - // Set the pixel based on destination color type
|
| - switch (dstInfo.colorType()) {
|
| - case kN32_SkColorType: {
|
| - SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst,
|
| - row * (int) dstRowBytes);
|
| - dstRow[x] = SkPackARGB32NoCheck(0xFF, red, green, blue);
|
| - break;
|
| - }
|
| - case kRGB_565_SkColorType: {
|
| - uint16_t* dstRow = SkTAddOffset<uint16_t>(dst, row * (int) dstRowBytes);
|
| - dstRow[x] = SkPack888ToRGB16(red, green, blue);
|
| - break;
|
| + int sampleX;
|
| + SkScaledCodec::ComputeSampleSize(dstInfo, this->getInfo(), &sampleX, NULL);
|
| + if (is_coord_necessary(x, sampleX >> 1, sampleX, dstInfo.width())) {
|
| + // Set the row
|
| + uint32_t row = this->getDstRow(y, dstInfo.height());
|
| +
|
| + // Set the pixel based on destination color type
|
| + switch (dstInfo.colorType()) {
|
| + case kN32_SkColorType: {
|
| + SkPMColor* dstRow = SkTAddOffset<SkPMColor>((SkPMColor*) dst,
|
| + row * (int) dstRowBytes);
|
| + dstRow[x] = SkPackARGB32NoCheck(0xFF, red, green, blue);
|
| + break;
|
| + }
|
| + case kRGB_565_SkColorType: {
|
| + uint16_t* dstRow = SkTAddOffset<uint16_t>(dst, row * (int) dstRowBytes);
|
| + dstRow[x] = SkPack888ToRGB16(red, green, blue);
|
| + break;
|
| + }
|
| + default:
|
| + // This case should not be reached. We should catch an invalid
|
| + // color type when we check that the conversion is possible.
|
| + SkASSERT(false);
|
| + break;
|
| }
|
| - default:
|
| - // This case should not be reached. We should catch an invalid
|
| - // color type when we check that the conversion is possible.
|
| - SkASSERT(false);
|
| - break;
|
| }
|
| }
|
|
|
| @@ -275,7 +261,7 @@ SkCodec::Result SkBmpRLECodec::decode(const SkImageInfo& dstInfo,
|
| static const uint8_t RLE_DELTA = 2;
|
|
|
| // Set constant values
|
| - const int width = dstInfo.width();
|
| + const int width = this->getInfo().width();
|
| const int height = dstInfo.height();
|
|
|
| // Destination parameters
|
| @@ -456,3 +442,24 @@ SkCodec::Result SkBmpRLECodec::decode(const SkImageInfo& dstInfo,
|
| }
|
| }
|
| }
|
| +
|
| +SkCodec::Result SkBmpRLECodec::prepareToDecode(const SkImageInfo& dstInfo,
|
| + const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputColorCount) {
|
| + // Create the color table if necessary and prepare the stream for decode
|
| + // Note that if it is non-NULL, inputColorCount will be modified
|
| + if (!this->createColorTable(inputColorCount)) {
|
| + SkCodecPrintf("Error: could not create color table.\n");
|
| + return SkCodec::kInvalidInput;
|
| + }
|
| +
|
| + // Copy the color table to the client if necessary
|
| + copy_color_table(dstInfo, this->fColorTable, inputColorPtr, inputColorCount);
|
| +
|
| + // Initialize a buffer for encoded RLE data
|
| + if (!this->initializeStreamBuffer()) {
|
| + SkCodecPrintf("Error: cannot initialize swizzler.\n");
|
| + return SkCodec::kInvalidConversion;
|
| + }
|
| +
|
| + return SkCodec::kSuccess;
|
| +}
|
|
|