Handle EXIF orientation in hwui/ImageDecoder
Bug: 160984428
Test: AImageDecoderTest#testRespectOrientation
ImageDecoderTest#testRespectOrientation
Ieda439910ae52e609f0710d424503616d99ae5c7
I23caef26b4c82173c758dd0ce7fb6f04e4154588
I345a13d20776a007052d32e74fa42865b42f726d
It is possible to create an animated image with an exif orientation.
Using kRespect, there is no clean way to handle the orientation plus
compositing frames. Switch ImageDecoder to use kIgnore (the default).
Depends on a change in Skia (https://review.skia.org/344762) to make
SkAnimatedImage handle the orientation even with kIgnore.
Change-Id: Ib93b0ced09fa3cca4a6681745406355c48158fae
diff --git a/native/graphics/jni/imagedecoder.cpp b/native/graphics/jni/imagedecoder.cpp
index ac4c16a..4aeebe4 100644
--- a/native/graphics/jni/imagedecoder.cpp
+++ b/native/graphics/jni/imagedecoder.cpp
@@ -65,17 +65,18 @@
SkCodec::Result result;
auto codec = SkCodec::MakeFromStream(std::move(stream), &result, nullptr,
SkCodec::SelectionPolicy::kPreferAnimation);
- auto androidCodec = SkAndroidCodec::MakeFromCodec(std::move(codec),
- SkAndroidCodec::ExifOrientationBehavior::kRespect);
+ // These may be swapped due to the SkEncodedOrigin, but we're just checking
+ // them to make sure they fit in int32_t.
+ auto dimensions = codec->dimensions();
+ auto androidCodec = SkAndroidCodec::MakeFromCodec(std::move(codec));
if (!androidCodec) {
return ResultToErrorCode(result);
}
// AImageDecoderHeaderInfo_getWidth/Height return an int32_t. Ensure that
// the conversion is safe.
- const auto& info = androidCodec->getInfo();
- if (info.width() > std::numeric_limits<int32_t>::max()
- || info.height() > std::numeric_limits<int32_t>::max()) {
+ if (dimensions.width() > std::numeric_limits<int32_t>::max() ||
+ dimensions.height() > std::numeric_limits<int32_t>::max()) {
return ANDROID_IMAGE_DECODER_INVALID_INPUT;
}
@@ -200,14 +201,14 @@
if (!info) {
return 0;
}
- return toDecoder(info)->mCodec->getInfo().width();
+ return toDecoder(info)->width();
}
int32_t AImageDecoderHeaderInfo_getHeight(const AImageDecoderHeaderInfo* info) {
if (!info) {
return 0;
}
- return toDecoder(info)->mCodec->getInfo().height();
+ return toDecoder(info)->height();
}
const char* AImageDecoderHeaderInfo_getMimeType(const AImageDecoderHeaderInfo* info) {