mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2026-03-26 07:52:32 +01:00
100 lines
3.0 KiB
Diff
100 lines
3.0 KiB
Diff
From 52202272d89da32a9f866c0d10305a5e3d954c50 Mon Sep 17 00:00:00 2001
|
|
From: Zach DeCook <zachdecook@gmail.com>
|
|
Date: Sun, 5 Jan 2025 17:14:50 -0500
|
|
Subject: [PATCH] core: Allow compiling without JXL support (#6)
|
|
|
|
* Allow compiling without JXL support
|
|
|
|
Remember to link the libraries and add the compile definitions
|
|
|
|
* tests: when compiled without JXL support, expect that to fail
|
|
---
|
|
CMakeLists.txt | 14 ++++++++++++--
|
|
src/image/Image.cpp | 9 +++++++++
|
|
tests/image.cpp | 7 +++++--
|
|
4 files changed, 29 insertions(+), 7 deletions(-)
|
|
|
|
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|
index 80944d7..072b7b4 100644
|
|
--- a/CMakeLists.txt
|
|
+++ b/CMakeLists.txt
|
|
@@ -47,10 +47,20 @@ pkg_check_modules(
|
|
hyprutils
|
|
libjpeg
|
|
libwebp
|
|
+ libmagic)
|
|
+
|
|
+pkg_check_modules(
|
|
+ JXL
|
|
libjxl
|
|
libjxl_cms
|
|
libjxl_threads
|
|
- libmagic)
|
|
+)
|
|
+if(NOT JXL_FOUND)
|
|
+ file(GLOB_RECURSE JPEGXLFILES CONFIGURE_DEPENDS "src/*JpegXL.cpp")
|
|
+ list(REMOVE_ITEM SRCFILES ${JPEGXLFILES})
|
|
+else()
|
|
+ add_compile_definitions(JXL_FOUND)
|
|
+endif()
|
|
|
|
add_library(hyprgraphics SHARED ${SRCFILES})
|
|
target_include_directories(
|
|
@@ -59,7 +69,7 @@ target_include_directories(
|
|
PRIVATE "./src")
|
|
set_target_properties(hyprgraphics PROPERTIES VERSION ${HYPRGRAPHICS_VERSION}
|
|
SOVERSION 0)
|
|
-target_link_libraries(hyprgraphics PkgConfig::deps)
|
|
+target_link_libraries(hyprgraphics PkgConfig::deps ${JXL_LIBRARIES})
|
|
|
|
# tests
|
|
add_custom_target(tests)
|
|
diff --git a/src/image/Image.cpp b/src/image/Image.cpp
|
|
index d3cd4a4..82467e9 100644
|
|
--- a/src/image/Image.cpp
|
|
+++ b/src/image/Image.cpp
|
|
@@ -1,7 +1,9 @@
|
|
#include <hyprgraphics/image/Image.hpp>
|
|
#include "formats/Bmp.hpp"
|
|
#include "formats/Jpeg.hpp"
|
|
+#ifdef JXL_FOUND
|
|
#include "formats/JpegXL.hpp"
|
|
+#endif
|
|
#include "formats/Webp.hpp"
|
|
#include <magic.h>
|
|
#include <format>
|
|
@@ -27,8 +29,15 @@ Hyprgraphics::CImage::CImage(const std::string& path) : filepath(path) {
|
|
CAIROSURFACE = WEBP::createSurfaceFromWEBP(path);
|
|
mime = "image/webp";
|
|
} else if (path.find(".jxl") == len - 4 || path.find(".JXL") == len - 4) {
|
|
+
|
|
+#ifdef JXL_FOUND
|
|
CAIROSURFACE = JXL::createSurfaceFromJXL(path);
|
|
mime = "image/jxl";
|
|
+#else
|
|
+ lastError = "hyprgraphics compiled without JXL support";
|
|
+ return;
|
|
+#endif
|
|
+
|
|
} else {
|
|
// magic is slow, so only use it when no recognized extension is found
|
|
auto handle = magic_open(MAGIC_NONE | MAGIC_COMPRESS | MAGIC_SYMLINK);
|
|
diff --git a/tests/image.cpp b/tests/image.cpp
|
|
index 4cd1287..7067f9a 100644
|
|
--- a/tests/image.cpp
|
|
+++ b/tests/image.cpp
|
|
@@ -25,8 +25,11 @@ int main(int argc, char** argv, char** envp) {
|
|
for (auto& file : std::filesystem::directory_iterator("./resource/images/")) {
|
|
if (!file.is_regular_file())
|
|
continue;
|
|
-
|
|
- EXPECT(tryLoadImage(file.path()), true);
|
|
+ auto expectation = true;
|
|
+#ifndef JXL_FOUND
|
|
+ if (file.path().filename() == "hyprland.jxl") expectation = false;
|
|
+#endif
|
|
+ EXPECT(tryLoadImage(file.path()), expectation);
|
|
}
|
|
|
|
return ret;
|