diff --git a/Readme.md b/Readme.md index 52261fb3..4e9701e1 100644 --- a/Readme.md +++ b/Readme.md @@ -29,6 +29,7 @@ It supports features such as: - Works with GCC, Clang, Xcode, MSVC 2015, ICC, TCC, MinGW, MingGW-w64/32. - Works on Linux, FreeBSD, OpenBSD, OS X, iOS and Windows. Also works on MSYS/MSYS2 and Cygwin. - Compiles for 32 and 64 bit. +- Compiles and works on big and little endian systems. - The only dependency is on `zlib`. Here is an example that was used to create the spreadsheet shown above: diff --git a/docs/src/getting_started.dox b/docs/src/getting_started.dox index 3f0fdef2..10633080 100644 --- a/docs/src/getting_started.dox +++ b/docs/src/getting_started.dox @@ -419,6 +419,12 @@ to dynamically link against that you can use the following compilation option: make USE_SYSTEM_MINIZIP=1 +@section gsg_endian Compiling on Big Endian Architecture + +Libxlsxwriter can be compiled on a big endian system as follows: + + make USE_BIG_ENDIAN=1 + @section gsg_next Next steps If you got libxlsxwriter built and working successfully then the next sections diff --git a/docs/src/mainpage.dox b/docs/src/mainpage.dox index 68088b48..025ca590 100644 --- a/docs/src/mainpage.dox +++ b/docs/src/mainpage.dox @@ -28,6 +28,7 @@ features such as: - Works with GCC, Clang, Xcode, MSVC 2015, ICC, TCC, MinGW, MingGW-w64/32. - Works on Linux, FreeBSD, OpenBSD, OS X, iOS and Windows. Also works on MSYS/MSYS2 and Cygwin. - Compiles for 32 and 64 bit. +- Compiles and works on big and little endian systems. - The only dependency is on `zlib`. This document explains how to use the libxlsxwriter library. See the @@ -44,7 +45,7 @@ following sections for more information: - @ref workbook.h "The Workbook object" - @ref worksheet.h "The Worksheet object" - @ref format.h "The Format object" -- @ref chart.h "The Chart object" +- @ref chart.h "The Chart object" - @ref working_with_formats - @ref working_with_colors diff --git a/include/xlsxwriter/common.h b/include/xlsxwriter/common.h index b3de7b66..337925e5 100644 --- a/include/xlsxwriter/common.h +++ b/include/xlsxwriter/common.h @@ -268,9 +268,14 @@ enum lxw_custom_property_types { (((n) & 0xFF0000) >> 8) | \ (((n) & 0xFF000000) >> 24)) #define LXW_UINT16_NETWORK(n) ((((n) & 0x00FF) << 8) | (((n) & 0xFF00) >> 8)) +#define LXW_UINT32_HOST(n) (n) #else #define LXW_UINT32_NETWORK(n) (n) #define LXW_UINT16_NETWORK(n) (n) +#define LXW_UINT32_HOST(n) ((((n) & 0xFF) << 24) | \ + (((n) & 0xFF00) << 8) | \ + (((n) & 0xFF0000) >> 8) | \ + (((n) & 0xFF000000) >> 24)) #endif /* *INDENT-OFF* */ diff --git a/libxlsxwriter.podspec b/libxlsxwriter.podspec index 368302d5..bfb4c45e 100644 --- a/libxlsxwriter.podspec +++ b/libxlsxwriter.podspec @@ -25,6 +25,7 @@ Pod::Spec.new do |s| * Works with GCC, Clang, Xcode, MSVC 2015, ICC, TCC, MinGW, MingGW-w64/32. * Works on Linux, FreeBSD, OpenBSD, OS X, iOS and Windows. Also works on MSYS/MSYS2 and Cygwin. * Compiles for 32 and 64 bit. + * Compiles and works on big and little endian systems. * The only dependency is on `zlib`. DESC diff --git a/src/Makefile b/src/Makefile index 71f237a0..03ce95aa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -38,6 +38,11 @@ TMPFILEPLUS_OBJ = $(TMPFILEPLUS_DIR)/tmpfileplus.o TMPFILEPLUS_SO = $(TMPFILEPLUS_DIR)/tmpfileplus.so endif +# Set flag for big endian architecture. +ifdef USE_BIG_ENDIAN +CFLAGS += -DLXW_BIG_ENDIAN +endif + # Flags passed to compiler. CFLAGS += -g -O3 -Wall -Wextra -pedantic -ansi diff --git a/src/worksheet.c b/src/worksheet.c index 2815d1d6..916a334c 100644 --- a/src/worksheet.c +++ b/src/worksheet.c @@ -2418,6 +2418,9 @@ _process_bmp(lxw_image_options *image_options) if (width == 0) goto file_error; + height = LXW_UINT32_HOST(height); + width = LXW_UINT32_HOST(width); + /* Set the image metadata. */ image_options->image_type = LXW_IMAGE_BMP; image_options->width = width;