core: Allow compiling without JXL support (#6)
Some checks failed
Build & Test (Arch) / Arch: Build and Test (gcc) (push) Has been cancelled
Build & Test (Arch) / Arch: Build and Test (clang) (push) Has been cancelled
Build & Test / nix (hyprgraphics) (push) Has been cancelled
Build & Test / nix (hyprgraphics-with-tests) (push) Has been cancelled

* 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
This commit is contained in:
Zach DeCook 2025-01-05 17:14:50 -05:00 committed by GitHub
parent b09980755d
commit 52202272d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 7 deletions

View file

@ -47,10 +47,20 @@ pkg_check_modules(
hyprutils hyprutils
libjpeg libjpeg
libwebp libwebp
libmagic)
pkg_check_modules(
JXL
libjxl libjxl
libjxl_cms libjxl_cms
libjxl_threads 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}) add_library(hyprgraphics SHARED ${SRCFILES})
target_include_directories( target_include_directories(
@ -59,7 +69,7 @@ target_include_directories(
PRIVATE "./src") PRIVATE "./src")
set_target_properties(hyprgraphics PROPERTIES VERSION ${HYPRGRAPHICS_VERSION} set_target_properties(hyprgraphics PROPERTIES VERSION ${HYPRGRAPHICS_VERSION}
SOVERSION 0) SOVERSION 0)
target_link_libraries(hyprgraphics PkgConfig::deps) target_link_libraries(hyprgraphics PkgConfig::deps ${JXL_LIBRARIES})
# tests # tests
add_custom_target(tests) add_custom_target(tests)

View file

@ -16,9 +16,9 @@ Dep list:
- hyprutils - hyprutils
- libjpeg - libjpeg
- libwebp - libwebp
- libjxl - libjxl [optional]
- libjxl_cms - libjxl_cms [optional]
- libjxl_threads - libjxl_threads [optional]
- libmagic - libmagic
## Building ## Building

View file

@ -1,7 +1,9 @@
#include <hyprgraphics/image/Image.hpp> #include <hyprgraphics/image/Image.hpp>
#include "formats/Bmp.hpp" #include "formats/Bmp.hpp"
#include "formats/Jpeg.hpp" #include "formats/Jpeg.hpp"
#ifdef JXL_FOUND
#include "formats/JpegXL.hpp" #include "formats/JpegXL.hpp"
#endif
#include "formats/Webp.hpp" #include "formats/Webp.hpp"
#include <magic.h> #include <magic.h>
#include <format> #include <format>
@ -27,8 +29,15 @@ Hyprgraphics::CImage::CImage(const std::string& path) : filepath(path) {
CAIROSURFACE = WEBP::createSurfaceFromWEBP(path); CAIROSURFACE = WEBP::createSurfaceFromWEBP(path);
mime = "image/webp"; mime = "image/webp";
} else if (path.find(".jxl") == len - 4 || path.find(".JXL") == len - 4) { } else if (path.find(".jxl") == len - 4 || path.find(".JXL") == len - 4) {
#ifdef JXL_FOUND
CAIROSURFACE = JXL::createSurfaceFromJXL(path); CAIROSURFACE = JXL::createSurfaceFromJXL(path);
mime = "image/jxl"; mime = "image/jxl";
#else
lastError = "hyprgraphics compiled without JXL support";
return;
#endif
} else { } else {
// magic is slow, so only use it when no recognized extension is found // magic is slow, so only use it when no recognized extension is found
auto handle = magic_open(MAGIC_NONE | MAGIC_COMPRESS | MAGIC_SYMLINK); auto handle = magic_open(MAGIC_NONE | MAGIC_COMPRESS | MAGIC_SYMLINK);

View file

@ -25,8 +25,11 @@ int main(int argc, char** argv, char** envp) {
for (auto& file : std::filesystem::directory_iterator("./resource/images/")) { for (auto& file : std::filesystem::directory_iterator("./resource/images/")) {
if (!file.is_regular_file()) if (!file.is_regular_file())
continue; continue;
auto expectation = true;
EXPECT(tryLoadImage(file.path()), true); #ifndef JXL_FOUND
if (file.path().filename() == "hyprland.jxl") expectation = false;
#endif
EXPECT(tryLoadImage(file.path()), expectation);
} }
return ret; return ret;