Title: [273970] trunk
Revision
273970
Author
changs...@webkit.org
Date
2021-03-05 08:15:08 -0800 (Fri, 05 Mar 2021)

Log Message

AVIF decoding support
https://bugs.webkit.org/show_bug.cgi?id=207750

Reviewed by Philippe Normand.

This patch brings an initial support of AVIF image format to the gtk port.
AVIF is a new royalty-free image format derived from the keyframes of AV1 video.
FireFox and Chromium-variant browsers already support it. Its specification can be found
at https://rawcdn.githack.com/AOMediaCodec/av1-avif/67a92add6cd642a8863e386fa4db87954a6735d1/index.html
This patch aims to land a build option for AVIF and a basic decoding ability
for still images by using libavif. Animated AVIF images will be covered later.

.:

* Source/cmake/FindAVIF.cmake: Added to find libavif.
* Source/cmake/OptionsGTK.cmake: A build option, USE_AVIF is added.

Source/WebCore:

A mimetype and a decoder for AVIF are newly added. The new tests verify
if an avif image can be decoded and properly rendered. Only the gtk port performs
these tests for now.

Tests: fast/images/avif-as-image.html
       fast/images/avif-image-decoding.html

* PlatformGTK.cmake: Add AVIFImageDecoder.cpp and AVIFImageReader.cpp as build targets
* platform/MIMETypeRegistry.cpp: avif mimetype added.
(WebCore::MIMETypeRegistry::supportedImageMIMETypes):
* platform/image-decoders/ScalableImageDecoder.cpp:
(WebCore::ScalableImageDecoder::create): AVIF file signature added.
* platform/image-decoders/avif/AVIFImageDecoder.cpp: Added.
(WebCore::AVIFImageDecoder::AVIFImageDecoder):
(WebCore::AVIFImageDecoder::frameBufferAtIndex): Decode a frame of avif image.
The first frame is decoded for now.
(WebCore::AVIFImageDecoder::setFailed):
(WebCore::AVIFImageDecoder::tryDecodeSize): Parses header of avif images.
(WebCore::AVIFImageDecoder::decode):
* platform/image-decoders/avif/AVIFImageDecoder.h: Added.
* platform/image-decoders/avif/AVIFImageReader.cpp: Added.
(WebCore::AVIFImageReader::AVIFImageReader):
(WebCore::AVIFImageReader::~AVIFImageReader):
(WebCore::AVIFImageReader::parseHeader): Actual parsing of the header with libavif
(WebCore::AVIFImageReader::decodeFrame): Actual decoding of an avif frame.
* platform/image-decoders/avif/AVIFImageReader.h: Added.
* platform/image-decoders/avif/AVIFUniquePtr.h: Added a smart pointer template for avifDecoder.
(WebCore::AVIFPtrDeleter<avifDecoder>::operator() const):

Tools:

* gtk/install-dependencies: Add dependencies of libavif for jhbuild
* gtk/jhbuild.modules: Add libavif for jhbuild

LayoutTests:

The new tests verify if an avif image can be decoded and properly rendered.
Only the gtk port performs these tests for now.

* TestExpectations: Skip avif tests for non-gtk ports
* fast/images/avif-as-image-expected.html: Added.
* fast/images/avif-as-image.html: Added.
* fast/images/avif-image-decoding-expected.txt: Added.
* fast/images/avif-image-decoding.html: Added.
* fast/images/resources/green-313x313.avif: Added.
* platform/gtk/TestExpectations: The gtk port should pass the tests.

Modified Paths

Added Paths

Diff

Modified: trunk/ChangeLog (273969 => 273970)


--- trunk/ChangeLog	2021-03-05 16:10:35 UTC (rev 273969)
+++ trunk/ChangeLog	2021-03-05 16:15:08 UTC (rev 273970)
@@ -1,3 +1,20 @@
+2021-03-05  ChangSeok Oh  <changs...@webkit.org>
+
+        AVIF decoding support
+        https://bugs.webkit.org/show_bug.cgi?id=207750
+
+        Reviewed by Philippe Normand.
+
+        This patch brings an initial support of AVIF image format to the gtk port.
+        AVIF is a new royalty-free image format derived from the keyframes of AV1 video.
+        FireFox and Chromium-variant browsers already support it. Its specification can be found
+        at https://rawcdn.githack.com/AOMediaCodec/av1-avif/67a92add6cd642a8863e386fa4db87954a6735d1/index.html
+        This patch aims to land a build option for AVIF and a basic decoding ability
+        for still images by using libavif. Animated AVIF images will be covered later.
+
+        * Source/cmake/FindAVIF.cmake: Added to find libavif.
+        * Source/cmake/OptionsGTK.cmake: A build option, USE_AVIF is added.
+
 2021-03-03  Commit Queue  <commit-qu...@webkit.org>
 
         Unreviewed, reverting r273814.

Modified: trunk/LayoutTests/ChangeLog (273969 => 273970)


--- trunk/LayoutTests/ChangeLog	2021-03-05 16:10:35 UTC (rev 273969)
+++ trunk/LayoutTests/ChangeLog	2021-03-05 16:15:08 UTC (rev 273970)
@@ -1,3 +1,28 @@
+2021-03-05  ChangSeok Oh  <changs...@webkit.org>
+
+        AVIF decoding support
+        https://bugs.webkit.org/show_bug.cgi?id=207750
+
+        Reviewed by Philippe Normand.
+
+        This patch brings an initial support of AVIF image format to the gtk port.
+        AVIF is a new royalty-free image format derived from the keyframes of AV1 video.
+        FireFox and Chromium-variant browsers already support it. Its specification can be found
+        at https://rawcdn.githack.com/AOMediaCodec/av1-avif/67a92add6cd642a8863e386fa4db87954a6735d1/index.html
+        This patch aims to land a build option for AVIF and a basic decoding ability
+        for still images by using libavif. Animated AVIF images will be covered later.
+
+        The new tests verify if an avif image can be decoded and properly rendered.
+        Only the gtk port performs these tests for now.
+
+        * TestExpectations: Skip avif tests for non-gtk ports
+        * fast/images/avif-as-image-expected.html: Added.
+        * fast/images/avif-as-image.html: Added.
+        * fast/images/avif-image-decoding-expected.txt: Added.
+        * fast/images/avif-image-decoding.html: Added.
+        * fast/images/resources/green-313x313.avif: Added.
+        * platform/gtk/TestExpectations: The gtk port should pass the tests.
+
 2021-03-05  Imanol Fernandez  <ifernan...@igalia.com>
 
         XRFrame getViewerPose has emulatedPosition set properly

Modified: trunk/LayoutTests/TestExpectations (273969 => 273970)


--- trunk/LayoutTests/TestExpectations	2021-03-05 16:10:35 UTC (rev 273969)
+++ trunk/LayoutTests/TestExpectations	2021-03-05 16:15:08 UTC (rev 273970)
@@ -116,6 +116,10 @@
 # These tests don't have to be platform-specific, but they are only implemented on Mac now.
 fast/images/eps-as-image.html [ Skip ]
 
+# These tests don't have to be platform-specific, but they are only implemented on GTK now.
+fast/images/avif-image-decoding.html [ Skip ]
+fast/images/avif-as-image.html [ Skip ]
+
 # Only applicable on platforms with dark mode support
 css-dark-mode [ Skip ]
 fast/css/apple-system-control-colors.html [ Skip ]

Added: trunk/LayoutTests/fast/images/avif-as-image-expected.html (0 => 273970)


--- trunk/LayoutTests/fast/images/avif-as-image-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/avif-as-image-expected.html	2021-03-05 16:15:08 UTC (rev 273970)
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<style>
+div {
+  width: 313px;
+  height: 313px;
+  background-color: green;
+}
+</style>
+<body>
+  <div></div>
+</body>

Added: trunk/LayoutTests/fast/images/avif-as-image.html (0 => 273970)


--- trunk/LayoutTests/fast/images/avif-as-image.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/avif-as-image.html	2021-03-05 16:15:08 UTC (rev 273970)
@@ -0,0 +1,4 @@
+<!DOCTYPE html>
+<body>
+  <img src=""
+</body>

Added: trunk/LayoutTests/fast/images/avif-image-decoding-expected.txt (0 => 273970)


--- trunk/LayoutTests/fast/images/avif-image-decoding-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/images/avif-image-decoding-expected.txt	2021-03-05 16:15:08 UTC (rev 273970)
@@ -0,0 +1,2 @@
+
+313x313

Added: trunk/LayoutTests/fast/images/avif-image-decoding.html (0 => 273970)


--- trunk/LayoutTests/fast/images/avif-image-decoding.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/avif-image-decoding.html	2021-03-05 16:15:08 UTC (rev 273970)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<body>
+<script>
+if (window.testRunner)
+  testRunner.dumpAsText();
+
+window._onload_ = function() {
+  document.getElementById('results').innerHTML =
+    document.getElementsByTagName('img')[0].width + 'x' +
+    document.getElementsByTagName('img')[0].height;
+}
+</script>
+<img src=""
+<div id="results"></div>
+</body>

Added: trunk/LayoutTests/fast/images/resources/green-313x313.avif (0 => 273970)


--- trunk/LayoutTests/fast/images/resources/green-313x313.avif	                        (rev 0)
+++ trunk/LayoutTests/fast/images/resources/green-313x313.avif	2021-03-05 16:15:08 UTC (rev 273970)
@@ -0,0 +1,3 @@
+ftypmif1mif1avifmiaf\xF3meta!hdlrpictpitmiloc@&(iinfinfeav01ImageriprpSipcoispe99paspav1C\x81 
+	8"'\x86\x90\xD0pixiipma\x83\x84.mdat
+	8"'\x86\x90\xD02\x90,\x9D\xFA\xFD\x98\xC3*\xD3$M\xEE\xB2\xC5\xECX
\ No newline at end of file

Modified: trunk/LayoutTests/platform/gtk/TestExpectations (273969 => 273970)


--- trunk/LayoutTests/platform/gtk/TestExpectations	2021-03-05 16:10:35 UTC (rev 273969)
+++ trunk/LayoutTests/platform/gtk/TestExpectations	2021-03-05 16:15:08 UTC (rev 273970)
@@ -112,6 +112,9 @@
 
 imported/w3c/web-platform-tests/service-workers/service-worker/fetch-audio-tainting.https.html [ Pass ]
 
+fast/images/avif-image-decoding.html [ Pass ]
+fast/images/avif-as-image.html [ Pass ]
+
 #////////////////////////////////////////////////////////////////////////////////////////
 # End of PASSING tests. See below where to put expected failures.
 #////////////////////////////////////////////////////////////////////////////////////////

Modified: trunk/Source/WebCore/ChangeLog (273969 => 273970)


--- trunk/Source/WebCore/ChangeLog	2021-03-05 16:10:35 UTC (rev 273969)
+++ trunk/Source/WebCore/ChangeLog	2021-03-05 16:15:08 UTC (rev 273970)
@@ -1,3 +1,46 @@
+2021-03-05  ChangSeok Oh  <changs...@webkit.org>
+
+        AVIF decoding support
+        https://bugs.webkit.org/show_bug.cgi?id=207750
+
+        Reviewed by Philippe Normand.
+
+        This patch brings an initial support of AVIF image format to the gtk port.
+        AVIF is a new royalty-free image format derived from the keyframes of AV1 video.
+        FireFox and Chromium-variant browsers already support it. Its specification can be found
+        at https://rawcdn.githack.com/AOMediaCodec/av1-avif/67a92add6cd642a8863e386fa4db87954a6735d1/index.html
+        This patch aims to land a build option for AVIF and a basic decoding ability
+        for still images by using libavif. Animated AVIF images will be covered later.
+
+        A mimetype and a decoder for AVIF are newly added. The new tests verify
+        if an avif image can be decoded and properly rendered. Only the gtk port performs
+        these tests for now.
+
+        Tests: fast/images/avif-as-image.html
+               fast/images/avif-image-decoding.html
+
+        * PlatformGTK.cmake: Add AVIFImageDecoder.cpp and AVIFImageReader.cpp as build targets
+        * platform/MIMETypeRegistry.cpp: avif mimetype added.
+        (WebCore::MIMETypeRegistry::supportedImageMIMETypes):
+        * platform/image-decoders/ScalableImageDecoder.cpp:
+        (WebCore::ScalableImageDecoder::create): AVIF file signature added.
+        * platform/image-decoders/avif/AVIFImageDecoder.cpp: Added.
+        (WebCore::AVIFImageDecoder::AVIFImageDecoder):
+        (WebCore::AVIFImageDecoder::frameBufferAtIndex): Decode a frame of avif image.
+        The first frame is decoded for now.
+        (WebCore::AVIFImageDecoder::setFailed):
+        (WebCore::AVIFImageDecoder::tryDecodeSize): Parses header of avif images.
+        (WebCore::AVIFImageDecoder::decode):
+        * platform/image-decoders/avif/AVIFImageDecoder.h: Added.
+        * platform/image-decoders/avif/AVIFImageReader.cpp: Added.
+        (WebCore::AVIFImageReader::AVIFImageReader):
+        (WebCore::AVIFImageReader::~AVIFImageReader):
+        (WebCore::AVIFImageReader::parseHeader): Actual parsing of the header with libavif
+        (WebCore::AVIFImageReader::decodeFrame): Actual decoding of an avif frame.
+        * platform/image-decoders/avif/AVIFImageReader.h: Added.
+        * platform/image-decoders/avif/AVIFUniquePtr.h: Added a smart pointer template for avifDecoder.
+        (WebCore::AVIFPtrDeleter<avifDecoder>::operator() const):
+
 2021-03-05  Chris Dumez  <cdu...@apple.com>
 
         Unreviewed Windows build fix after r273966.

Modified: trunk/Source/WebCore/PlatformGTK.cmake (273969 => 273970)


--- trunk/Source/WebCore/PlatformGTK.cmake	2021-03-05 16:10:35 UTC (rev 273969)
+++ trunk/Source/WebCore/PlatformGTK.cmake	2021-03-05 16:15:08 UTC (rev 273970)
@@ -44,6 +44,20 @@
     "${WEBCORE_DIR}/platform/text/gtk"
 )
 
+if (USE_AVIF)
+    list(APPEND WebCore_PRIVATE_INCLUDE_DIRECTORIES
+        "${WEBCORE_DIR}/platform/image-decoders/avif"
+    )
+    list(APPEND WebCore_PRIVATE_FRAMEWORK_HEADERS
+        platform/image-decoders/avif/AVIFUniquePtr.h
+    )
+    list(APPEND WebCore_SOURCES
+        platform/image-decoders/avif/AVIFImageDecoder.cpp
+        platform/image-decoders/avif/AVIFImageReader.cpp
+    )
+    list(APPEND WebCore_LIBRARIES AVIF::AVIF)
+endif ()
+
 if (USE_WPE_RENDERER)
     list(APPEND WebCore_INCLUDE_DIRECTORIES
         "${WEBCORE_DIR}/platform/graphics/libwpe"

Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.cpp (273969 => 273970)


--- trunk/Source/WebCore/platform/MIMETypeRegistry.cpp	2021-03-05 16:10:35 UTC (rev 273969)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.cpp	2021-03-05 16:15:08 UTC (rev 273970)
@@ -140,6 +140,9 @@
 #if ENABLE(APNG)
         "image/apng"_s,
 #endif
+#if USE(AVIF)
+        "image/avif"_s,
+#endif
 #if USE(OPENJPEG)
         "image/jp2"_s,
         "image/jpeg2000"_s,

Modified: trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp (273969 => 273970)


--- trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp	2021-03-05 16:10:35 UTC (rev 273969)
+++ trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp	2021-03-05 16:15:08 UTC (rev 273970)
@@ -30,6 +30,9 @@
 #include "NotImplemented.h"
 #include "PNGImageDecoder.h"
 #include "SharedBuffer.h"
+#if USE(AVIF)
+#include "AVIFImageDecoder.h"
+#endif
 #if USE(OPENJPEG)
 #include "JPEG2000ImageDecoder.h"
 #endif
@@ -77,6 +80,13 @@
     return !memcmp(contents, "\xFF\xD8\xFF", 3);
 }
 
+#if USE(AVIF)
+bool matchesAVIFSignature(char* contents)
+{
+    return !memcmp(contents + 4, "\x66\x74\x79\x70", 4);
+}
+#endif
+
 #if USE(OPENJPEG)
 bool matchesJP2Signature(char* contents)
 {
@@ -134,6 +144,11 @@
     if (matchesJPEGSignature(contents))
         return JPEGImageDecoder::create(alphaOption, gammaAndColorProfileOption);
 
+#if USE(AVIF)
+    if (matchesAVIFSignature(contents))
+        return AVIFImageDecoder::create(alphaOption, gammaAndColorProfileOption);
+#endif
+
 #if USE(OPENJPEG)
     if (matchesJP2Signature(contents))
         return JPEG2000ImageDecoder::create(JPEG2000ImageDecoder::Format::JP2, alphaOption, gammaAndColorProfileOption);

Added: trunk/Source/WebCore/platform/image-decoders/avif/AVIFImageDecoder.cpp (0 => 273970)


--- trunk/Source/WebCore/platform/image-decoders/avif/AVIFImageDecoder.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/image-decoders/avif/AVIFImageDecoder.cpp	2021-03-05 16:15:08 UTC (rev 273970)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2021 Igalia S.L. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AVIFImageDecoder.h"
+
+#include "AVIFImageReader.h"
+
+namespace WebCore {
+
+AVIFImageDecoder::AVIFImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
+    : ScalableImageDecoder(alphaOption, gammaAndColorProfileOption)
+{
+}
+
+AVIFImageDecoder::~AVIFImageDecoder() = default;
+
+ScalableImageDecoderFrame* AVIFImageDecoder::frameBufferAtIndex(size_t index)
+{
+    if (index)
+        return nullptr;
+
+    if (m_frameBufferCache.isEmpty())
+        m_frameBufferCache.grow(1);
+
+    auto& frame = m_frameBufferCache[0];
+    if (!frame.isComplete())
+        decode(frame, isAllDataReceived());
+    return &frame;
+}
+
+bool AVIFImageDecoder::setFailed()
+{
+    m_reader = nullptr;
+    return ScalableImageDecoder::setFailed();
+}
+
+void AVIFImageDecoder::tryDecodeSize(bool allDataReceived)
+{
+    if (!m_reader)
+        m_reader = makeUnique<AVIFImageReader>(this);
+    m_reader->parseHeader(*m_data, allDataReceived);
+}
+
+void AVIFImageDecoder::decode(ScalableImageDecoderFrame& frame, bool allDataReceived)
+{
+    if (failed())
+        return;
+
+    ASSERT(m_reader);
+    m_reader->decodeFrame(0, frame, *m_data);
+
+    if (allDataReceived && !m_frameBufferCache.isEmpty() && frame.isComplete())
+        m_reader = nullptr;
+}
+
+}

Added: trunk/Source/WebCore/platform/image-decoders/avif/AVIFImageDecoder.h (0 => 273970)


--- trunk/Source/WebCore/platform/image-decoders/avif/AVIFImageDecoder.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/image-decoders/avif/AVIFImageDecoder.h	2021-03-05 16:15:08 UTC (rev 273970)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2021 Igalia S.L. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "ScalableImageDecoder.h"
+
+namespace WebCore {
+
+class AVIFImageReader;
+
+// This class decodes the AVIF image format.
+class AVIFImageDecoder final : public ScalableImageDecoder {
+public:
+    static Ref<ScalableImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
+    {
+        return adoptRef(*new AVIFImageDecoder(alphaOption, gammaAndColorProfileOption));
+    }
+
+    virtual ~AVIFImageDecoder();
+
+    // ScalableImageDecoder
+    String filenameExtension() const final { return "avif"_s; }
+    ScalableImageDecoderFrame* frameBufferAtIndex(size_t index) final;
+    bool setFailed() final;
+
+private:
+    AVIFImageDecoder(AlphaOption, GammaAndColorProfileOption);
+
+    void tryDecodeSize(bool allDataReceived) final;
+    void decode(ScalableImageDecoderFrame&, bool allDataReceived);
+
+    std::unique_ptr<AVIFImageReader> m_reader { nullptr };
+};
+
+} // namespace WebCore

Added: trunk/Source/WebCore/platform/image-decoders/avif/AVIFImageReader.cpp (0 => 273970)


--- trunk/Source/WebCore/platform/image-decoders/avif/AVIFImageReader.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/image-decoders/avif/AVIFImageReader.cpp	2021-03-05 16:15:08 UTC (rev 273970)
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2021 Igalia S.L. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AVIFImageReader.h"
+
+#include "AVIFImageDecoder.h"
+
+namespace WebCore {
+
+AVIFImageReader::AVIFImageReader(RefPtr<AVIFImageDecoder>&& decoder)
+    : m_decoder(WTFMove(decoder))
+    , m_avifDecoder(avifDecoderCreate())
+{
+}
+
+AVIFImageReader::~AVIFImageReader()
+{
+}
+
+void AVIFImageReader::parseHeader(const SharedBuffer::DataSegment& data, bool allDataReceived)
+{
+    avifROData avifData;
+    avifData.data = "" uint8_t*>(data.data());
+    avifData.size = data.size();
+
+    if (!avifPeekCompatibleFileType(&avifData)) {
+        m_decoder->setFailed();
+        return;
+    }
+
+    if (avifDecoderParse(m_avifDecoder.get(), &avifData) != AVIF_RESULT_OK
+        || avifDecoderNextImage(m_avifDecoder.get()) != AVIF_RESULT_OK) {
+        m_decoder->setFailed();
+        return;
+    }
+
+    if (!m_dataParsed && allDataReceived)
+        m_dataParsed = true;
+
+    const avifImage* firstImage = m_avifDecoder->image;
+    m_decoder->setSize(IntSize(firstImage->width, firstImage->height));
+}
+
+void AVIFImageReader::decodeFrame(size_t frameIndex, ScalableImageDecoderFrame& buffer, const SharedBuffer::DataSegment& data)
+{
+    if (m_decoder->failed())
+        return;
+
+    if (!m_dataParsed) {
+        avifROData avifData;
+        avifData.data = "" uint8_t*>(data.data());
+        avifData.size = data.size();
+
+        if (avifDecoderParse(m_avifDecoder.get(), &avifData) != AVIF_RESULT_OK) {
+            m_decoder->setFailed();
+            return;
+        }
+
+        if (m_decoder->isAllDataReceived())
+            m_dataParsed = true;
+    }
+
+    if (avifDecoderNthImage(m_avifDecoder.get(), frameIndex) != AVIF_RESULT_OK) {
+        m_decoder->setFailed();
+        return;
+    }
+
+    IntSize imageSize(m_decoder->size());
+    if (buffer.isInvalid() && !buffer.initialize(imageSize, m_decoder->premultiplyAlpha())) {
+        m_decoder->setFailed();
+        return;
+    }
+
+    buffer.setDecodingStatus(DecodingStatus::Partial);
+
+    avifRGBImage decodedRGBImage;
+    avifRGBImageSetDefaults(&decodedRGBImage, m_avifDecoder->image);
+    decodedRGBImage.depth = 8;
+    decodedRGBImage.format = AVIF_RGB_FORMAT_BGRA;
+    decodedRGBImage.rowBytes = imageSize.width() * sizeof(uint32_t);
+    decodedRGBImage.pixels = reinterpret_cast<uint8_t*>(buffer.backingStore()->pixelAt(0, 0));
+    if (avifImageYUVToRGB(m_avifDecoder->image, &decodedRGBImage) != AVIF_RESULT_OK) {
+        m_decoder->setFailed();
+        return;
+    }
+
+    buffer.setHasAlpha(avifRGBFormatHasAlpha(decodedRGBImage.format));
+    buffer.setDecodingStatus(DecodingStatus::Complete);
+}
+
+}

Added: trunk/Source/WebCore/platform/image-decoders/avif/AVIFImageReader.h (0 => 273970)


--- trunk/Source/WebCore/platform/image-decoders/avif/AVIFImageReader.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/image-decoders/avif/AVIFImageReader.h	2021-03-05 16:15:08 UTC (rev 273970)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2021 Igalia S.L. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "AVIFImageDecoder.h"
+
+#include "AVIFUniquePtr.h"
+
+namespace WebCore {
+
+class ScalableImageDecoderFrame;
+
+class AVIFImageReader {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    AVIFImageReader(RefPtr<AVIFImageDecoder>&&);
+    ~AVIFImageReader();
+
+    void parseHeader(const SharedBuffer::DataSegment&, bool allDataReceived);
+    void decodeFrame(size_t index, ScalableImageDecoderFrame&, const SharedBuffer::DataSegment&);
+
+private:
+    RefPtr<WebCore::AVIFImageDecoder> m_decoder;
+    AVIFUniquePtr<avifDecoder> m_avifDecoder;
+
+    bool m_dataParsed { false };
+};
+
+}

Added: trunk/Source/WebCore/platform/image-decoders/avif/AVIFUniquePtr.h (0 => 273970)


--- trunk/Source/WebCore/platform/image-decoders/avif/AVIFUniquePtr.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/image-decoders/avif/AVIFUniquePtr.h	2021-03-05 16:15:08 UTC (rev 273970)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2021 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <avif/avif.h>
+#include <memory>
+
+namespace WebCore {
+
+template<typename T> struct AVIFPtrDeleter {
+    void operator()(T* ptr) const = delete;
+};
+
+template<typename T>
+using AVIFUniquePtr = std::unique_ptr<T, AVIFPtrDeleter<T>>;
+
+template<> struct AVIFPtrDeleter<avifDecoder> {
+    void operator() (avifDecoder* ptr) const
+    {
+        avifDecoderDestroy(ptr);
+    }
+};
+
+} // namespace WebCore

Added: trunk/Source/cmake/FindAVIF.cmake (0 => 273970)


--- trunk/Source/cmake/FindAVIF.cmake	                        (rev 0)
+++ trunk/Source/cmake/FindAVIF.cmake	2021-03-05 16:15:08 UTC (rev 273970)
@@ -0,0 +1,111 @@
+# Copyright (C) 2021 Igalia S.L.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+# THE POSSIBILITY OF SUCH DAMAGE.
+
+#[=======================================================================[.rst:
+FindAVIF
+--------
+
+Find libavif headers and libraries.
+
+Imported Targets
+^^^^^^^^^^^^^^^^
+
+``AVIF::AVIF``
+  The AVIF library, if found.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This will define the following variables in your project:
+
+``AVIF_FOUND``
+  true if (the requested version of) AVIF is available.
+``AVIF_VERSION``
+  the version of AVIF.
+``AVIF_LIBRARIES``
+  the libraries to link against to use AVIF.
+``AVIF_INCLUDE_DIRS``
+  where to find the AVIF headers.
+``AVIF_COMPILE_OPTIONS``
+  this should be passed to target_compile_options(), if the
+  target is not used for linking
+
+#]=======================================================================]
+
+find_package(PkgConfig)
+pkg_check_modules(PC_AVIF QUIET libavif)
+set(AVIF_COMPILE_OPTIONS ${PC_AVIF_CFLAGS_OTHER})
+set(AVIF_VERSION ${PC_AVIF_VERSION})
+
+find_path(AVIF_INCLUDE_DIR
+    NAMES avif.h
+    HINTS ${PC_AVIF_INCLUDEDIR}
+          ${PC_AVIF_INCLUDE_DIRS}
+    PATH_SUFFIXES avif
+)
+
+find_library(AVIF_LIBRARY
+    NAMES ${AVIF_NAMES} avif
+    HINTS ${PC_AVIF_LIBDIR}
+          ${PC_AVIF_LIBRARY_DIRS}
+)
+
+if (AVIF_INCLUDE_DIR AND NOT AVIF_VERSION)
+    if (EXISTS "${AVIF_INCLUDE_DIR}/avif.h")
+        file(READ "${AVIF_INCLUDE_DIR}/avif.h" AVIF_VERSION_CONTENT)
+
+        string(REGEX MATCH "#define +AVIF_VERSION_MAJOR +([0-9]+)" _dummy "${AVIF_VERSION_CONTENT}")
+        set(AVIF_VERSION_MAJOR "${CMAKE_MATCH_1}")
+
+        string(REGEX MATCH "#define +AVIF_VERSION_MINOR +([0-9]+)" _dummy "${AVIF_VERSION_CONTENT}")
+        set(AVIF_VERSION_MINOR "${CMAKE_MATCH_1}")
+
+        string(REGEX MATCH "#define +AVIF_VERSION_PATCH +([0-9]+)" _dummy "${AVIF_VERSION_CONTENT}")
+        set(AVIF_VERSION_PATCH "${CMAKE_MATCH_1}")
+
+        set(AVIF_VERSION "${AVIF_VERSION_MAJOR}.${AVIF_VERSION_MINOR}.${AVIF_VERSION_PATCH}")
+    endif ()
+endif ()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(AVIF
+    FOUND_VAR AVIF_FOUND
+    REQUIRED_VARS AVIF_INCLUDE_DIR AVIF_LIBRARY
+    VERSION_VAR AVIF_VERSION
+)
+
+if (AVIF_LIBRARY AND NOT TARGET AVIF::AVIF)
+    add_library(AVIF::AVIF UNKNOWN IMPORTED GLOBAL)
+    set_target_properties(AVIF::AVIF PROPERTIES
+        IMPORTED_LOCATION "${AVIF_LIBRARY}"
+        INTERFACE_COMPILE_OPTIONS "${AVIF_COMPILE_OPTIONS}"
+        INTERFACE_INCLUDE_DIRECTORIES "${AVIF_INCLUDE_DIR}"
+    )
+endif ()
+
+mark_as_advanced(AVIF_INCLUDE_DIR AVIF_LIBRARY)
+
+if (AVIF_FOUND)
+    set(AVIF_LIBRARIES ${AVIF_LIBRARY})
+    set(AVIF_INCLUDE_DIRS ${AVIF_INCLUDE_DIR})
+endif ()

Modified: trunk/Source/cmake/OptionsGTK.cmake (273969 => 273970)


--- trunk/Source/cmake/OptionsGTK.cmake	2021-03-05 16:10:35 UTC (rev 273969)
+++ trunk/Source/cmake/OptionsGTK.cmake	2021-03-05 16:15:08 UTC (rev 273970)
@@ -105,6 +105,7 @@
 # Private options specific to the GTK port. Changing these options is
 # completely unsupported. They are intended for use only by WebKit developers.
 WEBKIT_OPTION_DEFINE(USE_ANGLE_WEBGL "Whether to use ANGLE as WebGL backend." PRIVATE OFF)
+WEBKIT_OPTION_DEFINE(USE_AVIF "Whether to enable support for AVIF images." PRIVATE OFF)
 
 WEBKIT_OPTION_DEPEND(ENABLE_3D_TRANSFORMS USE_OPENGL_OR_ES)
 WEBKIT_OPTION_DEPEND(ENABLE_ASYNC_SCROLLING USE_OPENGL_OR_ES)
@@ -393,6 +394,13 @@
     endif ()
 endif ()
 
+if (USE_AVIF)
+    find_package(AVIF 0.7.3)
+    if (NOT AVIF_FOUND)
+        message(FATAL_ERROR "libavif 0.7.3 is required for USE_AVIF.")
+    endif ()
+endif ()
+
 if (USE_SYSTEMD)
     find_package(Systemd)
     if (Systemd_FOUND)

Modified: trunk/Tools/ChangeLog (273969 => 273970)


--- trunk/Tools/ChangeLog	2021-03-05 16:10:35 UTC (rev 273969)
+++ trunk/Tools/ChangeLog	2021-03-05 16:15:08 UTC (rev 273970)
@@ -1,3 +1,20 @@
+2021-03-05  ChangSeok Oh  <changs...@webkit.org>
+
+        AVIF decoding support
+        https://bugs.webkit.org/show_bug.cgi?id=207750
+
+        Reviewed by Philippe Normand.
+
+        This patch brings an initial support of AVIF image format to the gtk port.
+        AVIF is a new royalty-free image format derived from the keyframes of AV1 video.
+        FireFox and Chromium-variant browsers already support it. Its specification can be found
+        at https://rawcdn.githack.com/AOMediaCodec/av1-avif/67a92add6cd642a8863e386fa4db87954a6735d1/index.html
+        This patch aims to land a build option for AVIF and a basic decoding ability
+        for still images by using libavif. Animated AVIF images will be covered later.
+
+        * gtk/install-dependencies: Add dependencies of libavif for jhbuild
+        * gtk/jhbuild.modules: Add libavif for jhbuild
+
 2021-03-05  Chris Dumez  <cdu...@apple.com>
 
         Reduce use of CFRetain() / CFRelease() / CFAutoRelease() in WebKit

Modified: trunk/Tools/gtk/install-dependencies (273969 => 273970)


--- trunk/Tools/gtk/install-dependencies	2021-03-05 16:10:35 UTC (rev 273969)
+++ trunk/Tools/gtk/install-dependencies	2021-03-05 16:15:08 UTC (rev 273970)
@@ -147,6 +147,7 @@
         libxtst-dev \
         libxslt1-dev \
         libwayland-dev \
+        nasm \
         ninja-build \
         patch \
         ruby \
@@ -513,6 +514,7 @@
         libwayland-client-devel \
         libwayland-server-devel \
         mesa-libGL-devel \
+        nasm \
         ninja-build \
         openjpeg2-devel \
         openssl-devel \

Modified: trunk/Tools/gtk/jhbuild.modules (273969 => 273970)


--- trunk/Tools/gtk/jhbuild.modules	2021-03-05 16:10:35 UTC (rev 273969)
+++ trunk/Tools/gtk/jhbuild.modules	2021-03-05 16:15:08 UTC (rev 273970)
@@ -7,6 +7,7 @@
 
   <metamodule id="webkitgtk-testing-dependencies">
     <dependencies>
+      <dep package="avif"/>
       <dep package="cairo"/>
       <dep package="fonts"/>
       <dep package="dicts"/>
@@ -85,6 +86,8 @@
       href=""
   <repository type="tarball" name="wpewebkit"
       href=""
+  <repository type="tarball" name="downloads.videolan.org"
+      href=""
 
   <autotools id="cairo"
              autogen-sh="configure">
@@ -123,6 +126,25 @@
     <branch repo="github.com" module="WebKitGTK/webkitgtk-test-fonts.git" checkoutdir="webkitgtk-test-fonts" tag="0.0.8"/>
   </autotools>
 
+  <meson id="dav1d">
+    <branch repo="downloads.videolan.org"
+            module="/pub/videolan/dav1d/0.7.0/dav1d-0.7.0.tar.xz"
+            version="0.7.0"
+            hash="sha256:d3e2445006b9be4cf53625e7e37cf1693eca1aa361868e7ff5f309e2549e9e75">
+    </branch>
+  </meson>
+
+  <cmake id="avif" cmakeargs="-DCMAKE_BUILD_TYPE=Release -DAVIF_CODEC_DAV1D=ON">
+    <dependencies>
+      <dep package="dav1d"/>
+    </dependencies>
+    <branch repo="github-tarball"
+            module="AOMediaCodec/libavif/archive/v${version}.tar.gz"
+            checkoutdir="libavif-${version}"
+            version="0.7.3"
+            hash="sha256:a4ce03649c58ec9f3dc6ab2b7cf7d58474b149acf1e4c563be4081bad60ed2dd"/>
+  </cmake>
+
   <autotools id="dicts" supports-non-srcdir-builds="no"
              skip-autogen="true">
     <branch repo="github.com" module="mrobinson/webkitgtk-test-dicts.git" checkoutdir="webkitgtk-test-dicts" tag="0.0.1"/>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to