From 0aab81fa0cd412950fe1de0e2d0863264c2f8a26 Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Tue, 1 Jun 2004 19:43:21 +0000 Subject: [PATCH] Also handle OS2 v1.x (AKA windows 2.0) bitmaps. --- tools/wrc/newstruc.c | 59 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/tools/wrc/newstruc.c b/tools/wrc/newstruc.c index 9f7d382fcd..da6e4f0414 100644 --- a/tools/wrc/newstruc.c +++ b/tools/wrc/newstruc.c @@ -34,6 +34,17 @@ #include "wingdi.h" /* for BITMAPINFOHEADER */ +#include +typedef struct +{ + DWORD biSize; + WORD biWidth; + WORD biHeight; + WORD biPlanes; + WORD biBitCount; +} BITMAPOS2HEADER; +#include + /* Generate new_* functions that have no parameters (NOTE: no ';') */ __NEW_STRUCT_FUNC(dialog) __NEW_STRUCT_FUNC(dialogex) @@ -220,25 +231,40 @@ static void convert_bitmap_swap_v4(BITMAPV4HEADER *b4h) b4h->bV4GammaBlue = BYTESWAP_DWORD(b4h->bV4GammaBlue); } +static void convert_bitmap_swap_os2(BITMAPOS2HEADER *boh) +{ + boh->biSize = BYTESWAP_DWORD(boh->biSize); + boh->biWidth = BYTESWAP_WORD(boh->biWidth); + boh->biHeight = BYTESWAP_WORD(boh->biHeight); + boh->biPlanes = BYTESWAP_WORD(boh->biPlanes); + boh->biBitCount = BYTESWAP_WORD(boh->biBitCount); +} + #define FL_SIGBE 0x01 #define FL_SIZEBE 0x02 #define FL_V4 0x04 +#define FL_OS2 0x08 static int convert_bitmap(char *data, int size) { BITMAPINFOHEADER *bih = (BITMAPINFOHEADER *)data; BITMAPV4HEADER *b4h = (BITMAPV4HEADER *)data; + BITMAPOS2HEADER *boh = (BITMAPOS2HEADER *)data; int type = 0; - int returnSize = 0; /* size to be returned */ + int returnSize = 0; /* size to be returned */ #ifdef WORDS_BIGENDIAN DWORD bisizel = BYTESWAP_DWORD(sizeof(BITMAPINFOHEADER)); DWORD b4sizel = BYTESWAP_DWORD(sizeof(BITMAPV4HEADER)); + DWORD bosizel = BYTESWAP_DWORD(sizeof(BITMAPOS2HEADER)); DWORD bisizeb = sizeof(BITMAPINFOHEADER); DWORD b4sizeb = sizeof(BITMAPV4HEADER); + DWORD bosizeb = sizeof(BITMAPOS2HEADER); #else DWORD bisizel = sizeof(BITMAPINFOHEADER); DWORD b4sizel = sizeof(BITMAPV4HEADER); + DWORD bosizel = sizeof(BITMAPOS2HEADER); DWORD bisizeb = BYTESWAP_DWORD(sizeof(BITMAPINFOHEADER)); DWORD b4sizeb = BYTESWAP_DWORD(sizeof(BITMAPV4HEADER)); + DWORD bosizeb = BYTESWAP_DWORD(sizeof(BITMAPOS2HEADER)); #endif @@ -265,20 +291,28 @@ static int convert_bitmap(char *data, int size) { /* Little endian */ } - else if(bih->biSize == b4sizel) - { - type |= FL_V4; - } else if(bih->biSize == bisizeb) { type |= FL_SIZEBE; } + else if(bih->biSize == b4sizel) + { + type |= FL_V4; + } else if(bih->biSize == b4sizeb) { type |= FL_SIZEBE | FL_V4; } + else if(!bih->biSize || bih->biSize == bosizel) + { + type |= FL_OS2; + } + else if(bih->biSize == bosizeb) + { + type |= FL_SIZEBE | FL_OS2; + } else - type = -1; + yyerror("Invalid bitmap format, bih->biSize = %ld", bih->biSize); switch(type) { @@ -286,15 +320,14 @@ static int convert_bitmap(char *data, int size) break; case FL_SIZEBE: case FL_SIZEBE | FL_V4: + case FL_SIZEBE | FL_OS2: yywarning("Bitmap v%c signature little-endian, but size big-endian", type & FL_V4 ? '4' : '3'); break; case FL_SIGBE: case FL_SIGBE | FL_V4: + case FL_SIGBE | FL_OS2: yywarning("Bitmap v%c signature big-endian, but size little-endian", type & FL_V4 ? '4' : '3'); break; - case -1: - yyerror("Invalid bitmap format"); - break; } switch(byteorder) @@ -307,6 +340,10 @@ static int convert_bitmap(char *data, int size) { if(type & FL_V4) convert_bitmap_swap_v4(b4h); + else if(type & FL_OS2) + { + convert_bitmap_swap_os2(boh); + } else convert_bitmap_swap_v3(bih); } @@ -319,6 +356,10 @@ static int convert_bitmap(char *data, int size) { if(type & FL_V4) convert_bitmap_swap_v4(b4h); + else if(type & FL_OS2) + { + convert_bitmap_swap_os2(boh); + } else convert_bitmap_swap_v3(bih); } -- 2.32.0.93.g670b81a890