Skip to content

Commit

Permalink
feat: Initial JPEG XL support for image input/output (AcademySoftware…
Browse files Browse the repository at this point in the history
…Foundation#4055)

Preliminary support for JPEG XL.

A variety of additions are needed, but this is a good start.
Top items on our to-do list (not necessarily in priority order):

- [ ] Document in builtinformats.rst
- [ ] Handle different pixel types -- right now, always reads/writes float.
- [ ] Compression options
- [ ] EXIF
- [ ] Test cases in the testsuite

---------

Signed-off-by: Peter Kovář <[email protected]>
  • Loading branch information
1div0 authored Mar 16, 2024
1 parent 3b92011 commit 41a26ca
Show file tree
Hide file tree
Showing 10 changed files with 858 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ _coverage/
/*.exr
/*.tif
/*.jpg
/*.jxl
/*.tx
/*.log
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ OpenImageIO consists of:
plugin can be found at runtime.

* Plugins implementing I/O for several popular image file formats,
including TIFF, JPEG/JFIF, OpenEXR, PNG, HDR/RGBE, ICO, BMP, Targa,
including TIFF, JPEG/JFIF, JPEG XL, OpenEXR, PNG, HDR/RGBE, ICO, BMP, Targa,
JPEG-2000, RMan Zfile, FITS, DDS, Softimage PIC, PNM, DPX, Cineon,
IFF, OpenVDB, Ptex, Photoshop PSD, Wavefront RLA, SGI, WebP,
GIF, DICOM, HEIF/HEIC/AVIF, many "RAW" digital camera formats, and a variety
Expand Down
6 changes: 6 additions & 0 deletions src/cmake/externalpackages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ if (NOT TARGET libjpeg-turbo::jpeg) # Try to find the non-turbo version
checked_find_package (JPEG REQUIRED)
endif ()

# JPEG XL
option (USE_JXL "Enable JPEG XL support" ON)
checked_find_package (JXL
VERSION_MIN 0.10.1
DEFINITIONS -DUSE_JXL=1)

# Pugixml setup. Normally we just use the version bundled with oiio, but
# some linux distros are quite particular about having separate packages so we
# allow this to be overridden to use the distro-provided package if desired.
Expand Down
45 changes: 45 additions & 0 deletions src/cmake/modules/FindJXL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright Contributors to the OpenImageIO project.
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO
#
# Module to find libjxl
#
# Will define:
# - JXL_FOUND
# - JXL_INCLUDES directory to include for libjxl headers
# - JXL_LIBRARIES libraries to link to

include (FindPackageHandleStandardArgs)

find_path(JXL_INCLUDE_DIR
NAMES jxl/decode.h jxl/encode.h)
mark_as_advanced(JXL_INCLUDE_DIR)

if (JXL_INCLUDE_DIR)
file (STRINGS "${JXL_INCLUDE_DIR}/jxl/version.h" TMP REGEX "^#define JPEGXL_MAJOR_VERSION .*$")
string (REGEX MATCHALL "[0-9]+" JPEGXL_MAJOR_VERSION ${TMP})
file (STRINGS "${JXL_INCLUDE_DIR}/jxl/version.h" TMP REGEX "^#define JPEGXL_MINOR_VERSION .*$")
string (REGEX MATCHALL "[0-9]+" JPEGXL_MINOR_VERSION ${TMP})
file (STRINGS "${JXL_INCLUDE_DIR}/jxl/version.h" TMP REGEX "^#define JPEGXL_PATCH_VERSION .*$")
string (REGEX MATCHALL "[0-9]+" JPEGXL_PATCH_VERSION ${TMP})
set (JXL_VERSION "${JPEGXL_MAJOR_VERSION}.${JPEGXL_MINOR_VERSION}.${JPEGXL_PATCH_VERSION}")
endif ()

find_library(JXL_LIBRARY
NAMES jxl)
mark_as_advanced (
JXL_LIBRARY
JXL_VERSION
)

find_library(JXL_THREADS_LIBRARY
NAMES jxl_threads)
mark_as_advanced(JXL_THREADS_LIBRARY)

find_package_handle_standard_args(JXL
REQUIRED_VARS JXL_LIBRARY JXL_THREADS_LIBRARY JXL_INCLUDE_DIR)

if(JXL_FOUND)
set(JXL_LIBRARIES ${JXL_LIBRARY} ${JXL_THREADS_LIBRARY})
set(JXL_INCLUDES ${JXL_INCLUDE_DIR})
endif(JXL_FOUND)
3 changes: 2 additions & 1 deletion src/iv/imageviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ IsSpecSrgb(const ImageSpec& spec)
// clang-format off
static const char *s_file_filters = ""
"Image Files (*.bmp *.cin *.dcm *.dds *.dpx *.fits *.gif *.hdr *.ico *.iff "
"*.jpg *.jpe *.jpeg *.jif *.jfif *.jfi *.jp2 *.j2k *.exr *.png *.pbm *.pgm "
"*.jpg *.jpe *.jpeg *.jif *.jfif *.jfi *.jp2 *.j2k *.jxl *.exr *.png *.pbm *.pgm "
"*.ppm *.psd *.ptex *.rla *.sgi *.rgb *.rgba *.bw *.int *.inta *.pic *.tga "
"*.tpic *.tif *.tiff *.tx *.env *.sm *.vsm *.vdb *.webp *.zfile);;"
"BMP (*.bmp);;"
Expand All @@ -78,6 +78,7 @@ static const char *s_file_filters = ""
"IFF (*.iff);;"
"JPEG (*.jpg *.jpe *.jpeg *.jif *.jfif *.jfi);;"
"JPEG-2000 (*.jp2 *.j2k);;"
"JPEG XL (*.jxl);;"
"OpenEXR (*.exr);;"
"OpenVDB (*.vdb);;"
"PhotoShop (*.psd);;"
Expand Down
12 changes: 12 additions & 0 deletions src/jpegxl.imageio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright Contributors to the OpenImageIO project.
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO

if (JXL_FOUND)
add_oiio_plugin (jxlinput.cpp jxloutput.cpp
INCLUDE_DIRS ${JXL_INCLUDE_DIRS}
LINK_LIBRARIES ${JXL_LIBRARIES}
DEFINITIONS "-DUSE_JXL")
else()
message (WARNING "JPEG XL plugin will not be built")
endif()
Loading

0 comments on commit 41a26ca

Please sign in to comment.