[canvaskit] Respect Exif metadata for animated images.
Change-Id: I58a5095ea3314a21d895f34a4b8cab9484c29b1d Reviewed-on: https://skia-review.googlesource.com/c/skia/+/340717 Reviewed-by: Leon Scroggins <scroggo@google.com>
This commit is contained in:
parent
e7c1a731ff
commit
f3b959c000
@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Changed
|
||||
- `MakeImage` is now documented in the Typescript types (index.d.ts). The parameters have been
|
||||
streamlined to align with other, similar APIs.
|
||||
- `MakeAnimatedImageFromEncoded` respects Exif metadata. `MakeImageFromEncoded` already did so
|
||||
(and continues to do so).
|
||||
|
||||
### Fixed
|
||||
- `Canvas.drawPoints` correctly takes a flattened Array or TypedArray of points (as the
|
||||
|
@ -750,12 +750,16 @@ EMSCRIPTEN_BINDINGS(Skia) {
|
||||
function("_decodeAnimatedImage", optional_override([](uintptr_t /* uint8_t* */ iptr,
|
||||
size_t length)->sk_sp<SkAnimatedImage> {
|
||||
uint8_t* imgData = reinterpret_cast<uint8_t*>(iptr);
|
||||
sk_sp<SkData> bytes = SkData::MakeFromMalloc(imgData, length);
|
||||
auto codec = SkAndroidCodec::MakeFromData(bytes);
|
||||
if (nullptr == codec) {
|
||||
auto bytes = SkData::MakeFromMalloc(imgData, length);
|
||||
auto stream = SkMemoryStream::Make(std::move(bytes));
|
||||
auto codec = SkCodec::MakeFromStream(std::move(stream), nullptr, nullptr);
|
||||
auto aCodec = SkAndroidCodec::MakeFromCodec(std::move(codec),
|
||||
SkAndroidCodec::ExifOrientationBehavior::kRespect);
|
||||
if (nullptr == aCodec) {
|
||||
return nullptr;
|
||||
}
|
||||
return SkAnimatedImage::Make(std::move(codec));
|
||||
|
||||
return SkAnimatedImage::Make(std::move(aCodec));
|
||||
}), allow_raw_pointers());
|
||||
function("_decodeImage", optional_override([](uintptr_t /* uint8_t* */ iptr,
|
||||
size_t length)->sk_sp<SkImage> {
|
||||
|
BIN
modules/canvaskit/tests/assets/exif_rotated_heart.jpg
Normal file
BIN
modules/canvaskit/tests/assets/exif_rotated_heart.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
@ -196,6 +196,24 @@ describe('Core canvas behavior', () => {
|
||||
aImg.delete();
|
||||
}, '/assets/flightAnim.gif');
|
||||
|
||||
gm('exif_orientation', (canvas, fetchedByteBuffers) => {
|
||||
canvas.clear(CanvasKit.WHITE);
|
||||
const paint = new CanvasKit.Paint();
|
||||
const font = new CanvasKit.Font(null, 14);
|
||||
canvas.drawText('The following heart should be rotated 90 due to exif.',
|
||||
5, 25, paint, font);
|
||||
|
||||
// TODO(kjlubick) it would be nice to also to test MakeAnimatedImageFromEncoded but
|
||||
// I could not create a sample animated image that worked.
|
||||
const img = CanvasKit.MakeImageFromEncoded(fetchedByteBuffers[0]);
|
||||
expect(img).toBeTruthy();
|
||||
canvas.drawImage(img, 5, 35, null);
|
||||
|
||||
img.delete();
|
||||
paint.delete();
|
||||
font.delete();
|
||||
}, '/assets/exif_rotated_heart.jpg');
|
||||
|
||||
gm('1x4_from_scratch', (canvas) => {
|
||||
canvas.clear(CanvasKit.WHITE);
|
||||
const paint = new CanvasKit.Paint();
|
||||
|
Loading…
Reference in New Issue
Block a user