Skip to content

Commit

Permalink
core: fix build failed in big-endian system (#117)
Browse files Browse the repository at this point in the history
Close #40
  • Loading branch information
tobiichi3227 authored Dec 25, 2023
1 parent f8cab3c commit ef0e051
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/helpers/Jpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#include <sys/types.h>
#include <unistd.h>

#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)) {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
10 changes: 5 additions & 5 deletions src/helpers/Webp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ef0e051

Please sign in to comment.