Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use Exif orientation when creating ImageBitmap from Blob
https://bugs.webkit.org/show_bug.cgi?id=223326

Reviewed by Kenneth Russell and Kimmo Kinnunen.

Do not ignore embedded Exif orientation metadata
when creating ImageBitmap from Blob.

* LayoutTests/TestExpectations:
* LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/imagebitmap-replication-exif-orientation-expected.txt:
* Source/WebCore/html/ImageBitmap.cpp:
(WebCore::ImageBitmap::createFromBuffer):

Canonical link: https://commits.webkit.org/253004@main
  • Loading branch information
lexaknyazev authored and kenrussell committed Aug 1, 2022
1 parent a91bb4a commit 8758b1b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions LayoutTests/TestExpectations
Expand Up @@ -3805,6 +3805,7 @@ webgl/1.0.x/conformance/misc/invalid-passed-params.html [ Pass ]
webgl/1.0.x/conformance/glsl/bugs/character-set.html [ Pass ]
webgl/1.0.x/conformance/glsl/misc/fragcolor-fragdata-invariant.html [ Pass ]
webgl/1.0.x/conformance/context/constants-and-properties.html [ Pass ]
webgl/1.0.x/conformance/textures/misc/exif-orientation.html [ Pass ]
webgl/1.0.x/conformance/extensions/webgl-draw-buffers.html [ Pass ]
webgl/1.0.x/conformance/extensions/webgl-multi-draw.html [ Pass Slow ]
webgl/1.0.x/conformance/programs/program-test.html [ Pass ]
Expand All @@ -3821,6 +3822,7 @@ webgl/2.0.y/conformance/misc/invalid-passed-params.html [ Pass ]
webgl/2.0.y/conformance/misc/expando-loss.html [ Pass ]
webgl/2.0.y/conformance/glsl/bugs/character-set.html [ Pass ]
webgl/2.0.y/conformance/glsl/misc/fragcolor-fragdata-invariant.html [ Pass ]
webgl/2.0.y/conformance/textures/misc/exif-orientation.html [ Pass ]
webgl/2.0.y/conformance/extensions/webgl-multi-draw.html [ Pass Slow ]
webgl/2.0.y/conformance/programs/program-test.html [ Pass ]
webgl/2.0.y/conformance2/extensions/ext-texture-filter-anisotropic.html [ Pass ]
Expand Down
@@ -1,11 +1,11 @@


FAIL ImageBitmap from file with EXIF rotation, duplicated via structuredClone assert_array_approx_equals: Pixel value at (40,40) 255,0,0,255 =~ 0,0,0,255. property 0, expected 255 +/- 1, expected 255 but got 0
PASS ImageBitmap from file with EXIF rotation, duplicated via structuredClone
PASS ImageBitmap from file with EXIF rotation, loaded via <img>
PASS ImageBitmap from file with EXIF rotation, loaded via <img> not in DOM, imageOrientation = none
FAIL ImageBitmap from file with EXIF rotation, loaded via <img> in DOM, imageOrientation = none assert_equals: Bitmap width expected 320 but got 160
FAIL ImageBitmap from file with EXIF rotation, duplicated via createImageBitmap assert_array_approx_equals: Pixel value at (40,40) 255,0,0,255 =~ 0,0,0,255. property 0, expected 255 +/- 1, expected 255 but got 0
FAIL ImageBitmap from file with EXIF rotation, duplicated via worker serialization round-trip assert_array_approx_equals: Pixel value at (40,40) 255,0,0,255 =~ 0,0,0,255. property 0, expected 255 +/- 1, expected 255 but got 0
FAIL ImageBitmap from file with EXIF rotation, duplicated via worker transfer round-trip assert_array_approx_equals: Pixel value at (40,40) 255,0,0,255 =~ 0,0,0,255. property 0, expected 255 +/- 1, expected 255 but got 0
PASS ImageBitmap from file with EXIF rotation, duplicated via createImageBitmap
PASS ImageBitmap from file with EXIF rotation, duplicated via worker serialization round-trip
PASS ImageBitmap from file with EXIF rotation, duplicated via worker transfer round-trip
FAIL ImageBitmap from file with EXIF rotation, duplicated via worker transfer round-trip, while referenced by a CanvasPattern promise_test: Unhandled rejection with value: object "TypeError: Type error"

6 changes: 5 additions & 1 deletion Source/WebCore/html/ImageBitmap.cpp
Expand Up @@ -769,8 +769,12 @@ void ImageBitmap::createFromBuffer(ScriptExecutionContext& scriptExecutionContex
return;
}

auto orientation = image->orientation();
if (orientation == ImageOrientation::FromImage)
orientation = ImageOrientation::None;

FloatRect destRect(FloatPoint(), outputSize);
bitmapData->context().drawImage(image, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), options.resolvedImageOrientation(ImageOrientation::None) });
bitmapData->context().drawImage(image, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), options.resolvedImageOrientation(orientation) });

OptionSet<SerializationState> serializationState = SerializationState::OriginClean;
if (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied)
Expand Down

0 comments on commit 8758b1b

Please sign in to comment.