1 #ifndef _nImage__bmp_h_ 2 #define _nImage__bmp_h_ 3 4 #ifdef CPU_BIG_ENDIAD 5 #error "Fix big endian issues!" 6 #endif 7 8 #ifdef COMPILER_MSC 9 #pragma pack(push, 1) 10 #endif 11 12 struct BMP_FILEHEADER { 13 word bfType; 14 dword bfSize; 15 word bfReserved1; 16 word bfReserved2; 17 dword bfOffBits; 18 EndianSwapBMP_FILEHEADER19 void EndianSwap() 20 { 21 #ifdef CPU_BIG_ENDIAN 22 EndianSwap(bfType); 23 EndianSwap(bfSize); 24 EndianSwap(bfOffBits); 25 #endif 26 } 27 } 28 #ifdef COMPILER_GCC 29 __attribute__((packed)) 30 #endif 31 ; 32 33 struct BMP_INFOHEADER 34 { 35 dword biSize; 36 long biWidth; 37 long biHeight; 38 word biPlanes; 39 word biBitCount; 40 dword biCompression; 41 dword biSizeImage; 42 long biXPelsPerMeter; 43 long biYPelsPerMeter; 44 dword biClrUsed; 45 dword biClrImportant; 46 EndianSwapBMP_INFOHEADER47 void EndianSwap() 48 { 49 #ifdef CPU_BIG_ENDIAN 50 EndianSwap(biSize); 51 EndianSwap(biWidth); 52 EndianSwap(biHeight); 53 EndianSwap(biPlanes); 54 EndianSwap(biBitCount); 55 EndianSwap(biCompression); 56 EndianSwap(biSizeImage); 57 EndianSwap(biXPelsPerMeter); 58 EndianSwap(biYPelsPerMeter); 59 EndianSwap(biClrUsed); 60 EndianSwap(biClrImportant); 61 62 #endif 63 } 64 } 65 #ifdef COMPILER_GCC 66 __attribute__((packed)) 67 #endif 68 ; 69 70 struct BMP_RGB 71 { 72 byte rgbBlue; 73 byte rgbGreen; 74 byte rgbRed; 75 byte rgbReserved; 76 }; 77 78 struct ICONDIR 79 { 80 word idReserved; // Reserved (must be 0) 81 word idType; // Resource Type (1 for icons) 82 word idCount; // How many images? 83 EndianSwapICONDIR84 void EndianSwap() 85 { 86 #ifdef CPU_BIG_ENDIAN 87 EndianSwap(idReserved); 88 EndianSwap(idType); 89 EndianSwap(idCount); 90 #endif 91 } 92 } 93 #ifdef COMPILER_GCC 94 __attribute__((packed)) 95 #endif 96 ; 97 98 struct ICONDIRENTRY 99 { 100 byte bWidth; // Width, in pixels, of the image 101 byte bHeight; // Height, in pixels, of the image 102 byte bColorCount; 103 byte bReserved; 104 short wHotSpotX; 105 short wHotSpotY; 106 dword dwBytesInRes; // How many bytes in this resource? 107 dword dwImageOffset; // Where in the file is this image? 108 EndianSwapICONDIRENTRY109 void EndianSwap() 110 { 111 #ifdef CPU_BIG_ENDIAN 112 EndianSwap(wHotSpotX); 113 EndianSwap(wHotSpotY); 114 EndianSwap(dwBytesInRes); 115 EndianSwap(dwImageOffset); 116 117 #endif 118 } 119 } 120 #ifdef COMPILER_GCC 121 __attribute__((packed)) 122 #endif 123 ; 124 125 #ifdef COMPILER_MSC 126 #pragma pack(pop) 127 #endif 128 129 struct BMPHeader : public BMP_INFOHEADER 130 { 131 BMP_RGB palette[256]; 132 }; 133 134 #endif 135