aboutsummaryrefslogtreecommitdiff
path: root/tests/CodecTest.cpp
diff options
context:
space:
mode:
authormsarett <msarett@google.com>2016-08-22 07:41:28 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-22 07:41:28 -0700
commit35bb74b444bc4a9ed2f437d97c6a943012990fe3 (patch)
treecdf1630d2d7f351ad4479d5a6b0c132605001246 /tests/CodecTest.cpp
parenta629166d6edf25ba39b3fe6ff1b749f0787df104 (diff)
Fix color xform width bug when scaling/subsetting
This was not caught by the bots because we don't test color correct modes with our many image decoding tests (takes too long). Adding a unit test. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2247743002 Review-Url: https://codereview.chromium.org/2247743002
Diffstat (limited to 'tests/CodecTest.cpp')
-rw-r--r--tests/CodecTest.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp
index a6b44eb9a7..8023ff219d 100644
--- a/tests/CodecTest.cpp
+++ b/tests/CodecTest.cpp
@@ -1044,6 +1044,36 @@ DEF_TEST(Codec_jpeg_rewind, r) {
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
}
+static void check_color_xform(skiatest::Reporter* r, const char* path) {
+ SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(resource(path)));
+
+ SkAndroidCodec::AndroidOptions opts;
+ opts.fSampleSize = 3;
+ const int subsetWidth = codec->getInfo().width() / 2;
+ const int subsetHeight = codec->getInfo().height() / 2;
+ SkIRect subset = SkIRect::MakeWH(subsetWidth, subsetHeight);
+ opts.fSubset = &subset;
+
+ const int dstWidth = subsetWidth / opts.fSampleSize;
+ const int dstHeight = subsetHeight / opts.fSampleSize;
+ sk_sp<SkData> data = SkData::MakeFromFileName(
+ GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
+ sk_sp<SkColorSpace> colorSpace = SkColorSpace::NewICC(data->data(), data->size());
+ SkImageInfo dstInfo = codec->getInfo().makeWH(dstWidth, dstHeight)
+ .makeColorType(kN32_SkColorType)
+ .makeColorSpace(colorSpace);
+
+ size_t rowBytes = dstInfo.minRowBytes();
+ SkAutoMalloc pixelStorage(dstInfo.getSafeSize(rowBytes));
+ SkCodec::Result result = codec->getAndroidPixels(dstInfo, pixelStorage.get(), rowBytes, &opts);
+ REPORTER_ASSERT(r, SkCodec::kSuccess == result);
+}
+
+DEF_TEST(Codec_ColorXform, r) {
+ check_color_xform(r, "mandrill_512_q075.jpg");
+ check_color_xform(r, "mandrill_512.png");
+}
+
DEF_TEST(Codec_Png565, r) {
// Create an arbitrary 565 bitmap.
const char* path = "mandrill_512_q075.jpg";