| 1 | /* $Id: blit.cpp,v 1.21 2000-11-22 21:03:53 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 |
|
|---|
| 24 | static ULONG QueryPaletteSize(BITMAPINFOHEADER *pBHdr);
|
|---|
| 25 | static ULONG CalcBitmapSize(ULONG cBits, LONG cx, LONG cy);
|
|---|
| 26 |
|
|---|
| 27 | //******************************************************************************
|
|---|
| 28 | //******************************************************************************
|
|---|
| 29 | BOOL 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 | //******************************************************************************
|
|---|
| 57 | BOOL 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 | //******************************************************************************
|
|---|
| 93 | INT WIN32API 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, iHeight, bmpsize;
|
|---|
| 101 | WORD *newbits = 0;
|
|---|
| 102 |
|
|---|
| 103 | 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",
|
|---|
| 104 | hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, (LPVOID) bits, (PBITMAPINFO)info, coloruse));
|
|---|
| 105 |
|
|---|
| 106 | SetLastError(ERROR_SUCCESS);
|
|---|
| 107 | if(info == NULL) {
|
|---|
| 108 | goto invalid_parameter;
|
|---|
| 109 | }
|
|---|
| 110 | height = info->bmiHeader.biHeight;
|
|---|
| 111 | width = info->bmiHeader.biWidth;
|
|---|
| 112 |
|
|---|
| 113 | if (height < 0) height = -height;
|
|---|
| 114 | if (!lines || (startscan >= height)) {
|
|---|
| 115 | goto invalid_parameter;
|
|---|
| 116 | }
|
|---|
| 117 | if (startscan + lines > height) lines = height - startscan;
|
|---|
| 118 |
|
|---|
| 119 | if (ySrc < startscan) ySrc = startscan;
|
|---|
| 120 | else if (ySrc >= startscan + lines) goto invalid_parameter;
|
|---|
| 121 |
|
|---|
| 122 | if (xSrc >= width) goto invalid_parameter;
|
|---|
| 123 |
|
|---|
| 124 | if (ySrc + cy >= startscan + lines) cy = startscan + lines - ySrc;
|
|---|
| 125 |
|
|---|
| 126 | if (xSrc + cx >= width) cx = width - xSrc;
|
|---|
| 127 |
|
|---|
| 128 | if (!cx || !cy) goto invalid_parameter;
|
|---|
| 129 |
|
|---|
| 130 | // EB: ->>> Crazy. Nobody seen this Open32 bug ?
|
|---|
| 131 | // Dont't like dirty pointers, but Open32 needs a bit help.
|
|---|
| 132 | // Only tested with winmine.
|
|---|
| 133 | palsize = QueryPaletteSize((BITMAPINFOHEADER*)&info->bmiHeader);
|
|---|
| 134 | imgsize = CalcBitmapSize(info->bmiHeader.biBitCount,
|
|---|
| 135 | info->bmiHeader.biWidth, info->bmiHeader.biHeight);
|
|---|
| 136 | ptr = ((char *)info) + palsize + sizeof(BITMAPINFOHEADER);
|
|---|
| 137 | if(bits >= ptr && bits < ptr + imgsize)
|
|---|
| 138 | {
|
|---|
| 139 | bits = (char *)bits - imgsize +
|
|---|
| 140 | CalcBitmapSize(info->bmiHeader.biBitCount,
|
|---|
| 141 | info->bmiHeader.biWidth, lines);
|
|---|
| 142 | }
|
|---|
| 143 | // EB: <<<-
|
|---|
| 144 |
|
|---|
| 145 | //SvL: RP7's bitmap size is not correct; fix it here or else
|
|---|
| 146 | // the blit is messed up in Open32
|
|---|
| 147 | bmpsize = info->bmiHeader.biSizeImage;
|
|---|
| 148 | if(info->bmiHeader.biCompression == 0 && info->bmiHeader.biSizeImage &&
|
|---|
| 149 | info->bmiHeader.biSizeImage < imgsize)
|
|---|
| 150 | {
|
|---|
| 151 | ((BITMAPINFO *)info)->bmiHeader.biSizeImage = imgsize;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | //SvL: Ignore BI_BITFIELDS type (SetDIBitsToDevice fails otherwise)
|
|---|
| 155 | if(info->bmiHeader.biCompression == BI_BITFIELDS) {
|
|---|
| 156 | DWORD *bitfields = (DWORD *)info->bmiColors;
|
|---|
| 157 |
|
|---|
| 158 | ((BITMAPINFO *)info)->bmiHeader.biCompression = 0;
|
|---|
| 159 | compression = BI_BITFIELDS;
|
|---|
| 160 |
|
|---|
| 161 | if(*(bitfields+1) == 0x3E0)
|
|---|
| 162 | {//RGB 555?
|
|---|
| 163 | dprintf(("BI_BITFIELDS compression %x %x %x", *bitfields, *(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 |
|
|---|
| 174 | iHeight = info->bmiHeader.biHeight;
|
|---|
| 175 | if(info->bmiHeader.biHeight < 0) {
|
|---|
| 176 | ((BITMAPINFO *)info)->bmiHeader.biHeight = -info->bmiHeader.biHeight;
|
|---|
| 177 | }
|
|---|
| 178 | result = O32_SetDIBitsToDevice(hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, (PVOID) bits, (PBITMAPINFO)info, coloruse);
|
|---|
| 179 | //SvL: Wrong Open32 return value
|
|---|
| 180 | // result = (result == TRUE) ? lines : 0;
|
|---|
| 181 | result = (result == TRUE) ? cy : 0;
|
|---|
| 182 |
|
|---|
| 183 | 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",
|
|---|
| 184 | hdc, xDest, yDest, cx, cy, xSrc, ySrc, startscan, lines, (LPVOID) bits, (PBITMAPINFO)info, coloruse, result));
|
|---|
| 185 | 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));
|
|---|
| 186 |
|
|---|
| 187 | if(compression == BI_BITFIELDS) {
|
|---|
| 188 | ((BITMAPINFO *)info)->bmiHeader.biCompression = BI_BITFIELDS;
|
|---|
| 189 | if(newbits) free(newbits);
|
|---|
| 190 | }
|
|---|
| 191 | ((BITMAPINFO *)info)->bmiHeader.biHeight = iHeight;
|
|---|
| 192 | ((BITMAPINFO *)info)->bmiHeader.biSizeImage = bmpsize;
|
|---|
| 193 | return result;
|
|---|
| 194 |
|
|---|
| 195 | invalid_parameter:
|
|---|
| 196 | SetLastError(ERROR_INVALID_PARAMETER);
|
|---|
| 197 | return 0;
|
|---|
| 198 | }
|
|---|
| 199 | //******************************************************************************
|
|---|
| 200 | //******************************************************************************
|
|---|
| 201 | BOOL WIN32API PatBlt(HDC hdc,int nXLeft,int nYLeft,int nWidth,int nHeight,DWORD dwRop)
|
|---|
| 202 | {
|
|---|
| 203 | BOOL rc;
|
|---|
| 204 |
|
|---|
| 205 | //CB: Open32 bug: negative width/height not supported!
|
|---|
| 206 | if (nWidth < 0)
|
|---|
| 207 | {
|
|---|
| 208 | nXLeft += nWidth+1;
|
|---|
| 209 | nWidth = -nWidth;
|
|---|
| 210 | }
|
|---|
| 211 | if (nHeight < 0)
|
|---|
| 212 | {
|
|---|
| 213 | nYLeft += nHeight+1;
|
|---|
| 214 | nHeight = -nHeight;
|
|---|
| 215 | }
|
|---|
| 216 | rc = O32_PatBlt(hdc,nXLeft,nYLeft,nWidth,nHeight,dwRop);
|
|---|
| 217 | if(rc) {
|
|---|
| 218 | DIBSection *destdib = DIBSection::findHDC(hdc);
|
|---|
| 219 | if(destdib) {
|
|---|
| 220 | destdib->sync(hdc, nYLeft, nHeight);
|
|---|
| 221 | }
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | dprintf(("GDI32: PatBlt hdc %x (%d,%d) (%d,%d) returned %d\n",hdc, nXLeft,nYLeft,nWidth,nHeight,rc));
|
|---|
| 225 | return(rc);
|
|---|
| 226 | }
|
|---|
| 227 | //******************************************************************************
|
|---|
| 228 | //******************************************************************************
|
|---|
| 229 | BOOL 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)
|
|---|
| 230 | {
|
|---|
| 231 | dprintf(("GDI32: MaskBlt"));
|
|---|
| 232 | return O32_MaskBlt(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12);
|
|---|
| 233 | }
|
|---|
| 234 | //******************************************************************************
|
|---|
| 235 | //******************************************************************************
|
|---|
| 236 | BOOL WIN32API PlgBlt(HDC hdcDest, CONST POINT *lpPoint, HDC hdcSrc, int nXSrc,
|
|---|
| 237 | int nYSrc, int nWidth, int nHeight, HBITMAP hbmMask,
|
|---|
| 238 | int xMast, int yMask)
|
|---|
| 239 | {
|
|---|
| 240 | dprintf(("GDI32: PlgBlt, not implemented\n"));
|
|---|
| 241 | return(FALSE);
|
|---|
| 242 | }
|
|---|
| 243 | //******************************************************************************
|
|---|
| 244 | //******************************************************************************
|
|---|
| 245 | INT WIN32API StretchDIBits(HDC hdc, INT xDst, INT yDst, INT widthDst,
|
|---|
| 246 | INT heightDst, INT xSrc, INT ySrc, INT widthSrc,
|
|---|
| 247 | INT heightSrc, const void *bits,
|
|---|
| 248 | const BITMAPINFO *info, UINT wUsage, DWORD dwRop )
|
|---|
| 249 | {
|
|---|
| 250 | INT rc;
|
|---|
| 251 |
|
|---|
| 252 | 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));
|
|---|
| 253 |
|
|---|
| 254 | if(info->bmiHeader.biBitCount == 1) {
|
|---|
| 255 | dprintf(("WARNING: StretchDIBits does NOT work correctly for 1 bpp bitmaps!!"));
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | if(wUsage == DIB_PAL_COLORS && info->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
|
|---|
| 259 | {
|
|---|
| 260 | // workaround for open32 bug.
|
|---|
| 261 | // If syscolors > 256 and wUsage == DIB_PAL_COLORS.
|
|---|
| 262 |
|
|---|
| 263 | int i;
|
|---|
| 264 | USHORT *pColorIndex = (USHORT *)info->bmiColors;
|
|---|
| 265 | RGBQUAD *pColors = (RGBQUAD *) alloca(info->bmiHeader.biClrUsed *
|
|---|
| 266 | sizeof(RGBQUAD));
|
|---|
| 267 | BITMAPINFO *infoLoc = (BITMAPINFO *) alloca(sizeof(BITMAPINFO) +
|
|---|
| 268 | info->bmiHeader.biClrUsed * sizeof(RGBQUAD));
|
|---|
| 269 |
|
|---|
| 270 | memcpy(infoLoc, info, sizeof(BITMAPINFO));
|
|---|
| 271 |
|
|---|
| 272 | if(GetDIBColorTable(hdc, 0, info->bmiHeader.biClrUsed, pColors) == 0) {
|
|---|
| 273 | dprintf(("ERROR: StretchDIBits: GetDIBColorTable failed!!"));
|
|---|
| 274 | return FALSE;
|
|---|
| 275 | }
|
|---|
| 276 | for(i=0;i<info->bmiHeader.biClrUsed;i++, pColorIndex++)
|
|---|
| 277 | {
|
|---|
| 278 | infoLoc->bmiColors[i] = pColors[*pColorIndex];
|
|---|
| 279 | }
|
|---|
| 280 |
|
|---|
| 281 | rc = O32_StretchDIBits(hdc, xDst, yDst, widthDst, heightDst, xSrc, ySrc,
|
|---|
| 282 | widthSrc, heightSrc, (void *)bits,
|
|---|
| 283 | (PBITMAPINFO)infoLoc, DIB_RGB_COLORS, dwRop);
|
|---|
| 284 |
|
|---|
| 285 | //Open32 always returns height of bitmap (regardless of how many scanlines were copied)
|
|---|
| 286 | if(rc != heightSrc && rc != infoLoc->bmiHeader.biHeight) {
|
|---|
| 287 | dprintf(("StretchDIBits failed with rc %x", rc));
|
|---|
| 288 | }
|
|---|
| 289 | else {
|
|---|
| 290 | rc = heightSrc;
|
|---|
| 291 |
|
|---|
| 292 | DIBSection *destdib = DIBSection::findHDC(hdc);
|
|---|
| 293 | if(destdib) {
|
|---|
| 294 | if(widthDst == widthSrc && heightDst == heightSrc &&
|
|---|
| 295 | destdib->GetBitCount() == infoLoc->bmiHeader.biBitCount &&
|
|---|
| 296 | destdib->GetBitCount() == 8)
|
|---|
| 297 | {
|
|---|
| 298 | destdib->sync(xDst, yDst, widthDst, heightDst, (PVOID)bits);
|
|---|
| 299 | }
|
|---|
| 300 | else destdib->sync(hdc, yDst, heightDst);
|
|---|
| 301 | }
|
|---|
| 302 | }
|
|---|
| 303 |
|
|---|
| 304 | return rc;
|
|---|
| 305 | }
|
|---|
| 306 | rc = O32_StretchDIBits(hdc, xDst, yDst, widthDst, heightDst, xSrc, ySrc,
|
|---|
| 307 | widthSrc, heightSrc, (void *)bits,
|
|---|
| 308 | (PBITMAPINFO)info, wUsage, dwRop);
|
|---|
| 309 | //Open32 always returns height of bitmap (regardless of how many scanlines were copied)
|
|---|
| 310 | if(rc != heightSrc && rc != info->bmiHeader.biHeight) {
|
|---|
| 311 | dprintf(("StretchDIBits failed with rc %x", rc));
|
|---|
| 312 | }
|
|---|
| 313 | else
|
|---|
| 314 | {
|
|---|
| 315 | rc = heightSrc;
|
|---|
| 316 |
|
|---|
| 317 | DIBSection *destdib = DIBSection::findHDC(hdc);
|
|---|
| 318 | if(destdib) {
|
|---|
| 319 | if(widthDst == widthSrc && heightDst == heightSrc &&
|
|---|
| 320 | destdib->GetBitCount() == info->bmiHeader.biBitCount &&
|
|---|
| 321 | destdib->GetBitCount() == 8)
|
|---|
| 322 | {
|
|---|
| 323 | destdib->sync(xDst, yDst, widthDst, heightDst, (PVOID)bits);
|
|---|
| 324 | }
|
|---|
| 325 | else destdib->sync(hdc, yDst, heightDst);
|
|---|
| 326 | }
|
|---|
| 327 | }
|
|---|
| 328 |
|
|---|
| 329 | return rc;
|
|---|
| 330 | }
|
|---|
| 331 | //******************************************************************************
|
|---|
| 332 | //******************************************************************************
|
|---|
| 333 | int WIN32API SetStretchBltMode( HDC arg1, int arg2)
|
|---|
| 334 | {
|
|---|
| 335 | dprintf(("GDI32: SetStretchBltMode 0x%08X, 0x%08X\n",arg1, arg2));
|
|---|
| 336 |
|
|---|
| 337 | if(DIBSection::getSection() != NULL)
|
|---|
| 338 | {
|
|---|
| 339 | DIBSection *dsect = DIBSection::findHDC(arg1);
|
|---|
| 340 | if(dsect)
|
|---|
| 341 | {
|
|---|
| 342 | dprintf((" - DC is DIBSection\n"));
|
|---|
| 343 | }
|
|---|
| 344 | }
|
|---|
| 345 | return O32_SetStretchBltMode(arg1, arg2);
|
|---|
| 346 | }
|
|---|
| 347 | //******************************************************************************
|
|---|
| 348 | //******************************************************************************
|
|---|
| 349 | int WIN32API GetStretchBltMode( HDC arg1)
|
|---|
| 350 | {
|
|---|
| 351 | dprintf(("GDI32: GetStretchBltMode"));
|
|---|
| 352 | return O32_GetStretchBltMode(arg1);
|
|---|
| 353 | }
|
|---|
| 354 | //******************************************************************************
|
|---|
| 355 | //******************************************************************************
|
|---|
| 356 | static ULONG QueryPaletteSize(BITMAPINFOHEADER *pBHdr)
|
|---|
| 357 | {
|
|---|
| 358 | ULONG cbPalette;
|
|---|
| 359 |
|
|---|
| 360 | switch (pBHdr->biBitCount)
|
|---|
| 361 | {
|
|---|
| 362 | case 1:
|
|---|
| 363 | case 4:
|
|---|
| 364 | case 8:
|
|---|
| 365 | cbPalette = (1 << pBHdr->biBitCount) * sizeof(RGBQUAD);
|
|---|
| 366 | break;
|
|---|
| 367 |
|
|---|
| 368 | case 16:
|
|---|
| 369 | case 24:
|
|---|
| 370 | case 32:
|
|---|
| 371 | cbPalette = 0;
|
|---|
| 372 | break;
|
|---|
| 373 |
|
|---|
| 374 | default:
|
|---|
| 375 | dprintf(("QueryPaletteSize: error pBHdr->biBitCount = %d", pBHdr->biBitCount));
|
|---|
| 376 | cbPalette = -1;
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | return cbPalette;
|
|---|
| 380 | }
|
|---|
| 381 | //******************************************************************************
|
|---|
| 382 | //******************************************************************************
|
|---|
| 383 | static ULONG CalcBitmapSize(ULONG cBits, LONG cx, LONG cy)
|
|---|
| 384 | {
|
|---|
| 385 | ULONG alignment;
|
|---|
| 386 | ULONG factor;
|
|---|
| 387 | BOOL flag = TRUE; //true: '*' false: '/'
|
|---|
| 388 |
|
|---|
| 389 | cy = cy < 0 ? -cy : cy;
|
|---|
| 390 |
|
|---|
| 391 | switch(cBits)
|
|---|
| 392 | {
|
|---|
| 393 | case 1:
|
|---|
| 394 | factor = 8;
|
|---|
| 395 | flag = FALSE;
|
|---|
| 396 | break;
|
|---|
| 397 |
|
|---|
| 398 | case 4:
|
|---|
| 399 | factor = 2;
|
|---|
| 400 | flag = FALSE;
|
|---|
| 401 | break;
|
|---|
| 402 |
|
|---|
| 403 | case 8:
|
|---|
| 404 | factor = 1;
|
|---|
| 405 | break;
|
|---|
| 406 |
|
|---|
| 407 | case 16:
|
|---|
| 408 | factor = 2;
|
|---|
| 409 | break;
|
|---|
| 410 |
|
|---|
| 411 | case 24:
|
|---|
| 412 | factor = 3;
|
|---|
| 413 | break;
|
|---|
| 414 |
|
|---|
| 415 | case 32:
|
|---|
| 416 | return cx*cy;
|
|---|
| 417 |
|
|---|
| 418 | default:
|
|---|
| 419 | return 0;
|
|---|
| 420 | }
|
|---|
| 421 |
|
|---|
| 422 | if (flag)
|
|---|
| 423 | alignment = (cx = (cx*factor)) % 4;
|
|---|
| 424 | else
|
|---|
| 425 | alignment = (cx = ((cx+factor-1)/factor)) % 4;
|
|---|
| 426 |
|
|---|
| 427 | if (alignment != 0)
|
|---|
| 428 | cx += 4 - alignment;
|
|---|
| 429 |
|
|---|
| 430 | return cx*cy;
|
|---|
| 431 | }
|
|---|
| 432 | //******************************************************************************
|
|---|
| 433 | //******************************************************************************
|
|---|