aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/images/SkImageDecoder_pkm.cpp
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-23 20:00:59 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-23 20:00:59 +0000
commit4c4506441cad3917ce5797ae041853d31d8e7e2e (patch)
tree9a5ace85e28e2a1402f44417d2928f4390128157 /src/images/SkImageDecoder_pkm.cpp
parent2dcd24375bacb2d581986b5f886ee40871eab6a4 (diff)
Change the PKM decoder to adhere to sampler size
This fixes a bug where the red and blue channels seemed to be swapped on some platforms after decoding, and brings it more in line with the logic already in libbmp. BUG=skia: R=halcanary@google.com, robertphillips@google.com Author: krajcevski@google.com Review URL: https://codereview.chromium.org/297853005 git-svn-id: http://skia.googlecode.com/svn/trunk@14881 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/images/SkImageDecoder_pkm.cpp')
-rw-r--r--src/images/SkImageDecoder_pkm.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/images/SkImageDecoder_pkm.cpp b/src/images/SkImageDecoder_pkm.cpp
index 3d843ddf25..c299c23548 100644
--- a/src/images/SkImageDecoder_pkm.cpp
+++ b/src/images/SkImageDecoder_pkm.cpp
@@ -7,6 +7,7 @@
#include "SkColorPriv.h"
#include "SkImageDecoder.h"
+#include "SkScaledBitmapSampler.h"
#include "SkStream.h"
#include "SkStreamHelpers.h"
#include "SkTypes.h"
@@ -50,7 +51,12 @@ bool SkPKMImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
return false;
}
- bm->setConfig(SkBitmap::kARGB_8888_Config, width, height, 0, kOpaque_SkAlphaType);
+ // Setup the sampler...
+ SkScaledBitmapSampler sampler(width, height, this->getSampleSize());
+
+ // Set the config...
+ bm->setConfig(SkBitmap::kARGB_8888_Config, sampler.scaledWidth(), sampler.scaledHeight(),
+ 0, kOpaque_SkAlphaType);
if (SkImageDecoder::kDecodeBounds_Mode == mode) {
return true;
}
@@ -62,6 +68,10 @@ bool SkPKMImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
// Lock the pixels, since we're about to write to them...
SkAutoLockPixels alp(*bm);
+ if (!sampler.begin(bm, SkScaledBitmapSampler::kRGB, *this)) {
+ return false;
+ }
+
// Advance buffer past the header
buf += ETC_PKM_HEADER_SIZE;
@@ -76,14 +86,13 @@ bool SkPKMImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
}
// Set each of the pixels...
- const uint8_t *src = reinterpret_cast<uint8_t *>(outRGBDataPtr);
- uint8_t *dst = reinterpret_cast<uint8_t *>(bm->getPixels());
- for (int i = 0; i < width*height; ++i) {
- *dst++ = src[2]; // B
- *dst++ = src[1]; // G
- *dst++ = src[0]; // R
- *dst++ = 0xFF; // Opaque alpha...
- src += 3;
+ const int srcRowBytes = width * 3;
+ const int dstHeight = sampler.scaledHeight();
+ const uint8_t *srcRow = reinterpret_cast<uint8_t *>(outRGBDataPtr);
+ srcRow += sampler.srcY0() * srcRowBytes;
+ for (int y = 0; y < dstHeight; ++y) {
+ sampler.next(srcRow);
+ srcRow += sampler.srcDY() * srcRowBytes;
}
return true;