forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

dreamgl bmp2c portability fix

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development
View previous topic :: View next topic  
Author Message
Neil Stevens



Joined: 27 Jan 2005
Posts: 79
Location: California

PostPosted: Wed Feb 02, 2005 9:40 pm    Post subject: dreamgl bmp2c portability fix Reply with quote

#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:
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,
Back to top
View user's profile Send private message Visit poster's website
Neil Stevens



Joined: 27 Jan 2005
Posts: 79
Location: California

PostPosted: Wed Feb 02, 2005 10:24 pm    Post subject: Reply with quote

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

So, much smaller patch:

Code:
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
 
 //----------------------------------------------------------------------------
Back to top
View user's profile Send private message Visit poster's website
mrbrown



Joined: 17 Jan 2004
Posts: 1536

PostPosted: Thu Feb 03, 2005 3:46 am    Post subject: Reply with quote

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

Code:
/* Enable parsing of #pragma pack(push,<n>) and #pragma pack(pop).  */
#define HANDLE_PRAGMA_PACK_PUSH_POP 1


Comes in handy when porting massive amounts of crud from MSVC to GCC :P.
_________________
"He was warned..."
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group