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

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

Handle management updates

File size: 21.7 KB
Line 
1/* $Id: dibitmap.cpp,v 1.31 2002-07-15 10:02:28 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#ifdef NEW_GDIHANDLES
139 if(bitfields[1] == RGB565_GREEN_MASK) {
140 //mark bitmap as RGB565
141 dprintf(("RGB565 bitmap"));
142 ObjSetHandleFlag(rc, OBJHANDLE_FLAG_BMP_RGB565, TRUE);
143 }
144#endif
145 }
146
147 return rc;
148}
149//******************************************************************************
150//******************************************************************************
151HBITMAP WIN32API CreateCompatibleBitmap( HDC hdc, int nWidth, int nHeight)
152{
153 HBITMAP hBitmap;
154#ifdef NEW_GDIHANDLES
155 pDCData pHps;
156
157 pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
158 if(!pHps)
159 {
160 SetLastError(ERROR_INVALID_HANDLE);
161 return 0;
162 }
163#endif
164
165 hBitmap = O32_CreateCompatibleBitmap(hdc, nWidth, nHeight);
166 dprintf(("GDI32: CreateCompatibleBitmap %x (%d,%d) returned %x", hdc, nWidth, nHeight, hBitmap));
167 if(hBitmap) {
168 STATS_CreateCompatibleBitmap(hBitmap,hdc, nWidth, nHeight);
169#ifdef NEW_GDIHANDLES
170 if(pHps->hwnd == 1) { //1 == HWND_DESKTOP
171 dprintf(("Screen compatible bitmap"));
172 ObjSetHandleFlag(hBitmap, OBJHANDLE_FLAG_BMP_SCREEN_COMPATIBLE, 1);
173 }
174#endif
175 }
176
177 return hBitmap;
178}
179//******************************************************************************
180//CreateDisardableBitmap is obsolete and can be replaced by CreateCompatibleBitmap
181//******************************************************************************
182HBITMAP WIN32API CreateDiscardableBitmap(HDC hDC, int nWidth, int nHeight)
183{
184 dprintf(("GDI32: CreateDisardableBitmap"));
185 return CreateCompatibleBitmap(hDC, nWidth, nHeight);
186}
187//******************************************************************************
188//******************************************************************************
189HBITMAP WIN32API CreateBitmap(int nWidth, int nHeight, UINT cPlanes,
190 UINT cBitsPerPel, const void *lpvBits)
191{
192 HBITMAP hBitmap;
193
194 hBitmap = O32_CreateBitmap(nWidth, nHeight, cPlanes, cBitsPerPel, lpvBits);
195 dprintf(("GDI32: CreateBitmap (%d,%d) bps %d returned %x", nWidth, nHeight, cBitsPerPel, hBitmap));
196 if(hBitmap) STATS_CreateBitmap(hBitmap,nWidth, nHeight, cPlanes, cBitsPerPel, lpvBits);
197
198 return(hBitmap);
199}
200//******************************************************************************
201//******************************************************************************
202HBITMAP WIN32API CreateBitmapIndirect( const BITMAP *pBitmap)
203{
204 HBITMAP hBitmap;
205
206 dprintf(("GDI32: CreateBitmapIndirect (%d,%d) bpp %d bits %x", pBitmap->bmWidth, pBitmap->bmHeight, pBitmap->bmBitsPixel, pBitmap->bmBits));
207 hBitmap = O32_CreateBitmapIndirect(pBitmap);
208 if(hBitmap) STATS_CreateBitmapIndirect(hBitmap, pBitmap);
209
210 dprintf(("GDI32: CreateBitmapIndirect returned %x", hBitmap));
211 return hBitmap;
212}
213//******************************************************************************
214//*********************************************************************************
215HBITMAP WIN32API CreateDIBSection( HDC hdc, BITMAPINFO *pbmi, UINT iUsage,
216 VOID **ppvBits, HANDLE hSection, DWORD dwOffset)
217{
218 HBITMAP res = 0;
219 BOOL fFlip = 0;
220 int iHeight, iWidth;
221 BOOL fCreateDC = FALSE;
222
223 dprintf(("GDI32: CreateDIBSection %x %x %x %x %x %d", hdc, pbmi, iUsage, ppvBits, hSection, dwOffset));
224
225 //SvL: 13-9-98: StarCraft uses bitmap with negative height
226 iWidth = pbmi->bmiHeader.biWidth;
227 if(pbmi->bmiHeader.biWidth < 0)
228 {
229 dprintf(("CreateDIBSection: width %d", pbmi->bmiHeader.biWidth));
230 pbmi->bmiHeader.biWidth = -pbmi->bmiHeader.biWidth;
231 fFlip = FLIP_HOR;
232 }
233 iHeight = pbmi->bmiHeader.biHeight;
234 if(pbmi->bmiHeader.biHeight < 0)
235 {
236 dprintf(("CreateDIBSection: height %d", pbmi->bmiHeader.biHeight));
237 pbmi->bmiHeader.biHeight = -pbmi->bmiHeader.biHeight;
238 fFlip |= FLIP_VERT;
239 }
240
241 //SvL: RP7 (update) calls this api with hdc == 0
242 if(hdc == 0) {
243 hdc = CreateCompatibleDC(0);
244 fCreateDC = TRUE;
245 }
246 res = O32_CreateDIBitmap(hdc, &pbmi->bmiHeader, 0, NULL, pbmi, iUsage);
247 if (res)
248 {
249 char PalSize;
250 DIBSection *dsect;
251
252 dsect = new DIBSection((BITMAPINFOHEADER_W *)&pbmi->bmiHeader, (char *)&pbmi->bmiColors, iUsage, hSection, dwOffset, (DWORD)res, fFlip);
253
254 if(dsect != NULL)
255 {
256 PalSize = dsect->GetBitCount();
257 if(PalSize <= 8)
258 {
259 ULONG Pal[256], nrcolors;
260 LOGPALETTE tmpPal = { 0x300,1,{0,0,0,0}};
261 HPALETTE hpalCur, hpalTmp;
262
263 // Now get the current Palette from the DC
264 hpalTmp = CreatePalette(&tmpPal);
265 hpalCur = SelectPalette(hdc, hpalTmp, FALSE);
266
267 // and use it to set the DIBColorTable
268 nrcolors = GetPaletteEntries( hpalCur, 0, 1<<PalSize, (LPPALETTEENTRY)&Pal);
269 dsect->SetDIBColorTable(0, nrcolors, (LPPALETTEENTRY)&Pal);
270
271 // Restore the DC Palette
272 SelectPalette(hdc,hpalCur,FALSE);
273 DeleteObject(hpalTmp);
274 }
275
276 if(ppvBits!=NULL)
277 *ppvBits = dsect->GetDIBObject();
278
279 pbmi->bmiHeader.biWidth = iWidth;
280 pbmi->bmiHeader.biHeight = iHeight;
281
282 if(fCreateDC) DeleteDC(hdc);
283
284 STATS_CreateDIBSection(res, hdc, pbmi, iUsage, ppvBits, hSection, dwOffset);
285
286 return(res);
287 }
288 }
289 if(fCreateDC) DeleteDC(hdc);
290
291 /* Error. */
292 if (res)
293 DeleteObject(res);
294 *ppvBits = NULL;
295
296#ifdef DEBUG
297 dprintf(("GDI32: CreateDIBSection, error!\n"));
298 dprintf(("pbmi->biWidth %d", pbmi->bmiHeader.biWidth));
299 dprintf(("pbmi->biHeight %d", pbmi->bmiHeader.biHeight));
300 dprintf(("pbmi->biBitCount %d", pbmi->bmiHeader.biBitCount));
301#endif
302
303 return 0;
304}
305//******************************************************************************
306//******************************************************************************
307UINT WIN32API GetDIBColorTable(HDC hdc, UINT uStartIndex, UINT cEntries,
308 RGBQUAD *pColors)
309{
310 DIBSection *dsect = DIBSection::findHDC(hdc);
311 UINT rc;
312 int i;
313
314 dprintf(("GetDIBColorTable %x %d->%d %x", hdc, uStartIndex, cEntries, pColors));
315
316 if(dsect)
317 {
318 return(dsect->GetDIBColorTable(uStartIndex, cEntries, pColors));
319 }
320 //TODO: Is this correct?????
321 // Wine returns 0 if bitmap selected into dc with bpp > 8
322 HPALETTE hpal = GetCurrentObject(hdc, OBJ_PAL);
323 rc = O32_GetPaletteEntries(hpal, uStartIndex, cEntries, (PALETTEENTRY *)pColors);
324 for(i=0;i<cEntries;i++)
325 {
326 BYTE tmp;
327 tmp = pColors[i].rgbBlue;
328 pColors[i].rgbBlue = pColors[i].rgbRed;
329 pColors[i].rgbRed = tmp;
330 pColors[i].rgbReserved = 0;
331 }
332 dprintf(("GDI32: GetDIBColorTable returns %d\n", rc));
333 return(rc);
334}
335//******************************************************************************
336//******************************************************************************
337UINT WIN32API SetDIBColorTable(HDC hdc, UINT uStartIndex, UINT cEntries,
338 RGBQUAD *pColors)
339{
340 DIBSection *dsect = DIBSection::findHDC(hdc);
341
342 dprintf(("GDI32: SetDIBColorTable %x %d,%d %x", hdc, uStartIndex, cEntries, pColors));
343 if(dsect)
344 {
345 return(dsect->SetDIBColorTable(uStartIndex, cEntries, pColors));
346 }
347 else return(0);
348}
349//******************************************************************************
350//******************************************************************************
351LONG WIN32API GetBitmapBits( HBITMAP hBitmap, LONG arg2, PVOID arg3)
352{
353 dprintf(("GDI32: GetBitmapBits %x", hBitmap));
354 return O32_GetBitmapBits(hBitmap, arg2, arg3);
355}
356//******************************************************************************
357//******************************************************************************
358LONG WIN32API SetBitmapBits( HBITMAP hBitmap, LONG arg2, const VOID * arg3)
359{
360 dprintf(("GDI32: SetBitmapBits %x", hBitmap));
361 return O32_SetBitmapBits(hBitmap, (DWORD)arg2, arg3);
362}
363//******************************************************************************
364//******************************************************************************
365BOOL WIN32API GetBitmapDimensionEx( HBITMAP hBitmap, PSIZE pSize)
366{
367 dprintf(("GDI32: GetBitmapDimensionEx %x (%d,%d)", hBitmap, pSize->cx, pSize->cy));
368 return O32_GetBitmapDimensionEx(hBitmap, pSize);
369}
370//******************************************************************************
371//******************************************************************************
372BOOL WIN32API SetBitmapDimensionEx( HBITMAP arg1, int arg2, int arg3, PSIZE arg4)
373{
374 dprintf(("GDI32: SetBitmapDimensionEx"));
375 return O32_SetBitmapDimensionEx(arg1, arg2, arg3, arg4);
376}
377//******************************************************************************
378//******************************************************************************
379int WIN32API GetDIBits(HDC hdc, HBITMAP hBitmap, UINT uStartScan, UINT cScanLines,
380 void *lpvBits, PBITMAPINFO lpbi, UINT uUsage)
381{
382 int nrlines;
383
384 dprintf(("GDI32: GetDIBits %x %x %d %d %x %x (biBitCount %d) %d", hdc, hBitmap, uStartScan, cScanLines, lpvBits, lpbi, lpbi->bmiHeader.biBitCount, uUsage));
385
386 //SvL: WGSS screws up the DC if it's a memory DC
387 // TODO: Fix in WGSS
388 HDC hdcMem = CreateCompatibleDC(0);
389
390 nrlines = O32_GetDIBits(hdcMem, hBitmap, uStartScan, cScanLines, lpvBits, lpbi, uUsage);
391
392 DeleteDC(hdcMem);
393
394 if(lpvBits) {
395 // set proper color masks (only if lpvBits not NULL)
396 switch(lpbi->bmiHeader.biBitCount) {
397 case 15:
398 case 16: //RGB 565
399 {
400#ifdef NEW_GDIHANDLES
401 DWORD dwFlags;
402
403 dwFlags = ObjQueryHandleFlags(hBitmap);
404 if(dwFlags & (OBJHANDLE_FLAG_BMP_SCREEN_COMPATIBLE|OBJHANDLE_FLAG_BMP_RGB565)) {
405 ((DWORD*)(lpbi->bmiColors))[0] = RGB565_RED_MASK;
406 ((DWORD*)(lpbi->bmiColors))[1] = RGB565_GREEN_MASK;
407 ((DWORD*)(lpbi->bmiColors))[2] = RGB565_BLUE_MASK;
408 }
409 else {
410 ((DWORD*)(lpbi->bmiColors))[0] = RGB555_RED_MASK;
411 ((DWORD*)(lpbi->bmiColors))[1] = RGB555_GREEN_MASK;
412 ((DWORD*)(lpbi->bmiColors))[2] = RGB555_BLUE_MASK;
413 }
414 break;
415#else
416 ((DWORD*)(lpbi->bmiColors))[0] = RGB555_RED_MASK;
417 ((DWORD*)(lpbi->bmiColors))[1] = RGB555_GREEN_MASK;
418 ((DWORD*)(lpbi->bmiColors))[2] = RGB555_BLUE_MASK;
419#endif
420 }
421 case 24:
422 case 32:
423 ((DWORD*)(lpbi->bmiColors))[0] = DEFAULT_24BPP_RED_MASK;
424 ((DWORD*)(lpbi->bmiColors))[1] = DEFAULT_24BPP_GREEN_MASK;
425 ((DWORD*)(lpbi->bmiColors))[2] = DEFAULT_24BPP_BLUE_MASK;
426 break;
427 }
428 if(lpbi->bmiHeader.biCompression == BI_RGB && lpbi->bmiHeader.biBitCount > 8) {
429 lpbi->bmiHeader.biCompression = BI_BITFIELDS;
430 dprintf(("BI_BITFIELDS: %x %x %x", ((DWORD*)(lpbi->bmiColors))[0], ((DWORD*)(lpbi->bmiColors))[1], ((DWORD*)(lpbi->bmiColors))[2]));
431 }
432 }
433 if(nrlines && lpvBits && lpbi->bmiHeader.biBitCount == 16 && ((DWORD*)(lpbi->bmiColors))[1] == RGB555_GREEN_MASK)
434 {//RGB 555?
435 dprintf(("RGB 565->555 conversion required"));
436
437 int imgsize = CalcBitmapSize(lpbi->bmiHeader.biBitCount,
438 lpbi->bmiHeader.biWidth, nrlines);
439
440 if(CPUFeatures & CPUID_MMX) {
441 RGB565to555MMX((WORD *)lpvBits, (WORD *)lpvBits, imgsize/sizeof(WORD));
442 }
443 else RGB565to555((WORD *)lpvBits, (WORD *)lpvBits, imgsize/sizeof(WORD));
444 }
445
446 //WGSS/Open32 returns 0 when querying the bitmap info; must return nr of scanlines
447 //as 0 signals failure
448 if(lpvBits == NULL) {
449 nrlines = cScanLines;
450 }
451 dprintf(("GDI32: GetDIBits returned %d", nrlines));
452 return nrlines;
453}
454//******************************************************************************
455//******************************************************************************
456void WIN32API ConvertRGB555to565(LPVOID dest, LPVOID src, UINT imgsize)
457{
458 if(CPUFeatures & CPUID_MMX) {
459 RGB555to565MMX((WORD *)dest, (WORD *)src, imgsize/sizeof(WORD));
460 }
461 else RGB555to565((WORD *)dest, (WORD *)src, imgsize/sizeof(WORD));
462}
463//******************************************************************************
464//******************************************************************************
465int WIN32API SetDIBits(HDC hdc, HBITMAP hBitmap, UINT startscan, UINT numlines, const VOID *pBits,
466 const BITMAPINFO *pBitmapInfo, UINT usage)
467{
468 int ret;
469 DWORD bitfields[3];
470 WORD *newbits = NULL;
471
472 dprintf(("GDI32: SetDIBits %x %x %x %x %x %x %x", hdc, hBitmap, startscan, numlines, pBits, pBitmapInfo, usage));
473
474 //SvL: Open32's SetDIBits really messes things up for 1 bpp bitmaps, must use SetBitmapBits
475 if(pBitmapInfo->bmiHeader.biBitCount == 1 && startscan == 0 && numlines == pBitmapInfo->bmiHeader.biHeight)
476 {//WARNING: hack alert!
477 int dibwidth = DIB_GetDIBWidthBytes(pBitmapInfo->bmiHeader.biWidth, 1);
478 int bmpwidth = BITMAP_GetWidthBytes(pBitmapInfo->bmiHeader.biWidth, 1);
479 char *newpix = (char *)malloc(dibwidth*pBitmapInfo->bmiHeader.biHeight);
480 char *orgpix = (char *)pBits;
481 int ret;
482
483 dprintf(("Flipping 1bpp bitmap and calling SetBitmapBits (WORKAROUND) (%d -> %d)", dibwidth, bmpwidth));
484 newpix += ((pBitmapInfo->bmiHeader.biHeight-1)*bmpwidth);
485
486 //flip bitmap here; SetDIBits assumes origin is left bottom, SetBitmapBits left top
487 //SetDIBits assumes DWORD aligned data
488 //SetBitmapBits assumes WORD aligned data
489 for(int i=0;i<pBitmapInfo->bmiHeader.biHeight;i++) {
490 memcpy(newpix, orgpix, bmpwidth);
491
492 newpix -= bmpwidth;
493 orgpix += dibwidth;
494 }
495 newpix += bmpwidth;
496 ret = O32_SetBitmapBits(hBitmap, pBitmapInfo->bmiHeader.biSizeImage, newpix);
497
498 free(newpix);
499 return ret;
500 }
501#ifdef DEBUG
502 if(pBitmapInfo->bmiHeader.biBitCount == 1) {
503 dprintf(("ERROR: SetDIBits does NOT work well for 1 bpp bitmaps!!!!!"));
504 }
505#endif
506
507 switch(pBitmapInfo->bmiHeader.biBitCount) {
508 case 15:
509 case 16: //Default if BI_BITFIELDS not set is RGB 555
510 bitfields[0] = (pBitmapInfo->bmiHeader.biCompression == BI_BITFIELDS) ? *(DWORD *)pBitmapInfo->bmiColors : DEFAULT_16BPP_RED_MASK;
511 bitfields[1] = (pBitmapInfo->bmiHeader.biCompression == BI_BITFIELDS) ? *((DWORD *)pBitmapInfo->bmiColors + 1) : DEFAULT_16BPP_GREEN_MASK;
512 bitfields[2] = (pBitmapInfo->bmiHeader.biCompression == BI_BITFIELDS) ? *((DWORD *)pBitmapInfo->bmiColors + 2) : DEFAULT_16BPP_BLUE_MASK;
513 break;
514
515 case 24:
516 case 32:
517 bitfields[0] = (pBitmapInfo->bmiHeader.biCompression == BI_BITFIELDS) ? *(DWORD *)pBitmapInfo->bmiColors : DEFAULT_24BPP_RED_MASK;
518 bitfields[1] = (pBitmapInfo->bmiHeader.biCompression == BI_BITFIELDS) ? *((DWORD *)pBitmapInfo->bmiColors + 1) : DEFAULT_24BPP_GREEN_MASK;
519 bitfields[2] = (pBitmapInfo->bmiHeader.biCompression == BI_BITFIELDS) ? *((DWORD *)pBitmapInfo->bmiColors + 2) : DEFAULT_24BPP_BLUE_MASK;
520 break;
521 default:
522 bitfields[0] = 0;
523 bitfields[1] = 0;
524 bitfields[2] = 0;
525 break;
526 }
527 if(pBits && bitfields[1] == RGB555_GREEN_MASK)
528 {//RGB 555?
529 dprintf(("RGB 555->565 conversion required %x %x %x", bitfields[0], bitfields[1], bitfields[2]));
530
531 int imgsize = CalcBitmapSize(pBitmapInfo->bmiHeader.biBitCount,
532 pBitmapInfo->bmiHeader.biWidth, numlines);
533
534 newbits = (WORD *)malloc(imgsize);
535 if(CPUFeatures & CPUID_MMX) {
536 RGB555to565MMX(newbits, (WORD *)pBits, imgsize/sizeof(WORD));
537 }
538 else RGB555to565(newbits, (WORD *)pBits, imgsize/sizeof(WORD));
539 pBits = newbits;
540 }
541
542 if(pBitmapInfo->bmiHeader.biHeight < 0) {
543 dprintf(("!WARNING! Negative height!!"));
544 }
545 ret = O32_SetDIBits(hdc, hBitmap, startscan, numlines, pBits, pBitmapInfo, usage);
546 if(newbits) free(newbits);
547
548 if(DIBSection::getSection() != NULL)
549 {
550 DIBSection *dsect;
551
552 dsect = DIBSection::findObj(hBitmap);
553 if(dsect) {
554 HBITMAP hBmpOld = SelectObject(hdc, hBitmap);
555 dsect->sync(hdc, 0, dsect->GetHeight());
556 SelectObject(hdc, hBmpOld);
557 }
558 }
559
560 return ret;
561}
562//******************************************************************************
563//******************************************************************************
Note: See TracBrowser for help on using the repository browser.