dreamgl bmp2c portability fix

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
User avatar
Neil Stevens
Posts: 79
Joined: Thu Jan 27, 2005 2:22 pm
Location: California
Contact:

dreamgl bmp2c portability fix

Post by Neil Stevens »

#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.

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
Have fun,
User avatar
Neil Stevens
Posts: 79
Joined: Thu Jan 27, 2005 2:22 pm
Location: California
Contact:

Post by Neil Stevens »

Turns out that #pragma pack(1) is supported. It's just the push and pop that aren't.

So, much smaller patch:

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 12:23:08 -0000
@@ -12,6 +12,8 @@
 #ifdef WIN32 
 #pragma pack(push) 
 #pragma pack(1) 
+#elif defined(__GNUC__) 
+#pragma pack(1) 
 #endif 
  
 typedef struct 
@@ -39,6 +41,8 @@
  
 #ifdef WIN32 
 #pragma pack(pop) 
+#elif defined(__GNUC__) 
+#pragma pack(0) 
 #endif 
  
 //---------------------------------------------------------------------------- 
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

Hmm, I think you can turn on support for #pragma push/pop by setting a define in r5900.h ... Oh, here it is:

Code: Select all

/* Enable parsing of #pragma pack&#40;push,<n>&#41; and #pragma pack&#40;pop&#41;.  */
#define HANDLE_PRAGMA_PACK_PUSH_POP 1
Comes in handy when porting massive amounts of crud from MSVC to GCC :P.
"He was warned..."
Post Reply