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