core: fix build failed in big-endian system (#117)

Close #40
This commit is contained in:
tobiichi3227 2023-12-26 01:08:13 +08:00 committed by GitHub
parent f8cab3c370
commit ef0e051255
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View file

@ -4,10 +4,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.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) { cairo_surface_t* JPEG::createSurfaceFromJPEG(const std::string& path) {
if (!std::filesystem::exists(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_mem_src(&decompressStruct, (const unsigned char*)imageRawData, fileInfo.st_size);
jpeg_read_header(&decompressStruct, true); jpeg_read_header(&decompressStruct, true);
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
decompressStruct.out_color_space = JCS_EXT_BGRA; decompressStruct.out_color_space = JCS_EXT_BGRA;
#else
decompressStruct.out_color_space = JCS_EXT_ARGB;
#endif
// decompress // decompress
jpeg_start_decompress(&decompressStruct); jpeg_start_decompress(&decompressStruct);
@ -69,7 +69,7 @@ cairo_surface_t* JPEG::createSurfaceFromJPEG(const std::string& path) {
cairo_surface_mark_dirty(cairoSurface); cairo_surface_mark_dirty(cairoSurface);
cairo_surface_set_mime_data(cairoSurface, CAIRO_MIME_TYPE_JPEG, (const unsigned char*)imageRawData, fileInfo.st_size, free, imageRawData); cairo_surface_set_mime_data(cairoSurface, CAIRO_MIME_TYPE_JPEG, (const unsigned char*)imageRawData, fileInfo.st_size, free, imageRawData);
jpeg_finish_decompress(&decompressStruct); jpeg_finish_decompress(&decompressStruct);
jpeg_destroy_decompress(&decompressStruct); jpeg_destroy_decompress(&decompressStruct);
return cairoSurface; return cairoSurface;
} }

View file

@ -52,11 +52,11 @@ cairo_surface_t* WEBP::createSurfaceFromWEBP(const std::string& path) {
} }
if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
config.output.colorspace = MODE_bgrA; config.output.colorspace = MODE_bgrA;
else #else
config.output.colorspace = MODE_Argb; config.output.colorspace = MODE_Argb;
#endif
const auto CAIRODATA = cairo_image_surface_get_data(cairoSurface); const auto CAIRODATA = cairo_image_surface_get_data(cairoSurface);
const auto CAIROSTRIDE = cairo_image_surface_get_stride(cairoSurface); const auto CAIROSTRIDE = cairo_image_surface_get_stride(cairoSurface);