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