source: trunk/src/gdi32/blit.cpp@ 5790

Last change on this file since 5790 was 5790, checked in by sandervl, 24 years ago

SetDIBitsToDevice fix

File size: 22.5 KB
Line 
1/* $Id: blit.cpp,v 1.28 2001-05-24 08:18:45 sandervl Exp $ */
2
3/*
4 * GDI32 blit code
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1998 Patrick Haller
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#include <os2win.h>
13#include <stdlib.h>
14#include <stdarg.h>
15#include <string.h>
16#include <cpuhlp.h>
17#include "misc.h"
18#include "dibsect.h"
19#include "rgbcvt.h"
20
21#define DBG_LOCALLOG DBG_blit
22#include "dbglocal.h"
23
24static ULONG QueryPaletteSize(BITMAPINFOHEADER *pBHdr);
25static ULONG CalcBitmapSize(ULONG cBits, LONG cx, LONG cy);
26
27//******************************************************************************
28//******************************************************************************
29BOOL WIN32API StretchBlt(HDC hdcDest, int nXOriginDest, int nYOriginDest,
30 int nWidthDest, int nHeightDest,
31 HDC hdcSrc, int nXOriginSrc, int nYOriginSrc,
32 int nWidthSrc, int nHeightSrc, DWORD dwRop)
33{
34 BOOL rc;
35
36 dprintf(("GDI32: StretchBlt Dest: %x (%d, %d) size (%d, %d) ROP %x",
37 hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, dwRop));
38 dprintf(("GDI32: StretchBlt Src : %x (%d, %d) size (%d, %d)\n",
39 hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc));
40 SetLastError(ERROR_SUCCESS);
41 if(DIBSection::getSection() != NULL)
42 {
43 DIBSection *dsect = DIBSection::findHDC(hdcSrc);
44 if(dsect)
45 {
46 rc = dsect->BitBlt( hdcDest,
47 nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
48 nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
49 dwRop);
50 return rc;
51 }
52 }
53 return O32_StretchBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, dwRop);
54}
55//******************************************************************************
56//******************************************************************************
57BOOL WIN32API BitBlt(HDC hdcDest,
58 int nXDest,
59 int nYDest,
60 int nWidth,
61 int nHeight,
62 HDC hdcSrc,
63 int nXSrc,
64 int nYSrc,
65 DWORD dwRop)
66{
67 BOOL rc;
68
69 SetLastError(ERROR_SUCCESS);
70 if(DIBSection::getSection() != NULL)
71 {
72 DIBSection *dsect = DIBSection::findHDC(hdcSrc);
73 if(dsect)
74 {
75 return dsect->BitBlt(hdcDest,
76 nXDest,
77 nYDest,
78 nWidth,
79 nHeight,
80 nXSrc,
81 nYSrc,
82 nWidth,
83 nHeight,
84 dwRop);
85 }
86 }
87 dprintf(("GDI32: BitBlt to hdc %X from hdc %x (%d,%d) to (%d,%d), (%d,%d) rop %X\n",
88 hdcDest, hdcSrc, nXSrc, nYSrc, nXDest, nYDest, nWidth, nHeight, dwRop));
89 return O32_BitBlt(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, dwRop);
90}
91//******************************************************************************
92//******************************************************************************
93static INT SetDIBitsToDevice_(HDC hdc, INT xDest, INT yDest, DWORD cx,
94 DWORD cy, INT xSrc, INT ySrc,
95 UINT startscan, UINT lines, LPCVOID bits,
96 const BITMAPINFO *info, UINT coloruse)
97{
98 INT result, imgsize, palsize, height, width;
99 char *ptr;
100 ULONG compression = 0, bmpsize;
101 WORD *newbits = NULL;
102 DWORD bitfields[3];
103
104 dprintf(("GDI32: SetDIBitsToDevice hdc:%X xDest:%d yDest:%d, cx:%d, cy:%d, xSrc:%d, ySrc:%d, startscan:%d, lines:%d \nGDI32: bits 0x%X, info 0x%X, coloruse %d",
105 hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, (LPVOID) bits, (PBITMAPINFO)info, coloruse));
106
107 SetLastError(ERROR_SUCCESS);
108 if(info == NULL) {
109 goto invalid_parameter;
110 }
111 height = info->bmiHeader.biHeight;
112 width = info->bmiHeader.biWidth;
113
114 if (height < 0) height = -height;
115 if (!lines || (startscan >= height)) {
116 goto invalid_parameter;
117 }
118 if (startscan + lines > height) lines = height - startscan;
119
120 if (ySrc < startscan) ySrc = startscan;
121 else if (ySrc >= startscan + lines) goto invalid_parameter;
122
123 if (xSrc >= width) goto invalid_parameter;
124
125 if (ySrc + cy >= startscan + lines) cy = startscan + lines - ySrc;
126
127 if (xSrc + cx >= width) cx = width - xSrc;
128
129 if (!cx || !cy) goto invalid_parameter;
130
131 //SvL: RP7's bitmap size is not correct; fix it here or else
132 // the blit is messed up in Open32
133 imgsize = CalcBitmapSize(info->bmiHeader.biBitCount,
134 info->bmiHeader.biWidth, info->bmiHeader.biHeight);
135 bmpsize = info->bmiHeader.biSizeImage;
136 if(info->bmiHeader.biCompression == 0 && info->bmiHeader.biSizeImage &&
137 info->bmiHeader.biSizeImage < imgsize)
138 {
139 ((BITMAPINFO *)info)->bmiHeader.biSizeImage = imgsize;
140 }
141
142 switch(info->bmiHeader.biBitCount) {
143 case 15:
144 case 16:
145 bitfields[0] = (info->bmiHeader.biCompression == BI_BITFIELDS) ? *(DWORD *)info->bmiColors : 0x7c00;
146 bitfields[1] = (info->bmiHeader.biCompression == BI_BITFIELDS) ? *((DWORD *)info->bmiColors + 1) : 0x03e0;
147 bitfields[2] = (info->bmiHeader.biCompression == BI_BITFIELDS) ? *((DWORD *)info->bmiColors + 2) : 0x001f;
148 break;
149 case 32:
150 bitfields[0] = (info->bmiHeader.biCompression == BI_BITFIELDS) ? *(DWORD *)info->bmiColors : 0xff0000;
151 bitfields[1] = (info->bmiHeader.biCompression == BI_BITFIELDS) ? *((DWORD *)info->bmiColors + 1) : 0xff00;
152 bitfields[2] = (info->bmiHeader.biCompression == BI_BITFIELDS) ? *((DWORD *)info->bmiColors + 2) : 0xff;
153 break;
154 default:
155 bitfields[0] = 0;
156 bitfields[1] = 0;
157 bitfields[2] = 0;
158 break;
159 }
160
161 if(bitfields[1] == 0x3E0)
162 {//RGB 555?
163 dprintf(("RGB 555->565 conversion required %x %x %x", bitfields[0], bitfields[1], bitfields[2]));
164
165 newbits = (WORD *)malloc(imgsize);
166 if(CPUFeatures & CPUID_MMX) {
167 RGB555to565MMX(newbits, (WORD *)bits, imgsize/sizeof(WORD));
168 }
169 else RGB555to565(newbits, (WORD *)bits, imgsize/sizeof(WORD));
170 bits = newbits;
171 }
172
173 //SvL: Ignore BI_BITFIELDS type (SetDIBitsToDevice fails otherwise)
174 if(info->bmiHeader.biCompression == BI_BITFIELDS) {
175 ((BITMAPINFO *)info)->bmiHeader.biCompression = 0;
176 compression = BI_BITFIELDS;
177
178 }
179 if(startscan != 0 || lines != info->bmiHeader.biHeight) {
180 dprintf(("WARNING: SetDIBitsToDevice startscan != 0 || lines != info->bmiHeader.biHeight"));
181 }
182
183 result = O32_StretchDIBits(hdc, xDest, yDest, cx, cy, xSrc, ySrc,
184 cx, cy, (void *)bits,
185 (PBITMAPINFO)info, coloruse, SRCCOPY);
186
187 //Open32 always returns height of bitmap (regardless of how many scanlines were copied)
188 if(result != info->bmiHeader.biHeight) {
189 dprintf(("SetDIBitsToDevice failed with rc %x", result));
190 }
191 else
192 {
193 result = info->bmiHeader.biHeight;
194
195 DIBSection *destdib = DIBSection::findHDC(hdc);
196 if(destdib) {
197 if(cx == info->bmiHeader.biWidth && cy == info->bmiHeader.biHeight &&
198 destdib->GetBitCount() == info->bmiHeader.biBitCount &&
199 destdib->GetBitCount() == 8)
200 {
201 destdib->sync(xDest, yDest, cx, cy, (PVOID)bits);
202 }
203 else destdib->sync(hdc, yDest, cy);
204 }
205 }
206 dprintf(("GDI32: SetDIBitsToDevice hdc:%X xDest:%d yDest:%d, cx:%d, cy:%d, xSrc:%d, ySrc:%d, startscan:%d, lines:%d \nGDI32: bits 0x%X, info 0x%X, coloruse %d returned %d",
207 hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, (LPVOID) bits, (PBITMAPINFO)info, coloruse, result));
208 dprintf(("GDI32: SetDIBitsToDevice %d %d %d %d %x %d", info->bmiHeader.biWidth, info->bmiHeader.biHeight, info->bmiHeader.biPlanes, info->bmiHeader.biBitCount, info->bmiHeader.biCompression, info->bmiHeader.biSizeImage));
209
210 if(compression == BI_BITFIELDS) {
211 ((BITMAPINFO *)info)->bmiHeader.biCompression = BI_BITFIELDS;
212 }
213 if(newbits) free(newbits);
214 ((BITMAPINFO *)info)->bmiHeader.biSizeImage = bmpsize;
215 return result;
216
217invalid_parameter:
218 SetLastError(ERROR_INVALID_PARAMETER);
219 return 0;
220}
221//******************************************************************************
222//******************************************************************************
223INT WIN32API SetDIBitsToDevice(HDC hdc, INT xDest, INT yDest, DWORD cx,
224 DWORD cy, INT xSrc, INT ySrc,
225 UINT startscan, UINT lines, LPCVOID bits,
226 const BITMAPINFO *info, UINT coloruse)
227{
228 if(info->bmiHeader.biHeight < 0 && info->bmiHeader.biBitCount != 8 && info->bmiHeader.biCompression == 0) {
229 // upside down
230 INT rc = 0;
231 BITMAPINFO newInfo;
232 newInfo.bmiHeader = info->bmiHeader;
233 long lLineByte = ((newInfo.bmiHeader.biWidth * (info->bmiHeader.biBitCount == 15 ? 16 : info->bmiHeader.biBitCount) + 31) / 32) * 4;
234 long lHeight = -newInfo.bmiHeader.biHeight;
235 newInfo.bmiHeader.biHeight = -info->bmiHeader.biHeight;
236
237 char *newBits = (char *)malloc( lLineByte * lHeight );
238 if(newBits) {
239 unsigned char *pbSrc = (unsigned char *)bits + lLineByte * (lHeight - 1);
240 unsigned char *pbDst = (unsigned char *)newBits;
241 for(int y = 0; y < lHeight; y++) {
242 memcpy( pbDst, pbSrc, lLineByte );
243 pbDst += lLineByte;
244 pbSrc -= lLineByte;
245 }
246 rc = SetDIBitsToDevice_( hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, (void *)newBits, &newInfo, DIB_RGB_COLORS );
247 free( newBits );
248 }
249 return rc;
250 }
251//SvL: Breaks startup bitmap of Acrobat Reader 4.05
252#if 0
253 else
254 if(info->bmiHeader.biBitCount == 8 && info->bmiHeader.biCompression == 0 && !(GetDeviceCaps( hdc, RASTERCAPS ) & RC_PALETTE)) {
255 INT rc = 0;
256 // convert 8bit to 24bit
257
258 BITMAPINFO newInfo;
259 newInfo.bmiHeader = info->bmiHeader;
260 newInfo.bmiHeader.biBitCount = 24;
261 long lLineByte24 = ((newInfo.bmiHeader.biWidth * 24 + 31) / 32) * 4;
262 long lLineByte8 = ((newInfo.bmiHeader.biWidth * 8 + 31) / 32) * 4;
263 long lHeight = newInfo.bmiHeader.biHeight;
264 if(lHeight < 0) lHeight = -lHeight;
265
266 char *newBits = (char *)malloc( lLineByte24 * lHeight );
267 if(newBits) {
268 //
269 // Get Palette Entries
270 //
271 PALETTEENTRY aEntries[256];
272 LOGPALETTE *pLog = (LOGPALETTE *)malloc( sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * 256 );
273 pLog->palVersion = 0x300;
274 pLog->palNumEntries = 256;
275
276 HPALETTE hPaletteDummy = CreatePalette( pLog );
277 free( pLog );
278 HPALETTE hPalette = SelectPalette( hdc, hPaletteDummy, FALSE );
279 GetPaletteEntries( hPalette, 0, 255, aEntries );
280 SelectPalette( hdc, hPalette, FALSE );
281 DeleteObject( hPaletteDummy );
282
283 //
284 // convert 8bit to 24bit
285 //
286 if(newInfo.bmiHeader.biHeight > 0) {
287 unsigned char *pbSrc = (unsigned char *)bits;
288 unsigned char *pbDst = (unsigned char *)newBits;
289 for(int y = 0; y < lHeight; y++) {
290 for(int x = 0; x < newInfo.bmiHeader.biWidth; x++) {
291 PALETTEENTRY src = aEntries[pbSrc[x]];
292 pbDst[x * 3 + 0] = src.peBlue;
293 pbDst[x * 3 + 1] = src.peGreen;
294 pbDst[x * 3 + 2] = src.peRed;
295 }
296 pbDst += lLineByte24;
297 pbSrc += lLineByte8;
298 }
299 } else {
300 // upside down
301 newInfo.bmiHeader.biHeight = -info->bmiHeader.biHeight;
302 unsigned char *pbSrc = (unsigned char *)bits + lLineByte8 * (lHeight - 1);
303 unsigned char *pbDst = (unsigned char *)newBits;
304 for(int y = 0; y < lHeight; y++) {
305 for(int x = 0; x < newInfo.bmiHeader.biWidth; x++) {
306 PALETTEENTRY src = aEntries[pbSrc[x]];
307 pbDst[x * 3 + 0] = src.peBlue;
308 pbDst[x * 3 + 1] = src.peGreen;
309 pbDst[x * 3 + 2] = src.peRed;
310 }
311 pbDst += lLineByte24;
312 pbSrc -= lLineByte8;
313 }
314 }
315 rc = SetDIBitsToDevice_( hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, (void *)newBits, &newInfo, DIB_RGB_COLORS );
316 free( newBits );
317 }
318 return rc;
319 }
320#endif
321 else {
322 return SetDIBitsToDevice_( hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, bits, info, coloruse );
323 }
324}
325//******************************************************************************
326//******************************************************************************
327BOOL WIN32API PatBlt(HDC hdc,int nXLeft,int nYLeft,int nWidth,int nHeight,DWORD dwRop)
328{
329 BOOL rc;
330
331 //CB: Open32 bug: negative width/height not supported!
332 if (nWidth < 0)
333 {
334 nXLeft += nWidth+1;
335 nWidth = -nWidth;
336 }
337 if (nHeight < 0)
338 {
339 nYLeft += nHeight+1;
340 nHeight = -nHeight;
341 }
342 rc = O32_PatBlt(hdc,nXLeft,nYLeft,nWidth,nHeight,dwRop);
343 if(rc) {
344 DIBSection *destdib = DIBSection::findHDC(hdc);
345 if(destdib) {
346 destdib->sync(hdc, nYLeft, nHeight);
347 }
348 }
349
350 dprintf(("GDI32: PatBlt hdc %x (%d,%d) (%d,%d) returned %d\n",hdc, nXLeft,nYLeft,nWidth,nHeight,rc));
351 return(rc);
352}
353//******************************************************************************
354//******************************************************************************
355BOOL WIN32API MaskBlt( HDC arg1, int arg2, int arg3, int arg4, int arg5, HDC arg6, int arg7, int arg8, HBITMAP arg9, int arg10, int arg11, DWORD arg12)
356{
357 dprintf(("GDI32: MaskBlt"));
358 return O32_MaskBlt(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12);
359}
360//******************************************************************************
361//******************************************************************************
362BOOL WIN32API PlgBlt(HDC hdcDest, CONST POINT *lpPoint, HDC hdcSrc, int nXSrc,
363 int nYSrc, int nWidth, int nHeight, HBITMAP hbmMask,
364 int xMast, int yMask)
365{
366 dprintf(("GDI32: PlgBlt, not implemented\n"));
367 return(FALSE);
368}
369//******************************************************************************
370//******************************************************************************
371static INT StretchDIBits_(HDC hdc, INT xDst, INT yDst, INT widthDst,
372 INT heightDst, INT xSrc, INT ySrc, INT widthSrc,
373 INT heightSrc, const void *bits,
374 const BITMAPINFO *info, UINT wUsage, DWORD dwRop )
375{
376 INT rc;
377
378 dprintf(("GDI32: StretchDIBits %x to (%d,%d) (%d,%d) from (%d,%d) (%d,%d), %x %x %x %x", hdc, xDst, yDst, widthDst, heightDst, xSrc, ySrc, widthSrc, heightSrc, bits, info, wUsage, dwRop));
379
380 if(info->bmiHeader.biBitCount == 1) {
381 dprintf(("WARNING: StretchDIBits does NOT work correctly for 1 bpp bitmaps!!"));
382 }
383
384 if(wUsage == DIB_PAL_COLORS && info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
385 {
386 // workaround for open32 bug.
387 // If syscolors > 256 and wUsage == DIB_PAL_COLORS.
388
389 int i;
390 USHORT *pColorIndex = (USHORT *)info->bmiColors;
391 RGBQUAD *pColors = (RGBQUAD *) alloca(info->bmiHeader.biClrUsed *
392 sizeof(RGBQUAD));
393 BITMAPINFO *infoLoc = (BITMAPINFO *) alloca(sizeof(BITMAPINFO) +
394 info->bmiHeader.biClrUsed * sizeof(RGBQUAD));
395
396 memcpy(infoLoc, info, sizeof(BITMAPINFO));
397
398 if(GetDIBColorTable(hdc, 0, info->bmiHeader.biClrUsed, pColors) == 0) {
399 dprintf(("ERROR: StretchDIBits: GetDIBColorTable failed!!"));
400 return FALSE;
401 }
402 for(i=0;i<info->bmiHeader.biClrUsed;i++, pColorIndex++)
403 {
404 infoLoc->bmiColors[i] = pColors[*pColorIndex];
405 }
406
407 rc = O32_StretchDIBits(hdc, xDst, yDst, widthDst, heightDst, xSrc, ySrc,
408 widthSrc, heightSrc, (void *)bits,
409 (PBITMAPINFO)infoLoc, DIB_RGB_COLORS, dwRop);
410
411 //Open32 always returns height of bitmap (regardless of how many scanlines were copied)
412 if(rc != heightSrc && rc != infoLoc->bmiHeader.biHeight) {
413 dprintf(("StretchDIBits failed with rc %x", rc));
414 }
415 else {
416 rc = heightSrc;
417
418 DIBSection *destdib = DIBSection::findHDC(hdc);
419 if(destdib) {
420 if(widthDst == widthSrc && heightDst == heightSrc &&
421 destdib->GetBitCount() == infoLoc->bmiHeader.biBitCount &&
422 destdib->GetBitCount() == 8)
423 {
424 destdib->sync(xDst, yDst, widthDst, heightDst, (PVOID)bits);
425 }
426 else destdib->sync(hdc, yDst, heightDst);
427 }
428 }
429
430 return rc;
431 }
432 rc = O32_StretchDIBits(hdc, xDst, yDst, widthDst, heightDst, xSrc, ySrc,
433 widthSrc, heightSrc, (void *)bits,
434 (PBITMAPINFO)info, wUsage, dwRop);
435 //Open32 always returns height of bitmap (regardless of how many scanlines were copied)
436 if(rc != heightSrc && rc != info->bmiHeader.biHeight) {
437 dprintf(("StretchDIBits failed with rc %x", rc));
438 }
439 else
440 {
441 rc = heightSrc;
442
443 DIBSection *destdib = DIBSection::findHDC(hdc);
444 if(destdib) {
445 if(widthDst == widthSrc && heightDst == heightSrc &&
446 destdib->GetBitCount() == info->bmiHeader.biBitCount &&
447 destdib->GetBitCount() == 8)
448 {
449 destdib->sync(xDst, yDst, widthDst, heightDst, (PVOID)bits);
450 }
451 else destdib->sync(hdc, yDst, heightDst);
452 }
453 }
454
455 return rc;
456}
457//******************************************************************************
458//******************************************************************************
459INT WIN32API StretchDIBits(HDC hdc, INT xDst, INT yDst, INT widthDst,
460 INT heightDst, INT xSrc, INT ySrc, INT widthSrc,
461 INT heightSrc, const void *bits,
462 const BITMAPINFO *info, UINT wUsage, DWORD dwRop )
463{
464
465 if(info->bmiHeader.biHeight < 0) {
466 // upside down
467 INT rc = 0;
468 BITMAPINFO newInfo;
469 newInfo.bmiHeader = info->bmiHeader;
470 long lLineByte = ((newInfo.bmiHeader.biWidth * (info->bmiHeader.biBitCount == 15 ? 16 : info->bmiHeader.biBitCount) + 31) / 32) * 4;
471 long lHeight = -newInfo.bmiHeader.biHeight;
472 newInfo.bmiHeader.biHeight = -newInfo.bmiHeader.biHeight;
473
474 char *newBits = (char *)malloc( lLineByte * lHeight );
475 if(newBits) {
476 unsigned char *pbSrc = (unsigned char *)bits + lLineByte * (lHeight - 1);
477 unsigned char *pbDst = (unsigned char *)newBits;
478 for(int y = 0; y < lHeight; y++) {
479 memcpy( pbDst, pbSrc, lLineByte );
480 pbDst += lLineByte;
481 pbSrc -= lLineByte;
482 }
483 rc = StretchDIBits_(hdc, xDst, yDst, widthDst, heightDst, xSrc, ySrc, widthSrc, heightSrc, newBits, info, wUsage, dwRop);
484 free( newBits );
485 }
486 return rc;
487 } else {
488 return StretchDIBits_(hdc, xDst, yDst, widthDst, heightDst, xSrc, ySrc, widthSrc, heightSrc, bits, info, wUsage, dwRop);
489 }
490}
491//******************************************************************************
492//******************************************************************************
493int WIN32API SetStretchBltMode( HDC arg1, int arg2)
494{
495 dprintf(("GDI32: SetStretchBltMode 0x%08X, 0x%08X\n",arg1, arg2));
496
497 if(DIBSection::getSection() != NULL)
498 {
499 DIBSection *dsect = DIBSection::findHDC(arg1);
500 if(dsect)
501 {
502 dprintf((" - DC is DIBSection\n"));
503 }
504 }
505 return O32_SetStretchBltMode(arg1, arg2);
506}
507//******************************************************************************
508//******************************************************************************
509int WIN32API GetStretchBltMode( HDC arg1)
510{
511 dprintf(("GDI32: GetStretchBltMode"));
512 return O32_GetStretchBltMode(arg1);
513}
514//******************************************************************************
515//******************************************************************************
516static ULONG QueryPaletteSize(BITMAPINFOHEADER *pBHdr)
517{
518 ULONG cbPalette;
519
520 switch (pBHdr->biBitCount)
521 {
522 case 1:
523 case 4:
524 case 8:
525 cbPalette = (1 << pBHdr->biBitCount) * sizeof(RGBQUAD);
526 break;
527
528 case 16:
529 case 24:
530 case 32:
531 cbPalette = 0;
532 break;
533
534 default:
535 dprintf(("QueryPaletteSize: error pBHdr->biBitCount = %d", pBHdr->biBitCount));
536 cbPalette = -1;
537 }
538
539 return cbPalette;
540}
541//******************************************************************************
542//******************************************************************************
543static ULONG CalcBitmapSize(ULONG cBits, LONG cx, LONG cy)
544{
545 ULONG alignment;
546 ULONG factor;
547 BOOL flag = TRUE; //true: '*' false: '/'
548
549 cy = cy < 0 ? -cy : cy;
550
551 switch(cBits)
552 {
553 case 1:
554 factor = 8;
555 flag = FALSE;
556 break;
557
558 case 4:
559 factor = 2;
560 flag = FALSE;
561 break;
562
563 case 8:
564 factor = 1;
565 break;
566
567 case 16:
568 factor = 2;
569 break;
570
571 case 24:
572 factor = 3;
573 break;
574
575 case 32:
576 return cx*cy;
577
578 default:
579 return 0;
580 }
581
582 if (flag)
583 alignment = (cx = (cx*factor)) % 4;
584 else
585 alignment = (cx = ((cx+factor-1)/factor)) % 4;
586
587 if (alignment != 0)
588 cx += 4 - alignment;
589
590 return cx*cy;
591}
592//******************************************************************************
593//******************************************************************************
Note: See TracBrowser for help on using the repository browser.