dreamgl bmp2c portability fix
Posted: Wed Feb 02, 2005 9:40 pm
#pragma pack doesn't work on gcc on my platform (FreeBSD 5). I think the gcc people are trying to get rid of pragmas.
So, here's a patch to make dreamgl's bmp2c work on non-win32 platforms using gcc. The patch applies in CVS to dreamgl/tools/bmp2c/bmp2c.cpp. I can mail it by request if copying from here doesn't work for some reason.
Have fun,
So, here's a patch to make dreamgl's bmp2c work on non-win32 platforms using gcc. The patch applies in CVS to dreamgl/tools/bmp2c/bmp2c.cpp. I can mail it by request if copying from here doesn't work for some reason.
Code: Select all
Index: bmp2c.cpp
===================================================================
RCS file: /home/ps2cvs/dreamgl/tools/bmp2c/bmp2c.cpp,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 bmp2c.cpp
--- bmp2c.cpp 21 Jan 2005 02:28:35 -0000 1.1.1.1
+++ bmp2c.cpp 2 Feb 2005 11:35:10 -0000
@@ -14,27 +14,33 @@
#pragma pack(1)
#endif
+#if defined __GNUC__
+#define PACKED __attribute__ ((__packed__));
+#else
+#define PACKED
+#endif
+
typedef struct
{
- char sig[2]; // 'BM'
- uint32 file_size; // File size in bytes
- uint32 reserved; // unused (=0)
- uint32 data_offset; // File offset to Raster Data
+ char sig[2] PACKED; // 'BM'
+ uint32 file_size PACKED; // File size in bytes
+ uint32 reserved PACKED; // unused (=0)
+ uint32 data_offset PACKED; // File offset to Raster Data
} bmp_header_t;
typedef struct
{
- uint32 size; // Size of InfoHeader = 40
- uint32 width; // Bitmap Width
- uint32 height; // Bitmap Height
- uint16 planes; // Number of Planes = 1
- uint16 bpp; // Bits per Pixel = 24
- uint32 comp; // Type of Compression = 0
- uint32 image_size; // (compressed) Size of Image
- uint32 x_pixels_per_m; // horizontal resolution: Pixels/meter
- uint32 y_pixels_per_m; // vertical resolution: Pixels/meter
- uint32 colors_used; // Number of actually used colors
- uint32 colors_important;// Number of important colors
+ uint32 size PACKED; // Size of InfoHeader = 40
+ uint32 width PACKED; // Bitmap Width
+ uint32 height PACKED; // Bitmap Height
+ uint16 planes PACKED; // Number of Planes = 1
+ uint16 bpp PACKED; // Bits per Pixel = 24
+ uint32 comp PACKED; // Type of Compression = 0
+ uint32 image_size PACKED; // (compressed) Size of Image
+ uint32 x_pixels_per_m PACKED; // horizontal resolution: Pixels/meter
+ uint32 y_pixels_per_m PACKED; // vertical resolution: Pixels/meter
+ uint32 colors_used PACKED; // Number of actually used colors
+ uint32 colors_important PACKED;// Number of important colors
} bmp_iheader_t;
#ifdef WIN32