Skip to content

Commit

Permalink
Merge pull request #255 from Tom94/support-avif
Browse files Browse the repository at this point in the history
feat: add support for .avif images
  • Loading branch information
Tom94 authored Feb 23, 2025
2 parents 409fc00 + a147794 commit b037470
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 28 deletions.
19 changes: 19 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,45 +1,64 @@
[submodule "dependencies/args"]
path = dependencies/args
url = https://github.com/Taywee/args
shallow = true
[submodule "dependencies/Imath"]
path = dependencies/Imath
url = https://github.com/AcademySoftwareFoundation/Imath
shallow = true
[submodule "dependencies/openexr"]
path = dependencies/openexr
url = https://github.com/AcademySoftwareFoundation/openexr
shallow = true
[submodule "dependencies/zlib"]
path = dependencies/zlib
url = https://github.com/Tom94/zlib
shallow = true
[submodule "dependencies/utfcpp"]
path = dependencies/utfcpp
url = https://github.com/Tom94/utfcpp
shallow = true
[submodule "dependencies/tinylogger"]
path = dependencies/tinylogger
url = https://github.com/Tom94/tinylogger
shallow = true
[submodule "dependencies/clip"]
path = dependencies/clip
url = https://github.com/Tom94/clip
shallow = true
[submodule "dependencies/DirectXTex"]
path = dependencies/DirectXTex
url = https://github.com/Tom94/DirectXTex
shallow = true
[submodule "dependencies/nanogui"]
path = dependencies/nanogui
url = https://github.com/Tom94/nanogui-1
shallow = true
[submodule "dependencies/qoi"]
path = dependencies/qoi
url = https://github.com/phoboslab/qoi.git
shallow = true
[submodule "dependencies/fmt"]
path = dependencies/fmt
url = https://github.com/fmtlib/fmt
shallow = true
[submodule "scripts/create-dmg"]
path = scripts/create-dmg
url = https://github.com/create-dmg/create-dmg
shallow = true
[submodule "dependencies/libdeflate"]
path = dependencies/libdeflate
url = https://github.com/ebiggers/libdeflate
shallow = true
[submodule "dependencies/libheif"]
path = dependencies/libheif
url = https://github.com/Tom94/libheif
shallow = true
[submodule "dependencies/libde265"]
path = dependencies/libde265
url = https://github.com/strukturag/libde265
shallow = true
[submodule "dependencies/aom"]
path = dependencies/aom
url = https://github.com/Tom94/aom
shallow = true
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
set(TEV_VERSION_ARCH "${TEV_VERSION} (32 bit)")
endif()

option(TEV_SUPPORT_AVIF "Support loading AVIF images" ON)
option(TEV_SUPPORT_HEIC "Support loading HEIC images" OFF)

set(TEV_USE_LIBHEIF ${TEV_SUPPORT_HEIC}) # If other codecs supported by heif are used, adjust this condition.
set(TEV_USE_LIBHEIF ${TEV_SUPPORT_AVIF} OR ${TEV_SUPPORT_HEIC})

# Set ourselves as the startup project in visual studio.
# Not available until cmake 3.6, but doesn't break older versions.
Expand Down Expand Up @@ -244,6 +245,9 @@ if (APPLE)
# in keeping the warnings around.
set(TEV_DEFINITIONS ${TEV_DEFINITIONS} -DGL_SILENCE_DEPRECATION)
endif()
if (TEV_SUPPORT_AVIF)
set(TEV_DEFINITIONS ${TEV_DEFINITIONS} -DTEV_SUPPORT_AVIF)
endif()
if (TEV_SUPPORT_HEIC)
set(TEV_DEFINITIONS ${TEV_DEFINITIONS} -DTEV_SUPPORT_HEIC)
endif()
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ $ cpack --config build/CPackConfig.cmake
- __QOI__ (via [qoi](https://github.com/phoboslab/qoi). Shoutout to [Tiago Chaves](https://github.com/laurelkeys) for adding support!)
- __DDS__ (via [DirectXTex](https://github.com/microsoft/DirectXTex); Windows only. Shoutout to [Craig Kolb](https://github.com/cek) for adding support!)
- Supports BC1-BC7 compressed formats.
- __AVIF__ (via [aom](https://aomedia.googlesource.com/aom)+[libheif](https://github.com/strukturag/libheif))
- __HEIC__ (via [libde265](https://github.com/strukturag/libde265)+[libheif](https://github.com/strukturag/libheif); disabled in binary release. You must build __tev__ yourself with the `TEV_SUPPORT_HEIC` CMake option. Check patent laws in your juristiction before enabling this feature.)

## License
Expand Down
60 changes: 39 additions & 21 deletions dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,16 @@ if (WIN32)
include_directories(${DIRECTXTEX_INCLUDE_DIR})
endif()

# Compile OpenEXR
set(IMATH_INSTALL OFF CACHE BOOL " " FORCE)
set(IMATH_INSTALL_PKG_CONFIG OFF CACHE BOOL " " FORCE)
add_subdirectory(Imath)

set(LIBDEFLATE_BUILD_SHARED_LIB OFF CACHE BOOL " " FORCE)
set(LIBDEFLATE_BUILD_GZIP OFF CACHE BOOL " " FORCE)
add_subdirectory(libdeflate EXCLUDE_FROM_ALL)

set(OPENEXR_FORCE_INTERNAL_DEFLATE ON CACHE BOOL " " FORCE)
set(EXR_DEFLATE_LIB libdeflate::libdeflate_static)
# Compile aom (dependency of libheif, which follows)
if (TEV_SUPPORT_AVIF)
set(AOM_TARGET_CPU "generic" CACHE STRING " " FORCE)
set(BUILD_SHARED_LIBS OFF CACHE BOOL " " FORCE)
set(ENABLE_DOCS OFF CACHE BOOL " " FORCE)
add_subdirectory(aom EXCLUDE_FROM_ALL)

set(OPENEXR_INSTALL OFF CACHE BOOL " " FORCE)
set(OPENEXR_INSTALL_TOOLS OFF CACHE BOOL " " FORCE)
set(OPENEXR_INSTALL_PKG_CONFIG OFF CACHE BOOL " " FORCE)
set(OPENEXR_BUILD_EXAMPLES OFF CACHE BOOL " " FORCE)
set(OPENEXR_BUILD_TOOLS OFF CACHE BOOL " " FORCE)
add_subdirectory(openexr)
set(AOM_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/aom" CACHE PATH " " FORCE)
set(AOM_LIBRARY aom)
endif()

# Compile libde265 (dependency of libheif, which follows)
if (TEV_SUPPORT_HEIC)
Expand All @@ -76,7 +68,6 @@ if (TEV_SUPPORT_HEIC)

set(LIBDE265_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libde265" CACHE PATH " " FORCE)
set(LIBDE265_LIBRARY de265)
include_directories("${CMAKE_CURRENT_BINARY_DIR}/libde265")
endif()

# Compile libheif
Expand All @@ -87,28 +78,55 @@ if (TEV_USE_LIBHEIF)
set(WITH_EXAMPLES OFF CACHE BOOL " " FORCE)
set(WITH_FUZZERS OFF CACHE BOOL " " FORCE)
set(WITH_GDK_PIXBUF OFF CACHE BOOL " " FORCE)
set(WITH_INSTALL OFF CACHE BOOL " " FORCE)

# Codecs
set(WITH_LIBDE265 ${TEV_SUPPORT_HEIC})
set(WITH_X265 OFF CACHE BOOL " " FORCE)
set(WITH_OpenH264_ENCODER OFF CACHE BOOL " " FORCE)
set(WITH_OpenH264_DECODER OFF CACHE BOOL " " FORCE)

# TODO: Add aom as dependency to let libheif decode avif images for us.
# Also consider adding JPEG2000 support via libheif.
set(WITH_AOM_ENCODER OFF CACHE BOOL " " FORCE)
set(WITH_AOM_DECODER OFF CACHE BOOL " " FORCE)
set(WITH_AOM_DECODER ${TEV_SUPPORT_AVIF} CACHE BOOL " " FORCE)

# TODO: Also consider adding JPEG2000 support via libheif.

# libsharpyuv is not needed for us, because we're not interested in converting from RGB to YUV. tev is primarily an image viewer that
# goes from YUV to RGB upon loading images, where libsharpyuv does nothing. See https://www.ctrl.blog/entry/webp-sharp-yuv.html for more
# info.
set(WITH_LIBSHARPYUV OFF CACHE BOOL " " FORCE)

add_subdirectory(libheif EXCLUDE_FROM_ALL)
target_include_directories(heif PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/aom")
target_include_directories(heif PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/libde265")

set(LIBHEIF_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/libheif/libheif/api" "${CMAKE_CURRENT_BINARY_DIR}/libheif" PARENT_SCOPE)
endif()

# Compile OpenEXR
set(IMATH_INSTALL OFF CACHE BOOL " " FORCE)
set(IMATH_INSTALL_PKG_CONFIG OFF CACHE BOOL " " FORCE)
add_subdirectory(Imath)

set(LIBDEFLATE_BUILD_SHARED_LIB OFF CACHE BOOL " " FORCE)
set(LIBDEFLATE_BUILD_GZIP OFF CACHE BOOL " " FORCE)
add_subdirectory(libdeflate EXCLUDE_FROM_ALL)

set(OPENEXR_FORCE_INTERNAL_DEFLATE ON CACHE BOOL " " FORCE)
set(EXR_DEFLATE_LIB libdeflate::libdeflate_static)

set(OPENEXR_INSTALL OFF CACHE BOOL " " FORCE)
set(OPENEXR_INSTALL_TOOLS OFF CACHE BOOL " " FORCE)
set(OPENEXR_INSTALL_PKG_CONFIG OFF CACHE BOOL " " FORCE)
set(OPENEXR_BUILD_EXAMPLES OFF CACHE BOOL " " FORCE)
set(OPENEXR_BUILD_TOOLS OFF CACHE BOOL " " FORCE)
add_subdirectory(openexr)

if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# Fix compilation on Linux when code security checks are enabled
target_compile_definitions(OpenEXRCore PRIVATE _GNU_SOURCE)
endif()

# Compile clip
set(CLIP_EXAMPLES OFF CACHE BOOL " " FORCE)
set(CLIP_TESTS OFF CACHE BOOL " " FORCE)
Expand Down
2 changes: 1 addition & 1 deletion dependencies/Imath
Submodule Imath updated 70 files
+22 −0 .github/dependabot.yml
+6 −6 .github/workflows/analysis_workflow.yml
+203 −0 .github/workflows/ci_steps.yml
+106 −501 .github/workflows/ci_workflow.yml
+86 −0 .github/workflows/ci_workflow_old.yml
+91 −0 .github/workflows/codeql.yml
+4 −1 .github/workflows/release-notice.yml
+23 −10 .github/workflows/release-sign.yml
+56 −0 .github/workflows/scorecard.yml
+41 −0 .github/workflows/website_preview_link.yml
+2 −0 .gitignore
+9 −6 CMakeLists.txt
+1 −0 README.md
+22 −4 config/LibraryDefine.cmake
+45 −0 share/ci/install_manifest/install_manifest.macos.1.txt
+45 −0 share/ci/install_manifest/install_manifest.macos.2.txt
+42 −0 share/ci/install_manifest/install_manifest.macos.3.txt
+44 −0 share/ci/install_manifest/install_manifest.macos.4.txt
+45 −0 share/ci/install_manifest/install_manifest.macos.5.txt
+99 −0 share/ci/install_manifest/install_manifest.ubuntu.1.txt
+99 −0 share/ci/install_manifest/install_manifest.ubuntu.2.txt
+93 −0 share/ci/install_manifest/install_manifest.ubuntu.3.txt
+44 −0 share/ci/install_manifest/install_manifest.ubuntu.4.txt
+99 −0 share/ci/install_manifest/install_manifest.ubuntu.5.txt
+99 −0 share/ci/install_manifest/install_manifest.ubuntu.6.txt
+99 −0 share/ci/install_manifest/install_manifest.ubuntu.7.txt
+43 −0 share/ci/install_manifest/install_manifest.windows.1.txt
+43 −0 share/ci/install_manifest/install_manifest.windows.2.txt
+42 −0 share/ci/install_manifest/install_manifest.windows.3.txt
+42 −0 share/ci/install_manifest/install_manifest.windows.5.txt
+43 −0 share/ci/install_manifest/install_manifest.windows.6.txt
+145 −0 share/ci/scripts/validate_install.py
+11 −0 src/Imath/CMakeLists.txt
+56 −86 src/Imath/ImathBox.h
+4 −4 src/Imath/ImathColor.h
+10 −12 src/Imath/ImathEuler.h
+19 −15 src/Imath/ImathFrame.h
+6 −6 src/Imath/ImathMatrix.h
+6 −6 src/Imath/ImathMatrixAlgo.cpp
+8 −8 src/Imath/ImathMatrixAlgo.h
+3 −1 src/Imath/ImathPlatform.h
+14 −2 src/Imath/ImathShear.h
+187 −16 src/Imath/ImathVec.h
+7 −5 src/Imath/half.h
+4 −0 src/ImathTest/CMakeLists.txt
+17 −0 src/pybind11/CMakeLists.txt
+123 −0 src/pybind11/PyBindImath/CMakeLists.txt
+28 −0 src/pybind11/PyBindImath/PyBindImath.h
+17 −0 src/pybind11/PyBindImath/PyBindImath.pc.in
+7 −7 src/pybind11/PyBindImath/PyBindImathBox.cpp
+85 −0 src/pybind11/PyBindImath/PyBindImathEuler.cpp
+7 −7 src/pybind11/PyBindImath/PyBindImathExport.h
+59 −0 src/pybind11/PyBindImath/PyBindImathFrustum.cpp
+30 −0 src/pybind11/PyBindImath/PyBindImathLine.cpp
+53 −0 src/pybind11/PyBindImath/PyBindImathPlane.cpp
+9 −9 src/pybind11/PyBindImath/PyBindImathVec.cpp
+11 −6 src/pybind11/PyBindImath/pybindimathmodule.cpp
+4 −13 src/python/CMakeLists.txt
+0 −18 src/python/PyBindImath/CMakeLists.txt
+0 −25 src/python/PyBindImath/PyImath.h
+2 −2 src/python/PyImath/PyImath.h
+31 −31 src/python/PyImath/PyImathBufferProtocol.cpp
+24 −2 src/python/PyImath/PyImathFixedArray.h
+2 −2 src/python/PyImath/PyImathFixedVArray.cpp
+1 −1 src/python/PyImath/PyImathQuatOperators.h
+1 −1 src/python/PyImath/PyImathVec2Impl.h
+11 −11 src/python/PyImath/imathmodule.cpp
+1 −1 src/python/PyImathNumpy/imathnumpymodule.cpp
+530 −530 src/python/PyImathTest/main.cpp
+1 −1 website/requirements.txt
1 change: 1 addition & 0 deletions dependencies/aom
Submodule aom added at 22de8e
2 changes: 1 addition & 1 deletion dependencies/libheif
Submodule libheif updated 1 files
+12 −10 libheif/CMakeLists.txt
2 changes: 1 addition & 1 deletion dependencies/openexr
Submodule openexr updated 477 files
3 changes: 3 additions & 0 deletions src/HelpWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ HelpWindow::HelpWindow(Widget* parent, bool supportsHdr, function<void()> closeC
addSpacer(about, 20);

addLibrary(about, "args", "", "Single-header argument parsing library");
#ifdef TEV_SUPPORT_AVIF
addLibrary(about, "aom", "", "Alliance for Open Media Video Codec");
#endif
addLibrary(about, "clip", "", "Cross-platform clipboard library");
addLibrary(about, "{fmt}", "", "Fast & safe formatting library");
addLibrary(about, "Glad", "", "Multi-language GL loader-generator");
Expand Down
7 changes: 5 additions & 2 deletions src/ImageViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1735,15 +1735,18 @@ void ImageViewer::toggleHelpWindow() {
void ImageViewer::openImageDialog() {
vector<string> paths = file_dialog(
{
// HDR formats
// HDR formats
#ifdef TEV_SUPPORT_AVIF
{"avif", "AV1 Image File" },
#endif
{"exr", "OpenEXR image" },
{"hdr", "HDR image" },
#ifdef TEV_SUPPORT_HEIC
{"heic", "High Efficiency Image Container" },
#endif
{"pfm", "Portable Float Map image" },
// LDR formats
{"bmp", "Bitmap Image File" },
{"bmp", "Bitmap image" },
{"gif", "Graphics Interchange Format image"},
{"jpg", "JPEG image" },
{"jpeg", "JPEG image" },
Expand Down

0 comments on commit b037470

Please sign in to comment.