From bdb7b3b02e572b9f2ad9ecd4d4222aa7e7975a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Sun, 17 Nov 2024 20:38:43 +0900 Subject: [PATCH 1/6] Add support for JPEG-XL --- CMakeLists.txt | 3 + README.md | 7 +- nix/default.nix | 2 + src/helpers/JpegXL.cpp | 129 +++++++++++++++++++++++++++++++++ src/helpers/JpegXL.hpp | 7 ++ src/render/WallpaperTarget.cpp | 2 + src/render/WallpaperTarget.hpp | 1 + 7 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 src/helpers/JpegXL.cpp create mode 100644 src/helpers/JpegXL.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e19c8a7..cfd0150 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,9 @@ pkg_check_modules( pangocairo libjpeg libwebp + libjxl + libjxl_cms + libjxl_threads hyprlang>=0.2.0 hyprutils>=0.2.0) diff --git a/README.md b/README.md index 207b29d..f026787 100644 --- a/README.md +++ b/README.md @@ -29,18 +29,19 @@ The development files of these packages need to be installed on the system for ` - libglvnd-core - libjpeg-turbo - libwebp +- libjxl - hyprlang - hyprutils - hyprwayland-scanner To install all of these in Fedora, run this command: ``` -sudo dnf install wayland-devel wayland-protocols-devel hyprlang-devel pango-devel cairo-devel file-devel libglvnd-devel libglvnd-core-devel libjpeg-turbo-devel libwebp-devel gcc-c++ hyprutils-devel hyprwayland-scanner +sudo dnf install wayland-devel wayland-protocols-devel hyprlang-devel pango-devel cairo-devel file-devel libglvnd-devel libglvnd-core-devel libjpeg-turbo-devel libwebp-devel libjxl-devel gcc-c++ hyprutils-devel hyprwayland-scanner ``` On Arch: ``` -sudo pacman -S ninja gcc wayland-protocols libjpeg-turbo libwebp pango cairo pkgconf cmake libglvnd wayland hyprutils hyprwayland-scanner hyprlang +sudo pacman -S ninja gcc wayland-protocols libjpeg-turbo libwebp libjxl pango cairo pkgconf cmake libglvnd wayland hyprutils hyprwayland-scanner hyprlang ``` On OpenSUSE: @@ -89,7 +90,7 @@ splash = true ``` -Preload will tell Hyprland to load a particular image (supported formats: png, jpg, jpeg, webp). Wallpaper will apply the wallpaper to the selected output (`monitor` is the monitor's name, easily can be retrieved with `hyprctl monitors`. You can leave it empty to set all monitors without an active wallpaper. You can also use `desc:` followed by the monitor's description without the (PORT) at the end) +Preload will tell Hyprland to load a particular image (supported formats: png, jpg, jpeg, jpeg xl, webp). Wallpaper will apply the wallpaper to the selected output (`monitor` is the monitor's name, easily can be retrieved with `hyprctl monitors`. You can leave it empty to set all monitors without an active wallpaper. You can also use `desc:` followed by the monitor's description without the (PORT) at the end) You may add `contain:` or `tile:` before the file path in `wallpaper=` to set the mode to either contain or tile, respectively, instead of cover: diff --git a/nix/default.nix b/nix/default.nix index aa8e479..514a50f 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -13,6 +13,7 @@ libdatrie, libGL, libjpeg, + libjxl, libselinux, libsepol, libthai, @@ -66,6 +67,7 @@ stdenv.mkDerivation { libdatrie libGL libjpeg + libjxl libselinux libsepol libthai diff --git a/src/helpers/JpegXL.cpp b/src/helpers/JpegXL.cpp new file mode 100644 index 0000000..062896a --- /dev/null +++ b/src/helpers/JpegXL.cpp @@ -0,0 +1,129 @@ +#include "JpegXL.hpp" + +#include +#include +#include + +#include +#include +#include + +cairo_surface_t* JXL::createSurfaceFromJXL(const std::string& path) { + + if (!std::filesystem::exists(path)) { + Debug::log(ERR, "createSurfaceFromJXL: file doesn't exist??"); + exit(1); + } + + void* imageRawData; + + struct stat fileInfo = {}; + + const auto FD = open(path.c_str(), O_RDONLY); + + fstat(FD, &fileInfo); + + imageRawData = malloc(fileInfo.st_size); + + read(FD, imageRawData, fileInfo.st_size); + + close(FD); + + JxlSignature signature = JxlSignatureCheck(reinterpret_cast(imageRawData), fileInfo.st_size); + if (signature != JXL_SIG_CODESTREAM && signature != JXL_SIG_CONTAINER) { + Debug::log(ERR, "createSurfaceFromJXL: file is not JXL format"); + free(imageRawData); + exit(1); + } + + auto dec = JxlDecoderMake(nullptr); + auto runner = JxlResizableParallelRunnerMake(nullptr); + if (JXL_DEC_SUCCESS != JxlDecoderSetParallelRunner(dec.get(), JxlResizableParallelRunner, runner.get())) { + Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderSetParallelRunner failed"); + free(imageRawData); + exit(1); + } + + if (JXL_DEC_SUCCESS != JxlDecoderSubscribeEvents(dec.get(), JXL_DEC_BASIC_INFO | JXL_DEC_FULL_IMAGE)) { + Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderSubscribeEvents failed"); + free(imageRawData); + exit(1); + } + + JxlDecoderSetInput(dec.get(), reinterpret_cast(imageRawData), fileInfo.st_size); + JxlDecoderCloseInput(dec.get()); + if (JXL_DEC_BASIC_INFO != JxlDecoderProcessInput(dec.get())) { + Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderProcessInput failed"); + free(imageRawData); + exit(1); + } + + JxlBasicInfo basic_info; + if (JXL_DEC_SUCCESS != JxlDecoderGetBasicInfo(dec.get(), &basic_info)) { + Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderGetBasicInfo failed"); + free(imageRawData); + exit(1); + } + + auto cairoSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, basic_info.xsize, basic_info.ysize); + if (cairo_surface_status(cairoSurface) != CAIRO_STATUS_SUCCESS) { + Debug::log(ERR, "createSurfaceFromJXL: Cairo Failed (?)"); + free(imageRawData); + cairo_surface_destroy(cairoSurface); + exit(1); + } + + const auto CAIRODATA = cairo_image_surface_get_data(cairoSurface); + + JxlPixelFormat format = { + .num_channels = 4, + .data_type = JXL_TYPE_UINT8, + .endianness = JXL_BIG_ENDIAN, + .align = cairo_image_surface_get_stride(cairoSurface), + }; + + const auto output_size = basic_info.xsize * basic_info.ysize * format.num_channels; + + for (;;) { + JxlDecoderStatus status = JxlDecoderProcessInput(dec.get()); + if (status == JXL_DEC_ERROR) { + Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderProcessInput failed"); + free(imageRawData); + cairo_surface_destroy(cairoSurface); + exit(1); + } else if (status == JXL_DEC_NEED_MORE_INPUT) { + Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderProcessInput expected more input"); + free(imageRawData); + cairo_surface_destroy(cairoSurface); + exit(1); + } else if (status == JXL_DEC_NEED_IMAGE_OUT_BUFFER) { + JxlResizableParallelRunnerSetThreads(runner.get(), JxlResizableParallelRunnerSuggestThreads(basic_info.xsize, basic_info.ysize)); + size_t buffer_size; + if (JXL_DEC_SUCCESS != JxlDecoderImageOutBufferSize(dec.get(), &format, &buffer_size)) { + Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderImageOutBufferSize failed"); + free(imageRawData); + cairo_surface_destroy(cairoSurface); + exit(1); + } + if (buffer_size != output_size) { + Debug::log(ERR, "createSurfaceFromJXL: invalid output buffer size"); + free(imageRawData); + cairo_surface_destroy(cairoSurface); + exit(1); + } + if (JXL_DEC_SUCCESS != JxlDecoderSetImageOutBuffer(dec.get(), &format, CAIRODATA, buffer_size)) { + Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderSetImageOutBuffer failed"); + free(imageRawData); + cairo_surface_destroy(cairoSurface); + exit(1); + } + } else if (status == JXL_DEC_FULL_IMAGE) { + for (size_t i = 0; i < output_size - 2; i += format.num_channels) { + std::swap(CAIRODATA[i + 0], CAIRODATA[i + 2]); + } + cairo_surface_mark_dirty(cairoSurface); + cairo_surface_set_mime_data(cairoSurface, "image/jxl", (const unsigned char*)imageRawData, fileInfo.st_size, free, imageRawData); + return cairoSurface; + } + } +} diff --git a/src/helpers/JpegXL.hpp b/src/helpers/JpegXL.hpp new file mode 100644 index 0000000..f4ef60f --- /dev/null +++ b/src/helpers/JpegXL.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include "../defines.hpp" + +namespace JXL { + cairo_surface_t* createSurfaceFromJXL(const std::string&); +}; diff --git a/src/render/WallpaperTarget.cpp b/src/render/WallpaperTarget.cpp index 6c2ab3b..f64fdf0 100644 --- a/src/render/WallpaperTarget.cpp +++ b/src/render/WallpaperTarget.cpp @@ -24,6 +24,8 @@ void CWallpaperTarget::create(const std::string& path) { m_bHasAlpha = false; } else if (path.find(".webp") == len - 5 || path.find(".WEBP") == len - 5) { CAIROSURFACE = WEBP::createSurfaceFromWEBP(path); + } else if (path.find(".jxl") == len - 4 || path.find(".JXL") == len - 4) { + CAIROSURFACE = JXL::createSurfaceFromJXL(path); } else { // magic is slow, so only use it when no recognized extension is found auto handle = magic_open(MAGIC_NONE | MAGIC_COMPRESS); diff --git a/src/render/WallpaperTarget.hpp b/src/render/WallpaperTarget.hpp index 9a28d92..0c79a32 100644 --- a/src/render/WallpaperTarget.hpp +++ b/src/render/WallpaperTarget.hpp @@ -4,6 +4,7 @@ #include "../helpers/Jpeg.hpp" #include "../helpers/Bmp.hpp" #include "../helpers/Webp.hpp" +#include "../helpers/JpegXL.hpp" class CWallpaperTarget { public: From 862403aa82d9c7a3fae515e6fb203eaaa2905288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Fri, 22 Nov 2024 11:58:11 +0900 Subject: [PATCH 2/6] load JXL images using C++ streams --- src/helpers/JpegXL.cpp | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/src/helpers/JpegXL.cpp b/src/helpers/JpegXL.cpp index 062896a..8273613 100644 --- a/src/helpers/JpegXL.cpp +++ b/src/helpers/JpegXL.cpp @@ -1,10 +1,7 @@ #include "JpegXL.hpp" -#include -#include -#include - #include +#include #include #include @@ -15,24 +12,15 @@ cairo_surface_t* JXL::createSurfaceFromJXL(const std::string& path) { exit(1); } - void* imageRawData; - - struct stat fileInfo = {}; - - const auto FD = open(path.c_str(), O_RDONLY); - - fstat(FD, &fileInfo); - - imageRawData = malloc(fileInfo.st_size); - - read(FD, imageRawData, fileInfo.st_size); - - close(FD); + std::ifstream stream(path, std::ios::binary | std::ios::ate); + stream.exceptions(std::ifstream::failbit | std::ifstream::badbit | std::ifstream::eofbit); + std::vector bytes(stream.tellg()); + stream.seekg(0); + stream.read(reinterpret_cast(bytes.data()), bytes.size()); - JxlSignature signature = JxlSignatureCheck(reinterpret_cast(imageRawData), fileInfo.st_size); + JxlSignature signature = JxlSignatureCheck(bytes.data(), bytes.size()); if (signature != JXL_SIG_CODESTREAM && signature != JXL_SIG_CONTAINER) { Debug::log(ERR, "createSurfaceFromJXL: file is not JXL format"); - free(imageRawData); exit(1); } @@ -40,35 +28,30 @@ cairo_surface_t* JXL::createSurfaceFromJXL(const std::string& path) { auto runner = JxlResizableParallelRunnerMake(nullptr); if (JXL_DEC_SUCCESS != JxlDecoderSetParallelRunner(dec.get(), JxlResizableParallelRunner, runner.get())) { Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderSetParallelRunner failed"); - free(imageRawData); exit(1); } if (JXL_DEC_SUCCESS != JxlDecoderSubscribeEvents(dec.get(), JXL_DEC_BASIC_INFO | JXL_DEC_FULL_IMAGE)) { Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderSubscribeEvents failed"); - free(imageRawData); exit(1); } - JxlDecoderSetInput(dec.get(), reinterpret_cast(imageRawData), fileInfo.st_size); + JxlDecoderSetInput(dec.get(), bytes.data(), bytes.size()); JxlDecoderCloseInput(dec.get()); if (JXL_DEC_BASIC_INFO != JxlDecoderProcessInput(dec.get())) { Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderProcessInput failed"); - free(imageRawData); exit(1); } JxlBasicInfo basic_info; if (JXL_DEC_SUCCESS != JxlDecoderGetBasicInfo(dec.get(), &basic_info)) { Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderGetBasicInfo failed"); - free(imageRawData); exit(1); } auto cairoSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, basic_info.xsize, basic_info.ysize); if (cairo_surface_status(cairoSurface) != CAIRO_STATUS_SUCCESS) { Debug::log(ERR, "createSurfaceFromJXL: Cairo Failed (?)"); - free(imageRawData); cairo_surface_destroy(cairoSurface); exit(1); } @@ -88,12 +71,10 @@ cairo_surface_t* JXL::createSurfaceFromJXL(const std::string& path) { JxlDecoderStatus status = JxlDecoderProcessInput(dec.get()); if (status == JXL_DEC_ERROR) { Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderProcessInput failed"); - free(imageRawData); cairo_surface_destroy(cairoSurface); exit(1); } else if (status == JXL_DEC_NEED_MORE_INPUT) { Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderProcessInput expected more input"); - free(imageRawData); cairo_surface_destroy(cairoSurface); exit(1); } else if (status == JXL_DEC_NEED_IMAGE_OUT_BUFFER) { @@ -101,19 +82,16 @@ cairo_surface_t* JXL::createSurfaceFromJXL(const std::string& path) { size_t buffer_size; if (JXL_DEC_SUCCESS != JxlDecoderImageOutBufferSize(dec.get(), &format, &buffer_size)) { Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderImageOutBufferSize failed"); - free(imageRawData); cairo_surface_destroy(cairoSurface); exit(1); } if (buffer_size != output_size) { Debug::log(ERR, "createSurfaceFromJXL: invalid output buffer size"); - free(imageRawData); cairo_surface_destroy(cairoSurface); exit(1); } if (JXL_DEC_SUCCESS != JxlDecoderSetImageOutBuffer(dec.get(), &format, CAIRODATA, buffer_size)) { Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderSetImageOutBuffer failed"); - free(imageRawData); cairo_surface_destroy(cairoSurface); exit(1); } @@ -122,7 +100,7 @@ cairo_surface_t* JXL::createSurfaceFromJXL(const std::string& path) { std::swap(CAIRODATA[i + 0], CAIRODATA[i + 2]); } cairo_surface_mark_dirty(cairoSurface); - cairo_surface_set_mime_data(cairoSurface, "image/jxl", (const unsigned char*)imageRawData, fileInfo.st_size, free, imageRawData); + cairo_surface_set_mime_data(cairoSurface, "image/jxl", bytes.data(), bytes.size(), nullptr, nullptr); return cairoSurface; } } From c7c1ad98c916f44c4160c3ed2466e5f9ef98b84d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Fri, 22 Nov 2024 12:04:44 +0900 Subject: [PATCH 3/6] rename stream to file --- src/helpers/JpegXL.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/helpers/JpegXL.cpp b/src/helpers/JpegXL.cpp index 8273613..35c01fa 100644 --- a/src/helpers/JpegXL.cpp +++ b/src/helpers/JpegXL.cpp @@ -12,11 +12,11 @@ cairo_surface_t* JXL::createSurfaceFromJXL(const std::string& path) { exit(1); } - std::ifstream stream(path, std::ios::binary | std::ios::ate); - stream.exceptions(std::ifstream::failbit | std::ifstream::badbit | std::ifstream::eofbit); - std::vector bytes(stream.tellg()); - stream.seekg(0); - stream.read(reinterpret_cast(bytes.data()), bytes.size()); + std::ifstream file(path, std::ios::binary | std::ios::ate); + file.exceptions(std::ifstream::failbit | std::ifstream::badbit | std::ifstream::eofbit); + std::vector bytes(file.tellg()); + file.seekg(0); + file.read(reinterpret_cast(bytes.data()), bytes.size()); JxlSignature signature = JxlSignatureCheck(bytes.data(), bytes.size()); if (signature != JXL_SIG_CODESTREAM && signature != JXL_SIG_CONTAINER) { From c33444229063adc04680454fb3f1308cc6c86f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Fri, 22 Nov 2024 12:06:47 +0900 Subject: [PATCH 4/6] use camelCase for all variable names --- src/helpers/JpegXL.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/helpers/JpegXL.cpp b/src/helpers/JpegXL.cpp index 35c01fa..eba34fe 100644 --- a/src/helpers/JpegXL.cpp +++ b/src/helpers/JpegXL.cpp @@ -43,20 +43,20 @@ cairo_surface_t* JXL::createSurfaceFromJXL(const std::string& path) { exit(1); } - JxlBasicInfo basic_info; - if (JXL_DEC_SUCCESS != JxlDecoderGetBasicInfo(dec.get(), &basic_info)) { + JxlBasicInfo basicInfo; + if (JXL_DEC_SUCCESS != JxlDecoderGetBasicInfo(dec.get(), &basicInfo)) { Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderGetBasicInfo failed"); exit(1); } - auto cairoSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, basic_info.xsize, basic_info.ysize); + auto cairoSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, basicInfo.xsize, basicInfo.ysize); if (cairo_surface_status(cairoSurface) != CAIRO_STATUS_SUCCESS) { Debug::log(ERR, "createSurfaceFromJXL: Cairo Failed (?)"); cairo_surface_destroy(cairoSurface); exit(1); } - const auto CAIRODATA = cairo_image_surface_get_data(cairoSurface); + const auto cairoData = cairo_image_surface_get_data(cairoSurface); JxlPixelFormat format = { .num_channels = 4, @@ -65,7 +65,7 @@ cairo_surface_t* JXL::createSurfaceFromJXL(const std::string& path) { .align = cairo_image_surface_get_stride(cairoSurface), }; - const auto output_size = basic_info.xsize * basic_info.ysize * format.num_channels; + const auto outputSize = basicInfo.xsize * basicInfo.ysize * format.num_channels; for (;;) { JxlDecoderStatus status = JxlDecoderProcessInput(dec.get()); @@ -78,26 +78,26 @@ cairo_surface_t* JXL::createSurfaceFromJXL(const std::string& path) { cairo_surface_destroy(cairoSurface); exit(1); } else if (status == JXL_DEC_NEED_IMAGE_OUT_BUFFER) { - JxlResizableParallelRunnerSetThreads(runner.get(), JxlResizableParallelRunnerSuggestThreads(basic_info.xsize, basic_info.ysize)); - size_t buffer_size; - if (JXL_DEC_SUCCESS != JxlDecoderImageOutBufferSize(dec.get(), &format, &buffer_size)) { + JxlResizableParallelRunnerSetThreads(runner.get(), JxlResizableParallelRunnerSuggestThreads(basicInfo.xsize, basicInfo.ysize)); + size_t bufferSize; + if (JXL_DEC_SUCCESS != JxlDecoderImageOutBufferSize(dec.get(), &format, &bufferSize)) { Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderImageOutBufferSize failed"); cairo_surface_destroy(cairoSurface); exit(1); } - if (buffer_size != output_size) { + if (bufferSize != outputSize) { Debug::log(ERR, "createSurfaceFromJXL: invalid output buffer size"); cairo_surface_destroy(cairoSurface); exit(1); } - if (JXL_DEC_SUCCESS != JxlDecoderSetImageOutBuffer(dec.get(), &format, CAIRODATA, buffer_size)) { + if (JXL_DEC_SUCCESS != JxlDecoderSetImageOutBuffer(dec.get(), &format, cairoData, bufferSize)) { Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderSetImageOutBuffer failed"); cairo_surface_destroy(cairoSurface); exit(1); } } else if (status == JXL_DEC_FULL_IMAGE) { - for (size_t i = 0; i < output_size - 2; i += format.num_channels) { - std::swap(CAIRODATA[i + 0], CAIRODATA[i + 2]); + for (size_t i = 0; i < outputSize - 2; i += format.num_channels) { + std::swap(cairoData[i + 0], cairoData[i + 2]); } cairo_surface_mark_dirty(cairoSurface); cairo_surface_set_mime_data(cairoSurface, "image/jxl", bytes.data(), bytes.size(), nullptr, nullptr); From 20fcfd437978c5565f0f44692f29c9da2ad5f0eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Fri, 22 Nov 2024 12:13:19 +0900 Subject: [PATCH 5/6] make sure we use little endian (does not seem to affect, though) --- src/helpers/JpegXL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/JpegXL.cpp b/src/helpers/JpegXL.cpp index eba34fe..1b5ab26 100644 --- a/src/helpers/JpegXL.cpp +++ b/src/helpers/JpegXL.cpp @@ -61,7 +61,7 @@ cairo_surface_t* JXL::createSurfaceFromJXL(const std::string& path) { JxlPixelFormat format = { .num_channels = 4, .data_type = JXL_TYPE_UINT8, - .endianness = JXL_BIG_ENDIAN, + .endianness = JXL_LITTLE_ENDIAN, .align = cairo_image_surface_get_stride(cairoSurface), }; From 7b73aee0b5cd0addf8b5c7cec1ef1cf1079641ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Fri, 22 Nov 2024 14:28:43 +0900 Subject: [PATCH 6/6] make const variables UPPERCASE --- src/helpers/JpegXL.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/helpers/JpegXL.cpp b/src/helpers/JpegXL.cpp index 1b5ab26..1174fc5 100644 --- a/src/helpers/JpegXL.cpp +++ b/src/helpers/JpegXL.cpp @@ -56,7 +56,7 @@ cairo_surface_t* JXL::createSurfaceFromJXL(const std::string& path) { exit(1); } - const auto cairoData = cairo_image_surface_get_data(cairoSurface); + const auto CAIRODATA = cairo_image_surface_get_data(cairoSurface); JxlPixelFormat format = { .num_channels = 4, @@ -65,7 +65,7 @@ cairo_surface_t* JXL::createSurfaceFromJXL(const std::string& path) { .align = cairo_image_surface_get_stride(cairoSurface), }; - const auto outputSize = basicInfo.xsize * basicInfo.ysize * format.num_channels; + const auto OUTPUTSIZE = basicInfo.xsize * basicInfo.ysize * format.num_channels; for (;;) { JxlDecoderStatus status = JxlDecoderProcessInput(dec.get()); @@ -85,19 +85,19 @@ cairo_surface_t* JXL::createSurfaceFromJXL(const std::string& path) { cairo_surface_destroy(cairoSurface); exit(1); } - if (bufferSize != outputSize) { + if (bufferSize != OUTPUTSIZE) { Debug::log(ERR, "createSurfaceFromJXL: invalid output buffer size"); cairo_surface_destroy(cairoSurface); exit(1); } - if (JXL_DEC_SUCCESS != JxlDecoderSetImageOutBuffer(dec.get(), &format, cairoData, bufferSize)) { + if (JXL_DEC_SUCCESS != JxlDecoderSetImageOutBuffer(dec.get(), &format, CAIRODATA, bufferSize)) { Debug::log(ERR, "createSurfaceFromJXL: JxlDecoderSetImageOutBuffer failed"); cairo_surface_destroy(cairoSurface); exit(1); } } else if (status == JXL_DEC_FULL_IMAGE) { - for (size_t i = 0; i < outputSize - 2; i += format.num_channels) { - std::swap(cairoData[i + 0], cairoData[i + 2]); + for (size_t i = 0; i < OUTPUTSIZE - 2; i += format.num_channels) { + std::swap(CAIRODATA[i + 0], CAIRODATA[i + 2]); } cairo_surface_mark_dirty(cairoSurface); cairo_surface_set_mime_data(cairoSurface, "image/jxl", bytes.data(), bytes.size(), nullptr, nullptr);