Title: [286011] trunk
Revision
286011
Author
[email protected]
Date
2021-11-18 10:05:05 -0800 (Thu, 18 Nov 2021)

Log Message

Implement JPEG XL image decoder using libjxl
https://bugs.webkit.org/show_bug.cgi?id=233113

Reviewed by Michael Catanzaro.

This patch introduces the initial version of JPEG XL image decoder.
JPEG XL is a royalty-free raster-graphics file format that supports
both lossy and lossless compression and is experimentally supported by
Chrome, FireFox, and Edge.
The image decoder implemented by this patch uses libjxl, a reference
implementation of JPEG XL decoder (and encoder). JPEG XL animations
will be supported later.

.:

* Source/cmake/FindJPEGXL.cmake: Added.
* Source/cmake/OptionsWinCairo.cmake: Enable JPEG XL support if
libjxl is available.

Source/WebCore:

Tests: LayoutTests\fast\images\jpegxl-as-image.html
       LayoutTests\fast\images\jpegxl-image-decoding.html

* platform/ImageDecoders.cmake: Add JPEGXLImageDecoder.cpp if
USE(JPEGXL) is turned on.
* platform/MIMETypeRegistry.cpp: JPEG XL mime type added.
* platform/image-decoders/ScalableImageDecoder.cpp: JPEG XL signature
added.
* platform/image-decoders/jpegxl/JPEGXLImageDecoder.cpp: Added.
* platform/image-decoders/jpegxl/JPEGXLImageDecoder.h: Added.
* platform/win/MIMETypeRegistryWin.cpp: The .jxl file extension added.

LayoutTests:

* TestExpectations: Skip JPEG XL tests by default.
* fast/images/jpegxl-as-image-expected.html: Added.
* fast/images/jpegxl-as-image.html: Added.
* fast/images/jpegxl-image-decoding-expected.txt: Added.
* fast/images/jpegxl-image-decoding.html: Added.
* fast/images/resources/green-313x313.jxl: Added.
* platform/wincairo/TestExpectations: Skip JPEG XL tests until
WebKitReqirements release with libjxl.

Modified Paths

Added Paths

Diff

Modified: trunk/ChangeLog (286010 => 286011)


--- trunk/ChangeLog	2021-11-18 17:58:57 UTC (rev 286010)
+++ trunk/ChangeLog	2021-11-18 18:05:05 UTC (rev 286011)
@@ -1,3 +1,22 @@
+2021-11-18  Yoshiaki Jitsukawa  <[email protected]>
+
+        Implement JPEG XL image decoder using libjxl
+        https://bugs.webkit.org/show_bug.cgi?id=233113
+
+        Reviewed by Michael Catanzaro.
+
+        This patch introduces the initial version of JPEG XL image decoder.
+        JPEG XL is a royalty-free raster-graphics file format that supports
+        both lossy and lossless compression and is experimentally supported by
+        Chrome, FireFox, and Edge.
+        The image decoder implemented by this patch uses libjxl, a reference
+        implementation of JPEG XL decoder (and encoder). JPEG XL animations
+        will be supported later.
+
+        * Source/cmake/FindJPEGXL.cmake: Added.
+        * Source/cmake/OptionsWinCairo.cmake: Enable JPEG XL support if
+        libjxl is available.
+
 2021-11-17  Patrick Angle  <[email protected]>
 
         Update my (Patrick Angle's) status to reviewer

Modified: trunk/LayoutTests/ChangeLog (286010 => 286011)


--- trunk/LayoutTests/ChangeLog	2021-11-18 17:58:57 UTC (rev 286010)
+++ trunk/LayoutTests/ChangeLog	2021-11-18 18:05:05 UTC (rev 286011)
@@ -1,3 +1,27 @@
+2021-11-18  Yoshiaki Jitsukawa  <[email protected]>
+
+        Implement JPEG XL image decoder using libjxl
+        https://bugs.webkit.org/show_bug.cgi?id=233113
+
+        Reviewed by Michael Catanzaro.
+
+        This patch introduces the initial version of JPEG XL image decoder.
+        JPEG XL is a royalty-free raster-graphics file format that supports
+        both lossy and lossless compression and is experimentally supported by
+        Chrome, FireFox, and Edge.
+        The image decoder implemented by this patch uses libjxl, a reference
+        implementation of JPEG XL decoder (and encoder). JPEG XL animations
+        will be supported later.
+
+        * TestExpectations: Skip JPEG XL tests by default.
+        * fast/images/jpegxl-as-image-expected.html: Added.
+        * fast/images/jpegxl-as-image.html: Added.
+        * fast/images/jpegxl-image-decoding-expected.txt: Added.
+        * fast/images/jpegxl-image-decoding.html: Added.
+        * fast/images/resources/green-313x313.jxl: Added.
+        * platform/wincairo/TestExpectations: Skip JPEG XL tests until
+        WebKitReqirements release with libjxl.
+
 2021-11-18  Martin Robinson  <[email protected]>
 
         Update css-transforms WPT tests

Modified: trunk/LayoutTests/TestExpectations (286010 => 286011)


--- trunk/LayoutTests/TestExpectations	2021-11-18 17:58:57 UTC (rev 286010)
+++ trunk/LayoutTests/TestExpectations	2021-11-18 18:05:05 UTC (rev 286011)
@@ -132,6 +132,10 @@
 fast/images/animated-avif.html [ Skip ]
 http/tests/images/avif-partial-load-crash.html [ Skip ]
 
+# These tests don't have to be platform-specific, but they are only implemented on WinCairo now.
+fast/images/jpegxl-image-decoding.html [ Skip ]
+fast/images/jpegxl-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/jpegxl-as-image-expected.html (0 => 286011)


--- trunk/LayoutTests/fast/images/jpegxl-as-image-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/jpegxl-as-image-expected.html	2021-11-18 18:05:05 UTC (rev 286011)
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<style>
+div {
+  width: 313px;
+  height: 313px;
+  background-color: #0AFF05;
+}
+</style>
+<body>
+  <div></div>
+</body>

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


--- trunk/LayoutTests/fast/images/jpegxl-as-image.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/jpegxl-as-image.html	2021-11-18 18:05:05 UTC (rev 286011)
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<body>
+  <picture>
+    <source srcset="resources/green-313x313.jxl" type="image/jxl">
+    <img src=""
+  </picture>
+</body>

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


--- trunk/LayoutTests/fast/images/jpegxl-image-decoding-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/images/jpegxl-image-decoding-expected.txt	2021-11-18 18:05:05 UTC (rev 286011)
@@ -0,0 +1,2 @@
+
+313x313

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


--- trunk/LayoutTests/fast/images/jpegxl-image-decoding.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/jpegxl-image-decoding.html	2021-11-18 18:05:05 UTC (rev 286011)
@@ -0,0 +1,18 @@
+<!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>
+<picture>
+  <source srcset="resources/green-313x313.jxl" type="image/jxl">
+  <img src=""
+</picture>
+<div id="results"></div>
+</body>

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


--- trunk/LayoutTests/fast/images/resources/green-313x313.jxl	                        (rev 0)
+++ trunk/LayoutTests/fast/images/resources/green-313x313.jxl	2021-11-18 18:05:05 UTC (rev 286011)
@@ -0,0 +1,3 @@
+\xFF
+\xC0P\��\x94��K($\xC6EBB��\xD4c\x8Cc\xDCD����(\x80\x94B\x80\xA4\xEA\xB1
+\xF3@IёA9
\ No newline at end of file

Modified: trunk/LayoutTests/platform/wincairo/TestExpectations (286010 => 286011)


--- trunk/LayoutTests/platform/wincairo/TestExpectations	2021-11-18 17:58:57 UTC (rev 286010)
+++ trunk/LayoutTests/platform/wincairo/TestExpectations	2021-11-18 18:05:05 UTC (rev 286011)
@@ -272,8 +272,10 @@
 # PLATFORM(MAC), internals.rangeForDictionaryLookupAtLocation()
 fast/layers/prevent-hit-test-during-layout.html [ Skip ]
 
+# JPEG XL is disabled until WebKitRequirements is released with libjxl
+fast/images/jpegxl-as-image.html [ Skip ]
+fast/images/jpegxl-image-decoding.html [ Skip ]
 
-
 # DataTransferItems is not yet implemented
 fast/events/clipboard-dataTransferItemList.html [ Skip ]
 fast/events/drag-dataTransferItemList.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (286010 => 286011)


--- trunk/Source/WebCore/ChangeLog	2021-11-18 17:58:57 UTC (rev 286010)
+++ trunk/Source/WebCore/ChangeLog	2021-11-18 18:05:05 UTC (rev 286011)
@@ -1,3 +1,30 @@
+2021-11-18  Yoshiaki Jitsukawa  <[email protected]>
+
+        Implement JPEG XL image decoder using libjxl
+        https://bugs.webkit.org/show_bug.cgi?id=233113
+
+        Reviewed by Michael Catanzaro.
+
+        This patch introduces the initial version of JPEG XL image decoder.
+        JPEG XL is a royalty-free raster-graphics file format that supports
+        both lossy and lossless compression and is experimentally supported by
+        Chrome, FireFox, and Edge.
+        The image decoder implemented by this patch uses libjxl, a reference
+        implementation of JPEG XL decoder (and encoder). JPEG XL animations
+        will be supported later.
+
+        Tests: LayoutTests\fast\images\jpegxl-as-image.html
+               LayoutTests\fast\images\jpegxl-image-decoding.html
+
+        * platform/ImageDecoders.cmake: Add JPEGXLImageDecoder.cpp if
+        USE(JPEGXL) is turned on.
+        * platform/MIMETypeRegistry.cpp: JPEG XL mime type added.
+        * platform/image-decoders/ScalableImageDecoder.cpp: JPEG XL signature
+        added.
+        * platform/image-decoders/jpegxl/JPEGXLImageDecoder.cpp: Added.
+        * platform/image-decoders/jpegxl/JPEGXLImageDecoder.h: Added.
+        * platform/win/MIMETypeRegistryWin.cpp: The .jxl file extension added.
+
 2021-11-18  Alan Bujtas  <[email protected]>
 
         [LFC][IFC] Should not always keep the entire continuous content when the line is empty

Modified: trunk/Source/WebCore/platform/ImageDecoders.cmake (286010 => 286011)


--- trunk/Source/WebCore/platform/ImageDecoders.cmake	2021-11-18 17:58:57 UTC (rev 286010)
+++ trunk/Source/WebCore/platform/ImageDecoders.cmake	2021-11-18 18:05:05 UTC (rev 286011)
@@ -6,6 +6,7 @@
     "${WEBCORE_DIR}/platform/image-decoders/ico"
     "${WEBCORE_DIR}/platform/image-decoders/jpeg"
     "${WEBCORE_DIR}/platform/image-decoders/jpeg2000"
+    "${WEBCORE_DIR}/platform/image-decoders/jpegxl"
     "${WEBCORE_DIR}/platform/image-decoders/png"
     "${WEBCORE_DIR}/platform/image-decoders/webp"
 )
@@ -29,6 +30,8 @@
 
     platform/image-decoders/jpeg2000/JPEG2000ImageDecoder.cpp
 
+    platform/image-decoders/jpegxl/JPEGXLImageDecoder.cpp
+
     platform/image-decoders/png/PNGImageDecoder.cpp
 
     platform/image-decoders/webp/WEBPImageDecoder.cpp
@@ -50,6 +53,10 @@
     )
 endif ()
 
+if (JPEGXL_FOUND)
+    list(APPEND WebCore_LIBRARIES JPEGXL::jxl)
+endif ()
+
 if (USE_CAIRO)
     list(APPEND WebCore_SOURCES
         platform/image-decoders/cairo/ImageBackingStoreCairo.cpp

Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.cpp (286010 => 286011)


--- trunk/Source/WebCore/platform/MIMETypeRegistry.cpp	2021-11-18 17:58:57 UTC (rev 286010)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.cpp	2021-11-18 18:05:05 UTC (rev 286011)
@@ -111,6 +111,9 @@
 #if !USE(CG) && USE(OPENJPEG)
     "image/jpeg2000",
 #endif
+#if USE(JPEGXL)
+    "image/jxl",
+#endif
 #if PLATFORM(IOS_FAMILY)
     "image/ms-bmp",
     "image/pipeg",

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


--- trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp	2021-11-18 17:58:57 UTC (rev 286010)
+++ trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp	2021-11-18 18:05:05 UTC (rev 286011)
@@ -39,6 +39,9 @@
 #if USE(WEBP)
 #include "WEBPImageDecoder.h"
 #endif
+#if USE(JPEGXL)
+#include "JPEGXLImageDecoder.h"
+#endif
 
 #include <algorithm>
 #include <cmath>
@@ -107,6 +110,14 @@
 }
 #endif
 
+#if USE(JPEGXL)
+bool matchesJPEGXLSignature(const uint8_t* contents, size_t length)
+{
+    JxlSignature signature = JxlSignatureCheck(contents, length);
+    return signature != JXL_SIG_NOT_ENOUGH_BYTES && signature != JXL_SIG_INVALID;
+}
+#endif
+
 bool matchesBMPSignature(char* contents)
 {
     return !memcmp(contents, "BM", 2);
@@ -162,6 +173,11 @@
         return WEBPImageDecoder::create(alphaOption, gammaAndColorProfileOption);
 #endif
 
+#if USE(JPEGXL)
+    if (matchesJPEGXLSignature(reinterpret_cast<const uint8_t*>(contents), length))
+        return JPEGXLImageDecoder::create(alphaOption, gammaAndColorProfileOption);
+#endif
+
     if (matchesBMPSignature(contents))
         return BMPImageDecoder::create(alphaOption, gammaAndColorProfileOption);
 

Added: trunk/Source/WebCore/platform/image-decoders/jpegxl/JPEGXLImageDecoder.cpp (0 => 286011)


--- trunk/Source/WebCore/platform/image-decoders/jpegxl/JPEGXLImageDecoder.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/image-decoders/jpegxl/JPEGXLImageDecoder.cpp	2021-11-18 18:05:05 UTC (rev 286011)
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2021 Sony Interactive Entertainment Inc.
+ *
+ * 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 COMPUTER, 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 COMPUTER, 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 "JPEGXLImageDecoder.h"
+
+#if USE(JPEGXL)
+
+namespace WebCore {
+
+JPEGXLImageDecoder::JPEGXLImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
+    : ScalableImageDecoder(alphaOption, gammaAndColorProfileOption)
+{
+}
+
+JPEGXLImageDecoder::~JPEGXLImageDecoder()
+{
+    clear();
+}
+
+ScalableImageDecoderFrame* JPEGXLImageDecoder::frameBufferAtIndex(size_t index)
+{
+    // TODO: To support animated JPEG XL in the future we need to handle second and subsequent frames.
+    if (index)
+        return nullptr;
+
+    if (m_frameBufferCache.isEmpty())
+        m_frameBufferCache.grow(1);
+
+    auto& frame = m_frameBufferCache[0];
+    if (!frame.isComplete())
+        decode(false, isAllDataReceived());
+    return &frame;
+}
+
+void JPEGXLImageDecoder::clear()
+{
+    m_decoder.reset();
+    m_readOffset = 0;
+}
+
+bool JPEGXLImageDecoder::setFailed()
+{
+    clear();
+    return ScalableImageDecoder::setFailed();
+}
+
+void JPEGXLImageDecoder::decode(bool onlySize, bool allDataReceived)
+{
+    if (failed())
+        return;
+
+    if (!m_decoder) {
+        clear();
+        m_decoder = JxlDecoderMake(nullptr);
+        if (!m_decoder) {
+            setFailed();
+            return;
+        }
+
+        if (JxlDecoderSubscribeEvents(m_decoder.get(), JXL_DEC_BASIC_INFO | JXL_DEC_FRAME | JXL_DEC_FULL_IMAGE) != JXL_DEC_SUCCESS) {
+            setFailed();
+            return;
+        }
+    }
+
+    m_data->data();
+    size_t dataSize = m_data->size();
+    if (JxlDecoderSetInput(m_decoder.get(), m_data->data() + m_readOffset, dataSize - m_readOffset) != JXL_DEC_SUCCESS) {
+        setFailed();
+        return;
+    }
+
+    JxlDecoderStatus status = processInput(onlySize);
+    // We set the status as failed if the decoder reports an error or requires more data while all data has been received.
+    if (status == JXL_DEC_ERROR || (allDataReceived && status == JXL_DEC_NEED_MORE_INPUT)) {
+        setFailed();
+        return;
+    }
+
+    // We release the decoder when we finish the decoding.
+    if (status == JXL_DEC_SUCCESS) {
+        clear();
+        return;
+    }
+
+    // Otherwise we get the decoder ready for subsequent data.
+    size_t remainingDataSize = JxlDecoderReleaseInput(m_decoder.get());
+    m_readOffset = dataSize - remainingDataSize;
+}
+
+JxlDecoderStatus JPEGXLImageDecoder::processInput(bool onlySize)
+{
+    while (true) {
+        auto status = JxlDecoderProcessInput(m_decoder.get());
+
+        // JXL_DEC_ERROR and JXL_DEC_SUCCESS are terminal states. We also exit from the loop if more data is needed.
+        if (status == JXL_DEC_ERROR || status == JXL_DEC_SUCCESS || status == JXL_DEC_NEED_MORE_INPUT)
+            return status;
+
+        if (status == JXL_DEC_BASIC_INFO) {
+            JxlBasicInfo basicInfo;
+            if (JxlDecoderGetBasicInfo(m_decoder.get(), &basicInfo) != JXL_DEC_SUCCESS)
+                return JXL_DEC_ERROR;
+
+            setSize(IntSize(basicInfo.xsize, basicInfo.ysize));
+            if (onlySize)
+                return status;
+            continue;
+        }
+
+        if (status == JXL_DEC_FRAME) {
+            JxlPixelFormat format { 4, JXL_TYPE_UINT8, JXL_NATIVE_ENDIAN, 0 };
+            if (JxlDecoderSetImageOutCallback(m_decoder.get(), &format, imageOutCallback, this) != JXL_DEC_SUCCESS)
+                return JXL_DEC_ERROR;
+            continue;
+        }
+
+        if (status == JXL_DEC_FULL_IMAGE) {
+            if (m_frameBufferCache.isEmpty())
+                continue;
+
+            auto& buffer = m_frameBufferCache[0];
+            if (!buffer.isInvalid())
+                buffer.setDecodingStatus(DecodingStatus::Complete);
+
+            // TODO: To support animated JPEG XL in the future we need to handle subsequent data.
+            return JXL_DEC_SUCCESS;
+        }
+    }
+}
+
+void JPEGXLImageDecoder::imageOutCallback(void* that, size_t x, size_t y, size_t numPixels, const void* pixels)
+{
+    static_cast<JPEGXLImageDecoder*>(that)->imageOut(x, y, numPixels, static_cast<const uint8_t*>(pixels));
+}
+
+void JPEGXLImageDecoder::imageOut(size_t x, size_t y, size_t numPixels, const uint8_t* pixels)
+{
+    if (m_frameBufferCache.isEmpty())
+        return;
+
+    auto& buffer = m_frameBufferCache[0];
+    if (buffer.isInvalid()) {
+        if (!buffer.initialize(size(), m_premultiplyAlpha))
+            return;
+
+        buffer.setDecodingStatus(DecodingStatus::Partial);
+        buffer.setHasAlpha(false);
+    }
+
+    uint32_t* row = buffer.backingStore()->pixelAt(x, y);
+    uint32_t* currentAddress = row;
+    for (size_t i = 0; i < numPixels; i++) {
+        uint8_t r = *pixels++;
+        uint8_t g = *pixels++;
+        uint8_t b = *pixels++;
+        uint8_t a = *pixels++;
+        buffer.backingStore()->setPixel(currentAddress++, r, g, b, a);
+    }
+}
+
+}
+#endif // USE(JPEGXL)

Added: trunk/Source/WebCore/platform/image-decoders/jpegxl/JPEGXLImageDecoder.h (0 => 286011)


--- trunk/Source/WebCore/platform/image-decoders/jpegxl/JPEGXLImageDecoder.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/image-decoders/jpegxl/JPEGXLImageDecoder.h	2021-11-18 18:05:05 UTC (rev 286011)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2021 Sony Interactive Entertainment Inc.
+ *
+ * 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 COMPUTER, 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 COMPUTER, 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"
+
+#if USE(JPEGXL)
+
+#include <jxl/decode_cxx.h>
+
+namespace WebCore {
+
+// This class decodes the JPEG XL image format.
+class JPEGXLImageDecoder final : public ScalableImageDecoder {
+public:
+    static Ref<ScalableImageDecoder> create(AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
+    {
+        return adoptRef(*new JPEGXLImageDecoder(alphaOption, gammaAndColorProfileOption));
+    }
+
+    virtual ~JPEGXLImageDecoder();
+
+    // ScalableImageDecoder
+    String filenameExtension() const override { return "jxl"_s; }
+    ScalableImageDecoderFrame* frameBufferAtIndex(size_t index) override;
+
+    bool setFailed() override;
+
+private:
+    JPEGXLImageDecoder(AlphaOption, GammaAndColorProfileOption);
+    void tryDecodeSize(bool allDataReceived) override { decode(true, allDataReceived); }
+
+    void decode(bool onlySize, bool allDataReceived);
+
+    void clear();
+
+    JxlDecoderStatus processInput(bool onlySize);
+
+    static void imageOutCallback(void* that, size_t x, size_t y, size_t numPixels, const void* pixels);
+    void imageOut(size_t x, size_t y, size_t numPixels, const uint8_t* pixels);
+
+    JxlDecoderPtr m_decoder;
+    size_t m_readOffset = 0;
+};
+
+} // namespace WebCore
+
+#endif // USE(JPEGXL)

Modified: trunk/Source/WebCore/platform/win/MIMETypeRegistryWin.cpp (286010 => 286011)


--- trunk/Source/WebCore/platform/win/MIMETypeRegistryWin.cpp	2021-11-18 17:58:57 UTC (rev 286010)
+++ trunk/Source/WebCore/platform/win/MIMETypeRegistryWin.cpp	2021-11-18 18:05:05 UTC (rev 286011)
@@ -99,6 +99,9 @@
         mimetypeMap.add("wml", "text/vnd.wap.wml");
         mimetypeMap.add("wmlc", "application/vnd.wap.wmlc");
         mimetypeMap.add("m4a", "audio/x-m4a");
+#if USE(JPEGXL)
+        mimetypeMap.add("jxl", "image/jxl");
+#endif
     }
     String result = mimetypeMap.get(ext);
     if (result.isEmpty()) {

Added: trunk/Source/cmake/FindJPEGXL.cmake (0 => 286011)


--- trunk/Source/cmake/FindJPEGXL.cmake	                        (rev 0)
+++ trunk/Source/cmake/FindJPEGXL.cmake	2021-11-18 18:05:05 UTC (rev 286011)
@@ -0,0 +1,93 @@
+# Copyright (C) 2021 Sony Interactive Entertainment Inc.
+#
+# 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:
+FindJPEGXL
+---------
+
+Find JPEGXL headers and libraries.
+
+Imported Targets
+^^^^^^^^^^^^^^^^
+
+``JPEGXL::jxl``
+  The JPEGXL library, if found.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This will define the following variables in your project:
+
+``JPEGXL_FOUND``
+  true if (the requested version of) JPEGXL is available.
+``JPEGXL_VERSION``
+  the version of JPEGXL.
+``JPEGXL_LIBRARIES``
+  the libraries to link against to use JPEGXL.
+``JPEGXL_INCLUDE_DIRS``
+  where to find the JPEGXL headers.
+``JPEGXL_COMPILE_OPTIONS``
+  this should be passed to target_compile_options(), if the
+  target is not used for linking
+
+#]=======================================================================]
+
+find_package(PkgConfig QUIET)
+if (PkgConfig_FOUND)
+    pkg_check_modules(PC_JPEGXL QUIET jxl)
+    set(JPEGXL_COMPILE_OPTIONS ${PC_JPEGXL_CFLAGS_OTHER})
+    set(JPEGXL_VERSION ${PC_JPEGXL_VERSION})
+endif ()
+
+find_path(JPEGXL_INCLUDE_DIR
+    NAMES jxl/decode.h
+    HINTS ${PC_JPEGXL_INCLUDEDIR} ${PC_JPEGXL_INCLUDE_DIRS} ${JPEGXL_INCLUDE_DIR}
+)
+
+find_library(JPEGXL_LIBRARY
+    NAMES ${JPEGXL_NAMES} jxl
+    HINTS ${PC_JPEGXL_LIBDIR} ${PC_JPEGXL_LIBRARY_DIRS}
+)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(JPEGXL
+    FOUND_VAR JPEGXL_FOUND
+    REQUIRED_VARS JPEGXL_LIBRARY JPEGXL_INCLUDE_DIR
+    VERSION_VAR JPEGXL_VERSION
+)
+
+if (JPEGXL_LIBRARY AND NOT TARGET JPEGXL::jxl)
+    add_library(JPEGXL::jxl UNKNOWN IMPORTED GLOBAL)
+    set_target_properties(JPEGXL::jxl PROPERTIES
+        IMPORTED_LOCATION "${JPEGXL_LIBRARY}"
+        INTERFACE_COMPILE_OPTIONS "${JPEGXL_COMPILE_OPTIONS}"
+        INTERFACE_INCLUDE_DIRECTORIES "${JPEGXL_INCLUDE_DIR}"
+    )
+endif ()
+
+mark_as_advanced(JPEGXL_INCLUDE_DIR JPEGXL_LIBRARY)
+
+if (JPEGXL_FOUND)
+    set(JPEGXL_LIBRARIES ${JPEGXL_LIBRARY})
+    set(JPEGXL_INCLUDE_DIRS ${JPEGXL_INCLUDE_DIR})
+endif ()

Modified: trunk/Source/cmake/OptionsWinCairo.cmake (286010 => 286011)


--- trunk/Source/cmake/OptionsWinCairo.cmake	2021-11-18 17:58:57 UTC (rev 286010)
+++ trunk/Source/cmake/OptionsWinCairo.cmake	2021-11-18 18:05:05 UTC (rev 286011)
@@ -26,6 +26,11 @@
     SET_AND_EXPOSE_TO_BUILD(USE_LCMS ON)
 endif ()
 
+find_package(JPEGXL)
+if (JPEGXL_FOUND)
+    SET_AND_EXPOSE_TO_BUILD(USE_JPEGXL ON)
+endif ()
+
 find_package(OpenJPEG 2.3.1)
 if (OpenJPEG_FOUND)
     SET_AND_EXPOSE_TO_BUILD(USE_OPENJPEG ON)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to