Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,12 @@
path = dependencies/LibRaw-cmake
url = https://github.com/Tom94/LibRaw-cmake
shallow = true
[submodule "dependencies/DirectXMath"]
path = dependencies/DirectXMath
url = https://github.com/Tom94/DirectXMath
shallow = true
[submodule "dependencies/DirectX-Headers"]
path = dependencies/DirectX-Headers
url = https://github.com/Tom94/DirectX-Headers
shallow = true

13 changes: 11 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ if (TEV_LINUX_REVERSE_DNS_APP_ID)
endif()

option(TEV_SUPPORT_AVIF "Support loading AVIF images" ON)
option(TEV_SUPPORT_DDS "Support loading DDS images" ON)
option(TEV_SUPPORT_HEIC "Support loading HEIC images" OFF)
option(TEV_SUPPORT_JXL "Support loading/saving JPEG XL images" ON)

Expand Down Expand Up @@ -200,10 +201,12 @@ set(TEV_SOURCES
if (MSVC)
list(APPEND TEV_SOURCES resources/windows/icon.rc)
list(APPEND TEV_SOURCES resources/windows/tev.manifest)
list(APPEND TEV_SOURCES include/tev/imageio/DdsImageLoader.h src/imageio/DdsImageLoader.cpp)
elseif (APPLE)
list(APPEND TEV_SOURCES resources/macos/icon.icns)
endif()
if (TEV_SUPPORT_DDS)
list(APPEND TEV_SOURCES include/tev/imageio/DdsImageLoader.h src/imageio/DdsImageLoader.cpp)
endif()
if (TEV_USE_LIBHEIF)
list(APPEND TEV_SOURCES include/tev/imageio/HeifImageLoader.h src/imageio/HeifImageLoader.cpp)
endif()
Expand Down Expand Up @@ -258,6 +261,9 @@ endif()
if (TEV_SUPPORT_AVIF)
list(APPEND TEV_DEFINITIONS -DTEV_SUPPORT_AVIF)
endif()
if (TEV_SUPPORT_DDS)
list(APPEND TEV_DEFINITIONS -DTEV_SUPPORT_DDS)
endif()
if (TEV_SUPPORT_HEIC)
list(APPEND TEV_DEFINITIONS -DTEV_SUPPORT_HEIC)
endif()
Expand All @@ -272,11 +278,14 @@ target_compile_definitions(tev PRIVATE ${TEV_DEFINITIONS})

set(TEV_LIBS cfitsio clip exif_static gdcm-tev JPEG::JPEG jxrglue libraw::libraw_r nanogui OpenEXR::OpenEXR openjpeg-tev png_static tiff webpdemux XMPCore xsimd)
if (MSVC)
list(APPEND TEV_LIBS DirectXTex wsock32 ws2_32)
list(APPEND TEV_LIBS wsock32 ws2_32)
endif()
if (TEV_USE_LIBHEIF)
list(APPEND TEV_LIBS lcms2-tev heif)
endif()
if (TEV_SUPPORT_DDS)
list(APPEND TEV_LIBS DirectXTex)
endif()
if (TEV_SUPPORT_JXL)
# jxl_dec for decoding, jxl_extras for gain maps, jxl_threads for threading support
list(APPEND TEV_LIBS jxl jxl_dec jxl_extras_nocodec-internal jxl_threads)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ $ cpack --config build/CPackConfig.cmake
- __PNG__, APNG (via [libpng](https://github.com/pnggroup/libpng))
- __PFM__, PAM, PNM, PBM, PGM, PPM (generally: see [NetPBM](https://netpbm.sourceforge.net/) and [PFM](https://www.pauldebevec.com/Research/HDR/PFM/))
- __QOI__ (via [qoi](https://github.com/phoboslab/qoi))
- __DDS__ (via [DirectXTex](https://github.com/microsoft/DirectXTex); Windows only)
- __DDS__ (via [DirectXTex](https://github.com/microsoft/DirectXTex))
- __WEBP__ (via [libwebp](https://chromium.googlesource.com/webm/libwebp))
- __TIFF__, __DNG__ (via [libtiff](https://gitlab.com/libtiff/libtiff))
- __AVIF__ (including gain maps, e.g. HDR pictures from Android; via [dav1d](https://github.com/videolan/dav1d)+[libheif](https://github.com/strukturag/libheif))
Expand Down
9 changes: 7 additions & 2 deletions dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,18 @@ set(NANOGUI_SKIP_METAL_SHADER_PRECOMPILATION ON CACHE BOOL " " FORCE)
add_subdirectory(nanogui)

# Compile DirectXTex (only on Windows)
if (WIN32)
if (TEV_SUPPORT_DDS)
set(BUILD_TOOLS OFF CACHE BOOL " " FORCE)
set(BUILD_DX11 OFF CACHE BOOL " " FORCE)
set(BUILD_DX12 OFF CACHE BOOL " " FORCE)
set(BC_USE_OPENMP OFF CACHE BOOL " " FORCE)

add_subdirectory(DirectXTex)
if (NOT WIN32)
add_subdirectory(DirectXMath EXCLUDE_FROM_ALL)
add_subdirectory(DirectX-Headers EXCLUDE_FROM_ALL)
endif()

add_subdirectory(DirectXTex EXCLUDE_FROM_ALL)
endif()

# Compile Little-CMS for ICC color profile handling. The library name is set to lcms2-tev to avoid conflicts with libjxl which also comes
Expand Down
1 change: 1 addition & 0 deletions dependencies/DirectX-Headers
Submodule DirectX-Headers added at adbd6f
1 change: 1 addition & 0 deletions dependencies/DirectXMath
Submodule DirectXMath added at 519d47
2 changes: 1 addition & 1 deletion dependencies/DirectXTex
Submodule DirectXTex updated 241 files
12 changes: 6 additions & 6 deletions include/tev/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@
# define SYSTEM_COMMAND_RIGHT GLFW_KEY_RIGHT_CONTROL
#endif

#define TEV_ASSERT(cond, description, ...) \
if (!(cond)) [[unlikely]] { \
const auto s = std::source_location::current(); \
throw std::runtime_error{ \
fmt::format("{}({}:{}) `{}`: " description, s.file_name(), s.line(), s.column(), s.function_name(), ##__VA_ARGS__) \
}; \
#define TEV_ASSERT(cond, description, ...) \
if (!(cond)) [[unlikely]] { \
const auto s_ = std::source_location::current(); \
throw std::runtime_error{ \
fmt::format("{}({}:{}) `{}`: " description, s_.file_name(), s_.line(), s_.column(), s_.function_name(), ##__VA_ARGS__) \
}; \
}

#ifndef TEV_VERSION
Expand Down
4 changes: 3 additions & 1 deletion src/HelpWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ HelpWindow::HelpWindow(Widget* parent, weak_ptr<Ipc> weakIpc, function<void()> c
#ifdef TEV_SUPPORT_AVIF
addLibrary(about, "dav1d", "Fast AV1 decoder library");
#endif
#ifdef _WIN32
#ifdef TEV_SUPPORT_DDS
addLibrary(about, "DirectXTex", "DirectX texture processing library");
addLibrary(about, "DirectXMath", "DirectX math library");
addLibrary(about, "DirectX-Headers", "DirectX headers");
#endif
addLibrary(about, "GDCM", "Grassroots library for DICOM medical files");
addLibrary(about, "Glad", "Multi-language GL loader-generator");
Expand Down
2 changes: 1 addition & 1 deletion src/ImageViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2418,7 +2418,7 @@ void ImageViewer::openImageDialog() {
#endif
{"bmp", "Bitmap image" },
{"cur", "Microsoft cursor image" },
#ifdef _WIN32
#ifdef TEV_SUPPORT_DDS
{"dds", "DirectDraw Surface image" },
#endif
{"dng", "Digital Negative image" },
Expand Down
7 changes: 6 additions & 1 deletion src/imageio/DdsImageLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <tev/ThreadPool.h>
#include <tev/imageio/DdsImageLoader.h>

#include <sal.h>
#include <DirectXTex.h>

using namespace nanogui;
Expand Down Expand Up @@ -159,6 +160,7 @@ Task<vector<ImageData>>
throw FormatNotSupported{"File is not a DDS file."};
}

#ifdef _WIN32
// COM must be initialized on the thread executing the following DirectX calls. Thus: when editing this file *make sure* that no
// co_await calls are made before the last DirectX call! Note that it is not a problem that CoInitializeEx will potentially get called
// multiple times across different threads, or even multiple times by the same thread pool thread. Both situations are explicitly
Expand All @@ -167,6 +169,7 @@ Task<vector<ImageData>>
if (const auto res = CoInitializeEx(nullptr, COINIT_MULTITHREADED); res != S_OK && res != S_FALSE) {
throw ImageLoadError{"Failed to initialize COM."};
}
#endif

// The correct way to clean up would be to call CoUninitialize() on every task pool thread on shutdown. Using a scope guard here
// wouldn't work for multiple reasons: (i) the coroutine might have been scheduled to another thread once the scope ends, and (ii) it
Expand All @@ -177,7 +180,9 @@ Task<vector<ImageData>>

DirectX::ScratchImage scratchImage;
DirectX::TexMetadata metadata;
if (DirectX::LoadFromDDSMemory(data.data(), data.size(), DirectX::DDS_FLAGS_NONE, &metadata, scratchImage) != S_OK) {
if (DirectX::LoadFromDDSMemory(
reinterpret_cast<const std::byte*>(data.data()), data.size(), DirectX::DDS_FLAGS_NONE, &metadata, scratchImage
) != S_OK) {
throw ImageLoadError{"Failed to read DDS file."};
}

Expand Down
14 changes: 4 additions & 10 deletions src/imageio/ImageLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <tev/imageio/TiffImageLoader.h>
#include <tev/imageio/WebpImageLoader.h>

#ifdef _WIN32
#ifdef TEV_SUPPORT_DDS
# include <tev/imageio/DdsImageLoader.h>
#endif
#ifdef TEV_USE_LIBHEIF
Expand All @@ -59,7 +59,7 @@ const vector<unique_ptr<ImageLoader>>& ImageLoader::getLoaders() {
imageLoaders.emplace_back(new PfmImageLoader());
imageLoaders.emplace_back(new ClipboardImageLoader());
imageLoaders.emplace_back(new EmptyImageLoader());
#ifdef _WIN32
#ifdef TEV_SUPPORT_DDS
imageLoaders.emplace_back(new DdsImageLoader());
#endif
#ifdef TEV_USE_LIBHEIF
Expand Down Expand Up @@ -118,7 +118,7 @@ const vector<string_view>& ImageLoader::supportedMimeTypes() {
"image/vnd.radiance",
"image/webp",
"image/x-adobe-dng",
#ifdef _WIN32
#ifdef TEV_SUPPORT_DDS
"image/x-dds",
"image/x-direct-draw-surface",
#endif
Expand All @@ -141,13 +141,7 @@ const vector<string_view>& ImageLoader::supportedMimeTypes() {
}

Task<vector<Channel>> ImageLoader::makeInterleavedChannels(
size_t numChannels,
bool hasAlpha,
Vector2i size,
EPixelFormat pixelFormat,
EPixelFormat desiredFormat,
string_view layer,
int priority
size_t numChannels, bool hasAlpha, Vector2i size, EPixelFormat pixelFormat, EPixelFormat desiredFormat, string_view layer, int priority
) {
if (numChannels == 0) {
throw ImageLoadError{"Invalid number of rgba channels."};
Expand Down
Loading