Skip to content

Commit

Permalink
build: lcms: upstream in favor of fork; add fast float scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom94 committed Feb 23, 2025
1 parent 283d896 commit 5e742b1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@
shallow = true
[submodule "dependencies/Little-CMS"]
path = dependencies/Little-CMS
url = https://github.com/Tom94/Little-CMS
url = https://github.com/mm2/Little-CMS
shallow = true
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)
if (TEV_USE_LIBHEIF)
include_directories(${LCMS_INCLUDE} ${LIBHEIF_INCLUDE})
include_directories(${LIBHEIF_INCLUDE})
endif()

set(TEV_DEFINITIONS -DTEV_VERSION="${TEV_VERSION_ARCH}")
Expand Down
24 changes: 19 additions & 5 deletions dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,26 @@ if (TEV_USE_LIBHEIF)
set(LIBHEIF_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/libheif/libheif/api" "${CMAKE_CURRENT_BINARY_DIR}/libheif" PARENT_SCOPE)

# Compile Little-CMS for ICC color profile handling
set(BUILD_SHARED_LIBS OFF CACHE BOOL " " FORCE)
set(BUILD_TOOLS OFF CACHE BOOL " " FORCE)
set(BUILD_TESTS OFF CACHE BOOL " " FORCE)
add_subdirectory(Little-CMS EXCLUDE_FROM_ALL)

set(LCMS_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/Little-CMS/include" PARENT_SCOPE)
# WARNING: Enabling the fast float plugin (GPLv3) causes a License conflict with the rest of tev (BSD 3-clause). Therefore, we disable
# it here for now. Currently seeking to purchase a more permissive license as per https://www.littlecms.com/plugin/. Will enable once
# this is resolved.
file(GLOB LCMS_SRCS
Little-CMS/src/*.c Little-CMS/include/*.h
# Little-CMS/plugins/fast_float/src/*.c Little-CMS/plugins/fast_float/include/*.h
)

file(GLOB LCMS_HDRS
Little-CMS/include/*.h
# Little-CMS/plugins/fast_float/include/*.h
)

add_library(lcms2 STATIC ${LCMS_SRCS} ${LCMS_HDRS})
set_target_properties(lcms2 PROPERTIES PUBLIC_HEADER "${LCMS_HDRS}")
target_include_directories(lcms2 PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/Little-CMS/include"
# "${CMAKE_CURRENT_SOURCE_DIR}/Little-CMS/plugins/fast_float/include"
)
endif()

# Compile OpenEXR
Expand Down
2 changes: 1 addition & 1 deletion dependencies/Little-CMS
Submodule Little-CMS updated 1 files
+0 −170 CMakeLists.txt
2 changes: 2 additions & 0 deletions include/tev/imageio/HeifImageLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace tev {

class HeifImageLoader : public ImageLoader {
public:
HeifImageLoader();

bool canLoadFile(std::istream& iStream) const override;
Task<std::vector<ImageData>>
load(std::istream& iStream, const fs::path& path, const std::string& channelSelector, int priority) const override;
Expand Down
13 changes: 9 additions & 4 deletions src/imageio/HeifImageLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <libheif/heif.h>

#include <lcms2.h>
// #include <lcms2_fast_float.h>

#include <ImfChromaticities.h>

Expand All @@ -15,6 +16,14 @@ using namespace std;

namespace tev {

HeifImageLoader::HeifImageLoader() {
cmsSetLogErrorHandler([](cmsContext, cmsUInt32Number errorCode, const char* message) {
tlog::error() << fmt::format("lcms error #{}: {}", errorCode, message);
});

// cmsPlugin(cmsFastFloatExtensions());
}

bool HeifImageLoader::canLoadFile(istream& iStream) const {
// libheif's spec says it needs the first 12 bytes to determine whether the image can be read.
uint8_t header[12];
Expand Down Expand Up @@ -135,10 +144,6 @@ Task<vector<ImageData>> HeifImageLoader::load(istream& iStream, const fs::path&,
return (cmsHTRANSFORM) nullptr;
}

cmsSetLogErrorHandler([](cmsContext, cmsUInt32Number errorCode, const char* message) {
tlog::error() << fmt::format("lcms error #{}: {}", errorCode, message);
});

// Create ICC profile from the raw data
cmsHPROFILE srcProfile = cmsOpenProfileFromMem(profileData.data(), (cmsUInt32Number)profileSize);
if (!srcProfile) {
Expand Down

0 comments on commit 5e742b1

Please sign in to comment.