diff options
author | Leon Scroggins III <scroggo@google.com> | 2018-01-26 15:48:26 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-01-26 22:13:34 +0000 |
commit | da3e9ad894379713cbb66779136ca6877ccac7dd (patch) | |
tree | 6b2be2cf902fed8f4a311783e98c0d8e19fbea89 /tests | |
parent | 323df5720ce076f94709d20215e92e150ce60f6c (diff) |
Make SkAndroidCodec (optionally) respect origin
Bug: b/63909536
ImageDecoder will respect the origin, but BitmapFactory will maintain
its current behavior of not respecting it. Add an option to respect it.
In addition, add support for reading the EXIF data from a WEBP. This
seems to be an uncommon use case, but is occasionally used when
converting from a JPEG. Add 8 WEBPs, all converted (with cwebp) from
their analogous JPEG files already checked in.
Change-Id: I38afca58c86fa99ee9ab7d1dc83aaa4f23132c11
Reviewed-on: https://skia-review.googlesource.com/95300
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/AndroidCodecTest.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/AndroidCodecTest.cpp b/tests/AndroidCodecTest.cpp index b86a210279..d383713bb9 100644 --- a/tests/AndroidCodecTest.cpp +++ b/tests/AndroidCodecTest.cpp @@ -7,7 +7,9 @@ #include "SkAndroidCodec.h" #include "SkCodec.h" +#include "SkCodecImageGenerator.h" #include "SkEncodedImageFormat.h" +#include "SkPixmapPriv.h" #include "Resources.h" #include "Test.h" @@ -117,3 +119,69 @@ DEF_TEST(AndroidCodec_computeSampleSize, r) { } } } + +DEF_TEST(AndroidCodec_orientation, r) { + if (GetResourcePath().isEmpty()) { + return; + } + + for (const char* ext : { "jpg", "webp" }) + for (char i = '1'; i <= '8'; ++i) { + SkString path = SkStringPrintf("images/orientation/%c.%s", i, ext); + auto data = GetResourceAsData(path.c_str()); + auto gen = SkCodecImageGenerator::MakeFromEncodedCodec(data); + if (!gen) { + ERRORF(r, "failed to decode %s", path.c_str()); + return; + } + + // Dimensions after adjusting for the origin. + const SkISize expectedDims = { 100, 80 }; + + // SkCodecImageGenerator automatically adjusts for the origin. + REPORTER_ASSERT(r, gen->getInfo().dimensions() == expectedDims); + + auto androidCodec = SkAndroidCodec::MakeFromCodec(SkCodec::MakeFromData(data)); + if (!androidCodec) { + ERRORF(r, "failed to decode %s", path.c_str()); + return; + } + + // SkAndroidCodec does not adjust for the origin by default. Dimensions may be reversed. + if (SkPixmapPriv::ShouldSwapWidthHeight(androidCodec->codec()->getOrigin())) { + auto swappedDims = SkPixmapPriv::SwapWidthHeight(androidCodec->getInfo()).dimensions(); + REPORTER_ASSERT(r, expectedDims == swappedDims); + } else { + REPORTER_ASSERT(r, expectedDims == androidCodec->getInfo().dimensions()); + } + + // Passing kRespect adjusts for the origin. + androidCodec = SkAndroidCodec::MakeFromCodec(SkCodec::MakeFromData(std::move(data)), + SkAndroidCodec::ExifOrientationBehavior::kRespect); + auto info = androidCodec->getInfo(); + REPORTER_ASSERT(r, info.dimensions() == expectedDims); + + SkBitmap fromGenerator; + fromGenerator.allocPixels(info); + REPORTER_ASSERT(r, gen->getPixels(info, fromGenerator.getPixels(), + fromGenerator.rowBytes())); + + SkBitmap fromAndroidCodec; + fromAndroidCodec.allocPixels(info); + auto result = androidCodec->getPixels(info, fromAndroidCodec.getPixels(), + fromAndroidCodec.rowBytes()); + REPORTER_ASSERT(r, result == SkCodec::kSuccess); + + for (int i = 0; i < info.width(); ++i) + for (int j = 0; j < info.height(); ++j) { + SkColor c1 = *fromGenerator .getAddr32(i, j); + SkColor c2 = *fromAndroidCodec.getAddr32(i, j); + if (c1 != c2) { + ERRORF(r, "Bitmaps for %s do not match starting at position %i, %i\n" + "\tfromGenerator: %x\tfromAndroidCodec: %x", path.c_str(), i, j, + c1, c2); + return; + } + } + } +} |