Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 1 | /* |
Alexandre Julliard | 3a5816f | 1994-12-27 14:11:53 +0000 | [diff] [blame] | 2 | * GDI device-independent bitmaps |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 3 | * |
Alexandre Julliard | 3a5816f | 1994-12-27 14:11:53 +0000 | [diff] [blame] | 4 | * Copyright 1993,1994 Alexandre Julliard |
Huw D M Davies | 91d1608 | 1998-11-06 11:03:00 +0000 | [diff] [blame] | 5 | * |
Alexandre Julliard | 3a5816f | 1994-12-27 14:11:53 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Alexandre Julliard | 908464d | 2000-11-01 03:11:12 +0000 | [diff] [blame] | 8 | #include <stdlib.h> |
James Juran | f4d5fef | 2001-01-26 20:43:40 +0000 | [diff] [blame] | 9 | #include <string.h> |
Alexandre Julliard | 908464d | 2000-11-01 03:11:12 +0000 | [diff] [blame] | 10 | |
Michael Veksler | 92ae219 | 1999-05-02 11:39:09 +0000 | [diff] [blame] | 11 | #include "winbase.h" |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 12 | #include "bitmap.h" |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 13 | #include "callback.h" |
Alexandre Julliard | 2239abb | 2000-11-05 02:05:07 +0000 | [diff] [blame] | 14 | #include "gdi.h" |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 15 | #include "debugtools.h" |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 16 | #include "palette.h" |
Alexandre Julliard | 7ff1c41 | 1997-05-25 13:58:18 +0000 | [diff] [blame] | 17 | |
Alexandre Julliard | 946a444 | 2000-07-30 13:50:27 +0000 | [diff] [blame] | 18 | DEFAULT_DEBUG_CHANNEL(bitmap); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 19 | |
Alexandre Julliard | 7ff1c41 | 1997-05-25 13:58:18 +0000 | [diff] [blame] | 20 | /*********************************************************************** |
| 21 | * DIB_GetDIBWidthBytes |
| 22 | * |
| 23 | * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned. |
| 24 | * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/struc/src/str01.htm |
| 25 | */ |
| 26 | int DIB_GetDIBWidthBytes( int width, int depth ) |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 27 | { |
Alexandre Julliard | 3a5816f | 1994-12-27 14:11:53 +0000 | [diff] [blame] | 28 | int words; |
| 29 | |
| 30 | switch(depth) |
| 31 | { |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 32 | case 1: words = (width + 31) / 32; break; |
| 33 | case 4: words = (width + 7) / 8; break; |
| 34 | case 8: words = (width + 3) / 4; break; |
| 35 | case 15: |
| 36 | case 16: words = (width + 1) / 2; break; |
| 37 | case 24: words = (width * 3 + 3)/4; break; |
| 38 | |
| 39 | default: |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 40 | WARN("(%d): Unsupported depth\n", depth ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 41 | /* fall through */ |
| 42 | case 32: |
| 43 | words = width; |
Alexandre Julliard | 3a5816f | 1994-12-27 14:11:53 +0000 | [diff] [blame] | 44 | } |
| 45 | return 4 * words; |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 46 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 47 | |
Huw D M Davies | 608629b | 1999-04-18 12:07:00 +0000 | [diff] [blame] | 48 | /*********************************************************************** |
| 49 | * DIB_GetDIBImageBytes |
| 50 | * |
| 51 | * Return the number of bytes used to hold the image in a DIB bitmap. |
| 52 | */ |
| 53 | int DIB_GetDIBImageBytes( int width, int height, int depth ) |
| 54 | { |
| 55 | return DIB_GetDIBWidthBytes( width, depth ) * abs( height ); |
| 56 | } |
| 57 | |
Alexandre Julliard | 3a5816f | 1994-12-27 14:11:53 +0000 | [diff] [blame] | 58 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 59 | /*********************************************************************** |
| 60 | * DIB_BitmapInfoSize |
| 61 | * |
Alexandre Julliard | 7ff1c41 | 1997-05-25 13:58:18 +0000 | [diff] [blame] | 62 | * Return the size of the bitmap info structure including color table. |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 63 | */ |
Huw D M Davies | 56166a6 | 1999-04-19 16:45:24 +0000 | [diff] [blame] | 64 | int DIB_BitmapInfoSize( const BITMAPINFO * info, WORD coloruse ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 65 | { |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 66 | int colors; |
| 67 | |
| 68 | if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER)) |
| 69 | { |
| 70 | BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)info; |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 71 | colors = (core->bcBitCount <= 8) ? 1 << core->bcBitCount : 0; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 72 | return sizeof(BITMAPCOREHEADER) + colors * |
| 73 | ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBTRIPLE) : sizeof(WORD)); |
| 74 | } |
| 75 | else /* assume BITMAPINFOHEADER */ |
| 76 | { |
| 77 | colors = info->bmiHeader.biClrUsed; |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 78 | if (!colors && (info->bmiHeader.biBitCount <= 8)) |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 79 | colors = 1 << info->bmiHeader.biBitCount; |
| 80 | return sizeof(BITMAPINFOHEADER) + colors * |
| 81 | ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD)); |
| 82 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | |
| 86 | /*********************************************************************** |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 87 | * DIB_GetBitmapInfo |
| 88 | * |
| 89 | * Get the info from a bitmap header. |
| 90 | * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error. |
| 91 | */ |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 92 | int DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, DWORD *width, |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 93 | int *height, WORD *bpp, WORD *compr ) |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 94 | { |
| 95 | if (header->biSize == sizeof(BITMAPINFOHEADER)) |
| 96 | { |
| 97 | *width = header->biWidth; |
| 98 | *height = header->biHeight; |
| 99 | *bpp = header->biBitCount; |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 100 | *compr = header->biCompression; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 101 | return 1; |
| 102 | } |
| 103 | if (header->biSize == sizeof(BITMAPCOREHEADER)) |
| 104 | { |
| 105 | BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)header; |
| 106 | *width = core->bcWidth; |
| 107 | *height = core->bcHeight; |
| 108 | *bpp = core->bcBitCount; |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 109 | *compr = 0; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 110 | return 0; |
| 111 | } |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 112 | WARN("(%ld): wrong size for header\n", header->biSize ); |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 113 | return -1; |
| 114 | } |
| 115 | |
| 116 | |
| 117 | /*********************************************************************** |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 118 | * StretchDIBits16 (GDI.439) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 119 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 120 | INT16 WINAPI StretchDIBits16(HDC16 hdc, INT16 xDst, INT16 yDst, INT16 widthDst, |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 121 | INT16 heightDst, INT16 xSrc, INT16 ySrc, INT16 widthSrc, |
| 122 | INT16 heightSrc, const VOID *bits, |
| 123 | const BITMAPINFO *info, UINT16 wUsage, DWORD dwRop ) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 124 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 125 | return (INT16)StretchDIBits( hdc, xDst, yDst, widthDst, heightDst, |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 126 | xSrc, ySrc, widthSrc, heightSrc, bits, |
| 127 | info, wUsage, dwRop ); |
| 128 | } |
| 129 | |
| 130 | |
| 131 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 132 | * StretchDIBits (GDI32.@) |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 133 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 134 | INT WINAPI StretchDIBits(HDC hdc, INT xDst, INT yDst, INT widthDst, |
| 135 | INT heightDst, INT xSrc, INT ySrc, INT widthSrc, |
| 136 | INT heightSrc, const void *bits, |
| 137 | const BITMAPINFO *info, UINT wUsage, DWORD dwRop ) |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 138 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 139 | DC *dc = DC_GetDCUpdate( hdc ); |
Huw D M Davies | 14c99d0 | 1998-10-24 10:44:05 +0000 | [diff] [blame] | 140 | if(!dc) return FALSE; |
Alexandre Julliard | ded3038 | 1995-07-06 17:18:27 +0000 | [diff] [blame] | 141 | |
Huw D M Davies | 14c99d0 | 1998-10-24 10:44:05 +0000 | [diff] [blame] | 142 | if(dc->funcs->pStretchDIBits) |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 143 | heightSrc = dc->funcs->pStretchDIBits(dc, xDst, yDst, widthDst, |
Huw D M Davies | 14c99d0 | 1998-10-24 10:44:05 +0000 | [diff] [blame] | 144 | heightDst, xSrc, ySrc, widthSrc, |
| 145 | heightSrc, bits, info, wUsage, |
| 146 | dwRop); |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 147 | else { /* use StretchBlt */ |
Alexandre Julliard | 54e4775 | 1999-10-13 16:16:23 +0000 | [diff] [blame] | 148 | HBITMAP hBitmap, hOldBitmap; |
| 149 | HDC hdcMem; |
Matthew J. Francis | ed744e7 | 1999-10-24 17:28:23 +0000 | [diff] [blame] | 150 | |
Alexandre Julliard | 54e4775 | 1999-10-13 16:16:23 +0000 | [diff] [blame] | 151 | hdcMem = CreateCompatibleDC( hdc ); |
Eric Pouech | 2650159 | 2000-09-10 03:13:41 +0000 | [diff] [blame] | 152 | if (info->bmiHeader.biCompression == BI_RLE4 || |
| 153 | info->bmiHeader.biCompression == BI_RLE8) { |
| 154 | |
| 155 | /* when RLE compression is used, there may be some gaps (ie the DIB doesn't |
| 156 | * contain all the rectangle described in bmiHeader, but only part of it. |
| 157 | * This mean that those undescribed pixels must be left untouched. |
| 158 | * So, we first copy on a memory bitmap the current content of the |
| 159 | * destination rectangle, blit the DIB bits on top of it - hence leaving |
| 160 | * the gaps untouched -, and blitting the rectangle back. |
| 161 | * This insure that gaps are untouched on the destination rectangle |
| 162 | * Not doing so leads to trashed images (the gaps contain what was on the |
| 163 | * memory bitmap => generally black or garbage) |
| 164 | * Unfortunately, RLE DIBs without gaps will be slowed down. But this is |
| 165 | * another speed vs correctness issue. Anyway, if speed is needed, then the |
| 166 | * pStretchDIBits function shall be implemented. |
| 167 | * ericP (2000/09/09) |
| 168 | */ |
| 169 | hBitmap = CreateCompatibleBitmap(hdc, info->bmiHeader.biWidth, |
| 170 | info->bmiHeader.biHeight); |
| 171 | hOldBitmap = SelectObject( hdcMem, hBitmap ); |
| 172 | |
| 173 | /* copy existing bitmap from destination dc */ |
| 174 | StretchBlt( hdcMem, xSrc, abs(info->bmiHeader.biHeight) - heightSrc - ySrc, |
| 175 | widthSrc, heightSrc, hdc, xDst, yDst, widthDst, heightDst, |
| 176 | dwRop ); |
| 177 | SetDIBits(hdcMem, hBitmap, 0, info->bmiHeader.biHeight, bits, |
| 178 | info, DIB_RGB_COLORS); |
| 179 | |
| 180 | } else { |
| 181 | hBitmap = CreateDIBitmap( hdc, &info->bmiHeader, CBM_INIT, |
| 182 | bits, info, wUsage ); |
| 183 | hOldBitmap = SelectObject( hdcMem, hBitmap ); |
| 184 | } |
| 185 | |
Matthew J. Francis | ed744e7 | 1999-10-24 17:28:23 +0000 | [diff] [blame] | 186 | /* Origin for DIBitmap may be bottom left (positive biHeight) or top |
| 187 | left (negative biHeight) */ |
Alexandre Julliard | 54e4775 | 1999-10-13 16:16:23 +0000 | [diff] [blame] | 188 | StretchBlt( hdc, xDst, yDst, widthDst, heightDst, |
Eric Pouech | 2650159 | 2000-09-10 03:13:41 +0000 | [diff] [blame] | 189 | hdcMem, xSrc, abs(info->bmiHeader.biHeight) - heightSrc - ySrc, |
| 190 | widthSrc, heightSrc, dwRop ); |
Alexandre Julliard | 54e4775 | 1999-10-13 16:16:23 +0000 | [diff] [blame] | 191 | SelectObject( hdcMem, hOldBitmap ); |
| 192 | DeleteDC( hdcMem ); |
| 193 | DeleteObject( hBitmap ); |
Huw D M Davies | 14c99d0 | 1998-10-24 10:44:05 +0000 | [diff] [blame] | 194 | } |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 195 | GDI_ReleaseObj( hdc ); |
| 196 | return heightSrc; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Alexandre Julliard | 54e4775 | 1999-10-13 16:16:23 +0000 | [diff] [blame] | 199 | |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 200 | /*********************************************************************** |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 201 | * SetDIBits16 (GDI.440) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 202 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 203 | INT16 WINAPI SetDIBits16( HDC16 hdc, HBITMAP16 hbitmap, UINT16 startscan, |
| 204 | UINT16 lines, LPCVOID bits, const BITMAPINFO *info, |
| 205 | UINT16 coloruse ) |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 206 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 207 | return SetDIBits( hdc, hbitmap, startscan, lines, bits, info, coloruse ); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 211 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 212 | * SetDIBits [GDI32.@] Sets pixels in a bitmap using colors from DIB |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 213 | * |
| 214 | * PARAMS |
| 215 | * hdc [I] Handle to device context |
| 216 | * hbitmap [I] Handle to bitmap |
| 217 | * startscan [I] Starting scan line |
| 218 | * lines [I] Number of scan lines |
| 219 | * bits [I] Array of bitmap bits |
| 220 | * info [I] Address of structure with data |
| 221 | * coloruse [I] Type of color indexes to use |
| 222 | * |
| 223 | * RETURNS |
| 224 | * Success: Number of scan lines copied |
| 225 | * Failure: 0 |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 226 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 227 | INT WINAPI SetDIBits( HDC hdc, HBITMAP hbitmap, UINT startscan, |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 228 | UINT lines, LPCVOID bits, const BITMAPINFO *info, |
| 229 | UINT coloruse ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 230 | { |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 231 | DC *dc; |
| 232 | BITMAPOBJ *bitmap; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 233 | INT result; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 234 | |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 235 | /* Check parameters */ |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 236 | if (!(dc = DC_GetDCUpdate( hdc ))) return 0; |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 237 | |
| 238 | if (!(bitmap = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ))) |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 239 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 240 | GDI_ReleaseObj( hdc ); |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 241 | return 0; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 242 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 243 | |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 244 | result = BITMAP_Driver->pSetDIBits(bitmap, dc, startscan, |
| 245 | lines, bits, info, |
| 246 | coloruse, hbitmap); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 247 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 248 | GDI_ReleaseObj( hbitmap ); |
| 249 | GDI_ReleaseObj( hdc ); |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 250 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 251 | return result; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 252 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 253 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 254 | |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 255 | /*********************************************************************** |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 256 | * SetDIBitsToDevice16 (GDI.443) |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 257 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 258 | INT16 WINAPI SetDIBitsToDevice16(HDC16 hdc, INT16 xDest, INT16 yDest, INT16 cx, |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 259 | INT16 cy, INT16 xSrc, INT16 ySrc, UINT16 startscan, |
| 260 | UINT16 lines, LPCVOID bits, const BITMAPINFO *info, |
| 261 | UINT16 coloruse ) |
| 262 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 263 | return SetDIBitsToDevice( hdc, xDest, yDest, cx, cy, xSrc, ySrc, |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 264 | startscan, lines, bits, info, coloruse ); |
| 265 | } |
| 266 | |
| 267 | |
| 268 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 269 | * SetDIBitsToDevice (GDI32.@) |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 270 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 271 | INT WINAPI SetDIBitsToDevice(HDC hdc, INT xDest, INT yDest, DWORD cx, |
| 272 | DWORD cy, INT xSrc, INT ySrc, UINT startscan, |
| 273 | UINT lines, LPCVOID bits, const BITMAPINFO *info, |
| 274 | UINT coloruse ) |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 275 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 276 | INT ret; |
Huw D M Davies | 91d1608 | 1998-11-06 11:03:00 +0000 | [diff] [blame] | 277 | DC *dc; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 278 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 279 | if (!(dc = DC_GetDCUpdate( hdc ))) return 0; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 280 | |
Huw D M Davies | 91d1608 | 1998-11-06 11:03:00 +0000 | [diff] [blame] | 281 | if(dc->funcs->pSetDIBitsToDevice) |
| 282 | ret = dc->funcs->pSetDIBitsToDevice( dc, xDest, yDest, cx, cy, xSrc, |
| 283 | ySrc, startscan, lines, bits, |
| 284 | info, coloruse ); |
| 285 | else { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 286 | FIXME("unimplemented on hdc %08x\n", hdc); |
Huw D M Davies | 91d1608 | 1998-11-06 11:03:00 +0000 | [diff] [blame] | 287 | ret = 0; |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 288 | } |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 289 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 290 | GDI_ReleaseObj( hdc ); |
Huw D M Davies | 91d1608 | 1998-11-06 11:03:00 +0000 | [diff] [blame] | 291 | return ret; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 294 | /*********************************************************************** |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 295 | * SetDIBColorTable16 (GDI.602) |
| 296 | */ |
| 297 | UINT16 WINAPI SetDIBColorTable16( HDC16 hdc, UINT16 startpos, UINT16 entries, |
| 298 | RGBQUAD *colors ) |
| 299 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 300 | return SetDIBColorTable( hdc, startpos, entries, colors ); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 304 | * SetDIBColorTable (GDI32.@) |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 305 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 306 | UINT WINAPI SetDIBColorTable( HDC hdc, UINT startpos, UINT entries, |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 307 | RGBQUAD *colors ) |
| 308 | { |
| 309 | DC * dc; |
Ove Kaaven | a32ddc0 | 2000-11-25 21:42:00 +0000 | [diff] [blame] | 310 | BITMAPOBJ * bmp; |
| 311 | UINT result; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 312 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 313 | if (!(dc = DC_GetDCUpdate( hdc ))) return 0; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 314 | |
Ove Kaaven | a32ddc0 | 2000-11-25 21:42:00 +0000 | [diff] [blame] | 315 | if (!(bmp = (BITMAPOBJ*)GDI_GetObjPtr( dc->hBitmap, BITMAP_MAGIC ))) |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 316 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 317 | GDI_ReleaseObj( hdc ); |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 318 | return 0; |
| 319 | } |
| 320 | |
Ove Kaaven | a32ddc0 | 2000-11-25 21:42:00 +0000 | [diff] [blame] | 321 | result = BITMAP_Driver->pSetDIBColorTable(bmp, dc, startpos, entries, colors); |
Gerard Patel | 9dd16f0 | 1999-08-15 16:38:07 +0000 | [diff] [blame] | 322 | |
Ove Kaaven | a32ddc0 | 2000-11-25 21:42:00 +0000 | [diff] [blame] | 323 | GDI_ReleaseObj( dc->hBitmap ); |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 324 | GDI_ReleaseObj( hdc ); |
Ove Kaaven | a32ddc0 | 2000-11-25 21:42:00 +0000 | [diff] [blame] | 325 | return result; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /*********************************************************************** |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 329 | * GetDIBColorTable16 (GDI.603) |
| 330 | */ |
| 331 | UINT16 WINAPI GetDIBColorTable16( HDC16 hdc, UINT16 startpos, UINT16 entries, |
| 332 | RGBQUAD *colors ) |
| 333 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 334 | return GetDIBColorTable( hdc, startpos, entries, colors ); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 338 | * GetDIBColorTable (GDI32.@) |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 339 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 340 | UINT WINAPI GetDIBColorTable( HDC hdc, UINT startpos, UINT entries, |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 341 | RGBQUAD *colors ) |
| 342 | { |
| 343 | DC * dc; |
Ove Kaaven | a32ddc0 | 2000-11-25 21:42:00 +0000 | [diff] [blame] | 344 | BITMAPOBJ * bmp; |
| 345 | UINT result; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 346 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 347 | if (!(dc = DC_GetDCUpdate( hdc ))) return 0; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 348 | |
Ove Kaaven | a32ddc0 | 2000-11-25 21:42:00 +0000 | [diff] [blame] | 349 | if (!(bmp = (BITMAPOBJ*)GDI_GetObjPtr( dc->hBitmap, BITMAP_MAGIC ))) |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 350 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 351 | GDI_ReleaseObj( hdc ); |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 352 | return 0; |
| 353 | } |
| 354 | |
Ove Kaaven | a32ddc0 | 2000-11-25 21:42:00 +0000 | [diff] [blame] | 355 | result = BITMAP_Driver->pGetDIBColorTable(bmp, dc, startpos, entries, colors); |
| 356 | |
| 357 | GDI_ReleaseObj( dc->hBitmap ); |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 358 | GDI_ReleaseObj( hdc ); |
Ove Kaaven | a32ddc0 | 2000-11-25 21:42:00 +0000 | [diff] [blame] | 359 | return result; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 360 | } |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 361 | |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 362 | /* FIXME the following two structs should be combined with __sysPalTemplate in |
| 363 | objects/color.c - this should happen after de-X11-ing both of these |
| 364 | files. |
| 365 | NB. RGBQUAD and PALETTENTRY have different orderings of red, green |
| 366 | and blue - sigh */ |
| 367 | |
| 368 | static RGBQUAD EGAColors[16] = { |
| 369 | /* rgbBlue, rgbGreen, rgbRed, rgbReserverd */ |
| 370 | { 0x00, 0x00, 0x00, 0x00 }, |
| 371 | { 0x00, 0x00, 0x80, 0x00 }, |
| 372 | { 0x00, 0x80, 0x00, 0x00 }, |
| 373 | { 0x00, 0x80, 0x80, 0x00 }, |
| 374 | { 0x80, 0x00, 0x00, 0x00 }, |
| 375 | { 0x80, 0x00, 0x80, 0x00 }, |
| 376 | { 0x80, 0x80, 0x00, 0x00 }, |
| 377 | { 0x80, 0x80, 0x80, 0x00 }, |
| 378 | { 0xc0, 0xc0, 0xc0, 0x00 }, |
| 379 | { 0x00, 0x00, 0xff, 0x00 }, |
| 380 | { 0x00, 0xff, 0x00, 0x00 }, |
| 381 | { 0x00, 0xff, 0xff, 0x00 }, |
| 382 | { 0xff, 0x00, 0x00, 0x00 }, |
| 383 | { 0xff, 0x00, 0xff, 0x00 }, |
| 384 | { 0xff, 0xff, 0x00, 0x00 }, |
| 385 | { 0xff, 0xff, 0xff, 0x00 } |
| 386 | }; |
| 387 | |
| 388 | |
| 389 | static RGBQUAD DefLogPalette[20] = { /* Copy of Default Logical Palette */ |
| 390 | /* rgbBlue, rgbGreen, rgbRed, rgbReserverd */ |
| 391 | { 0x00, 0x00, 0x00, 0x00 }, |
| 392 | { 0x00, 0x00, 0x80, 0x00 }, |
| 393 | { 0x00, 0x80, 0x00, 0x00 }, |
| 394 | { 0x00, 0x80, 0x80, 0x00 }, |
| 395 | { 0x80, 0x00, 0x00, 0x00 }, |
| 396 | { 0x80, 0x00, 0x80, 0x00 }, |
| 397 | { 0x80, 0x80, 0x00, 0x00 }, |
| 398 | { 0xc0, 0xc0, 0xc0, 0x00 }, |
| 399 | { 0xc0, 0xdc, 0xc0, 0x00 }, |
| 400 | { 0xf0, 0xca, 0xa6, 0x00 }, |
| 401 | { 0xf0, 0xfb, 0xff, 0x00 }, |
| 402 | { 0xa4, 0xa0, 0xa0, 0x00 }, |
| 403 | { 0x80, 0x80, 0x80, 0x00 }, |
| 404 | { 0x00, 0x00, 0xf0, 0x00 }, |
| 405 | { 0x00, 0xff, 0x00, 0x00 }, |
| 406 | { 0x00, 0xff, 0xff, 0x00 }, |
| 407 | { 0xff, 0x00, 0x00, 0x00 }, |
| 408 | { 0xff, 0x00, 0xff, 0x00 }, |
| 409 | { 0xff, 0xff, 0x00, 0x00 }, |
| 410 | { 0xff, 0xff, 0xff, 0x00 } |
| 411 | }; |
| 412 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 413 | /*********************************************************************** |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 414 | * GetDIBits16 (GDI.441) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 415 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 416 | INT16 WINAPI GetDIBits16( HDC16 hdc, HBITMAP16 hbitmap, UINT16 startscan, |
Zygo Blaxell | 1084b2c | 1999-02-09 14:13:12 +0000 | [diff] [blame] | 417 | UINT16 lines, LPVOID bits, BITMAPINFO * info, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 418 | UINT16 coloruse ) |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 419 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 420 | return GetDIBits( hdc, hbitmap, startscan, lines, bits, info, coloruse ); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 424 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 425 | * GetDIBits [GDI32.@] Retrieves bits of bitmap and copies to buffer |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 426 | * |
| 427 | * RETURNS |
| 428 | * Success: Number of scan lines copied from bitmap |
| 429 | * Failure: 0 |
Alexandre Julliard | 7ff1c41 | 1997-05-25 13:58:18 +0000 | [diff] [blame] | 430 | * |
| 431 | * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/func/src/f30_14.htm |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 432 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 433 | INT WINAPI GetDIBits( |
| 434 | HDC hdc, /* [in] Handle to device context */ |
| 435 | HBITMAP hbitmap, /* [in] Handle to bitmap */ |
| 436 | UINT startscan, /* [in] First scan line to set in dest bitmap */ |
| 437 | UINT lines, /* [in] Number of scan lines to copy */ |
Zygo Blaxell | 1084b2c | 1999-02-09 14:13:12 +0000 | [diff] [blame] | 438 | LPVOID bits, /* [out] Address of array for bitmap bits */ |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 439 | BITMAPINFO * info, /* [out] Address of structure with bitmap data */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 440 | UINT coloruse) /* [in] RGB or palette index */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 441 | { |
| 442 | DC * dc; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 443 | BITMAPOBJ * bmp; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 444 | PALETTEENTRY * palEntry; |
| 445 | PALETTEOBJ * palette; |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 446 | int i; |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 447 | |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 448 | if (!info) return 0; |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 449 | if (!(dc = DC_GetDCUpdate( hdc ))) return 0; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 450 | if (!(bmp = (BITMAPOBJ *)GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ))) |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 451 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 452 | GDI_ReleaseObj( hdc ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 453 | return 0; |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 454 | } |
Alexandre Julliard | 2239abb | 2000-11-05 02:05:07 +0000 | [diff] [blame] | 455 | if (!(palette = (PALETTEOBJ*)GDI_GetObjPtr( dc->hPalette, PALETTE_MAGIC ))) |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 456 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 457 | GDI_ReleaseObj( hdc ); |
| 458 | GDI_ReleaseObj( hbitmap ); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 459 | return 0; |
| 460 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 461 | |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 462 | /* Transfer color info */ |
| 463 | |
| 464 | if (info->bmiHeader.biBitCount <= 8 && info->bmiHeader.biBitCount > 0 ) { |
| 465 | |
Eric Kohl | c011267 | 1998-11-15 18:10:11 +0000 | [diff] [blame] | 466 | info->bmiHeader.biClrUsed = 0; |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 467 | |
| 468 | if(info->bmiHeader.biBitCount >= bmp->bitmap.bmBitsPixel) { |
| 469 | palEntry = palette->logpalette.palPalEntry; |
| 470 | for (i = 0; i < (1 << bmp->bitmap.bmBitsPixel); i++, palEntry++) { |
| 471 | if (coloruse == DIB_RGB_COLORS) { |
| 472 | info->bmiColors[i].rgbRed = palEntry->peRed; |
| 473 | info->bmiColors[i].rgbGreen = palEntry->peGreen; |
| 474 | info->bmiColors[i].rgbBlue = palEntry->peBlue; |
| 475 | info->bmiColors[i].rgbReserved = 0; |
| 476 | } |
| 477 | else ((WORD *)info->bmiColors)[i] = (WORD)i; |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 478 | } |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 479 | } else { |
| 480 | switch (info->bmiHeader.biBitCount) { |
| 481 | case 1: |
| 482 | info->bmiColors[0].rgbRed = info->bmiColors[0].rgbGreen = |
| 483 | info->bmiColors[0].rgbBlue = 0; |
| 484 | info->bmiColors[0].rgbReserved = 0; |
| 485 | info->bmiColors[1].rgbRed = info->bmiColors[1].rgbGreen = |
| 486 | info->bmiColors[1].rgbBlue = 0xff; |
| 487 | info->bmiColors[1].rgbReserved = 0; |
| 488 | break; |
| 489 | |
| 490 | case 4: |
| 491 | memcpy(info->bmiColors, EGAColors, sizeof(EGAColors)); |
| 492 | break; |
| 493 | |
| 494 | case 8: |
| 495 | { |
| 496 | INT r, g, b; |
| 497 | RGBQUAD *color; |
| 498 | |
| 499 | memcpy(info->bmiColors, DefLogPalette, |
| 500 | 10 * sizeof(RGBQUAD)); |
| 501 | memcpy(info->bmiColors + 246, DefLogPalette + 10, |
| 502 | 10 * sizeof(RGBQUAD)); |
| 503 | color = info->bmiColors + 10; |
| 504 | for(r = 0; r <= 5; r++) /* FIXME */ |
| 505 | for(g = 0; g <= 5; g++) |
| 506 | for(b = 0; b <= 5; b++) { |
| 507 | color->rgbRed = (r * 0xff) / 5; |
| 508 | color->rgbGreen = (g * 0xff) / 5; |
| 509 | color->rgbBlue = (b * 0xff) / 5; |
| 510 | color->rgbReserved = 0; |
| 511 | color++; |
| 512 | } |
| 513 | } |
| 514 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 515 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 516 | } |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 517 | |
Alexandre Julliard | 2239abb | 2000-11-05 02:05:07 +0000 | [diff] [blame] | 518 | GDI_ReleaseObj( dc->hPalette ); |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 519 | |
Kai Morich | 9e9fc1b | 1999-09-13 15:13:24 +0000 | [diff] [blame] | 520 | if (bits && lines) |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 521 | { |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 522 | /* If the bitmap object already have a dib section that contains image data, get the bits from it*/ |
Karl Lessard | dee464c | 1999-09-14 11:51:01 +0000 | [diff] [blame] | 523 | if(bmp->dib && bmp->dib->dsBm.bmBitsPixel >= 15 && info->bmiHeader.biBitCount >= 15) |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 524 | { |
| 525 | /*FIXME: Only RGB dibs supported for now */ |
Joerg Mayer | 4d75640 | 2001-01-10 22:45:33 +0000 | [diff] [blame] | 526 | unsigned int srcwidth = bmp->dib->dsBm.bmWidth, srcwidthb = bmp->dib->dsBm.bmWidthBytes; |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 527 | int dstwidthb = DIB_GetDIBWidthBytes( info->bmiHeader.biWidth, info->bmiHeader.biBitCount ); |
Patrik Stridvall | 0ee98cc | 2000-02-26 13:17:55 +0000 | [diff] [blame] | 528 | LPBYTE dbits = bits, sbits = (LPBYTE) bmp->dib->dsBm.bmBits + (startscan * srcwidthb); |
Joerg Mayer | 4d75640 | 2001-01-10 22:45:33 +0000 | [diff] [blame] | 529 | unsigned int x, y; |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 530 | |
| 531 | if ((info->bmiHeader.biHeight < 0) ^ (bmp->dib->dsBmih.biHeight < 0)) |
| 532 | { |
Huw D M Davies | 1bb9860 | 1999-09-19 12:04:17 +0000 | [diff] [blame] | 533 | dbits = (LPBYTE)bits + (dstwidthb * (lines-1)); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 534 | dstwidthb = -dstwidthb; |
| 535 | } |
| 536 | |
| 537 | switch( info->bmiHeader.biBitCount ) { |
| 538 | |
Karl Lessard | dee464c | 1999-09-14 11:51:01 +0000 | [diff] [blame] | 539 | case 15: |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 540 | case 16: /* 16 bpp dstDIB */ |
| 541 | { |
| 542 | LPWORD dstbits = (LPWORD)dbits; |
| 543 | WORD rmask = 0x7c00, gmask= 0x03e0, bmask = 0x001f; |
| 544 | |
| 545 | /* FIXME: BI_BITFIELDS not supported yet */ |
| 546 | |
| 547 | switch(bmp->dib->dsBm.bmBitsPixel) { |
| 548 | |
| 549 | case 16: /* 16 bpp srcDIB -> 16 bpp dstDIB */ |
| 550 | { |
| 551 | /* FIXME: BI_BITFIELDS not supported yet */ |
| 552 | for (y = 0; y < lines; y++, dbits+=dstwidthb, sbits+=srcwidthb) |
| 553 | memcpy(dbits, sbits, srcwidthb); |
| 554 | } |
| 555 | break; |
| 556 | |
| 557 | case 24: /* 24 bpp srcDIB -> 16 bpp dstDIB */ |
| 558 | { |
Huw D M Davies | 1bb9860 | 1999-09-19 12:04:17 +0000 | [diff] [blame] | 559 | LPBYTE srcbits = sbits; |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 560 | |
| 561 | for( y = 0; y < lines; y++) { |
| 562 | for( x = 0; x < srcwidth; x++ ) |
| 563 | *dstbits++ = ((*srcbits++ >> 3) & bmask) | |
| 564 | (((WORD)*srcbits++ << 2) & gmask) | |
| 565 | (((WORD)*srcbits++ << 7) & rmask); |
| 566 | dstbits = (LPWORD)(dbits+=dstwidthb); |
Huw D M Davies | 1bb9860 | 1999-09-19 12:04:17 +0000 | [diff] [blame] | 567 | srcbits = (sbits += srcwidthb); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | break; |
| 571 | |
| 572 | case 32: /* 32 bpp srcDIB -> 16 bpp dstDIB */ |
| 573 | { |
| 574 | LPDWORD srcbits = (LPDWORD)sbits; |
| 575 | DWORD val; |
| 576 | |
| 577 | for( y = 0; y < lines; y++) { |
| 578 | for( x = 0; x < srcwidth; x++ ) { |
| 579 | val = *srcbits++; |
Karl Lessard | c73a1fd | 1999-09-19 14:15:41 +0000 | [diff] [blame] | 580 | *dstbits++ = (WORD)(((val >> 3) & bmask) | ((val >> 6) & gmask) | |
| 581 | ((val >> 9) & rmask)); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 582 | } |
Huw D M Davies | 1bb9860 | 1999-09-19 12:04:17 +0000 | [diff] [blame] | 583 | dstbits = (LPWORD)(dbits+=dstwidthb); |
| 584 | srcbits = (LPDWORD)(sbits+=srcwidthb); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 585 | } |
| 586 | } |
| 587 | break; |
| 588 | |
| 589 | default: /* ? bit bmp -> 16 bit DIB */ |
| 590 | FIXME("15/16 bit DIB %d bit bitmap\n", |
| 591 | bmp->bitmap.bmBitsPixel); |
| 592 | break; |
| 593 | } |
| 594 | } |
| 595 | break; |
| 596 | |
| 597 | case 24: /* 24 bpp dstDIB */ |
| 598 | { |
Huw D M Davies | 1bb9860 | 1999-09-19 12:04:17 +0000 | [diff] [blame] | 599 | LPBYTE dstbits = dbits; |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 600 | |
| 601 | switch(bmp->dib->dsBm.bmBitsPixel) { |
| 602 | |
| 603 | case 16: /* 16 bpp srcDIB -> 24 bpp dstDIB */ |
| 604 | { |
| 605 | LPWORD srcbits = (LPWORD)sbits; |
| 606 | WORD val; |
| 607 | |
| 608 | /* FIXME: BI_BITFIELDS not supported yet */ |
| 609 | for( y = 0; y < lines; y++) { |
| 610 | for( x = 0; x < srcwidth; x++ ) { |
| 611 | val = *srcbits++; |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 612 | *dstbits++ = (BYTE)(((val << 3) & 0xf8) | ((val >> 2) & 0x07)); |
Karl Lessard | c73a1fd | 1999-09-19 14:15:41 +0000 | [diff] [blame] | 613 | *dstbits++ = (BYTE)(((val >> 2) & 0xf8) | ((val >> 7) & 0x07)); |
| 614 | *dstbits++ = (BYTE)(((val >> 7) & 0xf8) | ((val >> 12) & 0x07)); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 615 | } |
Huw D M Davies | 1bb9860 | 1999-09-19 12:04:17 +0000 | [diff] [blame] | 616 | dstbits = (LPBYTE)(dbits+=dstwidthb); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 617 | srcbits = (LPWORD)(sbits+=srcwidthb); |
| 618 | } |
| 619 | } |
| 620 | break; |
| 621 | |
| 622 | case 24: /* 24 bpp srcDIB -> 24 bpp dstDIB */ |
| 623 | { |
| 624 | for (y = 0; y < lines; y++, dbits+=dstwidthb, sbits+=srcwidthb) |
| 625 | memcpy(dbits, sbits, srcwidthb); |
| 626 | } |
| 627 | break; |
| 628 | |
| 629 | case 32: /* 32 bpp srcDIB -> 24 bpp dstDIB */ |
| 630 | { |
| 631 | LPBYTE srcbits = (LPBYTE)sbits; |
| 632 | |
| 633 | for( y = 0; y < lines; y++) { |
| 634 | for( x = 0; x < srcwidth; x++, srcbits++ ) { |
| 635 | *dstbits++ = *srcbits++; |
| 636 | *dstbits++ = *srcbits++; |
| 637 | *dstbits++ = *srcbits++; |
| 638 | } |
| 639 | dstbits=(LPBYTE)(dbits+=dstwidthb); |
| 640 | srcbits = (LPBYTE)(sbits+=srcwidthb); |
| 641 | } |
| 642 | } |
| 643 | break; |
| 644 | |
| 645 | default: /* ? bit bmp -> 24 bit DIB */ |
| 646 | FIXME("24 bit DIB %d bit bitmap\n", |
| 647 | bmp->bitmap.bmBitsPixel); |
| 648 | break; |
| 649 | } |
| 650 | } |
| 651 | break; |
| 652 | |
| 653 | case 32: /* 32 bpp dstDIB */ |
| 654 | { |
| 655 | LPDWORD dstbits = (LPDWORD)dbits; |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 656 | |
| 657 | /* FIXME: BI_BITFIELDS not supported yet */ |
| 658 | |
| 659 | switch(bmp->dib->dsBm.bmBitsPixel) { |
| 660 | case 16: /* 16 bpp srcDIB -> 32 bpp dstDIB */ |
| 661 | { |
| 662 | LPWORD srcbits = (LPWORD)sbits; |
| 663 | DWORD val; |
| 664 | |
| 665 | /* FIXME: BI_BITFIELDS not supported yet */ |
| 666 | for( y = 0; y < lines; y++) { |
| 667 | for( x = 0; x < srcwidth; x++ ) { |
| 668 | val = (DWORD)*srcbits++; |
Karl Lessard | c73a1fd | 1999-09-19 14:15:41 +0000 | [diff] [blame] | 669 | *dstbits++ = ((val << 3) & 0xf8) | ((val >> 2) & 0x07) | |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 670 | ((val << 6) & 0xf800) | ((val << 1) & 0x0700) | |
Karl Lessard | c73a1fd | 1999-09-19 14:15:41 +0000 | [diff] [blame] | 671 | ((val << 9) & 0xf80000) | ((val << 4) & 0x070000); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 672 | } |
Huw D M Davies | 1bb9860 | 1999-09-19 12:04:17 +0000 | [diff] [blame] | 673 | dstbits=(LPDWORD)(dbits+=dstwidthb); |
| 674 | srcbits=(LPWORD)(sbits+=srcwidthb); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | break; |
| 678 | |
| 679 | case 24: /* 24 bpp srcDIB -> 32 bpp dstDIB */ |
| 680 | { |
Huw D M Davies | 1bb9860 | 1999-09-19 12:04:17 +0000 | [diff] [blame] | 681 | LPBYTE srcbits = sbits; |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 682 | |
| 683 | for( y = 0; y < lines; y++) { |
Karl Lessard | c73a1fd | 1999-09-19 14:15:41 +0000 | [diff] [blame] | 684 | for( x = 0; x < srcwidth; x++, srcbits+=3 ) |
| 685 | *dstbits++ = ((DWORD)*srcbits) & 0x00ffffff; |
Huw D M Davies | 1bb9860 | 1999-09-19 12:04:17 +0000 | [diff] [blame] | 686 | dstbits=(LPDWORD)(dbits+=dstwidthb); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 687 | srcbits=(sbits+=srcwidthb); |
| 688 | } |
| 689 | } |
| 690 | break; |
| 691 | |
| 692 | case 32: /* 32 bpp srcDIB -> 16 bpp dstDIB */ |
| 693 | { |
| 694 | /* FIXME: BI_BITFIELDS not supported yet */ |
| 695 | for (y = 0; y < lines; y++, dbits+=dstwidthb, sbits+=srcwidthb) |
| 696 | memcpy(dbits, sbits, srcwidthb); |
| 697 | } |
| 698 | break; |
| 699 | |
| 700 | default: /* ? bit bmp -> 16 bit DIB */ |
| 701 | FIXME("15/16 bit DIB %d bit bitmap\n", |
| 702 | bmp->bitmap.bmBitsPixel); |
| 703 | break; |
| 704 | } |
| 705 | } |
| 706 | break; |
| 707 | |
| 708 | default: /* ? bit DIB */ |
| 709 | FIXME("Unsupported DIB depth %d\n", info->bmiHeader.biBitCount); |
| 710 | break; |
| 711 | } |
| 712 | } |
| 713 | /* Otherwise, get bits from the XImage */ |
| 714 | else if(!BITMAP_Driver->pGetDIBits(bmp, dc, startscan, lines, bits, info, coloruse, hbitmap)) |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 715 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 716 | GDI_ReleaseObj( hdc ); |
| 717 | GDI_ReleaseObj( hbitmap ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 718 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 719 | return 0; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 720 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 721 | } |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 722 | else if( info->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER) ) |
| 723 | { |
| 724 | /* fill in struct members */ |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 725 | |
| 726 | if( info->bmiHeader.biBitCount == 0) |
| 727 | { |
| 728 | info->bmiHeader.biWidth = bmp->bitmap.bmWidth; |
| 729 | info->bmiHeader.biHeight = bmp->bitmap.bmHeight; |
| 730 | info->bmiHeader.biPlanes = 1; |
| 731 | info->bmiHeader.biBitCount = bmp->bitmap.bmBitsPixel; |
Huw D M Davies | 608629b | 1999-04-18 12:07:00 +0000 | [diff] [blame] | 732 | info->bmiHeader.biSizeImage = |
| 733 | DIB_GetDIBImageBytes( bmp->bitmap.bmWidth, |
| 734 | bmp->bitmap.bmHeight, |
| 735 | bmp->bitmap.bmBitsPixel ); |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 736 | info->bmiHeader.biCompression = 0; |
| 737 | } |
| 738 | else |
| 739 | { |
Huw D M Davies | 608629b | 1999-04-18 12:07:00 +0000 | [diff] [blame] | 740 | info->bmiHeader.biSizeImage = DIB_GetDIBImageBytes( |
| 741 | info->bmiHeader.biWidth, |
| 742 | info->bmiHeader.biHeight, |
| 743 | info->bmiHeader.biBitCount ); |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 744 | } |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 745 | } |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 746 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 747 | TRACE("biSizeImage = %ld, biWidth = %ld, biHeight = %ld\n", |
Huw D M Davies | 3da9ff3 | 1999-02-24 09:47:37 +0000 | [diff] [blame] | 748 | info->bmiHeader.biSizeImage, info->bmiHeader.biWidth, |
| 749 | info->bmiHeader.biHeight); |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 750 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 751 | GDI_ReleaseObj( hdc ); |
| 752 | GDI_ReleaseObj( hbitmap ); |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 753 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 754 | return lines; |
| 755 | } |
| 756 | |
| 757 | |
| 758 | /*********************************************************************** |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 759 | * CreateDIBitmap16 (GDI.442) |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 760 | * CreateDIBitmap16 (DISPLAY.442) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 761 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 762 | HBITMAP16 WINAPI CreateDIBitmap16( HDC16 hdc, const BITMAPINFOHEADER * header, |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 763 | DWORD init, LPCVOID bits, const BITMAPINFO * data, |
| 764 | UINT16 coloruse ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 765 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 766 | return CreateDIBitmap( hdc, header, init, bits, data, coloruse ); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | |
| 770 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 771 | * CreateDIBitmap (GDI32.@) |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 772 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 773 | HBITMAP WINAPI CreateDIBitmap( HDC hdc, const BITMAPINFOHEADER *header, |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 774 | DWORD init, LPCVOID bits, const BITMAPINFO *data, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 775 | UINT coloruse ) |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 776 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 777 | HBITMAP handle; |
| 778 | BOOL fColor; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 779 | DWORD width; |
| 780 | int height; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 781 | WORD bpp; |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 782 | WORD compr; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 783 | |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 784 | if (DIB_GetBitmapInfo( header, &width, &height, &bpp, &compr ) == -1) return 0; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 785 | if (height < 0) height = -height; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 786 | |
| 787 | /* Check if we should create a monochrome or color bitmap. */ |
| 788 | /* We create a monochrome bitmap only if it has exactly 2 */ |
Francois Boisvert | 3d696d9 | 1999-09-23 11:40:38 +0000 | [diff] [blame] | 789 | /* colors, which are black followed by white, nothing else. */ |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 790 | /* In all other cases, we create a color bitmap. */ |
| 791 | |
| 792 | if (bpp != 1) fColor = TRUE; |
| 793 | else if ((coloruse != DIB_RGB_COLORS) || |
| 794 | (init != CBM_INIT) || !data) fColor = FALSE; |
| 795 | else |
| 796 | { |
| 797 | if (data->bmiHeader.biSize == sizeof(BITMAPINFOHEADER)) |
| 798 | { |
| 799 | RGBQUAD *rgb = data->bmiColors; |
| 800 | DWORD col = RGB( rgb->rgbRed, rgb->rgbGreen, rgb->rgbBlue ); |
Francois Boisvert | 3d696d9 | 1999-09-23 11:40:38 +0000 | [diff] [blame] | 801 | |
| 802 | /* Check if the first color of the colormap is black */ |
| 803 | if ((col == RGB(0,0,0))) |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 804 | { |
| 805 | rgb++; |
| 806 | col = RGB( rgb->rgbRed, rgb->rgbGreen, rgb->rgbBlue ); |
Francois Boisvert | 3d696d9 | 1999-09-23 11:40:38 +0000 | [diff] [blame] | 807 | /* If the second color is white, create a monochrome bitmap */ |
| 808 | fColor = (col != RGB(0xff,0xff,0xff)); |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 809 | } |
Francois Boisvert | 3d696d9 | 1999-09-23 11:40:38 +0000 | [diff] [blame] | 810 | /* Note : If the first color of the colormap is white |
| 811 | followed by black, we have to create a color bitmap. |
| 812 | If we don't the white will be displayed in black later on!*/ |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 813 | else fColor = TRUE; |
| 814 | } |
| 815 | else if (data->bmiHeader.biSize == sizeof(BITMAPCOREHEADER)) |
| 816 | { |
| 817 | RGBTRIPLE *rgb = ((BITMAPCOREINFO *)data)->bmciColors; |
| 818 | DWORD col = RGB( rgb->rgbtRed, rgb->rgbtGreen, rgb->rgbtBlue ); |
Francois Boisvert | 3d696d9 | 1999-09-23 11:40:38 +0000 | [diff] [blame] | 819 | if ((col == RGB(0,0,0))) |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 820 | { |
| 821 | rgb++; |
| 822 | col = RGB( rgb->rgbtRed, rgb->rgbtGreen, rgb->rgbtBlue ); |
Francois Boisvert | 3d696d9 | 1999-09-23 11:40:38 +0000 | [diff] [blame] | 823 | fColor = (col != RGB(0xff,0xff,0xff)); |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 824 | } |
| 825 | else fColor = TRUE; |
| 826 | } |
| 827 | else |
| 828 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 829 | WARN("(%ld): wrong size for data\n", |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 830 | data->bmiHeader.biSize ); |
| 831 | return 0; |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | /* Now create the bitmap */ |
| 836 | |
Alexandre Julliard | 946a444 | 2000-07-30 13:50:27 +0000 | [diff] [blame] | 837 | if (fColor) |
| 838 | { |
| 839 | HDC tmpdc = CreateDCA( "DISPLAY", NULL, NULL, NULL ); |
| 840 | handle = CreateCompatibleBitmap( tmpdc, width, height ); |
| 841 | DeleteDC( tmpdc ); |
| 842 | } |
| 843 | else handle = CreateBitmap( width, height, 1, 1, NULL ); |
| 844 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 845 | if (!handle) return 0; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 846 | |
| 847 | if (init == CBM_INIT) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 848 | SetDIBits( hdc, handle, 0, height, bits, data, coloruse ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 849 | return handle; |
| 850 | } |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 851 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 852 | /*********************************************************************** |
| 853 | * CreateDIBSection16 (GDI.489) |
| 854 | */ |
| 855 | HBITMAP16 WINAPI CreateDIBSection16 (HDC16 hdc, BITMAPINFO *bmi, UINT16 usage, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 856 | SEGPTR *bits, HANDLE section, |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 857 | DWORD offset) |
| 858 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 859 | HBITMAP16 hbitmap = 0; |
Stephane Lussier | 23259ce | 2000-07-11 22:04:44 +0000 | [diff] [blame] | 860 | DC *dc; |
| 861 | BOOL bDesktopDC = FALSE; |
| 862 | |
| 863 | /* If the reference hdc is null, take the desktop dc */ |
| 864 | if (hdc == 0) |
| 865 | { |
| 866 | hdc = CreateCompatibleDC(0); |
| 867 | bDesktopDC = TRUE; |
| 868 | } |
| 869 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 870 | if ((dc = DC_GetDCPtr( hdc ))) |
| 871 | { |
| 872 | hbitmap = dc->funcs->pCreateDIBSection16(dc, bmi, usage, bits, section, offset, 0); |
| 873 | GDI_ReleaseObj(hdc); |
| 874 | } |
Ove Kaaven | 8b9f338 | 2000-04-29 16:47:07 +0000 | [diff] [blame] | 875 | |
Stephane Lussier | 23259ce | 2000-07-11 22:04:44 +0000 | [diff] [blame] | 876 | if (bDesktopDC) |
| 877 | DeleteDC(hdc); |
| 878 | |
Ove Kaaven | 8b9f338 | 2000-04-29 16:47:07 +0000 | [diff] [blame] | 879 | return hbitmap; |
| 880 | } |
| 881 | |
| 882 | /*********************************************************************** |
| 883 | * DIB_CreateDIBSection |
| 884 | */ |
| 885 | HBITMAP DIB_CreateDIBSection(HDC hdc, BITMAPINFO *bmi, UINT usage, |
| 886 | LPVOID *bits, HANDLE section, |
| 887 | DWORD offset, DWORD ovr_pitch) |
| 888 | { |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 889 | HBITMAP hbitmap = 0; |
Stephane Lussier | 23259ce | 2000-07-11 22:04:44 +0000 | [diff] [blame] | 890 | DC *dc; |
| 891 | BOOL bDesktopDC = FALSE; |
| 892 | |
| 893 | /* If the reference hdc is null, take the desktop dc */ |
| 894 | if (hdc == 0) |
| 895 | { |
| 896 | hdc = CreateCompatibleDC(0); |
| 897 | bDesktopDC = TRUE; |
| 898 | } |
| 899 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 900 | if ((dc = DC_GetDCPtr( hdc ))) |
| 901 | { |
| 902 | hbitmap = dc->funcs->pCreateDIBSection(dc, bmi, usage, bits, section, offset, ovr_pitch); |
| 903 | GDI_ReleaseObj(hdc); |
| 904 | } |
Ulrich Weigand | 4f85bad | 1999-02-09 15:30:22 +0000 | [diff] [blame] | 905 | |
Stephane Lussier | 23259ce | 2000-07-11 22:04:44 +0000 | [diff] [blame] | 906 | if (bDesktopDC) |
| 907 | DeleteDC(hdc); |
| 908 | |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 909 | return hbitmap; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 910 | } |
| 911 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 912 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 913 | * CreateDIBSection (GDI32.@) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 914 | */ |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 915 | HBITMAP WINAPI CreateDIBSection(HDC hdc, BITMAPINFO *bmi, UINT usage, |
| 916 | LPVOID *bits, HANDLE section, |
| 917 | DWORD offset) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 918 | { |
Ove Kaaven | 8b9f338 | 2000-04-29 16:47:07 +0000 | [diff] [blame] | 919 | return DIB_CreateDIBSection(hdc, bmi, usage, bits, section, offset, 0); |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 920 | } |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 921 | |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 922 | /*********************************************************************** |
| 923 | * DIB_DeleteDIBSection |
| 924 | */ |
| 925 | void DIB_DeleteDIBSection( BITMAPOBJ *bmp ) |
| 926 | { |
| 927 | if (bmp && bmp->dib) |
| 928 | { |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 929 | DIBSECTION *dib = bmp->dib; |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 930 | |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 931 | if (dib->dsBm.bmBits) |
Jesper Skov | 5c3e457 | 1998-11-01 19:27:22 +0000 | [diff] [blame] | 932 | { |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 933 | if (dib->dshSection) |
James Abbatiello | c559f3f | 2001-02-12 19:40:28 +0000 | [diff] [blame] | 934 | { |
| 935 | SYSTEM_INFO SystemInfo; |
| 936 | GetSystemInfo( &SystemInfo ); |
| 937 | UnmapViewOfFile( (char *)dib->dsBm.bmBits - |
| 938 | (dib->dsOffset % SystemInfo.dwAllocationGranularity) ); |
| 939 | } |
Ove Kaaven | 8b9f338 | 2000-04-29 16:47:07 +0000 | [diff] [blame] | 940 | else if (!dib->dsOffset) |
Marcus Meissner | 718b0e4 | 2000-01-23 02:18:52 +0000 | [diff] [blame] | 941 | VirtualFree(dib->dsBm.bmBits, 0L, MEM_RELEASE ); |
Jesper Skov | 5c3e457 | 1998-11-01 19:27:22 +0000 | [diff] [blame] | 942 | } |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 943 | |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 944 | BITMAP_Driver->pDeleteDIBSection(bmp); |
Ulrich Weigand | 4f85bad | 1999-02-09 15:30:22 +0000 | [diff] [blame] | 945 | |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 946 | HeapFree(GetProcessHeap(), 0, dib); |
| 947 | bmp->dib = NULL; |
| 948 | } |
| 949 | } |
| 950 | |
Turchanov Sergey | 9cd4df1 | 1998-10-18 13:39:41 +0000 | [diff] [blame] | 951 | /*********************************************************************** |
Noel Borthwick | d05b7be | 1999-09-20 15:42:47 +0000 | [diff] [blame] | 952 | * DIB_CreateDIBFromBitmap |
| 953 | * Allocates a packed DIB and copies the bitmap data into it. |
| 954 | */ |
| 955 | HGLOBAL DIB_CreateDIBFromBitmap(HDC hdc, HBITMAP hBmp) |
| 956 | { |
| 957 | BITMAPOBJ *pBmp = NULL; |
| 958 | HGLOBAL hPackedDIB = 0; |
| 959 | LPBYTE pPackedDIB = NULL; |
| 960 | LPBITMAPINFOHEADER pbmiHeader = NULL; |
| 961 | unsigned int width, height, depth, cDataSize = 0, cPackedSize = 0, |
| 962 | OffsetBits = 0, nLinesCopied = 0; |
| 963 | |
| 964 | /* Get a pointer to the BITMAPOBJ structure */ |
| 965 | pBmp = (BITMAPOBJ *)GDI_GetObjPtr( hBmp, BITMAP_MAGIC ); |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 966 | if (!pBmp) return hPackedDIB; |
Noel Borthwick | d05b7be | 1999-09-20 15:42:47 +0000 | [diff] [blame] | 967 | |
| 968 | /* Get the bitmap dimensions */ |
| 969 | width = pBmp->bitmap.bmWidth; |
| 970 | height = pBmp->bitmap.bmHeight; |
| 971 | depth = pBmp->bitmap.bmBitsPixel; |
| 972 | |
| 973 | /* |
| 974 | * A packed DIB contains a BITMAPINFO structure followed immediately by |
| 975 | * an optional color palette and the pixel data. |
| 976 | */ |
| 977 | |
| 978 | /* Calculate the size of the packed DIB */ |
| 979 | cDataSize = DIB_GetDIBImageBytes( width, height, depth ); |
| 980 | cPackedSize = sizeof(BITMAPINFOHEADER) |
| 981 | + ( (depth <= 8) ? (sizeof(RGBQUAD) * (1 << depth)) : 0 ) |
| 982 | + cDataSize; |
| 983 | /* Get the offset to the bits */ |
| 984 | OffsetBits = cPackedSize - cDataSize; |
| 985 | |
| 986 | /* Allocate the packed DIB */ |
| 987 | TRACE("\tAllocating packed DIB of size %d\n", cPackedSize); |
| 988 | hPackedDIB = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE /*| GMEM_ZEROINIT*/, |
| 989 | cPackedSize ); |
| 990 | if ( !hPackedDIB ) |
| 991 | { |
| 992 | WARN("Could not allocate packed DIB!\n"); |
| 993 | goto END; |
| 994 | } |
| 995 | |
| 996 | /* A packed DIB starts with a BITMAPINFOHEADER */ |
| 997 | pPackedDIB = (LPBYTE)GlobalLock(hPackedDIB); |
| 998 | pbmiHeader = (LPBITMAPINFOHEADER)pPackedDIB; |
| 999 | |
| 1000 | /* Init the BITMAPINFOHEADER */ |
| 1001 | pbmiHeader->biSize = sizeof(BITMAPINFOHEADER); |
| 1002 | pbmiHeader->biWidth = width; |
| 1003 | pbmiHeader->biHeight = height; |
| 1004 | pbmiHeader->biPlanes = 1; |
| 1005 | pbmiHeader->biBitCount = depth; |
| 1006 | pbmiHeader->biCompression = BI_RGB; |
| 1007 | pbmiHeader->biSizeImage = 0; |
| 1008 | pbmiHeader->biXPelsPerMeter = pbmiHeader->biYPelsPerMeter = 0; |
| 1009 | pbmiHeader->biClrUsed = 0; |
| 1010 | pbmiHeader->biClrImportant = 0; |
| 1011 | |
| 1012 | /* Retrieve the DIB bits from the bitmap and fill in the |
| 1013 | * DIB color table if present */ |
| 1014 | |
| 1015 | nLinesCopied = GetDIBits(hdc, /* Handle to device context */ |
| 1016 | hBmp, /* Handle to bitmap */ |
| 1017 | 0, /* First scan line to set in dest bitmap */ |
| 1018 | height, /* Number of scan lines to copy */ |
| 1019 | pPackedDIB + OffsetBits, /* [out] Address of array for bitmap bits */ |
| 1020 | (LPBITMAPINFO) pbmiHeader, /* [out] Address of BITMAPINFO structure */ |
| 1021 | 0); /* RGB or palette index */ |
| 1022 | GlobalUnlock(hPackedDIB); |
| 1023 | |
| 1024 | /* Cleanup if GetDIBits failed */ |
| 1025 | if (nLinesCopied != height) |
| 1026 | { |
| 1027 | TRACE("\tGetDIBits returned %d. Actual lines=%d\n", nLinesCopied, height); |
| 1028 | GlobalFree(hPackedDIB); |
| 1029 | hPackedDIB = 0; |
| 1030 | } |
| 1031 | |
| 1032 | END: |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 1033 | GDI_ReleaseObj( hBmp ); |
Noel Borthwick | d05b7be | 1999-09-20 15:42:47 +0000 | [diff] [blame] | 1034 | return hPackedDIB; |
| 1035 | } |