Changeset 551 for trunk/dll/loadbmp.c
- Timestamp:
- Feb 28, 2007, 2:33:51 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/loadbmp.c
r549 r551 49 49 USHORT usType; 50 50 PBITMAPARRAYFILEHEADER2 pbmafh2 = NULL; // Must init for xfree 51 PBITMAPFILEHEADER2 pbmfh2; 52 PBITMAPINFOHEADER2 pbmih2; 53 PBITMAPINFO2 pbmi2; 54 BOOL is2x; 51 PBITMAPFILEHEADER2 pbmfh2; // No color table 52 PBITMAPINFOHEADER2 pbmih2; // No color table 53 PBITMAPINFO2 pbmi2; // Includes color table 54 BOOL is2x; // Format 1.x or 2.x 55 55 ULONG ulColors; 56 56 ULONG ulRGBOffset; 57 PBYTE pData = NULL; 57 PBYTE pData = NULL; // Must init for xfree 58 58 ULONG ulDataSize; 59 59 SIZEL sizel; … … 61 61 62 62 if (!hPS) { 63 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__, 64 "WinGetPS"); 63 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__, "WinGetPS"); 65 64 goto ExitLoadBMP; 66 65 } … … 84 83 Allocate enough to hold a complete 2.x bitmap array file header 85 84 fixme to support > 256 colors? 86 */85 */ 87 86 pbmafh2 = 88 87 xmalloc(sizeof(*pbmafh2) + 256 * sizeof(RGB2), pszSrcFile, __LINE__); … … 92 91 Both the 1.x and 2.x structures are assigned to simplify code 93 92 fixme to clean this up - aliased pointers are evil 94 */93 */ 95 94 pbmfh2 = &pbmafh2->bfh2; 96 95 pbmih2 = &pbmfh2->bmp2; 97 pbmi2 = (PBITMAPINFO2) pbmih2;96 pbmi2 = (PBITMAPINFO2) pbmih2; 98 97 99 98 switch (usType) { … … 105 104 { 106 105 /* Assume image is a 2.0 image and read as a 2.x header 107 108 */106 OK for 1.x file - read will not fail unless file is corrupted 107 */ 109 108 rc = fseek(pf, 0, SEEK_SET); 110 109 if (rc) { … … 121 120 is2x = pbmih2->cbFix > sizeof(BITMAPINFOHEADER); // 1.x or 2.x bitmap 122 121 /* We will read the color table later 123 124 125 126 127 128 */122 Color table follows header but 123 location depends on the type of the bitmap (old vs new) 124 1.x header is fixed size 125 2.x header is variable sized, so offset must be calculated 126 cbFix contains actual size of BITMAPINFOHEADER2 in file 127 */ 129 128 ulRGBOffset = is2x ? sizeof(*pbmfh2) - sizeof(*pbmih2) + pbmih2->cbFix : 130 129 sizeof(BITMAPFILEHEADER); 131 130 } 132 131 break; … … 135 134 { 136 135 /* Now we are dealing with a bitmap array which is a collection of bitmaps 137 138 */136 Each bitmap has its own file header 137 */ 139 138 140 139 ULONG ulCurOffset; … … 149 148 150 149 /* Scan the array and chose the bitmap best suited 151 152 */150 for the current display size and color capacities 151 */ 153 152 hdc = GpiQueryDevice(hPS); 154 153 if (!hdc) { … … 157 156 goto ExitLoadBMP; 158 157 } 159 DevQueryCaps(hdc, CAPS_COLORS, 1, (PLONG) &ulDeviceColors);160 DevQueryCaps(hdc, CAPS_WIDTH, 1, (PLONG) &clScreenWidth);161 DevQueryCaps(hdc, CAPS_HEIGHT, 1, (PLONG) &clScreenHeight);158 DevQueryCaps(hdc, CAPS_COLORS, 1, (PLONG) & ulDeviceColors); 159 DevQueryCaps(hdc, CAPS_WIDTH, 1, (PLONG) & clScreenWidth); 160 DevQueryCaps(hdc, CAPS_HEIGHT, 1, (PLONG) & clScreenHeight); 162 161 pbmafh2->offNext = 0; 163 162 do { … … 179 178 } 180 179 else { 181 ulColors = 1 << (((PBITMAPARRAYFILEHEADER)pbmafh2)->bfh.bmp.cBitCount * 182 ((PBITMAPARRAYFILEHEADER)pbmafh2)->bfh.bmp.cPlanes); 180 ulColors = 181 1 << (((PBITMAPARRAYFILEHEADER) pbmafh2)->bfh.bmp.cBitCount * 182 ((PBITMAPARRAYFILEHEADER) pbmafh2)->bfh.bmp.cPlanes); 183 183 } 184 184 if (pbmafh2->cxDisplay == 0 && pbmafh2->cyDisplay == 0) { … … 188 188 } 189 189 ulSizeDiff = abs(pbmafh2->cxDisplay - clScreenWidth) + 190 190 abs(pbmafh2->cyDisplay - clScreenHeight); 191 191 if (ulDeviceColors == ulColors && ulSizeDiff == 0) { 192 192 // We found the perfect match … … 197 197 ulSizeDiff < ulSizeDiffPicked || // Better fit than any previous 198 198 (ulColors > ulColorsPicked && ulColors < ulDeviceColors) || // More colors than prev & less than device 199 (ulColors < ulColorsPicked && ulColors > ulDeviceColors)) 200 { 199 (ulColors < ulColorsPicked && ulColors > ulDeviceColors)) { 201 200 ulOffsetPicked = ulCurOffset; // Make this our current pick 202 201 ulColorsPicked = ulColors; … … 219 218 is2x = pbmih2->cbFix > sizeof(BITMAPINFOHEADER); 220 219 /* As before, we calculate offset in file stream to color table 221 222 */220 This code must match single bitmap logic 221 */ 223 222 ulRGBOffset = ulOffsetPicked; 224 ulRGBOffset += is2x ? sizeof(*pbmafh2) - sizeof(*pbmih2) + pbmih2->cbFix : 225 sizeof(BITMAPARRAYFILEHEADER); 223 ulRGBOffset += 224 is2x ? sizeof(*pbmafh2) - sizeof(*pbmih2) + 225 pbmih2->cbFix : sizeof(BITMAPARRAYFILEHEADER); 226 226 } 227 227 break; … … 246 246 pbmih2->cclrUsed or pbmih2->cclrImportant are non zero 247 247 fixme to test this 248 */248 */ 249 249 if (pbmih2->cBitCount < 24) { 250 250 ULONG ulRGBBytes; 251 251 252 ulColors = 1L << pbmih2->cBitCount; 252 253 253 254 if (ulColors > 256) { 254 Runtime_Error(pszSrcFile, __LINE__, "RGB exceeds 256 colors: %lu", ulColors); 255 Runtime_Error(pszSrcFile, __LINE__, "RGB exceeds 256 colors: %lu", 256 ulColors); 255 257 goto ExitLoadBMP; 256 258 } … … 263 265 } // endif 264 266 // Get pointer to bitmap info (header and color table) 265 pbmi2 = (PBITMAPINFO2) pbmih2;267 pbmi2 = (PBITMAPINFO2) pbmih2; 266 268 } 267 269 else { … … 269 271 Since the current standard format is the 2.0 270 272 convert the header and color table to 2.x format 271 */273 */ 272 274 ULONG ul; 273 275 RGB rgb; 274 PBITMAPINFOHEADER pbmih = &((PBITMAPARRAYFILEHEADER) pbmafh2)->bfh.bmp;276 PBITMAPINFOHEADER pbmih = &((PBITMAPARRAYFILEHEADER) pbmafh2)->bfh.bmp; 275 277 276 278 if (pbmih->cBitCount < 24) { 277 279 ulColors = 1 << pbmih->cBitCount; 278 280 if (ulColors > 256) { 279 Runtime_Error(pszSrcFile, __LINE__, "RGB exceeds 256 colors: %lu", ulColors); 281 Runtime_Error(pszSrcFile, __LINE__, "RGB exceeds 256 colors: %lu", 282 ulColors); 280 283 goto ExitLoadBMP; 281 284 } … … 287 290 pbmi2->argbColor[ul].bBlue = rgb.bBlue; 288 291 pbmi2->argbColor[ul].fcOptions = 0; // initialize 2.x extra byte to 0 289 } // for292 } // for 290 293 } 291 294 … … 297 300 pbmi2->cx = pbmih->cx; 298 301 // set rest to zero 299 memset((PCHAR) pbmi2 + 16, 0, sizeof(BITMAPINFOHEADER2) - 16);300 } 302 memset((PCHAR) pbmi2 + 16, 0, sizeof(BITMAPINFOHEADER2) - 16); 303 } // if 1.x 301 304 302 305 /* The 2.0 bitmap info structure set up 303 306 Position to start of the bitmap data 304 */307 */ 305 308 rc = fseek(pf, pbmfh2->offBits, SEEK_SET); 306 309 if (rc) { … … 315 318 After aligning it, we divide by 4 to get the number of bytes, and 316 319 multiply by the number of scan lines and the number of pel planes 317 */320 */ 318 321 if (pbmi2->ulCompression) 319 322 ulDataSize = pbmi2->cbImage;
Note:
See TracChangeset
for help on using the changeset viewer.