source: trunk/src/gdi32/dibitmap.cpp@ 8873

Last change on this file since 8873 was 8873, checked in by sandervl, 23 years ago

Handle management updates

File size: 21.4 KB
Line 
1/* $Id: dibitmap.cpp,v 1.32 2002-07-15 11:19:05 sandervl Exp $ */
2
3/*
4 * GDI32 dib & bitmap 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 <misc.h>
17#include <cpuhlp.h>
18#include <winuser32.h>
19#include "dibsect.h"
20#include "rgbcvt.h"
21#include <stats.h>
22#include "oslibgpi.h"
23#include <objhandle.h>
24
25#define DBG_LOCALLOG DBG_dibitmap
26#include "dbglocal.h"
27
28ULONG CalcBitmapSize(ULONG cBits, LONG cx, LONG cy);
29
30//******************************************************************************
31//******************************************************************************
32HBITMAP WIN32API CreateDIBitmap(HDC hdc, const BITMAPINFOHEADER *lpbmih,
33 DWORD fdwInit, const void *lpbInit,
34 const BITMAPINFO *lpbmi, UINT fuUsage)
35{
36 int iHeight;
37 HBITMAP rc;
38 DWORD bitfields[3];
39 WORD *newbits = NULL;
40
41 //SvL: Completely wrong result when creating a 1bpp bitmap here (converted
42 // to 8bpp by Open32)
43 if(lpbmih->biBitCount == 1) {
44 dprintf(("WARNING: CreateDIBitmap doesn't handle 1bpp bitmaps very well!!!!!"));
45 }
46
47 //TEMPORARY HACK TO PREVENT CRASH IN OPEN32 (WSeB GA)
48
49 iHeight = lpbmih->biHeight;
50 if(lpbmih->biHeight < 0)
51 {
52 dprintf(("GDI32: CreateDIBitmap negative height! (%d,%d)", lpbmih->biWidth, lpbmih->biHeight));
53 //TODO: doesn't work if memory is readonly!!
54 ((BITMAPINFOHEADER *)lpbmih)->biHeight = -lpbmih->biHeight;
55
56 if(lpbInit && fdwInit == CBM_INIT) {
57 // upside down
58 HBITMAP rc = 0;
59 long lLineByte = DIB_GetDIBWidthBytes(lpbmih->biWidth, lpbmih->biBitCount);
60 long lHeight = lpbmih->biHeight;
61
62 newbits = (WORD *)malloc( lLineByte * lHeight );
63 if(newbits) {
64 unsigned char *pbSrc = (unsigned char *)lpbInit + lLineByte * (lHeight - 1);
65 unsigned char *pbDst = (unsigned char *)newbits;
66 for(int y = 0; y < lHeight; y++) {
67 memcpy( pbDst, pbSrc, lLineByte );
68 pbDst += lLineByte;
69 pbSrc -= lLineByte;
70 }
71 rc = CreateDIBitmap(hdc, lpbmih, fdwInit, newbits, lpbmi, fuUsage);
72 free( newbits );
73 }
74
75 ((BITMAPINFOHEADER *)lpbmih)->biHeight = iHeight;
76 return rc;
77 }
78 }
79
80 // 2000/09/01 PH Netscape 4.7
81 // If color depth of lpbhmi is 16 bit and lpbmi is 8 bit,
82 // Open32 will crash since it won't allocate any palette color memory,
83 // however wants to copy it later on ...
84 int biBitCount = lpbmih->biBitCount;
85
86 if (lpbmih->biBitCount != lpbmi->bmiHeader.biBitCount)
87 {
88 dprintf(("GDI32: CreateDIBitmap: color depths of bitmaps differ! (%d,%d\n", lpbmih->biBitCount,
89 lpbmi->bmiHeader.biBitCount));
90
91 ((BITMAPINFOHEADER *)lpbmih)->biBitCount = lpbmi->bmiHeader.biBitCount;
92 }
93
94 switch(lpbmih->biBitCount) {
95 case 15:
96 case 16: //Default if BI_BITFIELDS not set is RGB 555
97 bitfields[0] = (lpbmih->biCompression == BI_BITFIELDS) ? *(DWORD *)lpbmi->bmiColors : DEFAULT_16BPP_RED_MASK;
98 bitfields[1] = (lpbmih->biCompression == BI_BITFIELDS) ? *((DWORD *)lpbmi->bmiColors + 1) : DEFAULT_16BPP_GREEN_MASK;
99 bitfields[2] = (lpbmih->biCompression == BI_BITFIELDS) ? *((DWORD *)lpbmi->bmiColors + 2) : DEFAULT_16BPP_BLUE_MASK;
100 break;
101 case 24:
102 case 32:
103 bitfields[0] = (lpbmih->biCompression == BI_BITFIELDS) ? *(DWORD *)lpbmi->bmiColors : DEFAULT_24BPP_RED_MASK;
104 bitfields[1] = (lpbmih->biCompression == BI_BITFIELDS) ? *((DWORD *)lpbmi->bmiColors + 1) : DEFAULT_24BPP_GREEN_MASK;
105 bitfields[2] = (lpbmih->biCompression == BI_BITFIELDS) ? *((DWORD *)lpbmi->bmiColors + 2) : DEFAULT_24BPP_BLUE_MASK;
106 break;
107 default:
108 bitfields[0] = 0;
109 bitfields[1] = 0;
110 bitfields[2] = 0;
111 break;
112 }
113 if(bitfields[1] == RGB555_GREEN_MASK && lpbInit && fdwInit == CBM_INIT)
114 {//RGB 555?
115 dprintf(("RGB 555->565 conversion required %x %x %x", bitfields[0], bitfields[1], bitfields[2]));
116
117 int imgsize = CalcBitmapSize(lpbmih->biBitCount, lpbmih->biWidth, lpbmih->biHeight);
118
119 newbits = (WORD *)malloc(imgsize);
120 if(CPUFeatures & CPUID_MMX) {
121 RGB555to565MMX(newbits, (WORD *)lpbInit, imgsize/sizeof(WORD));
122 }
123 else RGB555to565(newbits, (WORD *)lpbInit, imgsize/sizeof(WORD));
124 lpbInit = newbits;
125 }
126
127 rc = O32_CreateDIBitmap(hdc, lpbmih, fdwInit, lpbInit, lpbmi, fuUsage);
128
129 dprintf(("GDI32: CreateDIBitmap %x %x %x %x %x returned %x (%d,%d, bps %d)", hdc, lpbmih, fdwInit, lpbInit, fuUsage, rc, lpbmih->biWidth, lpbmih->biHeight, lpbmih->biBitCount));
130
131 if(newbits) free(newbits);
132
133 ((BITMAPINFOHEADER *)lpbmih)->biHeight = iHeight;
134 ((BITMAPINFOHEADER *)lpbmih)->biBitCount = biBitCount;
135
136 if(rc) {
137 STATS_CreateDIBitmap(rc, hdc, lpbmih, fdwInit, lpbInit, lpbmi, fuUsage);
138 if(bitfields[1] == RGB565_GREEN_MASK) {
139 //mark bitmap as RGB565
140 dprintf(("RGB565 bitmap"));
141 ObjSetHandleFlag(rc, OBJHANDLE_FLAG_BMP_RGB565, TRUE);
142 }
143 }
144
145 return rc;
146}
147//******************************************************************************
148//******************************************************************************
149HBITMAP WIN32API CreateCompatibleBitmap( HDC hdc, int nWidth, int nHeight)
150{
151 HBITMAP hBitmap;
152 pDCData pHps;
153
154 pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
155 if(!pHps)
156 {
157 SetLastError(ERROR_INVALID_HANDLE);
158 return 0;
159 }
160
161 hBitmap = O32_CreateCompatibleBitmap(hdc, nWidth, nHeight);
162 dprintf(("GDI32: CreateCompatibleBitmap %x (%d,%d) returned %x", hdc, nWidth, nHeight, hBitmap));
163 if(hBitmap) {
164 STATS_CreateCompatibleBitmap(hBitmap,hdc, nWidth, nHeight);
165 if(pHps->hwnd == 1) { //1 == HWND_DESKTOP
166 dprintf(("Screen compatible bitmap"));
167 ObjSetHandleFlag(hBitmap, OBJHANDLE_FLAG_BMP_SCREEN_COMPATIBLE, 1);
168 }
169 }
170
171 return hBitmap;
172}
173//******************************************************************************
174//CreateDisardableBitmap is obsolete and can be replaced by CreateCompatibleBitmap
175//******************************************************************************
176HBITMAP WIN32API CreateDiscardableBitmap(HDC hDC, int nWidth, int nHeight)
177{
178 dprintf(("GDI32: CreateDisardableBitmap"));
179 return CreateCompatibleBitmap(hDC, nWidth, nHeight);
180}
181//******************************************************************************
182//******************************************************************************
183HBITMAP WIN32API CreateBitmap(int nWidth, int nHeight, UINT cPlanes,
184 UINT cBitsPerPel, const void *lpvBits)
185{
186 HBITMAP hBitmap;
187
188 hBitmap = O32_CreateBitmap(nWidth, nHeight, cPlanes, cBitsPerPel, lpvBits);
189 dprintf(("GDI32: CreateBitmap (%d,%d) bps %d returned %x", nWidth, nHeight, cBitsPerPel, hBitmap));
190 if(hBitmap) STATS_CreateBitmap(hBitmap,nWidth, nHeight, cPlanes, cBitsPerPel, lpvBits);
191
192 return(hBitmap);
193}
194//******************************************************************************
195//******************************************************************************
196HBITMAP WIN32API CreateBitmapIndirect( const BITMAP *pBitmap)
197{
198 HBITMAP hBitmap;
199
200 dprintf(("GDI32: CreateBitmapIndirect (%d,%d) bpp %d bits %x", pBitmap->bmWidth, pBitmap->bmHeight, pBitmap->bmBitsPixel, pBitmap->bmBits));
201 hBitmap = O32_CreateBitmapIndirect(pBitmap);
202 if(hBitmap) STATS_CreateBitmapIndirect(hBitmap, pBitmap);
203
204 dprintf(("GDI32: CreateBitmapIndirect returned %x", hBitmap));
205 return hBitmap;
206}
207//******************************************************************************
208//*********************************************************************************
209HBITMAP WIN32API CreateDIBSection( HDC hdc, BITMAPINFO *pbmi, UINT iUsage,
210 VOID **ppvBits, HANDLE hSection, DWORD dwOffset)
211{
212 HBITMAP res = 0;
213 BOOL fFlip = 0;
214 int iHeight, iWidth;
215 BOOL fCreateDC = FALSE;
216
217 dprintf(("GDI32: CreateDIBSection %x %x %x %x %x %d", hdc, pbmi, iUsage, ppvBits, hSection, dwOffset));
218
219 //SvL: 13-9-98: StarCraft uses bitmap with negative height
220 iWidth = pbmi->bmiHeader.biWidth;
221 if(pbmi->bmiHeader.biWidth < 0)
222 {
223 dprintf(("CreateDIBSection: width %d", pbmi->bmiHeader.biWidth));
224 pbmi->bmiHeader.biWidth = -pbmi->bmiHeader.biWidth;
225 fFlip = FLIP_HOR;
226 }
227 iHeight = pbmi->bmiHeader.biHeight;
228 if(pbmi->bmiHeader.biHeight < 0)
229 {
230 dprintf(("CreateDIBSection: height %d", pbmi->bmiHeader.biHeight));
231 pbmi->bmiHeader.biHeight = -pbmi->bmiHeader.biHeight;
232 fFlip |= FLIP_VERT;
233 }
234
235 //SvL: RP7 (update) calls this api with hdc == 0
236 if(hdc == 0) {
237 hdc = CreateCompatibleDC(0);
238 fCreateDC = TRUE;
239 }
240 res = O32_CreateDIBitmap(hdc, &pbmi->bmiHeader, 0, NULL, pbmi, iUsage);
241 if (res)
242 {
243 char PalSize;
244 DIBSection *dsect;
245
246 dsect = new DIBSection((BITMAPINFOHEADER_W *)&pbmi->bmiHeader, (char *)&pbmi->bmiColors, iUsage, hSection, dwOffset, (DWORD)res, fFlip);
247
248 if(dsect != NULL)
249 {
250 PalSize = dsect->GetBitCount();
251 if(PalSize <= 8)
252 {
253 ULONG Pal[256], nrcolors;
254 LOGPALETTE tmpPal = { 0x300,1,{0,0,0,0}};
255 HPALETTE hpalCur, hpalTmp;
256
257 // Now get the current Palette from the DC
258 hpalTmp = CreatePalette(&tmpPal);
259 hpalCur = SelectPalette(hdc, hpalTmp, FALSE);
260
261 // and use it to set the DIBColorTable
262 nrcolors = GetPaletteEntries( hpalCur, 0, 1<<PalSize, (LPPALETTEENTRY)&Pal);
263 dsect->SetDIBColorTable(0, nrcolors, (LPPALETTEENTRY)&Pal);
264
265 // Restore the DC Palette
266 SelectPalette(hdc,hpalCur,FALSE);
267 DeleteObject(hpalTmp);
268 }
269
270 if(ppvBits!=NULL)
271 *ppvBits = dsect->GetDIBObject();
272
273 pbmi->bmiHeader.biWidth = iWidth;
274 pbmi->bmiHeader.biHeight = iHeight;
275
276 if(fCreateDC) DeleteDC(hdc);
277
278 STATS_CreateDIBSection(res, hdc, pbmi, iUsage, ppvBits, hSection, dwOffset);
279
280 return(res);
281 }
282 }
283 if(fCreateDC) DeleteDC(hdc);
284
285 /* Error. */
286 if (res)
287 DeleteObject(res);
288 *ppvBits = NULL;
289
290#ifdef DEBUG
291 dprintf(("GDI32: CreateDIBSection, error!\n"));
292 dprintf(("pbmi->biWidth %d", pbmi->bmiHeader.biWidth));
293 dprintf(("pbmi->biHeight %d", pbmi->bmiHeader.biHeight));
294 dprintf(("pbmi->biBitCount %d", pbmi->bmiHeader.biBitCount));
295#endif
296
297 return 0;
298}
299//******************************************************************************
300//******************************************************************************
301UINT WIN32API GetDIBColorTable(HDC hdc, UINT uStartIndex, UINT cEntries,
302 RGBQUAD *pColors)
303{
304 DIBSection *dsect = DIBSection::findHDC(hdc);
305 UINT rc;
306 int i;
307
308 dprintf(("GetDIBColorTable %x %d->%d %x", hdc, uStartIndex, cEntries, pColors));
309
310 if(dsect)
311 {
312 return(dsect->GetDIBColorTable(uStartIndex, cEntries, pColors));
313 }
314 //TODO: Is this correct?????
315 // Wine returns 0 if bitmap selected into dc with bpp > 8
316 HPALETTE hpal = GetCurrentObject(hdc, OBJ_PAL);
317 rc = O32_GetPaletteEntries(hpal, uStartIndex, cEntries, (PALETTEENTRY *)pColors);
318 for(i=0;i<cEntries;i++)
319 {
320 BYTE tmp;
321 tmp = pColors[i].rgbBlue;
322 pColors[i].rgbBlue = pColors[i].rgbRed;
323 pColors[i].rgbRed = tmp;
324 pColors[i].rgbReserved = 0;
325 }
326 dprintf(("GDI32: GetDIBColorTable returns %d\n", rc));
327 return(rc);
328}
329//******************************************************************************
330//******************************************************************************
331UINT WIN32API SetDIBColorTable(HDC hdc, UINT uStartIndex, UINT cEntries,
332 RGBQUAD *pColors)
333{
334 DIBSection *dsect = DIBSection::findHDC(hdc);
335
336 dprintf(("GDI32: SetDIBColorTable %x %d,%d %x", hdc, uStartIndex, cEntries, pColors));
337 if(dsect)
338 {
339 return(dsect->SetDIBColorTable(uStartIndex, cEntries, pColors));
340 }
341 else return(0);
342}
343//******************************************************************************
344//******************************************************************************
345LONG WIN32API GetBitmapBits( HBITMAP hBitmap, LONG arg2, PVOID arg3)
346{
347 dprintf(("GDI32: GetBitmapBits %x", hBitmap));
348 return O32_GetBitmapBits(hBitmap, arg2, arg3);
349}
350//******************************************************************************
351//******************************************************************************
352LONG WIN32API SetBitmapBits( HBITMAP hBitmap, LONG arg2, const VOID * arg3)
353{
354 dprintf(("GDI32: SetBitmapBits %x", hBitmap));
355 return O32_SetBitmapBits(hBitmap, (DWORD)arg2, arg3);
356}
357//******************************************************************************
358//******************************************************************************
359BOOL WIN32API GetBitmapDimensionEx( HBITMAP hBitmap, PSIZE pSize)
360{
361 dprintf(("GDI32: GetBitmapDimensionEx %x (%d,%d)", hBitmap, pSize->cx, pSize->cy));
362 return O32_GetBitmapDimensionEx(hBitmap, pSize);
363}
364//******************************************************************************
365//******************************************************************************
366BOOL WIN32API SetBitmapDimensionEx( HBITMAP arg1, int arg2, int arg3, PSIZE arg4)
367{
368 dprintf(("GDI32: SetBitmapDimensionEx"));
369 return O32_SetBitmapDimensionEx(arg1, arg2, arg3, arg4);
370}
371//******************************************************************************
372//******************************************************************************
373int WIN32API GetDIBits(HDC hdc, HBITMAP hBitmap, UINT uStartScan, UINT cScanLines,
374 void *lpvBits, PBITMAPINFO lpbi, UINT uUsage)
375{
376 int nrlines;
377
378 dprintf(("GDI32: GetDIBits %x %x %d %d %x %x (biBitCount %d) %d", hdc, hBitmap, uStartScan, cScanLines, lpvBits, lpbi, lpbi->bmiHeader.biBitCount, uUsage));
379
380 //SvL: WGSS screws up the DC if it's a memory DC
381 // TODO: Fix in WGSS
382 HDC hdcMem = CreateCompatibleDC(0);
383
384 nrlines = O32_GetDIBits(hdcMem, hBitmap, uStartScan, cScanLines, lpvBits, lpbi, uUsage);
385
386 DeleteDC(hdcMem);
387
388 if(lpvBits) {
389 // set proper color masks (only if lpvBits not NULL)
390 switch(lpbi->bmiHeader.biBitCount) {
391 case 15:
392 case 16: //RGB 565
393 {
394 DWORD dwFlags;
395
396 dwFlags = ObjQueryHandleFlags(hBitmap);
397 if(dwFlags & (OBJHANDLE_FLAG_BMP_SCREEN_COMPATIBLE|OBJHANDLE_FLAG_BMP_RGB565)) {
398 ((DWORD*)(lpbi->bmiColors))[0] = RGB565_RED_MASK;
399 ((DWORD*)(lpbi->bmiColors))[1] = RGB565_GREEN_MASK;
400 ((DWORD*)(lpbi->bmiColors))[2] = RGB565_BLUE_MASK;
401 }
402 else {
403 ((DWORD*)(lpbi->bmiColors))[0] = RGB555_RED_MASK;
404 ((DWORD*)(lpbi->bmiColors))[1] = RGB555_GREEN_MASK;
405 ((DWORD*)(lpbi->bmiColors))[2] = RGB555_BLUE_MASK;
406 }
407 break;
408 }
409 case 24:
410 case 32:
411 ((DWORD*)(lpbi->bmiColors))[0] = DEFAULT_24BPP_RED_MASK;
412 ((DWORD*)(lpbi->bmiColors))[1] = DEFAULT_24BPP_GREEN_MASK;
413 ((DWORD*)(lpbi->bmiColors))[2] = DEFAULT_24BPP_BLUE_MASK;
414 break;
415 }
416 if(lpbi->bmiHeader.biCompression == BI_RGB && lpbi->bmiHeader.biBitCount > 8) {
417 lpbi->bmiHeader.biCompression = BI_BITFIELDS;
418 dprintf(("BI_BITFIELDS: %x %x %x", ((DWORD*)(lpbi->bmiColors))[0], ((DWORD*)(lpbi->bmiColors))[1], ((DWORD*)(lpbi->bmiColors))[2]));
419 }
420 }
421 if(nrlines && lpvBits && lpbi->bmiHeader.biBitCount == 16 && ((DWORD*)(lpbi->bmiColors))[1] == RGB555_GREEN_MASK)
422 {//RGB 555?
423 dprintf(("RGB 565->555 conversion required"));
424
425 int imgsize = CalcBitmapSize(lpbi->bmiHeader.biBitCount,
426 lpbi->bmiHeader.biWidth, nrlines);
427
428 if(CPUFeatures & CPUID_MMX) {
429 RGB565to555MMX((WORD *)lpvBits, (WORD *)lpvBits, imgsize/sizeof(WORD));
430 }
431 else RGB565to555((WORD *)lpvBits, (WORD *)lpvBits, imgsize/sizeof(WORD));
432 }
433
434 //WGSS/Open32 returns 0 when querying the bitmap info; must return nr of scanlines
435 //as 0 signals failure
436 if(lpvBits == NULL) {
437 nrlines = cScanLines;
438 }
439 dprintf(("GDI32: GetDIBits returned %d", nrlines));
440 return nrlines;
441}
442//******************************************************************************
443//******************************************************************************
444void WIN32API ConvertRGB555to565(LPVOID dest, LPVOID src, UINT imgsize)
445{
446 if(CPUFeatures & CPUID_MMX) {
447 RGB555to565MMX((WORD *)dest, (WORD *)src, imgsize/sizeof(WORD));
448 }
449 else RGB555to565((WORD *)dest, (WORD *)src, imgsize/sizeof(WORD));
450}
451//******************************************************************************
452//******************************************************************************
453int WIN32API SetDIBits(HDC hdc, HBITMAP hBitmap, UINT startscan, UINT numlines, const VOID *pBits,
454 const BITMAPINFO *pBitmapInfo, UINT usage)
455{
456 int ret;
457 DWORD bitfields[3];
458 WORD *newbits = NULL;
459
460 dprintf(("GDI32: SetDIBits %x %x %x %x %x %x %x", hdc, hBitmap, startscan, numlines, pBits, pBitmapInfo, usage));
461
462 //SvL: Open32's SetDIBits really messes things up for 1 bpp bitmaps, must use SetBitmapBits
463 if(pBitmapInfo->bmiHeader.biBitCount == 1 && startscan == 0 && numlines == pBitmapInfo->bmiHeader.biHeight)
464 {//WARNING: hack alert!
465 int dibwidth = DIB_GetDIBWidthBytes(pBitmapInfo->bmiHeader.biWidth, 1);
466 int bmpwidth = BITMAP_GetWidthBytes(pBitmapInfo->bmiHeader.biWidth, 1);
467 char *newpix = (char *)malloc(dibwidth*pBitmapInfo->bmiHeader.biHeight);
468 char *orgpix = (char *)pBits;
469 int ret;
470
471 dprintf(("Flipping 1bpp bitmap and calling SetBitmapBits (WORKAROUND) (%d -> %d)", dibwidth, bmpwidth));
472 newpix += ((pBitmapInfo->bmiHeader.biHeight-1)*bmpwidth);
473
474 //flip bitmap here; SetDIBits assumes origin is left bottom, SetBitmapBits left top
475 //SetDIBits assumes DWORD aligned data
476 //SetBitmapBits assumes WORD aligned data
477 for(int i=0;i<pBitmapInfo->bmiHeader.biHeight;i++) {
478 memcpy(newpix, orgpix, bmpwidth);
479
480 newpix -= bmpwidth;
481 orgpix += dibwidth;
482 }
483 newpix += bmpwidth;
484 ret = O32_SetBitmapBits(hBitmap, pBitmapInfo->bmiHeader.biSizeImage, newpix);
485
486 free(newpix);
487 return ret;
488 }
489#ifdef DEBUG
490 if(pBitmapInfo->bmiHeader.biBitCount == 1) {
491 dprintf(("ERROR: SetDIBits does NOT work well for 1 bpp bitmaps!!!!!"));
492 }
493#endif
494
495 switch(pBitmapInfo->bmiHeader.biBitCount) {
496 case 15:
497 case 16: //Default if BI_BITFIELDS not set is RGB 555
498 bitfields[0] = (pBitmapInfo->bmiHeader.biCompression == BI_BITFIELDS) ? *(DWORD *)pBitmapInfo->bmiColors : DEFAULT_16BPP_RED_MASK;
499 bitfields[1] = (pBitmapInfo->bmiHeader.biCompression == BI_BITFIELDS) ? *((DWORD *)pBitmapInfo->bmiColors + 1) : DEFAULT_16BPP_GREEN_MASK;
500 bitfields[2] = (pBitmapInfo->bmiHeader.biCompression == BI_BITFIELDS) ? *((DWORD *)pBitmapInfo->bmiColors + 2) : DEFAULT_16BPP_BLUE_MASK;
501 break;
502
503 case 24:
504 case 32:
505 bitfields[0] = (pBitmapInfo->bmiHeader.biCompression == BI_BITFIELDS) ? *(DWORD *)pBitmapInfo->bmiColors : DEFAULT_24BPP_RED_MASK;
506 bitfields[1] = (pBitmapInfo->bmiHeader.biCompression == BI_BITFIELDS) ? *((DWORD *)pBitmapInfo->bmiColors + 1) : DEFAULT_24BPP_GREEN_MASK;
507 bitfields[2] = (pBitmapInfo->bmiHeader.biCompression == BI_BITFIELDS) ? *((DWORD *)pBitmapInfo->bmiColors + 2) : DEFAULT_24BPP_BLUE_MASK;
508 break;
509 default:
510 bitfields[0] = 0;
511 bitfields[1] = 0;
512 bitfields[2] = 0;
513 break;
514 }
515 if(pBits && bitfields[1] == RGB555_GREEN_MASK)
516 {//RGB 555?
517 dprintf(("RGB 555->565 conversion required %x %x %x", bitfields[0], bitfields[1], bitfields[2]));
518
519 int imgsize = CalcBitmapSize(pBitmapInfo->bmiHeader.biBitCount,
520 pBitmapInfo->bmiHeader.biWidth, numlines);
521
522 newbits = (WORD *)malloc(imgsize);
523 if(CPUFeatures & CPUID_MMX) {
524 RGB555to565MMX(newbits, (WORD *)pBits, imgsize/sizeof(WORD));
525 }
526 else RGB555to565(newbits, (WORD *)pBits, imgsize/sizeof(WORD));
527 pBits = newbits;
528 }
529
530 if(pBitmapInfo->bmiHeader.biHeight < 0) {
531 dprintf(("!WARNING! Negative height!!"));
532 }
533 ret = O32_SetDIBits(hdc, hBitmap, startscan, numlines, pBits, pBitmapInfo, usage);
534 if(newbits) free(newbits);
535
536 if(DIBSection::getSection() != NULL)
537 {
538 DIBSection *dsect;
539
540 dsect = DIBSection::findObj(hBitmap);
541 if(dsect) {
542 HBITMAP hBmpOld = SelectObject(hdc, hBitmap);
543 dsect->sync(hdc, 0, dsect->GetHeight());
544 SelectObject(hdc, hBmpOld);
545 }
546 }
547
548 return ret;
549}
550//******************************************************************************
551//******************************************************************************
Note: See TracBrowser for help on using the repository browser.