Title: [284804] branches/safari-612-branch
Revision
284804
Author
[email protected]
Date
2021-10-25 12:09:47 -0700 (Mon, 25 Oct 2021)

Log Message

Cherry-pick r284436. rdar://problem/83753956

    Make createImageBitmap() take EXIF orientation into account correctly
    https://bugs.webkit.org/show_bug.cgi?id=231063
    <rdar://problem/83753956>

    Reviewed by Myles Maxfield and Said Abou-Hallawa.

    LayoutTests/imported/w3c:

    * web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation-expected.txt: Added.
    * web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation.html: Added.
    * web-platform-tests/html/canvas/element/manual/imagebitmap/resources/squares.jpg: Added.

    Source/WebCore:

    Test: imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation.html

    This makes us treat {imageOrientation:"none"} as meaning "apply EXIF
    orientation without any additional transformation", and
    {imageOrientation:"flipY"} as meaning "apply EXIF orientation and then
    apply an additional vertical flip". This behavior matches Firefox;
    https://github.com/whatwg/html/issues/7210 is open on clarifying this
    behavior in the HTML spec.

    * html/ImageBitmap.cpp:
    (WebCore::ImageBitmap::createPromise):
    (WebCore::ImageBitmap::createFromBuffer):
    (WebCore::imageOrientationForOrientation): Deleted.
    * html/ImageBitmapOptions.h:
    (WebCore::ImageBitmapOptions::resolvedImageOrientation const):
    * html/ImageBitmapOptions.idl:
    * platform/graphics/ImageOrientation.h:
    (WebCore::ImageOrientation::withFlippedY const):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@284436 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-612-branch/LayoutTests/imported/w3c/ChangeLog (284803 => 284804)


--- branches/safari-612-branch/LayoutTests/imported/w3c/ChangeLog	2021-10-25 19:09:42 UTC (rev 284803)
+++ branches/safari-612-branch/LayoutTests/imported/w3c/ChangeLog	2021-10-25 19:09:47 UTC (rev 284804)
@@ -1,3 +1,55 @@
+2021-10-25  Null  <[email protected]>
+
+        Cherry-pick r284436. rdar://problem/83753956
+
+    Make createImageBitmap() take EXIF orientation into account correctly
+    https://bugs.webkit.org/show_bug.cgi?id=231063
+    <rdar://problem/83753956>
+    
+    Reviewed by Myles Maxfield and Said Abou-Hallawa.
+    
+    LayoutTests/imported/w3c:
+    
+    * web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation-expected.txt: Added.
+    * web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation.html: Added.
+    * web-platform-tests/html/canvas/element/manual/imagebitmap/resources/squares.jpg: Added.
+    
+    Source/WebCore:
+    
+    Test: imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation.html
+    
+    This makes us treat {imageOrientation:"none"} as meaning "apply EXIF
+    orientation without any additional transformation", and
+    {imageOrientation:"flipY"} as meaning "apply EXIF orientation and then
+    apply an additional vertical flip". This behavior matches Firefox;
+    https://github.com/whatwg/html/issues/7210 is open on clarifying this
+    behavior in the HTML spec.
+    
+    * html/ImageBitmap.cpp:
+    (WebCore::ImageBitmap::createPromise):
+    (WebCore::ImageBitmap::createFromBuffer):
+    (WebCore::imageOrientationForOrientation): Deleted.
+    * html/ImageBitmapOptions.h:
+    (WebCore::ImageBitmapOptions::resolvedImageOrientation const):
+    * html/ImageBitmapOptions.idl:
+    * platform/graphics/ImageOrientation.h:
+    (WebCore::ImageOrientation::withFlippedY const):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@284436 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-10-18  Cameron McCormack  <[email protected]>
+
+            Make createImageBitmap() take EXIF orientation into account correctly
+            https://bugs.webkit.org/show_bug.cgi?id=231063
+            <rdar://problem/83753956>
+
+            Reviewed by Myles Maxfield and Said Abou-Hallawa.
+
+            * web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation-expected.txt: Added.
+            * web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation.html: Added.
+            * web-platform-tests/html/canvas/element/manual/imagebitmap/resources/squares.jpg: Added.
+
 2021-10-19  Russell Epstein  <[email protected]>
 
         Revert r283931. rdar://problem/83953710

Added: branches/safari-612-branch/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation-expected.txt (0 => 284804)


--- branches/safari-612-branch/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation-expected.txt	                        (rev 0)
+++ branches/safari-612-branch/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation-expected.txt	2021-10-25 19:09:47 UTC (rev 284804)
@@ -0,0 +1,6 @@
+
+PASS createImageBitmap with EXIF rotation, imageOrientation none, and no cropping
+PASS createImageBitmap with EXIF rotation, imageOrientation flipY, and no cropping
+PASS createImageBitmap with EXIF rotation, imageOrientation none, and cropping
+PASS createImageBitmap with EXIF rotation, imageOrientation flipY, and cropping
+

Added: branches/safari-612-branch/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation.html (0 => 284804)


--- branches/safari-612-branch/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation.html	                        (rev 0)
+++ branches/safari-612-branch/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation.html	2021-10-25 19:09:47 UTC (rev 284804)
@@ -0,0 +1,121 @@
+<!DOCTYPE html>
+<title>Test that createImageBitmap honors EXIF orientation</title>
+<script src=""
+<script src=""
+<style>canvas { outline: 1px solid black; margin-right: 1em; }</style>
+<body>
+<script>
+function loadImage(src) {
+    return new Promise(function(resolve) {
+        const image = new Image();
+        image.addEventListener("load", () => resolve(image), { once: true });
+        image.src = ""
+    });
+}
+
+function checkColors(ctx, w, h, expectedColors) {
+    let data = "" 0, w, h).data;
+    for (let [row, col, r, g, b, a] of expectedColors) {
+        let x = col * 80 + 40;
+        let y = row * 80 + 40;
+        let i = (x + y * w) * 4;
+
+        let expected = [r, g, b, a];
+        let actual = [data[i], data[i + 1], data[i + 2], data[i + 3]];
+
+        assert_array_approx_equals(actual, expected, 1, `Pixel value at (${x},${y}) ${expected} =~ ${actual}.`);
+    }
+}
+
+async_test(function(t) {
+    const canvas = document.createElement("canvas");
+    canvas.width = 320;
+    canvas.height = 160;
+    document.body.append(canvas);
+
+    const ctx = canvas.getContext("2d");
+    loadImage("resources/squares.jpg")
+        .then((image) => createImageBitmap(image))
+        .then(t.step_func_done(function(imageBitmap) {
+            ctx.drawImage(imageBitmap, 0, 0);
+            checkColors(ctx, canvas.width, canvas.height, [
+                // row, col, r, g, b, a
+                [0, 0, 255, 0, 0, 255],
+                [0, 1, 0, 255, 0, 255],
+                [0, 2, 0, 0, 255, 255],
+                [0, 3, 0, 0, 0, 255],
+                [1, 0, 255, 128, 128, 255],
+                [1, 1, 128, 255, 128, 255],
+                [1, 2, 128, 128, 255, 255],
+                [1, 3, 128, 128, 128, 255],
+            ]);
+        }));
+}, "createImageBitmap with EXIF rotation, imageOrientation none, and no cropping");
+
+async_test(function(t) {
+    const canvas = document.createElement("canvas");
+    canvas.width = 320;
+    canvas.height = 160;
+    document.body.append(canvas);
+
+    const ctx = canvas.getContext("2d");
+    loadImage("resources/squares.jpg")
+        .then((image) => createImageBitmap(image, { imageOrientation: "flipY" }))
+        .then(t.step_func_done(function(imageBitmap) {
+            ctx.drawImage(imageBitmap, 0, 0);
+            checkColors(ctx, canvas.width, canvas.height, [
+                // row, col, r, g, b, a
+                [0, 0, 255, 128, 128, 255],
+                [0, 1, 128, 255, 128, 255],
+                [0, 2, 128, 128, 255, 255],
+                [0, 3, 128, 128, 128, 255],
+                [1, 0, 255, 0, 0, 255],
+                [1, 1, 0, 255, 0, 255],
+                [1, 2, 0, 0, 255, 255],
+                [1, 3, 0, 0, 0, 255],
+            ]);
+        }));
+}, "createImageBitmap with EXIF rotation, imageOrientation flipY, and no cropping");
+
+async_test(function(t) {
+    const canvas = document.createElement("canvas");
+    canvas.width = 160;
+    canvas.height = 160;
+    document.body.append(canvas);
+
+    const ctx = canvas.getContext("2d");
+    loadImage("resources/squares.jpg")
+        .then(image => createImageBitmap(image, 80, 0, 160, 160))
+        .then(t.step_func_done(function(imageBitmap) {
+            ctx.drawImage(imageBitmap, 0, 0);
+            checkColors(ctx, canvas.width, canvas.height, [
+                // row, col, r, g, b, a
+                [0, 0, 0, 255, 0, 255],
+                [0, 1, 0, 0, 255, 255],
+                [1, 0, 128, 255, 128, 255],
+                [1, 1, 128, 128, 255, 255],
+            ]);
+        }));
+}, "createImageBitmap with EXIF rotation, imageOrientation none, and cropping");
+
+async_test(function(t) {
+    const canvas = document.createElement("canvas");
+    canvas.width = 160;
+    canvas.height = 160;
+    document.body.append(canvas);
+
+    const ctx = canvas.getContext("2d");
+    loadImage("resources/squares.jpg")
+        .then(image => createImageBitmap(image, 80, 0, 160, 160, { imageOrientation: "flipY" }))
+        .then(t.step_func_done(function(imageBitmap) {
+            ctx.drawImage(imageBitmap, 0, 0);
+            checkColors(ctx, canvas.width, canvas.height, [
+                // row, col, r, g, b, a
+                [0, 0, 128, 255, 128, 255],
+                [0, 1, 128, 128, 255, 255],
+                [1, 0, 0, 255, 0, 255],
+                [1, 1, 0, 0, 255, 255],
+            ]);
+        }));
+}, "createImageBitmap with EXIF rotation, imageOrientation flipY, and cropping");
+</script>

Added: branches/safari-612-branch/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/resources/squares.jpg (0 => 284804)


--- branches/safari-612-branch/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/resources/squares.jpg	                        (rev 0)
+++ branches/safari-612-branch/LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/resources/squares.jpg	2021-10-25 19:09:47 UTC (rev 284804)
@@ -0,0 +1,21 @@
+\xFF\xD8\xFF\xE0��JFIF������������\xFF\xE1��bExif����MM��*������������������������������������J��������������R(������������������������������������������������������������\xFF\xDB��C��	
+
+			
+
+		++
+\xFF\xDB��C	\xFF\xC0��@��\xA0��\xFF\xC4������������������������������	\xFF\xC4����������������������������������\xFF\xC4��������������������������	\xFF\xC4����������������������������������\xFF\xDA������?��\x95@������������\xAA\x80������������	T��������������*\xA8��������������\x95@������������\xAA\x80������������	T��������������*\xA8��������������\x95@������������\xAA\x80������������	T��������������*\xA8��������������\x95@������������\xAA\x80������������	T��������������*\xA8��������������\x95@������������\xAA\x80������������	T��������������*\xA8��������������\x9E\xEFT\xD88������������
+Z\x95\xD0������������IU\xB4@������������)jTo@������������M%V\xD1��������������\xA5\xA9Q\xBD������������4\x95[D������������\x96\xA5F\xF4������������\xD2Um������������
+Z\x95\xD0������������IU\xB4@������������)jTo@������������M%V\xD1��������������\xA5\xA9Q\xBD������������4\x95[D������������\x96\xA5F\xF4������������\xD2Um������������
+Z\x95\xD0������������IU\xB4@������������)jTo@������������u\x9E;\xBC\xFD������������\xA3]\xC1H��������������\xCEN\x9B\xC0������������h\xD7pR��������������3\x93\x87\xA6\xF0������������5\xDC\x80������������\xE4\xE1\xE9\xBC������������\x8Dw ������������98zo������������\xA3]\xC1H��������������\xCEN\x9B\xC0������������h\xD7pR��������������3\x93\x87\xA6\xF0������������5\xDC\x80������������\xE4\xE1\xE9\xBC������������\x8Dw ������������98zo������������\xA3]\xC1H��������������\xCEN\x9B\xC0������������h\xD7pR��������������%c\xE1\xEF��������������+\xE0\xCEҠ������������\xC1X������������+\xE0\xCEҠ������������\xC1X������������+\xE0\xCEҠ������������\xC1X������������+\xE0\xCEҠ������������\xC1X������������+\xE0\xCEҠ������������\xC1X������������+\xE0\xCEҠ������������\xC1X������������+\xE0\xCEҠ������������\xC1X������������+\xE0\xCEҠ������������\xC1X������������+\xE0\xCEҠ������������\xC1X������������+\xE0\xCEҠ������������\xFF\xD9
\ No newline at end of file

Modified: branches/safari-612-branch/Source/WebCore/ChangeLog (284803 => 284804)


--- branches/safari-612-branch/Source/WebCore/ChangeLog	2021-10-25 19:09:42 UTC (rev 284803)
+++ branches/safari-612-branch/Source/WebCore/ChangeLog	2021-10-25 19:09:47 UTC (rev 284804)
@@ -1,5 +1,72 @@
 2021-10-25  Null  <[email protected]>
 
+        Cherry-pick r284436. rdar://problem/83753956
+
+    Make createImageBitmap() take EXIF orientation into account correctly
+    https://bugs.webkit.org/show_bug.cgi?id=231063
+    <rdar://problem/83753956>
+    
+    Reviewed by Myles Maxfield and Said Abou-Hallawa.
+    
+    LayoutTests/imported/w3c:
+    
+    * web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation-expected.txt: Added.
+    * web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation.html: Added.
+    * web-platform-tests/html/canvas/element/manual/imagebitmap/resources/squares.jpg: Added.
+    
+    Source/WebCore:
+    
+    Test: imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation.html
+    
+    This makes us treat {imageOrientation:"none"} as meaning "apply EXIF
+    orientation without any additional transformation", and
+    {imageOrientation:"flipY"} as meaning "apply EXIF orientation and then
+    apply an additional vertical flip". This behavior matches Firefox;
+    https://github.com/whatwg/html/issues/7210 is open on clarifying this
+    behavior in the HTML spec.
+    
+    * html/ImageBitmap.cpp:
+    (WebCore::ImageBitmap::createPromise):
+    (WebCore::ImageBitmap::createFromBuffer):
+    (WebCore::imageOrientationForOrientation): Deleted.
+    * html/ImageBitmapOptions.h:
+    (WebCore::ImageBitmapOptions::resolvedImageOrientation const):
+    * html/ImageBitmapOptions.idl:
+    * platform/graphics/ImageOrientation.h:
+    (WebCore::ImageOrientation::withFlippedY const):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@284436 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-10-18  Cameron McCormack  <[email protected]>
+
+            Make createImageBitmap() take EXIF orientation into account correctly
+            https://bugs.webkit.org/show_bug.cgi?id=231063
+            <rdar://problem/83753956>
+
+            Reviewed by Myles Maxfield and Said Abou-Hallawa.
+
+            Test: imported/w3c/web-platform-tests/html/canvas/element/manual/imagebitmap/createImageBitmap-exif-orientation.html
+
+            This makes us treat {imageOrientation:"none"} as meaning "apply EXIF
+            orientation without any additional transformation", and
+            {imageOrientation:"flipY"} as meaning "apply EXIF orientation and then
+            apply an additional vertical flip". This behavior matches Firefox;
+            https://github.com/whatwg/html/issues/7210 is open on clarifying this
+            behavior in the HTML spec.
+
+            * html/ImageBitmap.cpp:
+            (WebCore::ImageBitmap::createPromise):
+            (WebCore::ImageBitmap::createFromBuffer):
+            (WebCore::imageOrientationForOrientation): Deleted.
+            * html/ImageBitmapOptions.h:
+            (WebCore::ImageBitmapOptions::resolvedImageOrientation const):
+            * html/ImageBitmapOptions.idl:
+            * platform/graphics/ImageOrientation.h:
+            (WebCore::ImageOrientation::withFlippedY const):
+
+2021-10-25  Null  <[email protected]>
+
         Cherry-pick r283628. rdar://problem/83729357
 
     CoreAudioSharedUnit should not clear its persistentID when device capture changes

Modified: branches/safari-612-branch/Source/WebCore/html/ImageBitmap.cpp (284803 => 284804)


--- branches/safari-612-branch/Source/WebCore/html/ImageBitmap.cpp	2021-10-25 19:09:42 UTC (rev 284803)
+++ branches/safari-612-branch/Source/WebCore/html/ImageBitmap.cpp	2021-10-25 19:09:47 UTC (rev 284804)
@@ -235,13 +235,6 @@
     return InterpolationQuality::Default;
 }
 
-static ImageOrientation imageOrientationForOrientation(ImageBitmapOptions::Orientation orientation)
-{
-    if (orientation == ImageBitmapOptions::Orientation::FlipY)
-        return ImageOrientation(ImageOrientation::OriginBottomLeft);
-    return ImageOrientation();
-}
-
 static AlphaPremultiplication alphaPremultiplicationForPremultiplyAlpha(ImageBitmapOptions::PremultiplyAlpha premultiplyAlpha)
 {
     // The default is to premultiply - this is the least surprising behavior.
@@ -373,21 +366,25 @@
         return;
     }
 
-    auto imageForRender = cachedImage->imageForRenderer(imageElement->renderer());
-    if (!imageForRender) {
+    auto imageForRenderer = cachedImage->imageForRenderer(imageElement->renderer());
+    if (!imageForRenderer) {
         promise.reject(InvalidStateError, "Cannot create ImageBitmap from image that can't be rendered");
         return;
     }
 
     auto outputSize = outputSizeForSourceRectangle(sourceRectangle.returnValue(), options);
-    auto bitmapData = createImageBuffer(scriptExecutionContext, outputSize, bufferRenderingMode, imageForRender->colorSpace());
+    auto bitmapData = createImageBuffer(scriptExecutionContext, outputSize, bufferRenderingMode, imageForRenderer->colorSpace());
     if (!bitmapData) {
         resolveWithBlankImageBuffer(scriptExecutionContext, !taintsOrigin(*cachedImage), WTFMove(promise));
         return;
     }
 
+    auto orientation = imageForRenderer->orientation();
+    if (orientation == ImageOrientation::FromImage)
+        orientation = ImageOrientation::None;
+
     FloatRect destRect(FloatPoint(), outputSize);
-    bitmapData->context().drawImage(*imageForRender, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), imageOrientationForOrientation(options.imageOrientation) });
+    bitmapData->context().drawImage(*imageForRenderer, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), options.resolvedImageOrientation(orientation) });
 
     // 9. If the origin of image's image is not the same origin as the origin specified by the
     //    entry settings object, then set the origin-clean flag of the ImageBitmap object's
@@ -455,7 +452,7 @@
     }
 
     FloatRect destRect(FloatPoint(), outputSize);
-    bitmapData->context().drawImage(*imageForRender, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), imageOrientationForOrientation(options.imageOrientation) });
+    bitmapData->context().drawImage(*imageForRender, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), options.resolvedImageOrientation(ImageOrientation::None) });
 
     // 5. Set the origin-clean flag of the ImageBitmap object's bitmap to the same value as
     //    the origin-clean flag of the canvas element's bitmap.
@@ -525,7 +522,7 @@
         c.clip(FloatRect(FloatPoint(), outputSize));
         auto scaleX = float(outputSize.width()) / float(sourceRectangle.width());
         auto scaleY = float(outputSize.height()) / float(sourceRectangle.height());
-        if (options.imageOrientation == ImageBitmapOptions::Orientation::FlipY) {
+        if (options.orientation == ImageBitmapOptions::Orientation::FlipY) {
             c.scale(FloatSize(scaleX, -scaleY));
             c.translate(IntPoint(-sourceRectangle.location().x(), sourceRectangle.location().y() - outputSize.height()));
         } else {
@@ -588,7 +585,7 @@
     auto imageForRender = existingImageBitmap->buffer()->copyImage();
 
     FloatRect destRect(FloatPoint(), outputSize);
-    bitmapData->context().drawImage(*imageForRender, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), imageOrientationForOrientation(options.imageOrientation) });
+    bitmapData->context().drawImage(*imageForRender, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), options.resolvedImageOrientation(ImageOrientation::None) });
 
     // 5. Set the origin-clean flag of the ImageBitmap object's bitmap to the same
     //    value as the origin-clean flag of the bitmap of the image argument.
@@ -768,7 +765,7 @@
     }
 
     FloatRect destRect(FloatPoint(), outputSize);
-    bitmapData->context().drawImage(image, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), imageOrientationForOrientation(options.imageOrientation) });
+    bitmapData->context().drawImage(image, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), options.resolvedImageOrientation(ImageOrientation::None) });
 
     OptionSet<SerializationState> serializationState = SerializationState::OriginClean;
     if (alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha) == AlphaPremultiplication::Premultiplied)
@@ -815,7 +812,7 @@
     // If no cropping, resizing, flipping, etc. are needed, then simply use the
     // resulting ImageBuffer directly.
     auto alphaPremultiplication = alphaPremultiplicationForPremultiplyAlpha(options.premultiplyAlpha);
-    if (sourceRectangle.returnValue().location().isZero() && sourceRectangle.returnValue().size() == imageData->size() && sourceRectangle.returnValue().size() == outputSize && options.imageOrientation == ImageBitmapOptions::Orientation::None) {
+    if (sourceRectangle.returnValue().location().isZero() && sourceRectangle.returnValue().size() == imageData->size() && sourceRectangle.returnValue().size() == outputSize && options.orientation == ImageBitmapOptions::Orientation::None) {
         bitmapData->putPixelBuffer(imageData->pixelBuffer(), sourceRectangle.releaseReturnValue(), { }, alphaPremultiplication);
         
         auto imageBitmap = create(ImageBitmapBacking(WTFMove(bitmapData)));
@@ -833,7 +830,7 @@
     }
     tempBitmapData->putPixelBuffer(imageData->pixelBuffer(), IntRect(0, 0, imageData->width(), imageData->height()), { }, alphaPremultiplication);
     FloatRect destRect(FloatPoint(), outputSize);
-    bitmapData->context().drawImageBuffer(*tempBitmapData, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), imageOrientationForOrientation(options.imageOrientation) });
+    bitmapData->context().drawImageBuffer(*tempBitmapData, destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), options.resolvedImageOrientation(ImageOrientation::None) });
 
     // 6.4.1. Resolve p with ImageBitmap.
     auto imageBitmap = create({ WTFMove(bitmapData) });

Modified: branches/safari-612-branch/Source/WebCore/html/ImageBitmapOptions.h (284803 => 284804)


--- branches/safari-612-branch/Source/WebCore/html/ImageBitmapOptions.h	2021-10-25 19:09:42 UTC (rev 284803)
+++ branches/safari-612-branch/Source/WebCore/html/ImageBitmapOptions.h	2021-10-25 19:09:47 UTC (rev 284804)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include "ImageOrientation.h"
 #include <optional>
 
 namespace WebCore {
@@ -35,12 +36,17 @@
     enum class ColorSpaceConversion { None, Default };
     enum class ResizeQuality { Pixelated, Low, Medium, High };
 
-    Orientation imageOrientation { Orientation::None };
+    Orientation orientation { Orientation::None };
     PremultiplyAlpha premultiplyAlpha { PremultiplyAlpha::Default };
     ColorSpaceConversion colorSpaceConversion { ColorSpaceConversion::Default };
     std::optional<unsigned> resizeWidth;
     std::optional<unsigned> resizeHeight;
     ResizeQuality resizeQuality { ResizeQuality::Low };
+
+    ImageOrientation resolvedImageOrientation(ImageOrientation imageOrientation) const
+    {
+        return orientation == Orientation::FlipY ? imageOrientation.withFlippedY() : imageOrientation;
+    }
 };
 
 }

Modified: branches/safari-612-branch/Source/WebCore/html/ImageBitmapOptions.idl (284803 => 284804)


--- branches/safari-612-branch/Source/WebCore/html/ImageBitmapOptions.idl	2021-10-25 19:09:42 UTC (rev 284803)
+++ branches/safari-612-branch/Source/WebCore/html/ImageBitmapOptions.idl	2021-10-25 19:09:47 UTC (rev 284804)
@@ -29,7 +29,7 @@
 enum ResizeQuality { "pixelated", "low", "medium", "high" };
 
 dictionary ImageBitmapOptions {
-    ImageOrientation imageOrientation = "none";
+    [ImplementedAs=orientation] ImageOrientation imageOrientation = "none";
     PremultiplyAlpha premultiplyAlpha = "default";
     ColorSpaceConversion colorSpaceConversion = "default";
     [EnforceRange] unsigned long resizeWidth;

Modified: branches/safari-612-branch/Source/WebCore/platform/graphics/ImageOrientation.h (284803 => 284804)


--- branches/safari-612-branch/Source/WebCore/platform/graphics/ImageOrientation.h	2021-10-25 19:09:42 UTC (rev 284803)
+++ branches/safari-612-branch/Source/WebCore/platform/graphics/ImageOrientation.h	2021-10-25 19:09:47 UTC (rev 284804)
@@ -102,6 +102,36 @@
         return AffineTransform();
     }
 
+    ImageOrientation withFlippedY() const
+    {
+        ASSERT(isValidEXIFOrientation(m_orientation));
+
+        switch (m_orientation) {
+        case FromImage:
+            ASSERT_NOT_REACHED();
+            return None;
+        case OriginTopLeft:
+            return OriginBottomLeft;
+        case OriginTopRight:
+            return OriginBottomRight;
+        case OriginBottomRight:
+            return OriginTopRight;
+        case OriginBottomLeft:
+            return OriginTopLeft;
+        case OriginLeftTop:
+            return OriginLeftBottom;
+        case OriginRightTop:
+            return OriginRightBottom;
+        case OriginRightBottom:
+            return OriginRightTop;
+        case OriginLeftBottom:
+            return OriginLeftTop;
+        }
+
+        ASSERT_NOT_REACHED();
+        return None;
+    }
+
 private:
     static const Orientation EXIFFirst = OriginTopLeft;
     static const Orientation EXIFLast = OriginLeftBottom;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to