WebP image format is not supported
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Feb 2020 05:53:32 +0000 (05:53 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Feb 2020 05:53:32 +0000 (05:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192672

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2020-02-12
Reviewed by Youenn Fablet.

Source/WebCore:

Add the mime type and the UTI of the WebP to the list of the allowed image
formats. WebP should be enabled only on macOS and iOS post Catalina.

Tests: fast/images/animated-webp-as-image.html
       fast/images/webp-as-image.html

* platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::supportedImageMIMETypes):
* platform/graphics/cg/ImageDecoderCG.cpp:
(WebCore::animationPropertiesFromProperties):
* platform/graphics/cg/UTIRegistry.cpp:
(WebCore::defaultSupportedImageTypes):

Source/WTF:

Introduce HAVE(WEBP) for macOS and iOS.

* wtf/PlatformHave.h:

LayoutTests:

Disable the tests for all ports and enable it only for [ Catalina+ ].

* TestExpectations:
* fast/images/animated-webp-as-image-expected.html: Added.
* fast/images/animated-webp-as-image.html: Added.
* fast/images/resources/animated-red-green-blue-repeat-infinite.webp: Added.
* fast/images/resources/green-400x400.webp: Added.
* fast/images/webp-as-image-expected.html: Added.
* fast/images/webp-as-image.html: Added.
* platform/mac/TestExpectations:

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

15 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/fast/images/animated-webp-as-image-expected.html [new file with mode: 0644]
LayoutTests/fast/images/animated-webp-as-image.html [new file with mode: 0644]
LayoutTests/fast/images/resources/animated-red-green-blue-repeat-infinite.webp [new file with mode: 0644]
LayoutTests/fast/images/resources/green-400x400.webp [new file with mode: 0644]
LayoutTests/fast/images/webp-as-image-expected.html [new file with mode: 0644]
LayoutTests/fast/images/webp-as-image.html [new file with mode: 0644]
LayoutTests/platform/mac/TestExpectations
Source/WTF/ChangeLog
Source/WTF/wtf/PlatformHave.h
Source/WebCore/ChangeLog
Source/WebCore/platform/MIMETypeRegistry.cpp
Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp
Source/WebCore/platform/graphics/cg/UTIRegistry.cpp

index 61b94d0..98fa561 100644 (file)
@@ -1,3 +1,21 @@
+2020-02-12  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        WebP image format is not supported
+        https://bugs.webkit.org/show_bug.cgi?id=192672
+
+        Reviewed by Youenn Fablet.
+
+        Disable the tests for all ports and enable it only for [ Catalina+ ].
+
+        * TestExpectations:
+        * fast/images/animated-webp-as-image-expected.html: Added.
+        * fast/images/animated-webp-as-image.html: Added.
+        * fast/images/resources/animated-red-green-blue-repeat-infinite.webp: Added.
+        * fast/images/resources/green-400x400.webp: Added.
+        * fast/images/webp-as-image-expected.html: Added.
+        * fast/images/webp-as-image.html: Added.
+        * platform/mac/TestExpectations:
+
 2020-02-12  Pavel Feldman  <pavel.feldman@gmail.com>
 
         Web Inspector: encode binary web socket frames using base64
index ec66d7c..53b5492 100644 (file)
@@ -1793,6 +1793,11 @@ fast/images/gif-loop-count.html [ ImageOnlyFailure ]
 fast/images/animated-heics-draw.html [ Skip ]
 fast/images/animated-heics-verify.html [ Skip ]
 
+# WebP images are only supported on macOS and iOS post Catalina
+fast/images/webp-as-image.html [ Skip ]
+fast/images/animated-webp-as-image.html [ Skip ]
+fast/images/animated-webp.html [ Skip ]
+
 webkit.org/b/146182 editing/selection/leak-document-with-selection-inside.html [ Pass Failure ]
 
 # Media Sessions is not yet enabled by default: ENABLE(MEDIA_SESSION)
diff --git a/LayoutTests/fast/images/animated-webp-as-image-expected.html b/LayoutTests/fast/images/animated-webp-as-image-expected.html
new file mode 100644 (file)
index 0000000..4eb16a7
--- /dev/null
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<style>
+    .box {
+        width: 100px;
+        height: 100px;
+        display: inline-block;
+    } 
+</style>    
+<body>
+    <div>
+        <p>Frames of a 3-frame animated image with infinite loopCount:</p>
+        <div class="box" style="background-color: red;"></div>
+        <div class="box" style="background-color: green;"></div>
+        <div class="box" style="background-color: blue;"></div>
+        <div class="box" style="background-color: red;"></div>
+        <div class="box" style="background-color: green;"></div>
+        <div class="box" style="background-color: blue;"></div>
+        <div class="box" style="background-color: red;"></div>
+    </div>
+</body>
+</html>
diff --git a/LayoutTests/fast/images/animated-webp-as-image.html b/LayoutTests/fast/images/animated-webp-as-image.html
new file mode 100644 (file)
index 0000000..55915fc
--- /dev/null
@@ -0,0 +1,72 @@
+<!DOCTYPE html>
+<html>
+<style>
+    canvas {
+        width: 100px;
+        height: 100px;
+    }
+</style>    
+<body>
+    <div>
+        <p>Frames of a 3-frame animated image with infinite loopCount:</p>
+        <canvas id="canvas-A"></canvas>
+        <canvas id="canvas-B"></canvas>
+        <canvas id="canvas-C"></canvas>
+        <canvas id="canvas-D"></canvas>
+        <canvas id="canvas-E"></canvas>
+        <canvas id="canvas-F"></canvas>
+        <canvas id="canvas-G"></canvas>
+    </div>
+    <script>
+        function drawFrame(image, canvasId) {
+            return new Promise((resolve) => {
+                let canvas = document.getElementById("canvas-" + canvasId);
+                let context = canvas.getContext("2d");
+                context.drawImage(image, 0, 0, canvas.width, canvas.height);
+                setTimeout(() => {
+                    resolve(String.fromCharCode(canvasId.charCodeAt() + 1));
+                }, 30);
+            });
+        }
+
+        function drawImage(image, canvasId, frameCount) {
+            let promise = drawFrame(image, canvasId);
+            for (let frame = 1; frame < frameCount; ++frame) {
+                promise = promise.then((canvasId) => {
+                    return drawFrame(image, canvasId);
+                });
+            }
+            return promise;
+        }
+
+        function loadImage(src, canvasId, frameCount) {
+            return new Promise((resolve) => {
+                let image = new Image;
+                image.onload = (() => {
+                    drawImage(image, canvasId, frameCount).then(resolve);
+                });
+                image.src = src;
+            });
+        }
+
+        (function() {
+            if (window.internals) {
+                internals.clearMemoryCache();
+                internals.settings.setAnimatedImageDebugCanvasDrawingEnabled(true);
+            }
+
+            if (window.testRunner)
+                testRunner.waitUntilDone();
+
+            var imageSrc = "resources/animated-red-green-blue-repeat-infinite.gif";
+            var firstCanvasId = 'A';
+            var frameCount = 7;
+
+            loadImage(imageSrc, firstCanvasId, frameCount).then(() => {
+                if (window.testRunner)
+                    testRunner.notifyDone();
+            });
+        })();
+    </script>
+</body>
+</html>
diff --git a/LayoutTests/fast/images/resources/animated-red-green-blue-repeat-infinite.webp b/LayoutTests/fast/images/resources/animated-red-green-blue-repeat-infinite.webp
new file mode 100644 (file)
index 0000000..1938410
Binary files /dev/null and b/LayoutTests/fast/images/resources/animated-red-green-blue-repeat-infinite.webp differ
diff --git a/LayoutTests/fast/images/resources/green-400x400.webp b/LayoutTests/fast/images/resources/green-400x400.webp
new file mode 100644 (file)
index 0000000..786f1b0
Binary files /dev/null and b/LayoutTests/fast/images/resources/green-400x400.webp differ
diff --git a/LayoutTests/fast/images/webp-as-image-expected.html b/LayoutTests/fast/images/webp-as-image-expected.html
new file mode 100644 (file)
index 0000000..fd119ea
--- /dev/null
@@ -0,0 +1,10 @@
+<style>
+       div {
+               width: 400px;
+               height: 400px;
+               background-color: green;
+       }
+</style>
+<body>
+    <div></div>
+</body>
diff --git a/LayoutTests/fast/images/webp-as-image.html b/LayoutTests/fast/images/webp-as-image.html
new file mode 100644 (file)
index 0000000..873a698
--- /dev/null
@@ -0,0 +1,3 @@
+<body>
+    <img src="resources/green-400x400.webp">
+</body>
index fee64ba..ca6ab84 100644 (file)
@@ -1790,6 +1790,13 @@ webkit.org/b/195635 scrollingcoordinator/mac/multiple-fixed.html [ Pass Timeout
 [ Catalina+ ] fast/images/animated-heics-draw.html [ Pass ]
 [ Catalina+ ] fast/images/animated-heics-verify.html [ Pass ]
 
+# <rdar://problem/8509491>
+[ Catalina+ ] fast/images/webp-as-image.html [ Pass ]
+[ Catalina+ ] fast/images/animated-webp-as-image.html [ Pass ]
+
+# <rdar://problem/59015708>
+[ Catalina+ ] fast/images/animated-webp.html [ ImageOnlyFailure ]
+
 # <rdar://problem/40172428>
 [ Catalina+ ] fast/text/font-collection.html [ ImageOnlyFailure ]
 [ Catalina+ ] fast/text/woff2.html [ ImageOnlyFailure ]
index e5b9856..2c91c30 100644 (file)
@@ -1,3 +1,14 @@
+2020-02-12  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        WebP image format is not supported
+        https://bugs.webkit.org/show_bug.cgi?id=192672
+
+        Reviewed by Youenn Fablet.
+
+        Introduce HAVE(WEBP) for macOS and iOS.
+
+        * wtf/PlatformHave.h:
+
 2020-02-12  Yusuke Suzuki  <ysuzuki@apple.com>
 
         [JSC] Compact JITCodeMap by storing BytecodeIndex and CodeLocation separately
index 91cabff..8686db9 100644 (file)
 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS_FAMILY))
 #define HAVE_GCEXTENDEDGAMEPAD_BUTTONS_THUMBSTICK 1
 #endif
+
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101600) || (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 140000)
+#define HAVE_WEBP 1
+#endif
index 8b3b2f6..25c4a25 100644 (file)
@@ -1,3 +1,23 @@
+2020-02-12  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        WebP image format is not supported
+        https://bugs.webkit.org/show_bug.cgi?id=192672
+
+        Reviewed by Youenn Fablet.
+
+        Add the mime type and the UTI of the WebP to the list of the allowed image
+        formats. WebP should be enabled only on macOS and iOS post Catalina.
+
+        Tests: fast/images/animated-webp-as-image.html
+               fast/images/webp-as-image.html
+
+        * platform/MIMETypeRegistry.cpp:
+        (WebCore::MIMETypeRegistry::supportedImageMIMETypes):
+        * platform/graphics/cg/ImageDecoderCG.cpp:
+        (WebCore::animationPropertiesFromProperties):
+        * platform/graphics/cg/UTIRegistry.cpp:
+        (WebCore::defaultSupportedImageTypes):
+
 2020-02-12  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][IFC] Remove LineLayoutContext::m_partialTrailingTextItem
index 636123e..61fa058 100644 (file)
@@ -82,7 +82,9 @@ const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::supportedImag
 
         "image/x-icon"_s, // Favicons don't have a MIME type in the registry either.
         "image/pjpeg"_s, //  We only get one MIME type per UTI, hence our need to add these manually
-
+#if HAVE(WEBP)
+        "image/webp"_s,
+#endif
 #if PLATFORM(IOS_FAMILY)
         // Add malformed image mimetype for compatibility with Mail and to handle malformed mimetypes from the net
         // These were removed for <rdar://problem/6564538> Re-enable UTI code in WebCore now that MobileCoreServices exists
index c2abd19..1a4dd0c 100644 (file)
@@ -120,7 +120,10 @@ static CFDictionaryRef animationPropertiesFromProperties(CFDictionaryRef propert
 
     if (auto animationProperties = (CFDictionaryRef)CFDictionaryGetValue(properties, kCGImagePropertyGIFDictionary))
         return animationProperties;
-
+#if HAVE(WEBP)
+    if (auto animationProperties = (CFDictionaryRef)CFDictionaryGetValue(properties, kCGImagePropertyWebPDictionary))
+        return animationProperties;
+#endif
     if (auto animationProperties = (CFDictionaryRef)CFDictionaryGetValue(properties, kCGImagePropertyPNGDictionary))
         return animationProperties;
 
index 8501da0..ecedc07 100644 (file)
 #include <wtf/NeverDestroyed.h>
 #include <ImageIO/ImageIO.h>
 
-#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
-#include "ArchiveFactory.h"
-#endif
-
 namespace WebCore {
 
 const HashSet<String>& defaultSupportedImageTypes()
 {
     // CG at least supports the following standard image types:
     static NeverDestroyed<HashSet<String>> defaultSupportedImageTypes = std::initializer_list<String> {
-        "com.compuserve.gif",
-        "com.microsoft.bmp",
-        "com.microsoft.cur",
-        "com.microsoft.ico",
-        "public.jpeg",
-        "public.png",
-        "public.tiff",
+        "com.compuserve.gif"_s,
+        "com.microsoft.bmp"_s,
+        "com.microsoft.cur"_s,
+        "com.microsoft.ico"_s,
+        "public.jpeg"_s,
+        "public.png"_s,
+        "public.tiff"_s,
 #if !PLATFORM(WIN)
-        "public.jpeg-2000",
-        "public.mpo-image",
+        "public.jpeg-2000"_s,
+        "public.mpo-image"_s,
+#endif
+#if HAVE(WEBP)
+        "public.webp"_s,
 #endif
     };