From ef0e051255af1b96155b222da94c94ecad1f7708 Mon Sep 17 00:00:00 2001 From: tobiichi3227 <86729076+tobiichi3227@users.noreply.github.com> Date: Tue, 26 Dec 2023 01:08:13 +0800 Subject: [PATCH] core: fix build failed in big-endian system (#117) Close #40 --- src/helpers/Jpeg.cpp | 10 +++++----- src/helpers/Webp.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/helpers/Jpeg.cpp b/src/helpers/Jpeg.cpp index 5719e89..833f88a 100644 --- a/src/helpers/Jpeg.cpp +++ b/src/helpers/Jpeg.cpp @@ -4,10 +4,6 @@ #include #include -#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ -#error "your system is not little endian, jpeg will not work, ping vaxry or something" -#endif - cairo_surface_t* JPEG::createSurfaceFromJPEG(const std::string& path) { if (!std::filesystem::exists(path)) { @@ -44,7 +40,11 @@ cairo_surface_t* JPEG::createSurfaceFromJPEG(const std::string& path) { jpeg_mem_src(&decompressStruct, (const unsigned char*)imageRawData, fileInfo.st_size); jpeg_read_header(&decompressStruct, true); +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ decompressStruct.out_color_space = JCS_EXT_BGRA; +#else + decompressStruct.out_color_space = JCS_EXT_ARGB; +#endif // decompress jpeg_start_decompress(&decompressStruct); @@ -69,7 +69,7 @@ cairo_surface_t* JPEG::createSurfaceFromJPEG(const std::string& path) { cairo_surface_mark_dirty(cairoSurface); cairo_surface_set_mime_data(cairoSurface, CAIRO_MIME_TYPE_JPEG, (const unsigned char*)imageRawData, fileInfo.st_size, free, imageRawData); jpeg_finish_decompress(&decompressStruct); - jpeg_destroy_decompress(&decompressStruct); + jpeg_destroy_decompress(&decompressStruct); return cairoSurface; } diff --git a/src/helpers/Webp.cpp b/src/helpers/Webp.cpp index de80f89..4b90597 100644 --- a/src/helpers/Webp.cpp +++ b/src/helpers/Webp.cpp @@ -52,11 +52,11 @@ cairo_surface_t* WEBP::createSurfaceFromWEBP(const std::string& path) { } - if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) - config.output.colorspace = MODE_bgrA; - else - config.output.colorspace = MODE_Argb; - +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + config.output.colorspace = MODE_bgrA; +#else + config.output.colorspace = MODE_Argb; +#endif const auto CAIRODATA = cairo_image_surface_get_data(cairoSurface); const auto CAIROSTRIDE = cairo_image_surface_get_stride(cairoSurface);