| Index: src/codec/SkBmpStandardCodec.cpp
|
| diff --git a/src/codec/SkBmpStandardCodec.cpp b/src/codec/SkBmpStandardCodec.cpp
|
| index 27cea4ead0e816a9d5f77e3abba484e0c633050f..08477b2f0be5ca076db2b348c14560db4fd24b32 100644
|
| --- a/src/codec/SkBmpStandardCodec.cpp
|
| +++ b/src/codec/SkBmpStandardCodec.cpp
|
| @@ -53,20 +53,9 @@ SkCodec::Result SkBmpStandardCodec::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(dstInfo.alphaType(), 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->initializeSwizzler(dstInfo, opts)) {
|
| - SkCodecPrintf("Error: cannot initialize swizzler.\n");
|
| - return kInvalidConversion;
|
| + Result result = this->prepareToDecode(dstInfo, opts, inputColorPtr, inputColorCount);
|
| + if (kSuccess != result) {
|
| + return result;
|
| }
|
|
|
| return this->decode(dstInfo, dst, dstRowBytes, opts);
|
| @@ -170,7 +159,8 @@ SkCodec::Result SkBmpStandardCodec::onGetPixels(const SkImageInfo& dstInfo,
|
| bool SkBmpStandardCodec::initializeSwizzler(const SkImageInfo& dstInfo,
|
| const Options& opts) {
|
| // Allocate space for a row buffer
|
| - const size_t rowBytes = SkAlign4(compute_row_bytes(dstInfo.width(), this->bitsPerPixel()));
|
| + const size_t rowBytes = SkAlign4(compute_row_bytes(this->getInfo().width(),
|
| + this->bitsPerPixel()));
|
| fSrcBuffer.reset(SkNEW_ARRAY(uint8_t, rowBytes));
|
|
|
| // Get swizzler configuration
|
| @@ -251,10 +241,10 @@ static uint32_t get_fill_color_or_index(uint16_t bitsPerPixels, SkAlphaType alph
|
| * Performs the bitmap decoding for standard input format
|
| */
|
| SkCodec::Result SkBmpStandardCodec::decode(const SkImageInfo& dstInfo,
|
| - void* dst, size_t dstRowBytes,
|
| - const Options& opts) {
|
| + void* dst, size_t dstRowBytes,
|
| + const Options& opts) {
|
| // Set constant values
|
| - const int width = dstInfo.width();
|
| + const int width = this->getInfo().width();
|
| const int height = dstInfo.height();
|
| const size_t rowBytes = SkAlign4(compute_row_bytes(width, this->bitsPerPixel()));
|
|
|
| @@ -281,12 +271,7 @@ SkCodec::Result SkBmpStandardCodec::decode(const SkImageInfo& dstInfo,
|
| }
|
|
|
| // Decode the row in destination format
|
| - uint32_t row;
|
| - if (SkBmpCodec::kTopDown_RowOrder == this->rowOrder()) {
|
| - row = y;
|
| - } else {
|
| - row = height - 1 - y;
|
| - }
|
| + uint32_t row = this->getDstRow(y, dstInfo.height());
|
|
|
| void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes);
|
| fSwizzler->swizzle(dstRow, fSrcBuffer.get());
|
| @@ -310,12 +295,7 @@ SkCodec::Result SkBmpStandardCodec::decode(const SkImageInfo& dstInfo,
|
| return kIncompleteInput;
|
| }
|
|
|
| - int row;
|
| - if (SkBmpCodec::kBottomUp_RowOrder == this->rowOrder()) {
|
| - row = height - y - 1;
|
| - } else {
|
| - row = y;
|
| - }
|
| + int row = this->getDstRow(y, dstInfo.height());
|
|
|
| SkPMColor* dstRow =
|
| SkTAddOffset<SkPMColor>(dstPtr, row * dstRowBytes);
|
| @@ -335,3 +315,23 @@ SkCodec::Result SkBmpStandardCodec::decode(const SkImageInfo& dstInfo,
|
| // Finished decoding the entire image
|
| return kSuccess;
|
| }
|
| +
|
| +SkCodec::Result SkBmpStandardCodec::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(dstInfo.alphaType(), 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 swizzler if necessary
|
| + if (!this->initializeSwizzler(dstInfo, options)) {
|
| + SkCodecPrintf("Error: cannot initialize swizzler.\n");
|
| + return SkCodec::kInvalidConversion;
|
| + }
|
| + return SkCodec::kSuccess;
|
| +}
|
|
|