Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b9b57a9

Browse files
[skwasm] Use displayWidth/displayHeight instead of codedWidth/codedHeight (#56686)
This addresses flutter/flutter#159088 If the image is rotated in its exif data, the coded width/height may differ from the display width/height. It's important to use the display width/height so that `texImage2D` does the right thing with the `VideoFrame`.
1 parent 7f2d56b commit b9b57a9

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/web_ui/lib/src/engine/skwasm/skwasm_impl/codecs.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class SkwasmImageDecoder extends BrowserImageDecoder {
1717

1818
@override
1919
ui.Image generateImageFromVideoFrame(VideoFrame frame) {
20-
final int width = frame.codedWidth.toInt();
21-
final int height = frame.codedHeight.toInt();
20+
final int width = frame.displayWidth.toInt();
21+
final int height = frame.displayHeight.toInt();
2222
final SkwasmSurface surface = (renderer as SkwasmRenderer).surface;
2323
return SkwasmImage(imageCreateFromTextureSource(
2424
frame as JSObject,

lib/web_ui/test/ui/image_golden_test.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,19 @@ Future<void> testMain() async {
385385
return info.image;
386386
});
387387

388+
test('decode rotated jpeg', () async {
389+
// This image (from skia's test images) has a rotated orientation in its exif data.
390+
// This should result in a 3024x4032 image, not 4032x3024 image.
391+
final ui.Codec codec = await renderer.instantiateImageCodecFromUrl(
392+
Uri(path: '/test_images/iphone_15.jpeg')
393+
);
394+
expect(codec.frameCount, 1);
395+
396+
final ui.FrameInfo info = await codec.getNextFrame();
397+
expect(info.image.width, 3024);
398+
expect(info.image.height, 4032);
399+
});
400+
388401
// This API doesn't work in headless Firefox due to requiring WebGL
389402
// See https://github.com/flutter/flutter/issues/109265
390403
if (!isFirefox) {

0 commit comments

Comments
 (0)