diff options
author | msarett <msarett@google.com> | 2016-04-22 16:27:24 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-22 16:27:24 -0700 |
commit | 34e0ec40b10320765d4a4432f56e090556f9c75e (patch) | |
tree | f7b05f9dce7e83b666fe0309519daeab4b8f3f1f /src/codec/SkBmpRLECodec.cpp | |
parent | a45a668fa57eb968e24f379eceb2e56324e2cca2 (diff) |
Support the non-native (RGBA/BGRA) swizzle
BUG=skia:4456
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1907593004
Review URL: https://codereview.chromium.org/1907593004
Diffstat (limited to 'src/codec/SkBmpRLECodec.cpp')
-rw-r--r-- | src/codec/SkBmpRLECodec.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/codec/SkBmpRLECodec.cpp b/src/codec/SkBmpRLECodec.cpp index d80dd1a18a..02b42f6d90 100644 --- a/src/codec/SkBmpRLECodec.cpp +++ b/src/codec/SkBmpRLECodec.cpp @@ -70,7 +70,7 @@ SkCodec::Result SkBmpRLECodec::onGetPixels(const SkImageInfo& dstInfo, /* * Process the color table for the bmp input */ - bool SkBmpRLECodec::createColorTable(int* numColors) { + bool SkBmpRLECodec::createColorTable(SkColorType dstColorType, int* numColors) { // Allocate memory for color table uint32_t colorBytes = 0; SkPMColor colorTable[256]; @@ -96,12 +96,13 @@ SkCodec::Result SkBmpRLECodec::onGetPixels(const SkImageInfo& dstInfo, } // Fill in the color table + PackColorProc packARGB = choose_pack_color_proc(false, dstColorType); uint32_t i = 0; for (; i < numColorsToRead; i++) { uint8_t blue = get_byte(cBuffer.get(), i*fBytesPerColor); uint8_t green = get_byte(cBuffer.get(), i*fBytesPerColor + 1); uint8_t red = get_byte(cBuffer.get(), i*fBytesPerColor + 2); - colorTable[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); + colorTable[i] = packARGB(0xFF, red, green, blue); } // To avoid segmentation faults on bad pixel data, fill the end of the @@ -208,7 +209,8 @@ void SkBmpRLECodec::setPixel(void* dst, size_t dstRowBytes, // Set the pixel based on destination color type const int dstX = get_dst_coord(x, fSampleX); switch (dstInfo.colorType()) { - case kN32_SkColorType: { + case kRGBA_8888_SkColorType: + case kBGRA_8888_SkColorType: { SkPMColor* dstRow = SkTAddOffset<SkPMColor>(dst, row * (int) dstRowBytes); dstRow[dstX] = fColorTable->operator[](index); break; @@ -241,9 +243,14 @@ void SkBmpRLECodec::setRGBPixel(void* dst, size_t dstRowBytes, // Set the pixel based on destination color type const int dstX = get_dst_coord(x, fSampleX); switch (dstInfo.colorType()) { - case kN32_SkColorType: { + case kRGBA_8888_SkColorType: { SkPMColor* dstRow = SkTAddOffset<SkPMColor>(dst, row * (int) dstRowBytes); - dstRow[dstX] = SkPackARGB32NoCheck(0xFF, red, green, blue); + dstRow[dstX] = SkPackARGB_as_RGBA(0xFF, red, green, blue); + break; + } + case kBGRA_8888_SkColorType: { + SkPMColor* dstRow = SkTAddOffset<SkPMColor>(dst, row * (int) dstRowBytes); + dstRow[dstX] = SkPackARGB_as_BGRA(0xFF, red, green, blue); break; } case kRGB_565_SkColorType: { @@ -275,7 +282,7 @@ SkCodec::Result SkBmpRLECodec::prepareToDecode(const SkImageInfo& dstInfo, // 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)) { + if (!this->createColorTable(dstInfo.colorType(), inputColorCount)) { SkCodecPrintf("Error: could not create color table.\n"); return SkCodec::kInvalidInput; } @@ -315,7 +322,8 @@ int SkBmpRLECodec::decodeRows(const SkImageInfo& info, void* dst, size_t dstRowB // the skipped pixels will be transparent. // Because of the need for transparent pixels, kN32 is the only color // type that makes sense for the destination format. - SkASSERT(kN32_SkColorType == dstInfo.colorType()); + SkASSERT(kRGBA_8888_SkColorType == dstInfo.colorType() || + kBGRA_8888_SkColorType == dstInfo.colorType()); if (dst) { SkSampler::Fill(dstInfo, dst, dstRowBytes, SK_ColorTRANSPARENT, opts.fZeroInitialized); } |