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>
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp
index aa3547d..d9b13e8 100644
--- a/src/codec/SkWebpCodec.cpp
+++ b/src/codec/SkWebpCodec.cpp
@@ -87,14 +87,25 @@
}
}
- WebPChunkIterator chunkIterator;
- SkAutoTCallVProc<WebPChunkIterator, WebPDemuxReleaseChunkIterator> autoCI(&chunkIterator);
sk_sp<SkColorSpace> colorSpace = nullptr;
- if (WebPDemuxGetChunk(demux, "ICCP", 1, &chunkIterator)) {
- colorSpace = SkColorSpace::MakeICC(chunkIterator.chunk.bytes, chunkIterator.chunk.size);
+ {
+ WebPChunkIterator chunkIterator;
+ SkAutoTCallVProc<WebPChunkIterator, WebPDemuxReleaseChunkIterator> autoCI(&chunkIterator);
+ if (WebPDemuxGetChunk(demux, "ICCP", 1, &chunkIterator)) {
+ colorSpace = SkColorSpace::MakeICC(chunkIterator.chunk.bytes, chunkIterator.chunk.size);
+ }
+ if (!colorSpace || colorSpace->type() != SkColorSpace::kRGB_Type) {
+ colorSpace = SkColorSpace::MakeSRGB();
+ }
}
- if (!colorSpace || colorSpace->type() != SkColorSpace::kRGB_Type) {
- colorSpace = SkColorSpace::MakeSRGB();
+
+ SkEncodedOrigin origin = kDefault_SkEncodedOrigin;
+ {
+ WebPChunkIterator chunkIterator;
+ SkAutoTCallVProc<WebPChunkIterator, WebPDemuxReleaseChunkIterator> autoCI(&chunkIterator);
+ if (WebPDemuxGetChunk(demux, "EXIF", 1, &chunkIterator)) {
+ is_orientation_marker(chunkIterator.chunk.bytes, chunkIterator.chunk.size, &origin);
+ }
}
// Get the first frame and its "features" to determine the color and alpha types.
@@ -156,10 +167,12 @@
return nullptr;
}
+
*result = kSuccess;
SkEncodedInfo info = SkEncodedInfo::Make(color, alpha, 8);
return std::unique_ptr<SkCodec>(new SkWebpCodec(width, height, info, std::move(colorSpace),
- std::move(stream), demux.release(), std::move(data)));
+ std::move(stream), demux.release(), std::move(data),
+ origin));
}
SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const {
@@ -646,9 +659,9 @@
SkWebpCodec::SkWebpCodec(int width, int height, const SkEncodedInfo& info,
sk_sp<SkColorSpace> colorSpace, std::unique_ptr<SkStream> stream,
- WebPDemuxer* demux, sk_sp<SkData> data)
+ WebPDemuxer* demux, sk_sp<SkData> data, SkEncodedOrigin origin)
: INHERITED(width, height, info, SkColorSpaceXform::kBGRA_8888_ColorFormat, std::move(stream),
- std::move(colorSpace))
+ std::move(colorSpace), origin)
, fDemux(demux)
, fData(std::move(data))
, fFailed(false)