Fix bug in sampling rotated decodes

Bug: b/122338652
Bug: b/77339676

getSampledDimensions is supposed to report dimensions that
SkAndroidCodec can decode to. But if SkAndroidCodec is respecting an
orientation that requires swapping the width and the height,
getSampledDimensions needs to do so, too.

Change-Id: I0cacefc2b02eb9832b8c029c88bcaaedcb2ba82b
Reviewed-on: https://skia-review.googlesource.com/c/188035
Auto-Submit: Leon Scroggins <scroggo@google.com>
Commit-Queue: Derek Sollenberger <djsollen@google.com>
Reviewed-by: Derek Sollenberger <djsollen@google.com>
This commit is contained in:
Leon Scroggins III 2019-01-30 15:33:09 -05:00 committed by Skia Commit-Bot
parent 9c8ad03161
commit 95d0c8d21c
2 changed files with 38 additions and 1 deletions

View File

@ -300,7 +300,13 @@ SkISize SkAndroidCodec::getSampledDimensions(int sampleSize) const {
return fInfo.dimensions();
}
return this->onGetSampledDimensions(sampleSize);
auto dims = this->onGetSampledDimensions(sampleSize);
if (fOrientationBehavior == SkAndroidCodec::ExifOrientationBehavior::kIgnore
|| !SkPixmapPriv::ShouldSwapWidthHeight(fCodec->getOrigin())) {
return dims;
}
return { dims.height(), dims.width() };
}
bool SkAndroidCodec::getSupportedSubset(SkIRect* desiredSubset) const {

View File

@ -264,3 +264,34 @@ DEF_TEST(AndroidCodec_orientation, r) {
}
}
}
DEF_TEST(AndroidCodec_sampledOrientation, r) {
if (GetResourcePath().isEmpty()) {
return;
}
// kRightTop_SkEncodedOrigin = 6, // Rotated 90 CW
auto path = "images/orientation/6.jpg";
auto data = GetResourceAsData(path);
if (!data) {
ERRORF(r, "Failed to get resource %s", path);
return;
}
auto androidCodec = SkAndroidCodec::MakeFromCodec(SkCodec::MakeFromData(std::move(data)),
SkAndroidCodec::ExifOrientationBehavior::kRespect);
constexpr int sampleSize = 7;
auto sampledDims = androidCodec->getSampledDimensions(sampleSize);
SkAndroidCodec::AndroidOptions options;
options.fSampleSize = sampleSize;
SkBitmap bm;
auto info = androidCodec->getInfo().makeWH(sampledDims.width(), sampledDims.height());
bm.allocPixels(info);
auto result = androidCodec->getAndroidPixels(info, bm.getPixels(), bm.rowBytes(), &options);
if (result != SkCodec::kSuccess) {
ERRORF(r, "got result \"%s\"\n", SkCodec::ResultToString(result));
}
}