2022-12-19 13:01:00 +01:00
|
|
|
From 057cd06c19875bcf8b5d34d41d92a8abdb856b7c Mon Sep 17 00:00:00 2001
|
|
|
|
From: Kleis Auke Wolthuizen <github@kleisauke.nl>
|
|
|
|
Date: Fri, 11 Mar 2022 21:11:24 +0100
|
|
|
|
Subject: [PATCH] Remove LCMS mutex (#112)
|
|
|
|
|
|
|
|
* Remove LCMS mutex
|
|
|
|
|
|
|
|
Requires mm2/Little-CMS@a35bacd, which is released in LCMS v2.11.
|
|
|
|
|
|
|
|
* Use a threadsafe alternative of gmtime in LCMS
|
|
|
|
|
|
|
|
Requires mm2/Little-CMS@68ee2ff, which is released in LCMS v2.13.
|
|
|
|
|
|
|
|
LCMS submodule was updated to version 2.13.1 instead.
|
|
|
|
---
|
2023-04-17 09:36:54 +02:00
|
|
|
lib/jxl/enc_color_management.cc | 15 +++++++++++++++
|
|
|
|
third_party/CMakeLists.txt | 2 +-
|
|
|
|
third_party/lcms2.cmake | 14 --------------
|
|
|
|
3 files changed, 16 insertions(+), 15 deletions(-)
|
2022-12-19 13:01:00 +01:00
|
|
|
|
2023-04-17 09:36:54 +02:00
|
|
|
Index: libjxl-0.8.1/lib/jxl/enc_color_management.cc
|
|
|
|
===================================================================
|
|
|
|
--- libjxl-0.8.1.orig/lib/jxl/enc_color_management.cc
|
|
|
|
+++ libjxl-0.8.1/lib/jxl/enc_color_management.cc
|
|
|
|
@@ -18,6 +18,7 @@
|
2022-12-19 13:01:00 +01:00
|
|
|
#include <array>
|
|
|
|
#include <atomic>
|
|
|
|
#include <memory>
|
2023-04-17 09:36:54 +02:00
|
|
|
+#include <mutex>
|
2022-12-19 13:01:00 +01:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
|
2023-04-17 09:36:54 +02:00
|
|
|
@@ -308,6 +309,14 @@ int DoColorSpaceTransform(void* t, size_
|
2022-12-19 13:01:00 +01:00
|
|
|
// Define to 1 on OS X as a workaround for older LCMS lacking MD5.
|
|
|
|
#define JXL_CMS_OLD_VERSION 0
|
|
|
|
|
2023-04-17 09:36:54 +02:00
|
|
|
+// cms functions (even *THR) are not thread-safe, except cmsDoTransform.
|
|
|
|
+// To ensure all functions are covered without frequent lock-taking nor risk of
|
|
|
|
+// recursive lock, we lock in the top-level APIs.
|
|
|
|
+static std::mutex& LcmsMutex() {
|
|
|
|
+ static std::mutex m;
|
|
|
|
+ return m;
|
|
|
|
+}
|
|
|
|
+
|
2022-12-19 13:01:00 +01:00
|
|
|
#if JPEGXL_ENABLE_SKCMS
|
|
|
|
|
|
|
|
JXL_MUST_USE_RESULT CIExy CIExyFromXYZ(const float XYZ[3]) {
|
2023-04-17 09:36:54 +02:00
|
|
|
@@ -871,6 +880,9 @@ bool ApplyCICP(const uint8_t color_prima
|
2022-12-19 13:01:00 +01:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2023-04-17 09:36:54 +02:00
|
|
|
+// All functions that call lcms directly (except ColorSpaceTransform::Run) must
|
|
|
|
+// lock LcmsMutex().
|
|
|
|
+
|
2022-12-19 13:01:00 +01:00
|
|
|
Status ColorEncoding::SetFieldsFromICC() {
|
|
|
|
// In case parsing fails, mark the ColorEncoding as invalid.
|
|
|
|
SetColorSpace(ColorSpace::kUnknown);
|
2023-04-17 09:36:54 +02:00
|
|
|
@@ -917,6 +929,7 @@ Status ColorEncoding::SetFieldsFromICC()
|
|
|
|
DetectTransferFunction(profile, this);
|
2022-12-19 13:01:00 +01:00
|
|
|
#else // JPEGXL_ENABLE_SKCMS
|
|
|
|
|
2023-04-17 09:36:54 +02:00
|
|
|
+ std::lock_guard<std::mutex> guard(LcmsMutex());
|
2022-12-19 13:01:00 +01:00
|
|
|
const cmsContext context = GetContext();
|
|
|
|
|
|
|
|
Profile profile;
|
2023-04-17 09:36:54 +02:00
|
|
|
@@ -984,6 +997,7 @@ void JxlCmsDestroy(void* cms_data) {
|
2022-12-19 13:01:00 +01:00
|
|
|
if (cms_data == nullptr) return;
|
|
|
|
JxlCms* t = reinterpret_cast<JxlCms*>(cms_data);
|
|
|
|
#if !JPEGXL_ENABLE_SKCMS
|
2023-04-17 09:36:54 +02:00
|
|
|
+ std::lock_guard<std::mutex> guard(LcmsMutex());
|
2022-12-19 13:01:00 +01:00
|
|
|
TransformDeleter()(t->lcms_transform);
|
|
|
|
#endif
|
|
|
|
delete t;
|
2023-04-17 09:36:54 +02:00
|
|
|
@@ -1020,6 +1034,7 @@ void* JxlCmsInit(void* init_data, size_t
|
2022-12-19 13:01:00 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#else // JPEGXL_ENABLE_SKCMS
|
2023-04-17 09:36:54 +02:00
|
|
|
+ std::lock_guard<std::mutex> guard(LcmsMutex());
|
2022-12-19 13:01:00 +01:00
|
|
|
const cmsContext context = GetContext();
|
|
|
|
Profile profile_src, profile_dst;
|
|
|
|
if (!DecodeProfile(context, c_src.ICC(), &profile_src)) {
|
2023-04-17 09:36:54 +02:00
|
|
|
Index: libjxl-0.8.1/third_party/CMakeLists.txt
|
|
|
|
===================================================================
|
|
|
|
--- libjxl-0.8.1.orig/third_party/CMakeLists.txt
|
|
|
|
+++ libjxl-0.8.1/third_party/CMakeLists.txt
|
|
|
|
@@ -111,7 +111,7 @@ if (JPEGXL_ENABLE_SKCMS OR JPEGXL_ENABLE
|
2022-12-19 13:01:00 +01:00
|
|
|
endif ()
|
|
|
|
if (JPEGXL_ENABLE_VIEWERS OR NOT JPEGXL_ENABLE_SKCMS)
|
|
|
|
if( NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lcms/.git" OR JPEGXL_FORCE_SYSTEM_LCMS2 )
|
2023-04-17 09:36:54 +02:00
|
|
|
- find_package(LCMS2 2.13)
|
|
|
|
+ find_package(LCMS2 2.10)
|
2022-12-19 13:01:00 +01:00
|
|
|
if ( NOT LCMS2_FOUND )
|
|
|
|
message(FATAL_ERROR "Please install lcms2 or run git submodule update --init")
|
|
|
|
endif ()
|
2023-04-17 09:36:54 +02:00
|
|
|
Index: libjxl-0.8.1/third_party/lcms2.cmake
|
|
|
|
===================================================================
|
|
|
|
--- libjxl-0.8.1.orig/third_party/lcms2.cmake
|
|
|
|
+++ libjxl-0.8.1/third_party/lcms2.cmake
|
|
|
|
@@ -60,18 +60,4 @@ target_compile_definitions(lcms2
|
2022-12-19 13:01:00 +01:00
|
|
|
target_compile_definitions(lcms2
|
|
|
|
PUBLIC "-DCMS_NO_REGISTER_KEYWORD=1")
|
|
|
|
|
2023-04-17 09:36:54 +02:00
|
|
|
-# Ensure that a thread safe alternative of gmtime is used in LCMS
|
|
|
|
-include(CheckSymbolExists)
|
|
|
|
-check_symbol_exists(gmtime_r "time.h" HAVE_GMTIME_R)
|
|
|
|
-if (HAVE_GMTIME_R)
|
|
|
|
- target_compile_definitions(lcms2
|
|
|
|
- PUBLIC "-DHAVE_GMTIME_R=1")
|
|
|
|
-else()
|
|
|
|
- check_symbol_exists(gmtime_s "time.h" HAVE_GMTIME_S)
|
|
|
|
- if (HAVE_GMTIME_S)
|
|
|
|
- target_compile_definitions(lcms2
|
|
|
|
- PUBLIC "-DHAVE_GMTIME_S=1")
|
|
|
|
- endif()
|
|
|
|
-endif()
|
|
|
|
-
|
2022-12-19 13:01:00 +01:00
|
|
|
set_property(TARGET lcms2 PROPERTY POSITION_INDEPENDENT_CODE ON)
|