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 |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Alexandre Julliard | 3a5816f | 1994-12-27 14:11:53 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 21 | /* |
| 22 | Important information: |
| 23 | |
| 24 | * Current Windows versions support two different DIB structures: |
| 25 | |
| 26 | - BITMAPCOREINFO / BITMAPCOREHEADER (legacy structures; used in OS/2) |
| 27 | - BITMAPINFO / BITMAPINFOHEADER |
| 28 | |
| 29 | Most Windows API functions taking a BITMAPINFO* / BITMAPINFOHEADER* also |
| 30 | accept the old "core" structures, and so must WINE. |
| 31 | You can distinguish them by looking at the first member (bcSize/biSize), |
| 32 | or use the internal function DIB_GetBitmapInfo. |
| 33 | |
| 34 | |
| 35 | * The palettes are stored in different formats: |
| 36 | |
| 37 | - BITMAPCOREINFO: Array of RGBTRIPLE |
| 38 | - BITMAPINFO: Array of RGBQUAD |
| 39 | |
| 40 | |
| 41 | * There are even more DIB headers, but they all extend BITMAPINFOHEADER: |
| 42 | |
| 43 | - BITMAPV4HEADER: Introduced in Windows 95 / NT 4.0 |
| 44 | - BITMAPV5HEADER: Introduced in Windows 98 / 2000 |
Michael Kaufmann | 0f2c2b8 | 2005-08-08 18:40:14 +0000 | [diff] [blame] | 45 | |
| 46 | If biCompression is BI_BITFIELDS, the color masks are at the same position |
| 47 | in all the headers (they start at bmiColors of BITMAPINFOHEADER), because |
| 48 | the new headers have structure members for the masks. |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 49 | |
| 50 | |
| 51 | * You should never access the color table using the bmiColors member, |
| 52 | because the passed structure may have one of the extended headers |
| 53 | mentioned above. Use this to calculate the location: |
| 54 | |
| 55 | BITMAPINFO* info; |
| 56 | void* colorPtr = (LPBYTE) info + (WORD) info->bmiHeader.biSize; |
| 57 | |
| 58 | |
| 59 | * More information: |
| 60 | Search for "Bitmap Structures" in MSDN |
| 61 | */ |
| 62 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 63 | #include <stdarg.h> |
Alexandre Julliard | 908464d | 2000-11-01 03:11:12 +0000 | [diff] [blame] | 64 | #include <stdlib.h> |
James Juran | f4d5fef | 2001-01-26 20:43:40 +0000 | [diff] [blame] | 65 | #include <string.h> |
Alexandre Julliard | 908464d | 2000-11-01 03:11:12 +0000 | [diff] [blame] | 66 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 67 | #include "windef.h" |
Michael Veksler | 92ae219 | 1999-05-02 11:39:09 +0000 | [diff] [blame] | 68 | #include "winbase.h" |
Michael Stefaniuc | 28a632a | 2002-11-21 21:50:04 +0000 | [diff] [blame] | 69 | #include "wownt32.h" |
Alexandre Julliard | 6ec42c0 | 2004-01-15 00:35:38 +0000 | [diff] [blame] | 70 | #include "gdi_private.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 71 | #include "wine/debug.h" |
Alexandre Julliard | 7ff1c41 | 1997-05-25 13:58:18 +0000 | [diff] [blame] | 72 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 73 | WINE_DEFAULT_DEBUG_CHANNEL(bitmap); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 74 | |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | Some of the following helper functions are duplicated in |
| 78 | dlls/x11drv/dib.c |
| 79 | */ |
| 80 | |
Alexandre Julliard | 7ff1c41 | 1997-05-25 13:58:18 +0000 | [diff] [blame] | 81 | /*********************************************************************** |
| 82 | * DIB_GetDIBWidthBytes |
| 83 | * |
| 84 | * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned. |
Alexandre Julliard | 7ff1c41 | 1997-05-25 13:58:18 +0000 | [diff] [blame] | 85 | */ |
| 86 | int DIB_GetDIBWidthBytes( int width, int depth ) |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 87 | { |
Alexandre Julliard | 3a5816f | 1994-12-27 14:11:53 +0000 | [diff] [blame] | 88 | int words; |
| 89 | |
| 90 | switch(depth) |
| 91 | { |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 92 | case 1: words = (width + 31) / 32; break; |
| 93 | case 4: words = (width + 7) / 8; break; |
| 94 | case 8: words = (width + 3) / 4; break; |
| 95 | case 15: |
| 96 | case 16: words = (width + 1) / 2; break; |
| 97 | case 24: words = (width * 3 + 3)/4; break; |
| 98 | |
| 99 | default: |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 100 | WARN("(%d): Unsupported depth\n", depth ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 101 | /* fall through */ |
| 102 | case 32: |
| 103 | words = width; |
Alexandre Julliard | 3a5816f | 1994-12-27 14:11:53 +0000 | [diff] [blame] | 104 | } |
| 105 | return 4 * words; |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 106 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 107 | |
Huw D M Davies | 608629b | 1999-04-18 12:07:00 +0000 | [diff] [blame] | 108 | /*********************************************************************** |
| 109 | * DIB_GetDIBImageBytes |
| 110 | * |
| 111 | * Return the number of bytes used to hold the image in a DIB bitmap. |
| 112 | */ |
| 113 | int DIB_GetDIBImageBytes( int width, int height, int depth ) |
| 114 | { |
| 115 | return DIB_GetDIBWidthBytes( width, depth ) * abs( height ); |
| 116 | } |
| 117 | |
Alexandre Julliard | 3a5816f | 1994-12-27 14:11:53 +0000 | [diff] [blame] | 118 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 119 | /*********************************************************************** |
Huw Davies | 515b40c | 2008-05-02 12:35:40 +0100 | [diff] [blame] | 120 | * bitmap_info_size |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 121 | * |
Alexandre Julliard | 7ff1c41 | 1997-05-25 13:58:18 +0000 | [diff] [blame] | 122 | * Return the size of the bitmap info structure including color table. |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 123 | */ |
Huw Davies | 515b40c | 2008-05-02 12:35:40 +0100 | [diff] [blame] | 124 | int bitmap_info_size( const BITMAPINFO * info, WORD coloruse ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 125 | { |
Huw Davies | 515b40c | 2008-05-02 12:35:40 +0100 | [diff] [blame] | 126 | int colors, masks = 0; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 127 | |
| 128 | if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER)) |
| 129 | { |
Andrew Talbot | 6d070ea | 2006-09-14 00:58:30 +0100 | [diff] [blame] | 130 | const BITMAPCOREHEADER *core = (const BITMAPCOREHEADER *)info; |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 131 | colors = (core->bcBitCount <= 8) ? 1 << core->bcBitCount : 0; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 132 | return sizeof(BITMAPCOREHEADER) + colors * |
| 133 | ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBTRIPLE) : sizeof(WORD)); |
| 134 | } |
| 135 | else /* assume BITMAPINFOHEADER */ |
| 136 | { |
| 137 | colors = info->bmiHeader.biClrUsed; |
Marcus Meissner | a34c234 | 2005-02-14 11:08:22 +0000 | [diff] [blame] | 138 | if (colors > 256) colors = 256; |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 139 | if (!colors && (info->bmiHeader.biBitCount <= 8)) |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 140 | colors = 1 << info->bmiHeader.biBitCount; |
Huw Davies | 515b40c | 2008-05-02 12:35:40 +0100 | [diff] [blame] | 141 | if (info->bmiHeader.biCompression == BI_BITFIELDS) masks = 3; |
| 142 | return sizeof(BITMAPINFOHEADER) + masks * sizeof(DWORD) + colors * |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 143 | ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD)); |
| 144 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | |
| 148 | /*********************************************************************** |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 149 | * DIB_GetBitmapInfo |
| 150 | * |
| 151 | * Get the info from a bitmap header. |
Dmitry Timoshkov | 2a81c1a | 2007-06-13 19:18:55 +0900 | [diff] [blame] | 152 | * Return 0 for COREHEADER, 1 for INFOHEADER, -1 for error. |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 153 | */ |
Michael Kaufmann | 970b221 | 2004-09-20 21:45:00 +0000 | [diff] [blame] | 154 | static int DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, LONG *width, |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 155 | LONG *height, WORD *planes, WORD *bpp, DWORD *compr, DWORD *size ) |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 156 | { |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 157 | if (header->biSize == sizeof(BITMAPCOREHEADER)) |
| 158 | { |
Andrew Talbot | 6d070ea | 2006-09-14 00:58:30 +0100 | [diff] [blame] | 159 | const BITMAPCOREHEADER *core = (const BITMAPCOREHEADER *)header; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 160 | *width = core->bcWidth; |
| 161 | *height = core->bcHeight; |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 162 | *planes = core->bcPlanes; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 163 | *bpp = core->bcBitCount; |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 164 | *compr = 0; |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 165 | *size = 0; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 166 | return 0; |
| 167 | } |
Dmitry Timoshkov | 2a81c1a | 2007-06-13 19:18:55 +0900 | [diff] [blame] | 168 | if (header->biSize >= sizeof(BITMAPINFOHEADER)) /* assume BITMAPINFOHEADER */ |
Andreas Mohr | 1d8ef19 | 2001-08-03 18:11:23 +0000 | [diff] [blame] | 169 | { |
Dmitry Timoshkov | 2a81c1a | 2007-06-13 19:18:55 +0900 | [diff] [blame] | 170 | *width = header->biWidth; |
| 171 | *height = header->biHeight; |
| 172 | *planes = header->biPlanes; |
| 173 | *bpp = header->biBitCount; |
| 174 | *compr = header->biCompression; |
| 175 | *size = header->biSizeImage; |
| 176 | return 1; |
Andreas Mohr | 1d8ef19 | 2001-08-03 18:11:23 +0000 | [diff] [blame] | 177 | } |
Michael Stefaniuc | a0b260e | 2006-10-12 22:56:56 +0200 | [diff] [blame] | 178 | ERR("(%d): unknown/wrong size for header\n", header->biSize ); |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 179 | return -1; |
| 180 | } |
| 181 | |
| 182 | |
| 183 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 184 | * StretchDIBits (GDI32.@) |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 185 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 186 | INT WINAPI StretchDIBits(HDC hdc, INT xDst, INT yDst, INT widthDst, |
| 187 | INT heightDst, INT xSrc, INT ySrc, INT widthSrc, |
| 188 | INT heightSrc, const void *bits, |
| 189 | const BITMAPINFO *info, UINT wUsage, DWORD dwRop ) |
Alexandre Julliard | 7e6ae4b | 1996-12-08 19:25:27 +0000 | [diff] [blame] | 190 | { |
Steve Lustbader | 473d6cb | 2002-11-25 01:10:04 +0000 | [diff] [blame] | 191 | DC *dc; |
Alexandre Julliard | 6e387f3 | 2008-03-26 20:51:58 +0100 | [diff] [blame] | 192 | INT ret; |
Alexandre Julliard | ded3038 | 1995-07-06 17:18:27 +0000 | [diff] [blame] | 193 | |
Steve Lustbader | 473d6cb | 2002-11-25 01:10:04 +0000 | [diff] [blame] | 194 | if (!bits || !info) |
| 195 | return 0; |
| 196 | |
Alexandre Julliard | 6e387f3 | 2008-03-26 20:51:58 +0100 | [diff] [blame] | 197 | if (!(dc = get_dc_ptr( hdc ))) return 0; |
Huw Davies | 352b8bc | 2003-11-12 22:42:26 +0000 | [diff] [blame] | 198 | |
Huw D M Davies | 14c99d0 | 1998-10-24 10:44:05 +0000 | [diff] [blame] | 199 | if(dc->funcs->pStretchDIBits) |
Alexandre Julliard | 658cdb4 | 2001-08-15 23:33:20 +0000 | [diff] [blame] | 200 | { |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 201 | update_dc( dc ); |
Alexandre Julliard | 6e387f3 | 2008-03-26 20:51:58 +0100 | [diff] [blame] | 202 | ret = dc->funcs->pStretchDIBits(dc->physDev, xDst, yDst, widthDst, |
| 203 | heightDst, xSrc, ySrc, widthSrc, |
| 204 | heightSrc, bits, info, wUsage, dwRop); |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 205 | release_dc_ptr( dc ); |
Alexandre Julliard | 658cdb4 | 2001-08-15 23:33:20 +0000 | [diff] [blame] | 206 | } |
| 207 | else /* use StretchBlt */ |
| 208 | { |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 209 | LONG height; |
| 210 | LONG width; |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 211 | WORD planes, bpp; |
| 212 | DWORD compr, size; |
Rob Shearman | 582de7b | 2008-02-21 16:44:52 +0000 | [diff] [blame] | 213 | HBITMAP hBitmap; |
| 214 | BOOL fastpath = FALSE; |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 215 | |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 216 | release_dc_ptr( dc ); |
Juan Lang | 31acf7f | 2005-07-14 10:15:42 +0000 | [diff] [blame] | 217 | |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 218 | if (DIB_GetBitmapInfo( &info->bmiHeader, &width, &height, &planes, &bpp, &compr, &size ) == -1) |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 219 | { |
| 220 | ERR("Invalid bitmap\n"); |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | if (width < 0) |
| 225 | { |
| 226 | ERR("Bitmap has a negative width\n"); |
| 227 | return 0; |
| 228 | } |
Matthew J. Francis | ed744e7 | 1999-10-24 17:28:23 +0000 | [diff] [blame] | 229 | |
Rob Shearman | 582de7b | 2008-02-21 16:44:52 +0000 | [diff] [blame] | 230 | hBitmap = GetCurrentObject(hdc, OBJ_BITMAP); |
| 231 | |
| 232 | if (xDst == 0 && yDst == 0 && xSrc == 0 && ySrc == 0 && |
| 233 | widthDst == widthSrc && heightDst == heightSrc && |
| 234 | info->bmiHeader.biCompression == BI_RGB && |
| 235 | dwRop == SRCCOPY) |
Huw Davies | 89b6080 | 2004-03-27 01:36:47 +0000 | [diff] [blame] | 236 | { |
Rob Shearman | 582de7b | 2008-02-21 16:44:52 +0000 | [diff] [blame] | 237 | BITMAPOBJ *bmp; |
Alexandre Julliard | 5811a2c | 2009-01-28 16:20:56 +0100 | [diff] [blame^] | 238 | if ((bmp = GDI_GetObjPtr( hBitmap, OBJ_BITMAP ))) |
Rob Shearman | 582de7b | 2008-02-21 16:44:52 +0000 | [diff] [blame] | 239 | { |
| 240 | if (bmp->bitmap.bmBitsPixel == bpp && |
| 241 | bmp->bitmap.bmWidth == widthSrc && |
| 242 | bmp->bitmap.bmHeight == heightSrc && |
| 243 | bmp->bitmap.bmPlanes == planes) |
| 244 | fastpath = TRUE; |
| 245 | GDI_ReleaseObj( hBitmap ); |
| 246 | } |
Huw Davies | 89b6080 | 2004-03-27 01:36:47 +0000 | [diff] [blame] | 247 | } |
Huw Davies | 352b8bc | 2003-11-12 22:42:26 +0000 | [diff] [blame] | 248 | |
Rob Shearman | 582de7b | 2008-02-21 16:44:52 +0000 | [diff] [blame] | 249 | if (fastpath) |
| 250 | { |
| 251 | /* fast path */ |
| 252 | TRACE("using fast path\n"); |
Alexandre Julliard | 6e387f3 | 2008-03-26 20:51:58 +0100 | [diff] [blame] | 253 | ret = SetDIBits( hdc, hBitmap, 0, height, bits, info, wUsage); |
Huw Davies | 352b8bc | 2003-11-12 22:42:26 +0000 | [diff] [blame] | 254 | } |
Rob Shearman | 582de7b | 2008-02-21 16:44:52 +0000 | [diff] [blame] | 255 | else |
| 256 | { |
| 257 | /* slow path - need to use StretchBlt */ |
| 258 | HBITMAP hOldBitmap; |
| 259 | HPALETTE hpal = NULL; |
| 260 | HDC hdcMem; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 261 | |
Rob Shearman | 582de7b | 2008-02-21 16:44:52 +0000 | [diff] [blame] | 262 | hdcMem = CreateCompatibleDC( hdc ); |
| 263 | hBitmap = CreateCompatibleBitmap(hdc, width, height); |
| 264 | hOldBitmap = SelectObject( hdcMem, hBitmap ); |
| 265 | if(wUsage == DIB_PAL_COLORS) |
| 266 | { |
| 267 | hpal = GetCurrentObject(hdc, OBJ_PAL); |
| 268 | hpal = SelectPalette(hdcMem, hpal, FALSE); |
| 269 | } |
Eric Pouech | 2650159 | 2000-09-10 03:13:41 +0000 | [diff] [blame] | 270 | |
Rob Shearman | 582de7b | 2008-02-21 16:44:52 +0000 | [diff] [blame] | 271 | if (info->bmiHeader.biCompression == BI_RLE4 || |
| 272 | info->bmiHeader.biCompression == BI_RLE8) { |
| 273 | |
| 274 | /* when RLE compression is used, there may be some gaps (ie the DIB doesn't |
| 275 | * contain all the rectangle described in bmiHeader, but only part of it. |
| 276 | * This mean that those undescribed pixels must be left untouched. |
| 277 | * So, we first copy on a memory bitmap the current content of the |
| 278 | * destination rectangle, blit the DIB bits on top of it - hence leaving |
| 279 | * the gaps untouched -, and blitting the rectangle back. |
| 280 | * This insure that gaps are untouched on the destination rectangle |
| 281 | * Not doing so leads to trashed images (the gaps contain what was on the |
| 282 | * memory bitmap => generally black or garbage) |
| 283 | * Unfortunately, RLE DIBs without gaps will be slowed down. But this is |
| 284 | * another speed vs correctness issue. Anyway, if speed is needed, then the |
| 285 | * pStretchDIBits function shall be implemented. |
| 286 | * ericP (2000/09/09) |
| 287 | */ |
| 288 | |
| 289 | /* copy existing bitmap from destination dc */ |
| 290 | StretchBlt( hdcMem, xSrc, abs(height) - heightSrc - ySrc, |
| 291 | widthSrc, heightSrc, hdc, xDst, yDst, widthDst, heightDst, |
| 292 | dwRop ); |
| 293 | } |
| 294 | |
Alexandre Julliard | 6e387f3 | 2008-03-26 20:51:58 +0100 | [diff] [blame] | 295 | ret = SetDIBits(hdcMem, hBitmap, 0, height, bits, info, wUsage); |
Rob Shearman | 582de7b | 2008-02-21 16:44:52 +0000 | [diff] [blame] | 296 | |
| 297 | /* Origin for DIBitmap may be bottom left (positive biHeight) or top |
| 298 | left (negative biHeight) */ |
Alexandre Julliard | 6e387f3 | 2008-03-26 20:51:58 +0100 | [diff] [blame] | 299 | if (ret) StretchBlt( hdc, xDst, yDst, widthDst, heightDst, |
| 300 | hdcMem, xSrc, abs(height) - heightSrc - ySrc, |
| 301 | widthSrc, heightSrc, dwRop ); |
Rob Shearman | 582de7b | 2008-02-21 16:44:52 +0000 | [diff] [blame] | 302 | if(hpal) |
| 303 | SelectPalette(hdcMem, hpal, FALSE); |
| 304 | SelectObject( hdcMem, hOldBitmap ); |
| 305 | DeleteDC( hdcMem ); |
| 306 | DeleteObject( hBitmap ); |
| 307 | } |
Huw D M Davies | 14c99d0 | 1998-10-24 10:44:05 +0000 | [diff] [blame] | 308 | } |
Alexandre Julliard | 6e387f3 | 2008-03-26 20:51:58 +0100 | [diff] [blame] | 309 | return ret; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Alexandre Julliard | 54e4775 | 1999-10-13 16:16:23 +0000 | [diff] [blame] | 312 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 313 | /****************************************************************************** |
Jon Griffiths | 783a395 | 2004-02-09 20:47:42 +0000 | [diff] [blame] | 314 | * SetDIBits [GDI32.@] |
| 315 | * |
| 316 | * Sets pixels in a bitmap using colors from DIB. |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 317 | * |
| 318 | * PARAMS |
| 319 | * hdc [I] Handle to device context |
| 320 | * hbitmap [I] Handle to bitmap |
| 321 | * startscan [I] Starting scan line |
| 322 | * lines [I] Number of scan lines |
| 323 | * bits [I] Array of bitmap bits |
| 324 | * info [I] Address of structure with data |
| 325 | * coloruse [I] Type of color indexes to use |
| 326 | * |
| 327 | * RETURNS |
| 328 | * Success: Number of scan lines copied |
| 329 | * Failure: 0 |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 330 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 331 | INT WINAPI SetDIBits( HDC hdc, HBITMAP hbitmap, UINT startscan, |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 332 | UINT lines, LPCVOID bits, const BITMAPINFO *info, |
| 333 | UINT coloruse ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 334 | { |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 335 | DC *dc; |
Alexandre Julliard | d8a9244 | 2002-05-31 18:43:22 +0000 | [diff] [blame] | 336 | BITMAPOBJ *bitmap; |
Alexandre Julliard | e21c15e | 2002-03-28 22:22:05 +0000 | [diff] [blame] | 337 | INT result = 0; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 338 | |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 339 | if (!(dc = get_dc_ptr( hdc ))) |
Alexandre Julliard | d8a9244 | 2002-05-31 18:43:22 +0000 | [diff] [blame] | 340 | { |
| 341 | if (coloruse == DIB_RGB_COLORS) FIXME( "shouldn't require a DC for DIB_RGB_COLORS\n" ); |
Huw Davies | 8e34fa6 | 2005-02-22 19:34:33 +0000 | [diff] [blame] | 342 | return 0; |
| 343 | } |
| 344 | |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 345 | update_dc( dc ); |
| 346 | |
Alexandre Julliard | 5811a2c | 2009-01-28 16:20:56 +0100 | [diff] [blame^] | 347 | if (!(bitmap = GDI_GetObjPtr( hbitmap, OBJ_BITMAP ))) |
Huw Davies | 8e34fa6 | 2005-02-22 19:34:33 +0000 | [diff] [blame] | 348 | { |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 349 | release_dc_ptr( dc ); |
Alexandre Julliard | d8a9244 | 2002-05-31 18:43:22 +0000 | [diff] [blame] | 350 | return 0; |
| 351 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 352 | |
Alexandre Julliard | d8a9244 | 2002-05-31 18:43:22 +0000 | [diff] [blame] | 353 | if (!bitmap->funcs && !BITMAP_SetOwnerDC( hbitmap, dc )) goto done; |
| 354 | |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 355 | result = lines; |
| 356 | if (bitmap->funcs) |
| 357 | { |
| 358 | if (bitmap->funcs != dc->funcs) |
| 359 | ERR( "not supported: DDB bitmap %p not belonging to device %p\n", hbitmap, hdc ); |
| 360 | else if (dc->funcs->pSetDIBits) |
| 361 | result = dc->funcs->pSetDIBits( dc->physDev, hbitmap, startscan, lines, |
Alexandre Julliard | d8a9244 | 2002-05-31 18:43:22 +0000 | [diff] [blame] | 362 | bits, info, coloruse ); |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 363 | } |
Alexandre Julliard | d8a9244 | 2002-05-31 18:43:22 +0000 | [diff] [blame] | 364 | |
| 365 | done: |
Alexandre Julliard | d8a9244 | 2002-05-31 18:43:22 +0000 | [diff] [blame] | 366 | GDI_ReleaseObj( hbitmap ); |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 367 | release_dc_ptr( dc ); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 368 | return result; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 369 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 370 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 371 | |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 372 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 373 | * SetDIBitsToDevice (GDI32.@) |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 374 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 375 | INT WINAPI SetDIBitsToDevice(HDC hdc, INT xDest, INT yDest, DWORD cx, |
| 376 | DWORD cy, INT xSrc, INT ySrc, UINT startscan, |
| 377 | UINT lines, LPCVOID bits, const BITMAPINFO *info, |
| 378 | UINT coloruse ) |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 379 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 380 | INT ret; |
Huw D M Davies | 91d1608 | 1998-11-06 11:03:00 +0000 | [diff] [blame] | 381 | DC *dc; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 382 | |
Louis Lenders | d711728 | 2007-05-07 21:03:16 +0100 | [diff] [blame] | 383 | if (!bits) return 0; |
| 384 | |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 385 | if (!(dc = get_dc_ptr( hdc ))) return 0; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 386 | |
Huw D M Davies | 91d1608 | 1998-11-06 11:03:00 +0000 | [diff] [blame] | 387 | if(dc->funcs->pSetDIBitsToDevice) |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 388 | { |
| 389 | update_dc( dc ); |
Alexandre Julliard | e21c15e | 2002-03-28 22:22:05 +0000 | [diff] [blame] | 390 | 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] | 391 | ySrc, startscan, lines, bits, |
| 392 | info, coloruse ); |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 393 | } |
Huw D M Davies | 91d1608 | 1998-11-06 11:03:00 +0000 | [diff] [blame] | 394 | else { |
Alexandre Julliard | 547cdc2 | 2002-11-22 22:16:53 +0000 | [diff] [blame] | 395 | FIXME("unimplemented on hdc %p\n", hdc); |
Huw D M Davies | 91d1608 | 1998-11-06 11:03:00 +0000 | [diff] [blame] | 396 | ret = 0; |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 397 | } |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 398 | |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 399 | release_dc_ptr( dc ); |
Huw D M Davies | 91d1608 | 1998-11-06 11:03:00 +0000 | [diff] [blame] | 400 | return ret; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 403 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 404 | * SetDIBColorTable (GDI32.@) |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 405 | */ |
Robert Shearman | b4eee49 | 2004-10-18 19:35:50 +0000 | [diff] [blame] | 406 | UINT WINAPI SetDIBColorTable( HDC hdc, UINT startpos, UINT entries, CONST RGBQUAD *colors ) |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 407 | { |
| 408 | DC * dc; |
Alexandre Julliard | e21c15e | 2002-03-28 22:22:05 +0000 | [diff] [blame] | 409 | UINT result = 0; |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 410 | BITMAPOBJ * bitmap; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 411 | |
Alexandre Julliard | 67a9edb | 2008-02-05 17:35:40 +0100 | [diff] [blame] | 412 | if (!(dc = get_dc_ptr( hdc ))) return 0; |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 413 | |
Alexandre Julliard | 5811a2c | 2009-01-28 16:20:56 +0100 | [diff] [blame^] | 414 | if ((bitmap = GDI_GetObjPtr( dc->hBitmap, OBJ_BITMAP ))) |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 415 | { |
| 416 | /* Check if currently selected bitmap is a DIB */ |
| 417 | if (bitmap->color_table) |
| 418 | { |
| 419 | if (startpos < bitmap->nb_colors) |
| 420 | { |
| 421 | if (startpos + entries > bitmap->nb_colors) entries = bitmap->nb_colors - startpos; |
| 422 | memcpy(bitmap->color_table + startpos, colors, entries * sizeof(RGBQUAD)); |
| 423 | result = entries; |
| 424 | } |
| 425 | } |
| 426 | GDI_ReleaseObj( dc->hBitmap ); |
| 427 | } |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 428 | |
Alexandre Julliard | e21c15e | 2002-03-28 22:22:05 +0000 | [diff] [blame] | 429 | if (dc->funcs->pSetDIBColorTable) |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 430 | dc->funcs->pSetDIBColorTable(dc->physDev, startpos, entries, colors); |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 431 | |
Alexandre Julliard | 67a9edb | 2008-02-05 17:35:40 +0100 | [diff] [blame] | 432 | release_dc_ptr( dc ); |
Ove Kaaven | a32ddc0 | 2000-11-25 21:42:00 +0000 | [diff] [blame] | 433 | return result; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 436 | |
| 437 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 438 | * GetDIBColorTable (GDI32.@) |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 439 | */ |
Alexandre Julliard | e21c15e | 2002-03-28 22:22:05 +0000 | [diff] [blame] | 440 | UINT WINAPI GetDIBColorTable( HDC hdc, UINT startpos, UINT entries, RGBQUAD *colors ) |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 441 | { |
| 442 | DC * dc; |
Alexandre Julliard | e21c15e | 2002-03-28 22:22:05 +0000 | [diff] [blame] | 443 | UINT result = 0; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 444 | |
Alexandre Julliard | 67a9edb | 2008-02-05 17:35:40 +0100 | [diff] [blame] | 445 | if (!(dc = get_dc_ptr( hdc ))) return 0; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 446 | |
Alexandre Julliard | e21c15e | 2002-03-28 22:22:05 +0000 | [diff] [blame] | 447 | if (dc->funcs->pGetDIBColorTable) |
| 448 | result = dc->funcs->pGetDIBColorTable(dc->physDev, startpos, entries, colors); |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 449 | else |
| 450 | { |
Alexandre Julliard | 5811a2c | 2009-01-28 16:20:56 +0100 | [diff] [blame^] | 451 | BITMAPOBJ *bitmap = GDI_GetObjPtr( dc->hBitmap, OBJ_BITMAP ); |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 452 | if (bitmap) |
| 453 | { |
| 454 | /* Check if currently selected bitmap is a DIB */ |
| 455 | if (bitmap->color_table) |
| 456 | { |
| 457 | if (startpos < bitmap->nb_colors) |
| 458 | { |
| 459 | if (startpos + entries > bitmap->nb_colors) entries = bitmap->nb_colors - startpos; |
| 460 | memcpy(colors, bitmap->color_table + startpos, entries * sizeof(RGBQUAD)); |
| 461 | result = entries; |
| 462 | } |
| 463 | } |
| 464 | GDI_ReleaseObj( dc->hBitmap ); |
| 465 | } |
| 466 | } |
Alexandre Julliard | 67a9edb | 2008-02-05 17:35:40 +0100 | [diff] [blame] | 467 | release_dc_ptr( dc ); |
Ove Kaaven | a32ddc0 | 2000-11-25 21:42:00 +0000 | [diff] [blame] | 468 | return result; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 469 | } |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 470 | |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 471 | /* FIXME the following two structs should be combined with __sysPalTemplate in |
| 472 | objects/color.c - this should happen after de-X11-ing both of these |
| 473 | files. |
Andreas Mohr | f32f918 | 2001-04-20 18:36:05 +0000 | [diff] [blame] | 474 | NB. RGBQUAD and PALETTEENTRY have different orderings of red, green |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 475 | and blue - sigh */ |
| 476 | |
Andrew Ziem | 122b800 | 2006-05-24 07:58:57 -0600 | [diff] [blame] | 477 | static const RGBQUAD EGAColorsQuads[16] = { |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 478 | /* rgbBlue, rgbGreen, rgbRed, rgbReserved */ |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 479 | { 0x00, 0x00, 0x00, 0x00 }, |
| 480 | { 0x00, 0x00, 0x80, 0x00 }, |
| 481 | { 0x00, 0x80, 0x00, 0x00 }, |
| 482 | { 0x00, 0x80, 0x80, 0x00 }, |
| 483 | { 0x80, 0x00, 0x00, 0x00 }, |
| 484 | { 0x80, 0x00, 0x80, 0x00 }, |
| 485 | { 0x80, 0x80, 0x00, 0x00 }, |
| 486 | { 0x80, 0x80, 0x80, 0x00 }, |
| 487 | { 0xc0, 0xc0, 0xc0, 0x00 }, |
| 488 | { 0x00, 0x00, 0xff, 0x00 }, |
| 489 | { 0x00, 0xff, 0x00, 0x00 }, |
| 490 | { 0x00, 0xff, 0xff, 0x00 }, |
| 491 | { 0xff, 0x00, 0x00, 0x00 }, |
| 492 | { 0xff, 0x00, 0xff, 0x00 }, |
| 493 | { 0xff, 0xff, 0x00, 0x00 }, |
| 494 | { 0xff, 0xff, 0xff, 0x00 } |
| 495 | }; |
| 496 | |
Andrew Ziem | 122b800 | 2006-05-24 07:58:57 -0600 | [diff] [blame] | 497 | static const RGBTRIPLE EGAColorsTriples[16] = { |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 498 | /* rgbBlue, rgbGreen, rgbRed */ |
| 499 | { 0x00, 0x00, 0x00 }, |
| 500 | { 0x00, 0x00, 0x80 }, |
| 501 | { 0x00, 0x80, 0x00 }, |
| 502 | { 0x00, 0x80, 0x80 }, |
| 503 | { 0x80, 0x00, 0x00 }, |
| 504 | { 0x80, 0x00, 0x80 }, |
| 505 | { 0x80, 0x80, 0x00 }, |
| 506 | { 0x80, 0x80, 0x80 }, |
| 507 | { 0xc0, 0xc0, 0xc0 }, |
| 508 | { 0x00, 0x00, 0xff }, |
| 509 | { 0x00, 0xff, 0x00 }, |
| 510 | { 0x00, 0xff, 0xff }, |
| 511 | { 0xff, 0x00, 0x00 } , |
| 512 | { 0xff, 0x00, 0xff }, |
| 513 | { 0xff, 0xff, 0x00 }, |
| 514 | { 0xff, 0xff, 0xff } |
| 515 | }; |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 516 | |
Andrew Ziem | 122b800 | 2006-05-24 07:58:57 -0600 | [diff] [blame] | 517 | static const RGBQUAD DefLogPaletteQuads[20] = { /* Copy of Default Logical Palette */ |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 518 | /* rgbBlue, rgbGreen, rgbRed, rgbReserved */ |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 519 | { 0x00, 0x00, 0x00, 0x00 }, |
| 520 | { 0x00, 0x00, 0x80, 0x00 }, |
| 521 | { 0x00, 0x80, 0x00, 0x00 }, |
| 522 | { 0x00, 0x80, 0x80, 0x00 }, |
| 523 | { 0x80, 0x00, 0x00, 0x00 }, |
| 524 | { 0x80, 0x00, 0x80, 0x00 }, |
| 525 | { 0x80, 0x80, 0x00, 0x00 }, |
| 526 | { 0xc0, 0xc0, 0xc0, 0x00 }, |
| 527 | { 0xc0, 0xdc, 0xc0, 0x00 }, |
| 528 | { 0xf0, 0xca, 0xa6, 0x00 }, |
| 529 | { 0xf0, 0xfb, 0xff, 0x00 }, |
| 530 | { 0xa4, 0xa0, 0xa0, 0x00 }, |
| 531 | { 0x80, 0x80, 0x80, 0x00 }, |
| 532 | { 0x00, 0x00, 0xf0, 0x00 }, |
| 533 | { 0x00, 0xff, 0x00, 0x00 }, |
| 534 | { 0x00, 0xff, 0xff, 0x00 }, |
| 535 | { 0xff, 0x00, 0x00, 0x00 }, |
| 536 | { 0xff, 0x00, 0xff, 0x00 }, |
| 537 | { 0xff, 0xff, 0x00, 0x00 }, |
| 538 | { 0xff, 0xff, 0xff, 0x00 } |
| 539 | }; |
| 540 | |
Andrew Ziem | 122b800 | 2006-05-24 07:58:57 -0600 | [diff] [blame] | 541 | static const RGBTRIPLE DefLogPaletteTriples[20] = { /* Copy of Default Logical Palette */ |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 542 | /* rgbBlue, rgbGreen, rgbRed */ |
| 543 | { 0x00, 0x00, 0x00 }, |
| 544 | { 0x00, 0x00, 0x80 }, |
| 545 | { 0x00, 0x80, 0x00 }, |
| 546 | { 0x00, 0x80, 0x80 }, |
| 547 | { 0x80, 0x00, 0x00 }, |
| 548 | { 0x80, 0x00, 0x80 }, |
| 549 | { 0x80, 0x80, 0x00 }, |
| 550 | { 0xc0, 0xc0, 0xc0 }, |
| 551 | { 0xc0, 0xdc, 0xc0 }, |
| 552 | { 0xf0, 0xca, 0xa6 }, |
| 553 | { 0xf0, 0xfb, 0xff }, |
| 554 | { 0xa4, 0xa0, 0xa0 }, |
| 555 | { 0x80, 0x80, 0x80 }, |
| 556 | { 0x00, 0x00, 0xf0 }, |
| 557 | { 0x00, 0xff, 0x00 }, |
| 558 | { 0x00, 0xff, 0xff }, |
| 559 | { 0xff, 0x00, 0x00 }, |
| 560 | { 0xff, 0x00, 0xff }, |
| 561 | { 0xff, 0xff, 0x00 }, |
| 562 | { 0xff, 0xff, 0xff} |
| 563 | }; |
| 564 | |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 565 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 566 | /****************************************************************************** |
Jon Griffiths | 783a395 | 2004-02-09 20:47:42 +0000 | [diff] [blame] | 567 | * GetDIBits [GDI32.@] |
| 568 | * |
| 569 | * Retrieves bits of bitmap and copies to buffer. |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 570 | * |
| 571 | * RETURNS |
| 572 | * Success: Number of scan lines copied from bitmap |
| 573 | * Failure: 0 |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 574 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 575 | INT WINAPI GetDIBits( |
| 576 | HDC hdc, /* [in] Handle to device context */ |
| 577 | HBITMAP hbitmap, /* [in] Handle to bitmap */ |
| 578 | UINT startscan, /* [in] First scan line to set in dest bitmap */ |
| 579 | UINT lines, /* [in] Number of scan lines to copy */ |
Zygo Blaxell | 1084b2c | 1999-02-09 14:13:12 +0000 | [diff] [blame] | 580 | LPVOID bits, /* [out] Address of array for bitmap bits */ |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 581 | BITMAPINFO * info, /* [out] Address of structure with bitmap data */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 582 | UINT coloruse) /* [in] RGB or palette index */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 583 | { |
| 584 | DC * dc; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 585 | BITMAPOBJ * bmp; |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 586 | int i; |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 587 | int bitmap_type; |
| 588 | BOOL core_header; |
| 589 | LONG width; |
| 590 | LONG height; |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 591 | WORD planes, bpp; |
| 592 | DWORD compr, size; |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 593 | void* colorPtr; |
| 594 | RGBTRIPLE* rgbTriples; |
| 595 | RGBQUAD* rgbQuads; |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 596 | |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 597 | if (!info) return 0; |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 598 | |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 599 | bitmap_type = DIB_GetBitmapInfo( &info->bmiHeader, &width, &height, &planes, &bpp, &compr, &size); |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 600 | if (bitmap_type == -1) |
| 601 | { |
| 602 | ERR("Invalid bitmap format\n"); |
| 603 | return 0; |
| 604 | } |
| 605 | core_header = (bitmap_type == 0); |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 606 | if (!(dc = get_dc_ptr( hdc ))) |
Huw Davies | fddf5ce | 2004-03-30 20:38:45 +0000 | [diff] [blame] | 607 | { |
Dmitry Timoshkov | f31b67a | 2007-01-22 18:31:02 +0800 | [diff] [blame] | 608 | SetLastError( ERROR_INVALID_PARAMETER ); |
Huw Davies | fddf5ce | 2004-03-30 20:38:45 +0000 | [diff] [blame] | 609 | return 0; |
| 610 | } |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 611 | update_dc( dc ); |
Alexandre Julliard | 5811a2c | 2009-01-28 16:20:56 +0100 | [diff] [blame^] | 612 | if (!(bmp = GDI_GetObjPtr( hbitmap, OBJ_BITMAP ))) |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 613 | { |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 614 | release_dc_ptr( dc ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 615 | return 0; |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 616 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 617 | |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 618 | colorPtr = (LPBYTE) info + (WORD) info->bmiHeader.biSize; |
Michael Stefaniuc | 667a1ed | 2009-01-26 11:01:12 +0100 | [diff] [blame] | 619 | rgbTriples = colorPtr; |
| 620 | rgbQuads = colorPtr; |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 621 | |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 622 | /* Transfer color info */ |
| 623 | |
Alexandre Julliard | 99892d6 | 2008-04-18 12:08:12 +0200 | [diff] [blame] | 624 | switch (bpp) |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 625 | { |
Alexandre Julliard | 99892d6 | 2008-04-18 12:08:12 +0200 | [diff] [blame] | 626 | case 0: /* query bitmap info only */ |
| 627 | if (core_header) |
| 628 | { |
| 629 | BITMAPCOREHEADER* coreheader = (BITMAPCOREHEADER*) info; |
| 630 | coreheader->bcWidth = bmp->bitmap.bmWidth; |
| 631 | coreheader->bcHeight = bmp->bitmap.bmHeight; |
| 632 | coreheader->bcPlanes = 1; |
| 633 | coreheader->bcBitCount = bmp->bitmap.bmBitsPixel; |
| 634 | } |
| 635 | else |
| 636 | { |
| 637 | info->bmiHeader.biWidth = bmp->bitmap.bmWidth; |
| 638 | info->bmiHeader.biHeight = bmp->bitmap.bmHeight; |
| 639 | info->bmiHeader.biPlanes = 1; |
| 640 | info->bmiHeader.biSizeImage = |
| 641 | DIB_GetDIBImageBytes( bmp->bitmap.bmWidth, |
| 642 | bmp->bitmap.bmHeight, |
| 643 | bmp->bitmap.bmBitsPixel ); |
Alexandre Julliard | baceb8d | 2008-04-21 11:57:30 +0200 | [diff] [blame] | 644 | info->bmiHeader.biCompression = (bmp->bitmap.bmBitsPixel > 8) ? BI_BITFIELDS : BI_RGB; |
Alexandre Julliard | 99892d6 | 2008-04-18 12:08:12 +0200 | [diff] [blame] | 645 | switch(bmp->bitmap.bmBitsPixel) |
| 646 | { |
| 647 | case 15: |
| 648 | info->bmiHeader.biBitCount = 16; |
Alexandre Julliard | 99892d6 | 2008-04-18 12:08:12 +0200 | [diff] [blame] | 649 | break; |
Alexandre Julliard | baceb8d | 2008-04-21 11:57:30 +0200 | [diff] [blame] | 650 | case 24: |
| 651 | info->bmiHeader.biBitCount = 32; |
Alexandre Julliard | 99892d6 | 2008-04-18 12:08:12 +0200 | [diff] [blame] | 652 | break; |
| 653 | default: |
| 654 | info->bmiHeader.biBitCount = bmp->bitmap.bmBitsPixel; |
Alexandre Julliard | 99892d6 | 2008-04-18 12:08:12 +0200 | [diff] [blame] | 655 | break; |
| 656 | } |
| 657 | info->bmiHeader.biXPelsPerMeter = 0; |
| 658 | info->bmiHeader.biYPelsPerMeter = 0; |
| 659 | info->bmiHeader.biClrUsed = 0; |
| 660 | info->bmiHeader.biClrImportant = 0; |
| 661 | |
| 662 | /* Windows 2000 doesn't touch the additional struct members if |
| 663 | it's a BITMAPV4HEADER or a BITMAPV5HEADER */ |
| 664 | } |
| 665 | lines = abs(bmp->bitmap.bmHeight); |
| 666 | goto done; |
| 667 | |
| 668 | case 1: |
| 669 | case 4: |
| 670 | case 8: |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 671 | if (!core_header) info->bmiHeader.biClrUsed = 0; |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 672 | |
Dave Belanger | 4db092c | 2003-10-11 05:23:45 +0000 | [diff] [blame] | 673 | /* If the bitmap object already has a dib section at the |
| 674 | same color depth then get the color map from it */ |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 675 | if (bmp->dib && bmp->dib->dsBm.bmBitsPixel == bpp) { |
Huw Davies | fddf5ce | 2004-03-30 20:38:45 +0000 | [diff] [blame] | 676 | if(coloruse == DIB_RGB_COLORS) { |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 677 | unsigned int colors = min( bmp->nb_colors, 1 << bpp ); |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 678 | |
| 679 | if (core_header) |
| 680 | { |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 681 | /* Convert the color table (RGBQUAD to RGBTRIPLE) */ |
| 682 | RGBTRIPLE* index = rgbTriples; |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 683 | |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 684 | for (i=0; i < colors; i++, index++) |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 685 | { |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 686 | index->rgbtRed = bmp->color_table[i].rgbRed; |
| 687 | index->rgbtGreen = bmp->color_table[i].rgbGreen; |
| 688 | index->rgbtBlue = bmp->color_table[i].rgbBlue; |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 689 | } |
| 690 | } |
| 691 | else |
| 692 | { |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 693 | if (colors != 1 << bpp) info->bmiHeader.biClrUsed = colors; |
| 694 | memcpy(colorPtr, bmp->color_table, colors * sizeof(RGBQUAD)); |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 695 | } |
Huw Davies | fddf5ce | 2004-03-30 20:38:45 +0000 | [diff] [blame] | 696 | } |
Huw Davies | 1614517 | 2004-03-29 21:39:04 +0000 | [diff] [blame] | 697 | else { |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 698 | WORD *index = colorPtr; |
Huw Davies | 1614517 | 2004-03-29 21:39:04 +0000 | [diff] [blame] | 699 | for(i = 0; i < 1 << info->bmiHeader.biBitCount; i++, index++) |
| 700 | *index = i; |
| 701 | } |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 702 | } |
Dave Belanger | 4db092c | 2003-10-11 05:23:45 +0000 | [diff] [blame] | 703 | else { |
Michael Karcher | 5333923 | 2008-06-08 01:44:10 +0200 | [diff] [blame] | 704 | if (coloruse == DIB_PAL_COLORS) { |
| 705 | for (i = 0; i < (1 << bpp); i++) |
| 706 | ((WORD *)colorPtr)[i] = (WORD)i; |
| 707 | } |
Michael Karcher | fd8746b | 2008-06-29 13:30:01 +0200 | [diff] [blame] | 708 | else if(bpp > 1 && bpp == bmp->bitmap.bmBitsPixel) { |
| 709 | /* For color DDBs in native depth (mono DDBs always have |
| 710 | a black/white palette): |
| 711 | Generate the color map from the selected palette */ |
Alexandre Julliard | c60757b | 2006-11-17 14:34:20 +0100 | [diff] [blame] | 712 | PALETTEENTRY palEntry[256]; |
| 713 | |
| 714 | memset( palEntry, 0, sizeof(palEntry) ); |
| 715 | if (!GetPaletteEntries( dc->hPalette, 0, 1 << bmp->bitmap.bmBitsPixel, palEntry )) |
| 716 | { |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 717 | release_dc_ptr( dc ); |
Dave Belanger | 4db092c | 2003-10-11 05:23:45 +0000 | [diff] [blame] | 718 | GDI_ReleaseObj( hbitmap ); |
| 719 | return 0; |
| 720 | } |
Alexandre Julliard | c60757b | 2006-11-17 14:34:20 +0100 | [diff] [blame] | 721 | for (i = 0; i < (1 << bmp->bitmap.bmBitsPixel); i++) { |
Michael Karcher | 5333923 | 2008-06-08 01:44:10 +0200 | [diff] [blame] | 722 | if (core_header) |
| 723 | { |
| 724 | rgbTriples[i].rgbtRed = palEntry[i].peRed; |
| 725 | rgbTriples[i].rgbtGreen = palEntry[i].peGreen; |
| 726 | rgbTriples[i].rgbtBlue = palEntry[i].peBlue; |
Dave Belanger | 4db092c | 2003-10-11 05:23:45 +0000 | [diff] [blame] | 727 | } |
Michael Karcher | 5333923 | 2008-06-08 01:44:10 +0200 | [diff] [blame] | 728 | else |
| 729 | { |
| 730 | rgbQuads[i].rgbRed = palEntry[i].peRed; |
| 731 | rgbQuads[i].rgbGreen = palEntry[i].peGreen; |
| 732 | rgbQuads[i].rgbBlue = palEntry[i].peBlue; |
| 733 | rgbQuads[i].rgbReserved = 0; |
| 734 | } |
Dave Belanger | 4db092c | 2003-10-11 05:23:45 +0000 | [diff] [blame] | 735 | } |
Dave Belanger | 4db092c | 2003-10-11 05:23:45 +0000 | [diff] [blame] | 736 | } else { |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 737 | switch (bpp) { |
Dave Belanger | 4db092c | 2003-10-11 05:23:45 +0000 | [diff] [blame] | 738 | case 1: |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 739 | if (core_header) |
| 740 | { |
| 741 | rgbTriples[0].rgbtRed = rgbTriples[0].rgbtGreen = |
| 742 | rgbTriples[0].rgbtBlue = 0; |
| 743 | rgbTriples[1].rgbtRed = rgbTriples[1].rgbtGreen = |
| 744 | rgbTriples[1].rgbtBlue = 0xff; |
| 745 | } |
| 746 | else |
| 747 | { |
| 748 | rgbQuads[0].rgbRed = rgbQuads[0].rgbGreen = |
| 749 | rgbQuads[0].rgbBlue = 0; |
| 750 | rgbQuads[0].rgbReserved = 0; |
| 751 | rgbQuads[1].rgbRed = rgbQuads[1].rgbGreen = |
| 752 | rgbQuads[1].rgbBlue = 0xff; |
| 753 | rgbQuads[1].rgbReserved = 0; |
| 754 | } |
Dave Belanger | 4db092c | 2003-10-11 05:23:45 +0000 | [diff] [blame] | 755 | break; |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 756 | |
Dave Belanger | 4db092c | 2003-10-11 05:23:45 +0000 | [diff] [blame] | 757 | case 4: |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 758 | if (core_header) |
| 759 | memcpy(colorPtr, EGAColorsTriples, sizeof(EGAColorsTriples)); |
| 760 | else |
| 761 | memcpy(colorPtr, EGAColorsQuads, sizeof(EGAColorsQuads)); |
| 762 | |
Dave Belanger | 4db092c | 2003-10-11 05:23:45 +0000 | [diff] [blame] | 763 | break; |
| 764 | |
| 765 | case 8: |
| 766 | { |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 767 | if (core_header) |
| 768 | { |
| 769 | INT r, g, b; |
| 770 | RGBTRIPLE *color; |
Dave Belanger | 4db092c | 2003-10-11 05:23:45 +0000 | [diff] [blame] | 771 | |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 772 | memcpy(rgbTriples, DefLogPaletteTriples, |
| 773 | 10 * sizeof(RGBTRIPLE)); |
| 774 | memcpy(rgbTriples + 246, DefLogPaletteTriples + 10, |
| 775 | 10 * sizeof(RGBTRIPLE)); |
| 776 | color = rgbTriples + 10; |
| 777 | for(r = 0; r <= 5; r++) /* FIXME */ |
| 778 | for(g = 0; g <= 5; g++) |
| 779 | for(b = 0; b <= 5; b++) { |
| 780 | color->rgbtRed = (r * 0xff) / 5; |
| 781 | color->rgbtGreen = (g * 0xff) / 5; |
| 782 | color->rgbtBlue = (b * 0xff) / 5; |
| 783 | color++; |
| 784 | } |
| 785 | } |
| 786 | else |
| 787 | { |
| 788 | INT r, g, b; |
| 789 | RGBQUAD *color; |
| 790 | |
| 791 | memcpy(rgbQuads, DefLogPaletteQuads, |
| 792 | 10 * sizeof(RGBQUAD)); |
| 793 | memcpy(rgbQuads + 246, DefLogPaletteQuads + 10, |
| 794 | 10 * sizeof(RGBQUAD)); |
| 795 | color = rgbQuads + 10; |
| 796 | for(r = 0; r <= 5; r++) /* FIXME */ |
| 797 | for(g = 0; g <= 5; g++) |
| 798 | for(b = 0; b <= 5; b++) { |
| 799 | color->rgbRed = (r * 0xff) / 5; |
| 800 | color->rgbGreen = (g * 0xff) / 5; |
| 801 | color->rgbBlue = (b * 0xff) / 5; |
| 802 | color->rgbReserved = 0; |
| 803 | color++; |
| 804 | } |
| 805 | } |
Dave Belanger | 4db092c | 2003-10-11 05:23:45 +0000 | [diff] [blame] | 806 | } |
| 807 | } |
| 808 | } |
| 809 | } |
Alexandre Julliard | 99892d6 | 2008-04-18 12:08:12 +0200 | [diff] [blame] | 810 | break; |
| 811 | |
| 812 | case 15: |
| 813 | if (info->bmiHeader.biCompression == BI_BITFIELDS) |
| 814 | { |
| 815 | ((PDWORD)info->bmiColors)[0] = 0x7c00; |
| 816 | ((PDWORD)info->bmiColors)[1] = 0x03e0; |
| 817 | ((PDWORD)info->bmiColors)[2] = 0x001f; |
| 818 | } |
| 819 | break; |
| 820 | |
| 821 | case 16: |
| 822 | if (info->bmiHeader.biCompression == BI_BITFIELDS) |
| 823 | { |
| 824 | ((PDWORD)info->bmiColors)[0] = 0xf800; |
| 825 | ((PDWORD)info->bmiColors)[1] = 0x07e0; |
| 826 | ((PDWORD)info->bmiColors)[2] = 0x001f; |
| 827 | } |
| 828 | break; |
Alexandre Julliard | baceb8d | 2008-04-21 11:57:30 +0200 | [diff] [blame] | 829 | |
| 830 | case 24: |
| 831 | case 32: |
| 832 | if (info->bmiHeader.biCompression == BI_BITFIELDS) |
| 833 | { |
| 834 | ((PDWORD)info->bmiColors)[0] = 0xff0000; |
| 835 | ((PDWORD)info->bmiColors)[1] = 0x00ff00; |
| 836 | ((PDWORD)info->bmiColors)[2] = 0x0000ff; |
| 837 | } |
| 838 | break; |
Dave Belanger | 4db092c | 2003-10-11 05:23:45 +0000 | [diff] [blame] | 839 | } |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 840 | |
Kai Morich | 9e9fc1b | 1999-09-13 15:13:24 +0000 | [diff] [blame] | 841 | if (bits && lines) |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 842 | { |
Andreas Mohr | f32f918 | 2001-04-20 18:36:05 +0000 | [diff] [blame] | 843 | /* If the bitmap object already have a dib section that contains image data, get the bits from it */ |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 844 | if(bmp->dib && bmp->dib->dsBm.bmBitsPixel >= 15 && bpp >= 15) |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 845 | { |
| 846 | /*FIXME: Only RGB dibs supported for now */ |
Joerg Mayer | 4d75640 | 2001-01-10 22:45:33 +0000 | [diff] [blame] | 847 | unsigned int srcwidth = bmp->dib->dsBm.bmWidth, srcwidthb = bmp->dib->dsBm.bmWidthBytes; |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 848 | unsigned int dstwidth = width; |
| 849 | int dstwidthb = DIB_GetDIBWidthBytes( width, bpp ); |
Patrik Stridvall | 0ee98cc | 2000-02-26 13:17:55 +0000 | [diff] [blame] | 850 | LPBYTE dbits = bits, sbits = (LPBYTE) bmp->dib->dsBm.bmBits + (startscan * srcwidthb); |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 851 | unsigned int x, y, width, widthb; |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 852 | |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 853 | if ((height < 0) ^ (bmp->dib->dsBmih.biHeight < 0)) |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 854 | { |
Huw D M Davies | 1bb9860 | 1999-09-19 12:04:17 +0000 | [diff] [blame] | 855 | dbits = (LPBYTE)bits + (dstwidthb * (lines-1)); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 856 | dstwidthb = -dstwidthb; |
| 857 | } |
| 858 | |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 859 | switch( bpp ) { |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 860 | |
Karl Lessard | dee464c | 1999-09-14 11:51:01 +0000 | [diff] [blame] | 861 | case 15: |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 862 | case 16: /* 16 bpp dstDIB */ |
| 863 | { |
| 864 | LPWORD dstbits = (LPWORD)dbits; |
| 865 | WORD rmask = 0x7c00, gmask= 0x03e0, bmask = 0x001f; |
| 866 | |
| 867 | /* FIXME: BI_BITFIELDS not supported yet */ |
| 868 | |
| 869 | switch(bmp->dib->dsBm.bmBitsPixel) { |
| 870 | |
| 871 | case 16: /* 16 bpp srcDIB -> 16 bpp dstDIB */ |
| 872 | { |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 873 | widthb = min(srcwidthb, abs(dstwidthb)); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 874 | /* FIXME: BI_BITFIELDS not supported yet */ |
| 875 | for (y = 0; y < lines; y++, dbits+=dstwidthb, sbits+=srcwidthb) |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 876 | memcpy(dbits, sbits, widthb); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 877 | } |
| 878 | break; |
| 879 | |
| 880 | case 24: /* 24 bpp srcDIB -> 16 bpp dstDIB */ |
| 881 | { |
Huw D M Davies | 1bb9860 | 1999-09-19 12:04:17 +0000 | [diff] [blame] | 882 | LPBYTE srcbits = sbits; |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 883 | |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 884 | width = min(srcwidth, dstwidth); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 885 | for( y = 0; y < lines; y++) { |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 886 | for( x = 0; x < width; x++, srcbits += 3) |
Marcus Meissner | 183eae9 | 2001-06-14 19:22:55 +0000 | [diff] [blame] | 887 | *dstbits++ = ((srcbits[0] >> 3) & bmask) | |
| 888 | (((WORD)srcbits[1] << 2) & gmask) | |
| 889 | (((WORD)srcbits[2] << 7) & rmask); |
| 890 | |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 891 | dstbits = (LPWORD)(dbits+=dstwidthb); |
Huw D M Davies | 1bb9860 | 1999-09-19 12:04:17 +0000 | [diff] [blame] | 892 | srcbits = (sbits += srcwidthb); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | break; |
| 896 | |
| 897 | case 32: /* 32 bpp srcDIB -> 16 bpp dstDIB */ |
| 898 | { |
| 899 | LPDWORD srcbits = (LPDWORD)sbits; |
| 900 | DWORD val; |
| 901 | |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 902 | width = min(srcwidth, dstwidth); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 903 | for( y = 0; y < lines; y++) { |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 904 | for( x = 0; x < width; x++ ) { |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 905 | val = *srcbits++; |
Karl Lessard | c73a1fd | 1999-09-19 14:15:41 +0000 | [diff] [blame] | 906 | *dstbits++ = (WORD)(((val >> 3) & bmask) | ((val >> 6) & gmask) | |
| 907 | ((val >> 9) & rmask)); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 908 | } |
Huw D M Davies | 1bb9860 | 1999-09-19 12:04:17 +0000 | [diff] [blame] | 909 | dstbits = (LPWORD)(dbits+=dstwidthb); |
| 910 | srcbits = (LPDWORD)(sbits+=srcwidthb); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 911 | } |
| 912 | } |
| 913 | break; |
| 914 | |
| 915 | default: /* ? bit bmp -> 16 bit DIB */ |
| 916 | FIXME("15/16 bit DIB %d bit bitmap\n", |
| 917 | bmp->bitmap.bmBitsPixel); |
| 918 | break; |
| 919 | } |
| 920 | } |
| 921 | break; |
| 922 | |
| 923 | case 24: /* 24 bpp dstDIB */ |
| 924 | { |
Huw D M Davies | 1bb9860 | 1999-09-19 12:04:17 +0000 | [diff] [blame] | 925 | LPBYTE dstbits = dbits; |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 926 | |
| 927 | switch(bmp->dib->dsBm.bmBitsPixel) { |
| 928 | |
| 929 | case 16: /* 16 bpp srcDIB -> 24 bpp dstDIB */ |
| 930 | { |
| 931 | LPWORD srcbits = (LPWORD)sbits; |
| 932 | WORD val; |
| 933 | |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 934 | width = min(srcwidth, dstwidth); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 935 | /* FIXME: BI_BITFIELDS not supported yet */ |
| 936 | for( y = 0; y < lines; y++) { |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 937 | for( x = 0; x < width; x++ ) { |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 938 | val = *srcbits++; |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 939 | *dstbits++ = (BYTE)(((val << 3) & 0xf8) | ((val >> 2) & 0x07)); |
Karl Lessard | c73a1fd | 1999-09-19 14:15:41 +0000 | [diff] [blame] | 940 | *dstbits++ = (BYTE)(((val >> 2) & 0xf8) | ((val >> 7) & 0x07)); |
| 941 | *dstbits++ = (BYTE)(((val >> 7) & 0xf8) | ((val >> 12) & 0x07)); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 942 | } |
Andrew Talbot | d0d4c74 | 2008-01-05 16:44:09 +0000 | [diff] [blame] | 943 | dstbits = dbits+=dstwidthb; |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 944 | srcbits = (LPWORD)(sbits+=srcwidthb); |
| 945 | } |
| 946 | } |
| 947 | break; |
| 948 | |
| 949 | case 24: /* 24 bpp srcDIB -> 24 bpp dstDIB */ |
| 950 | { |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 951 | widthb = min(srcwidthb, abs(dstwidthb)); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 952 | for (y = 0; y < lines; y++, dbits+=dstwidthb, sbits+=srcwidthb) |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 953 | memcpy(dbits, sbits, widthb); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 954 | } |
| 955 | break; |
| 956 | |
| 957 | case 32: /* 32 bpp srcDIB -> 24 bpp dstDIB */ |
| 958 | { |
Andrew Talbot | d0d4c74 | 2008-01-05 16:44:09 +0000 | [diff] [blame] | 959 | LPBYTE srcbits = sbits; |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 960 | |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 961 | width = min(srcwidth, dstwidth); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 962 | for( y = 0; y < lines; y++) { |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 963 | for( x = 0; x < width; x++, srcbits++ ) { |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 964 | *dstbits++ = *srcbits++; |
| 965 | *dstbits++ = *srcbits++; |
| 966 | *dstbits++ = *srcbits++; |
| 967 | } |
Andrew Talbot | d0d4c74 | 2008-01-05 16:44:09 +0000 | [diff] [blame] | 968 | dstbits = dbits+=dstwidthb; |
| 969 | srcbits = sbits+=srcwidthb; |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | break; |
| 973 | |
| 974 | default: /* ? bit bmp -> 24 bit DIB */ |
| 975 | FIXME("24 bit DIB %d bit bitmap\n", |
| 976 | bmp->bitmap.bmBitsPixel); |
| 977 | break; |
| 978 | } |
| 979 | } |
| 980 | break; |
| 981 | |
| 982 | case 32: /* 32 bpp dstDIB */ |
| 983 | { |
| 984 | LPDWORD dstbits = (LPDWORD)dbits; |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 985 | |
| 986 | /* FIXME: BI_BITFIELDS not supported yet */ |
| 987 | |
| 988 | switch(bmp->dib->dsBm.bmBitsPixel) { |
| 989 | case 16: /* 16 bpp srcDIB -> 32 bpp dstDIB */ |
| 990 | { |
| 991 | LPWORD srcbits = (LPWORD)sbits; |
| 992 | DWORD val; |
| 993 | |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 994 | width = min(srcwidth, dstwidth); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 995 | /* FIXME: BI_BITFIELDS not supported yet */ |
| 996 | for( y = 0; y < lines; y++) { |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 997 | for( x = 0; x < width; x++ ) { |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 998 | val = (DWORD)*srcbits++; |
Karl Lessard | c73a1fd | 1999-09-19 14:15:41 +0000 | [diff] [blame] | 999 | *dstbits++ = ((val << 3) & 0xf8) | ((val >> 2) & 0x07) | |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 1000 | ((val << 6) & 0xf800) | ((val << 1) & 0x0700) | |
Karl Lessard | c73a1fd | 1999-09-19 14:15:41 +0000 | [diff] [blame] | 1001 | ((val << 9) & 0xf80000) | ((val << 4) & 0x070000); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 1002 | } |
Huw D M Davies | 1bb9860 | 1999-09-19 12:04:17 +0000 | [diff] [blame] | 1003 | dstbits=(LPDWORD)(dbits+=dstwidthb); |
| 1004 | srcbits=(LPWORD)(sbits+=srcwidthb); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 1005 | } |
| 1006 | } |
| 1007 | break; |
| 1008 | |
| 1009 | case 24: /* 24 bpp srcDIB -> 32 bpp dstDIB */ |
| 1010 | { |
Huw D M Davies | 1bb9860 | 1999-09-19 12:04:17 +0000 | [diff] [blame] | 1011 | LPBYTE srcbits = sbits; |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 1012 | |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 1013 | width = min(srcwidth, dstwidth); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 1014 | for( y = 0; y < lines; y++) { |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 1015 | for( x = 0; x < width; x++, srcbits+=3 ) |
Huw Davies | e32932e | 2005-12-08 13:53:07 +0100 | [diff] [blame] | 1016 | *dstbits++ = srcbits[0] | |
| 1017 | (srcbits[1] << 8) | |
| 1018 | (srcbits[2] << 16); |
Huw D M Davies | 1bb9860 | 1999-09-19 12:04:17 +0000 | [diff] [blame] | 1019 | dstbits=(LPDWORD)(dbits+=dstwidthb); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 1020 | srcbits=(sbits+=srcwidthb); |
| 1021 | } |
| 1022 | } |
| 1023 | break; |
| 1024 | |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 1025 | case 32: /* 32 bpp srcDIB -> 32 bpp dstDIB */ |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 1026 | { |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 1027 | widthb = min(srcwidthb, abs(dstwidthb)); |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 1028 | /* FIXME: BI_BITFIELDS not supported yet */ |
Huw Davies | dd8922f | 2004-08-12 20:02:39 +0000 | [diff] [blame] | 1029 | for (y = 0; y < lines; y++, dbits+=dstwidthb, sbits+=srcwidthb) { |
| 1030 | memcpy(dbits, sbits, widthb); |
| 1031 | } |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 1032 | } |
| 1033 | break; |
| 1034 | |
Dave Belanger | 4db092c | 2003-10-11 05:23:45 +0000 | [diff] [blame] | 1035 | default: /* ? bit bmp -> 32 bit DIB */ |
| 1036 | FIXME("32 bit DIB %d bit bitmap\n", |
Karl Lessard | 4187579 | 1999-09-03 16:49:17 +0000 | [diff] [blame] | 1037 | bmp->bitmap.bmBitsPixel); |
| 1038 | break; |
| 1039 | } |
| 1040 | } |
| 1041 | break; |
| 1042 | |
| 1043 | default: /* ? bit DIB */ |
| 1044 | FIXME("Unsupported DIB depth %d\n", info->bmiHeader.biBitCount); |
| 1045 | break; |
| 1046 | } |
| 1047 | } |
| 1048 | /* Otherwise, get bits from the XImage */ |
Alexandre Julliard | d8a9244 | 2002-05-31 18:43:22 +0000 | [diff] [blame] | 1049 | else |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1050 | { |
Alexandre Julliard | d8a9244 | 2002-05-31 18:43:22 +0000 | [diff] [blame] | 1051 | if (!bmp->funcs && !BITMAP_SetOwnerDC( hbitmap, dc )) lines = 0; |
| 1052 | else |
| 1053 | { |
| 1054 | if (bmp->funcs && bmp->funcs->pGetDIBits) |
| 1055 | lines = bmp->funcs->pGetDIBits( dc->physDev, hbitmap, startscan, |
| 1056 | lines, bits, info, coloruse ); |
| 1057 | else |
| 1058 | lines = 0; /* FIXME: should copy from bmp->bitmap.bmBits */ |
| 1059 | } |
| 1060 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 1061 | } |
Alexandre Julliard | 99892d6 | 2008-04-18 12:08:12 +0200 | [diff] [blame] | 1062 | else lines = abs(height); |
Huw D M Davies | cc3e5d7 | 1999-03-25 10:48:01 +0000 | [diff] [blame] | 1063 | |
Alexandre Julliard | 99892d6 | 2008-04-18 12:08:12 +0200 | [diff] [blame] | 1064 | /* The knowledge base article Q81498 ("DIBs and Their Uses") states that |
| 1065 | if bits == NULL and bpp != 0, only biSizeImage and the color table are |
| 1066 | filled in. */ |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 1067 | if (!core_header) |
| 1068 | { |
Alexandre Julliard | 99892d6 | 2008-04-18 12:08:12 +0200 | [diff] [blame] | 1069 | /* FIXME: biSizeImage should be calculated according to the selected |
| 1070 | compression algorithm if biCompression != BI_RGB */ |
| 1071 | info->bmiHeader.biSizeImage = DIB_GetDIBImageBytes( width, height, bpp ); |
Michael Stefaniuc | a0b260e | 2006-10-12 22:56:56 +0200 | [diff] [blame] | 1072 | TRACE("biSizeImage = %d, ", info->bmiHeader.biSizeImage); |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 1073 | } |
Michael Stefaniuc | a0b260e | 2006-10-12 22:56:56 +0200 | [diff] [blame] | 1074 | TRACE("biWidth = %d, biHeight = %d\n", width, height); |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 1075 | |
Alexandre Julliard | 99892d6 | 2008-04-18 12:08:12 +0200 | [diff] [blame] | 1076 | done: |
Alexandre Julliard | baa8d22 | 2007-09-17 16:48:56 +0200 | [diff] [blame] | 1077 | release_dc_ptr( dc ); |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 1078 | GDI_ReleaseObj( hbitmap ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 1079 | return lines; |
| 1080 | } |
| 1081 | |
| 1082 | |
| 1083 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 1084 | * CreateDIBitmap (GDI32.@) |
Alexandre Julliard | cdcdbe5 | 2004-09-13 19:37:03 +0000 | [diff] [blame] | 1085 | * |
| 1086 | * Creates a DDB (device dependent bitmap) from a DIB. |
| 1087 | * The DDB will have the same color depth as the reference DC. |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1088 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1089 | HBITMAP WINAPI CreateDIBitmap( HDC hdc, const BITMAPINFOHEADER *header, |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1090 | DWORD init, LPCVOID bits, const BITMAPINFO *data, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1091 | UINT coloruse ) |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1092 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1093 | HBITMAP handle; |
Michael Kaufmann | 970b221 | 2004-09-20 21:45:00 +0000 | [diff] [blame] | 1094 | LONG width; |
| 1095 | LONG height; |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1096 | WORD planes, bpp; |
| 1097 | DWORD compr, size; |
Alexandre Julliard | d8a9244 | 2002-05-31 18:43:22 +0000 | [diff] [blame] | 1098 | DC *dc; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 1099 | |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1100 | if (DIB_GetBitmapInfo( header, &width, &height, &planes, &bpp, &compr, &size ) == -1) return 0; |
Michael Kaufmann | 970b221 | 2004-09-20 21:45:00 +0000 | [diff] [blame] | 1101 | |
| 1102 | if (width < 0) |
| 1103 | { |
| 1104 | TRACE("Bitmap has a negative width\n"); |
| 1105 | return 0; |
| 1106 | } |
| 1107 | |
| 1108 | /* Top-down DIBs have a negative height */ |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 1109 | if (height < 0) height = -height; |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 1110 | |
Michael Stefaniuc | a0b260e | 2006-10-12 22:56:56 +0200 | [diff] [blame] | 1111 | TRACE("hdc=%p, header=%p, init=%u, bits=%p, data=%p, coloruse=%u (bitmap: width=%d, height=%d, bpp=%u, compr=%u)\n", |
Michael Kaufmann | 970b221 | 2004-09-20 21:45:00 +0000 | [diff] [blame] | 1112 | hdc, header, init, bits, data, coloruse, width, height, bpp, compr); |
| 1113 | |
Alexandre Julliard | cdcdbe5 | 2004-09-13 19:37:03 +0000 | [diff] [blame] | 1114 | if (hdc == NULL) |
| 1115 | handle = CreateBitmap( width, height, 1, 1, NULL ); |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 1116 | else |
Alexandre Julliard | cdcdbe5 | 2004-09-13 19:37:03 +0000 | [diff] [blame] | 1117 | handle = CreateCompatibleBitmap( hdc, width, height ); |
Alexandre Julliard | 946a444 | 2000-07-30 13:50:27 +0000 | [diff] [blame] | 1118 | |
Alexandre Julliard | d8a9244 | 2002-05-31 18:43:22 +0000 | [diff] [blame] | 1119 | if (handle) |
| 1120 | { |
Lei Zhang | ce552d4 | 2008-07-18 15:28:44 -0700 | [diff] [blame] | 1121 | if (init == CBM_INIT) |
| 1122 | { |
| 1123 | if (SetDIBits( hdc, handle, 0, height, bits, data, coloruse ) == 0) |
| 1124 | { |
| 1125 | DeleteObject( handle ); |
| 1126 | handle = 0; |
| 1127 | } |
| 1128 | } |
Alexandre Julliard | cdcdbe5 | 2004-09-13 19:37:03 +0000 | [diff] [blame] | 1129 | |
Alexandre Julliard | 67a9edb | 2008-02-05 17:35:40 +0100 | [diff] [blame] | 1130 | else if (hdc && ((dc = get_dc_ptr( hdc )) != NULL) ) |
Alexandre Julliard | d8a9244 | 2002-05-31 18:43:22 +0000 | [diff] [blame] | 1131 | { |
Alexandre Julliard | cdcdbe5 | 2004-09-13 19:37:03 +0000 | [diff] [blame] | 1132 | if (!BITMAP_SetOwnerDC( handle, dc )) |
| 1133 | { |
| 1134 | DeleteObject( handle ); |
| 1135 | handle = 0; |
| 1136 | } |
Alexandre Julliard | 67a9edb | 2008-02-05 17:35:40 +0100 | [diff] [blame] | 1137 | release_dc_ptr( dc ); |
Alexandre Julliard | d8a9244 | 2002-05-31 18:43:22 +0000 | [diff] [blame] | 1138 | } |
| 1139 | } |
Alexandre Julliard | af0bae5 | 1995-10-03 17:06:08 +0000 | [diff] [blame] | 1140 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 1141 | return handle; |
| 1142 | } |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1143 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1144 | /*********************************************************************** |
Patrik Stridvall | 17fd4e3 | 2001-06-28 18:04:41 +0000 | [diff] [blame] | 1145 | * CreateDIBSection (GDI.489) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1146 | */ |
Dmitry Timoshkov | 21fc3c8 | 2004-03-12 19:46:12 +0000 | [diff] [blame] | 1147 | HBITMAP16 WINAPI CreateDIBSection16 (HDC16 hdc, const BITMAPINFO *bmi, UINT16 usage, |
Alexandre Julliard | 6bbc745 | 2001-07-22 23:13:08 +0000 | [diff] [blame] | 1148 | SEGPTR *bits16, HANDLE section, DWORD offset) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1149 | { |
Alexandre Julliard | 6bbc745 | 2001-07-22 23:13:08 +0000 | [diff] [blame] | 1150 | LPVOID bits32; |
| 1151 | HBITMAP hbitmap; |
Stephane Lussier | 23259ce | 2000-07-11 22:04:44 +0000 | [diff] [blame] | 1152 | |
Michael Stefaniuc | 28a632a | 2002-11-21 21:50:04 +0000 | [diff] [blame] | 1153 | hbitmap = CreateDIBSection( HDC_32(hdc), bmi, usage, &bits32, section, offset ); |
Alexandre Julliard | 6bbc745 | 2001-07-22 23:13:08 +0000 | [diff] [blame] | 1154 | if (hbitmap) |
Stephane Lussier | 23259ce | 2000-07-11 22:04:44 +0000 | [diff] [blame] | 1155 | { |
Alexandre Julliard | 5811a2c | 2009-01-28 16:20:56 +0100 | [diff] [blame^] | 1156 | BITMAPOBJ *bmp = GDI_GetObjPtr(hbitmap, OBJ_BITMAP); |
Alexandre Julliard | 6bbc745 | 2001-07-22 23:13:08 +0000 | [diff] [blame] | 1157 | if (bmp && bmp->dib && bits32) |
| 1158 | { |
Dmitry Timoshkov | 21fc3c8 | 2004-03-12 19:46:12 +0000 | [diff] [blame] | 1159 | const BITMAPINFOHEADER *bi = &bmi->bmiHeader; |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 1160 | LONG width, height; |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1161 | WORD planes, bpp; |
| 1162 | DWORD compr, size; |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 1163 | INT width_bytes; |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 1164 | WORD count, sel; |
| 1165 | int i; |
| 1166 | |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1167 | DIB_GetBitmapInfo(bi, &width, &height, &planes, &bpp, &compr, &size); |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 1168 | |
| 1169 | height = height >= 0 ? height : -height; |
| 1170 | width_bytes = DIB_GetDIBWidthBytes(width, bpp); |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1171 | |
| 1172 | if (!size || (compr != BI_RLE4 && compr != BI_RLE8)) size = width_bytes * height; |
Alexandre Julliard | 6bbc745 | 2001-07-22 23:13:08 +0000 | [diff] [blame] | 1173 | |
Andreas Mohr | 757e7cb | 2002-05-08 00:20:40 +0000 | [diff] [blame] | 1174 | /* calculate number of sel's needed for size with 64K steps */ |
Michael Kaufmann | 0dd2910 | 2004-11-02 05:23:49 +0000 | [diff] [blame] | 1175 | count = (size + 0xffff) / 0x10000; |
| 1176 | sel = AllocSelectorArray16(count); |
Andreas Mohr | 757e7cb | 2002-05-08 00:20:40 +0000 | [diff] [blame] | 1177 | |
| 1178 | for (i = 0; i < count; i++) |
| 1179 | { |
| 1180 | SetSelectorBase(sel + (i << __AHSHIFT), (DWORD)bits32 + i * 0x10000); |
| 1181 | SetSelectorLimit16(sel + (i << __AHSHIFT), size - 1); /* yep, limit is correct */ |
| 1182 | size -= 0x10000; |
| 1183 | } |
Alexandre Julliard | 6bbc745 | 2001-07-22 23:13:08 +0000 | [diff] [blame] | 1184 | bmp->segptr_bits = MAKESEGPTR( sel, 0 ); |
| 1185 | if (bits16) *bits16 = bmp->segptr_bits; |
| 1186 | } |
| 1187 | if (bmp) GDI_ReleaseObj( hbitmap ); |
Stephane Lussier | 23259ce | 2000-07-11 22:04:44 +0000 | [diff] [blame] | 1188 | } |
Michael Stefaniuc | 28a632a | 2002-11-21 21:50:04 +0000 | [diff] [blame] | 1189 | return HBITMAP_16(hbitmap); |
Ove Kaaven | 8b9f338 | 2000-04-29 16:47:07 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
Francois Gouget | 44b52b1 | 2008-01-16 12:20:50 +0100 | [diff] [blame] | 1192 | /* Copy/synthesize RGB palette from BITMAPINFO. Ripped from dlls/winex11.drv/dib.c */ |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 1193 | static void DIB_CopyColorTable( DC *dc, BITMAPOBJ *bmp, WORD coloruse, const BITMAPINFO *info ) |
| 1194 | { |
| 1195 | RGBQUAD *colorTable; |
Andrew Talbot | 44be6c7 | 2008-10-02 22:18:38 +0100 | [diff] [blame] | 1196 | unsigned int colors, i; |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 1197 | BOOL core_info = info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER); |
| 1198 | |
| 1199 | if (core_info) |
| 1200 | { |
| 1201 | colors = 1 << ((const BITMAPCOREINFO*) info)->bmciHeader.bcBitCount; |
| 1202 | } |
| 1203 | else |
| 1204 | { |
| 1205 | colors = info->bmiHeader.biClrUsed; |
| 1206 | if (!colors) colors = 1 << info->bmiHeader.biBitCount; |
| 1207 | } |
| 1208 | |
| 1209 | if (colors > 256) { |
| 1210 | ERR("called with >256 colors!\n"); |
| 1211 | return; |
| 1212 | } |
| 1213 | |
| 1214 | if (!(colorTable = HeapAlloc(GetProcessHeap(), 0, colors * sizeof(RGBQUAD) ))) return; |
| 1215 | |
| 1216 | if(coloruse == DIB_RGB_COLORS) |
| 1217 | { |
| 1218 | if (core_info) |
| 1219 | { |
| 1220 | /* Convert RGBTRIPLEs to RGBQUADs */ |
| 1221 | for (i=0; i < colors; i++) |
| 1222 | { |
| 1223 | colorTable[i].rgbRed = ((const BITMAPCOREINFO*) info)->bmciColors[i].rgbtRed; |
| 1224 | colorTable[i].rgbGreen = ((const BITMAPCOREINFO*) info)->bmciColors[i].rgbtGreen; |
| 1225 | colorTable[i].rgbBlue = ((const BITMAPCOREINFO*) info)->bmciColors[i].rgbtBlue; |
| 1226 | colorTable[i].rgbReserved = 0; |
| 1227 | } |
| 1228 | } |
| 1229 | else |
| 1230 | { |
| 1231 | memcpy(colorTable, (const BYTE*) info + (WORD) info->bmiHeader.biSize, colors * sizeof(RGBQUAD)); |
| 1232 | } |
| 1233 | } |
| 1234 | else |
| 1235 | { |
Alexandre Julliard | c60757b | 2006-11-17 14:34:20 +0100 | [diff] [blame] | 1236 | PALETTEENTRY entries[256]; |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 1237 | const WORD *index = (const WORD*) ((const BYTE*) info + (WORD) info->bmiHeader.biSize); |
Alexandre Julliard | c60757b | 2006-11-17 14:34:20 +0100 | [diff] [blame] | 1238 | UINT count = GetPaletteEntries( dc->hPalette, 0, colors, entries ); |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 1239 | |
Alexandre Julliard | c60757b | 2006-11-17 14:34:20 +0100 | [diff] [blame] | 1240 | for (i = 0; i < colors; i++, index++) |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 1241 | { |
Alexandre Julliard | c60757b | 2006-11-17 14:34:20 +0100 | [diff] [blame] | 1242 | PALETTEENTRY *entry = &entries[*index % count]; |
| 1243 | colorTable[i].rgbRed = entry->peRed; |
| 1244 | colorTable[i].rgbGreen = entry->peGreen; |
| 1245 | colorTable[i].rgbBlue = entry->peBlue; |
| 1246 | colorTable[i].rgbReserved = 0; |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 1247 | } |
| 1248 | } |
| 1249 | bmp->color_table = colorTable; |
| 1250 | bmp->nb_colors = colors; |
| 1251 | } |
| 1252 | |
Ove Kaaven | 8b9f338 | 2000-04-29 16:47:07 +0000 | [diff] [blame] | 1253 | /*********************************************************************** |
Alexandre Julliard | 1a2417d | 2006-06-19 11:25:42 +0200 | [diff] [blame] | 1254 | * CreateDIBSection (GDI32.@) |
Ove Kaaven | 8b9f338 | 2000-04-29 16:47:07 +0000 | [diff] [blame] | 1255 | */ |
Alexandre Julliard | 1a2417d | 2006-06-19 11:25:42 +0200 | [diff] [blame] | 1256 | HBITMAP WINAPI CreateDIBSection(HDC hdc, CONST BITMAPINFO *bmi, UINT usage, |
| 1257 | VOID **bits, HANDLE section, DWORD offset) |
Ove Kaaven | 8b9f338 | 2000-04-29 16:47:07 +0000 | [diff] [blame] | 1258 | { |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1259 | HBITMAP ret = 0; |
Stephane Lussier | 23259ce | 2000-07-11 22:04:44 +0000 | [diff] [blame] | 1260 | DC *dc; |
| 1261 | BOOL bDesktopDC = FALSE; |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1262 | DIBSECTION *dib; |
| 1263 | BITMAPOBJ *bmp; |
| 1264 | int bitmap_type; |
| 1265 | LONG width, height; |
| 1266 | WORD planes, bpp; |
| 1267 | DWORD compression, sizeImage; |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1268 | void *mapBits = NULL; |
| 1269 | |
Nikolay Sivov | 1441311 | 2008-05-10 11:14:29 +0400 | [diff] [blame] | 1270 | if(!bmi){ |
| 1271 | if(bits) *bits = NULL; |
| 1272 | return NULL; |
| 1273 | } |
| 1274 | |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1275 | if (((bitmap_type = DIB_GetBitmapInfo( &bmi->bmiHeader, &width, &height, |
| 1276 | &planes, &bpp, &compression, &sizeImage )) == -1)) |
| 1277 | return 0; |
| 1278 | |
Ulrich Czekalla | 4f5cbfb | 2006-01-03 12:09:03 +0100 | [diff] [blame] | 1279 | if (compression != BI_RGB && compression != BI_BITFIELDS) |
| 1280 | { |
Michael Stefaniuc | a0b260e | 2006-10-12 22:56:56 +0200 | [diff] [blame] | 1281 | TRACE("can't create a compressed (%u) dibsection\n", compression); |
Ulrich Czekalla | 4f5cbfb | 2006-01-03 12:09:03 +0100 | [diff] [blame] | 1282 | return 0; |
| 1283 | } |
| 1284 | |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1285 | if (!(dib = HeapAlloc( GetProcessHeap(), 0, sizeof(*dib) ))) return 0; |
| 1286 | |
Michael Stefaniuc | a0b260e | 2006-10-12 22:56:56 +0200 | [diff] [blame] | 1287 | TRACE("format (%d,%d), planes %d, bpp %d, size %d, %s\n", |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1288 | width, height, planes, bpp, sizeImage, usage == DIB_PAL_COLORS? "PAL" : "RGB"); |
| 1289 | |
| 1290 | dib->dsBm.bmType = 0; |
| 1291 | dib->dsBm.bmWidth = width; |
| 1292 | dib->dsBm.bmHeight = height >= 0 ? height : -height; |
Alexandre Julliard | 1a2417d | 2006-06-19 11:25:42 +0200 | [diff] [blame] | 1293 | dib->dsBm.bmWidthBytes = DIB_GetDIBWidthBytes(width, bpp); |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1294 | dib->dsBm.bmPlanes = planes; |
| 1295 | dib->dsBm.bmBitsPixel = bpp; |
| 1296 | dib->dsBm.bmBits = NULL; |
| 1297 | |
| 1298 | if (!bitmap_type) /* core header */ |
| 1299 | { |
| 1300 | /* convert the BITMAPCOREHEADER to a BITMAPINFOHEADER */ |
| 1301 | dib->dsBmih.biSize = sizeof(BITMAPINFOHEADER); |
| 1302 | dib->dsBmih.biWidth = width; |
| 1303 | dib->dsBmih.biHeight = height; |
| 1304 | dib->dsBmih.biPlanes = planes; |
| 1305 | dib->dsBmih.biBitCount = bpp; |
| 1306 | dib->dsBmih.biCompression = compression; |
| 1307 | dib->dsBmih.biXPelsPerMeter = 0; |
| 1308 | dib->dsBmih.biYPelsPerMeter = 0; |
| 1309 | dib->dsBmih.biClrUsed = 0; |
| 1310 | dib->dsBmih.biClrImportant = 0; |
| 1311 | } |
| 1312 | else |
| 1313 | { |
| 1314 | /* truncate extended bitmap headers (BITMAPV4HEADER etc.) */ |
| 1315 | dib->dsBmih = bmi->bmiHeader; |
| 1316 | dib->dsBmih.biSize = sizeof(BITMAPINFOHEADER); |
| 1317 | } |
| 1318 | |
Peter Beutner | c9e02e1 | 2005-11-14 15:10:23 +0000 | [diff] [blame] | 1319 | /* set number of entries in bmi.bmiColors table */ |
| 1320 | if( bpp <= 8 ) |
| 1321 | dib->dsBmih.biClrUsed = 1 << bpp; |
| 1322 | |
Ulrich Czekalla | 4f5cbfb | 2006-01-03 12:09:03 +0100 | [diff] [blame] | 1323 | dib->dsBmih.biSizeImage = dib->dsBm.bmWidthBytes * dib->dsBm.bmHeight; |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1324 | |
| 1325 | /* set dsBitfields values */ |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1326 | if (usage == DIB_PAL_COLORS || bpp <= 8) |
| 1327 | { |
| 1328 | dib->dsBitfields[0] = dib->dsBitfields[1] = dib->dsBitfields[2] = 0; |
| 1329 | } |
| 1330 | else switch( bpp ) |
| 1331 | { |
| 1332 | case 15: |
| 1333 | case 16: |
Michael Kaufmann | 0f2c2b8 | 2005-08-08 18:40:14 +0000 | [diff] [blame] | 1334 | dib->dsBitfields[0] = (compression == BI_BITFIELDS) ? *(const DWORD *)bmi->bmiColors : 0x7c00; |
| 1335 | dib->dsBitfields[1] = (compression == BI_BITFIELDS) ? *((const DWORD *)bmi->bmiColors + 1) : 0x03e0; |
| 1336 | dib->dsBitfields[2] = (compression == BI_BITFIELDS) ? *((const DWORD *)bmi->bmiColors + 2) : 0x001f; |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1337 | break; |
| 1338 | case 24: |
| 1339 | case 32: |
Michael Kaufmann | 0f2c2b8 | 2005-08-08 18:40:14 +0000 | [diff] [blame] | 1340 | dib->dsBitfields[0] = (compression == BI_BITFIELDS) ? *(const DWORD *)bmi->bmiColors : 0xff0000; |
| 1341 | dib->dsBitfields[1] = (compression == BI_BITFIELDS) ? *((const DWORD *)bmi->bmiColors + 1) : 0x00ff00; |
| 1342 | dib->dsBitfields[2] = (compression == BI_BITFIELDS) ? *((const DWORD *)bmi->bmiColors + 2) : 0x0000ff; |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1343 | break; |
| 1344 | } |
| 1345 | |
| 1346 | /* get storage location for DIB bits */ |
| 1347 | |
| 1348 | if (section) |
| 1349 | { |
| 1350 | SYSTEM_INFO SystemInfo; |
| 1351 | DWORD mapOffset; |
| 1352 | INT mapSize; |
| 1353 | |
| 1354 | GetSystemInfo( &SystemInfo ); |
| 1355 | mapOffset = offset - (offset % SystemInfo.dwAllocationGranularity); |
| 1356 | mapSize = dib->dsBmih.biSizeImage + (offset - mapOffset); |
| 1357 | mapBits = MapViewOfFile( section, FILE_MAP_ALL_ACCESS, 0, mapOffset, mapSize ); |
| 1358 | if (mapBits) dib->dsBm.bmBits = (char *)mapBits + (offset - mapOffset); |
| 1359 | } |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1360 | else |
| 1361 | { |
| 1362 | offset = 0; |
| 1363 | dib->dsBm.bmBits = VirtualAlloc( NULL, dib->dsBmih.biSizeImage, |
| 1364 | MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE ); |
| 1365 | } |
| 1366 | dib->dshSection = section; |
| 1367 | dib->dsOffset = offset; |
| 1368 | |
| 1369 | if (!dib->dsBm.bmBits) |
| 1370 | { |
| 1371 | HeapFree( GetProcessHeap(), 0, dib ); |
| 1372 | return 0; |
| 1373 | } |
Stephane Lussier | 23259ce | 2000-07-11 22:04:44 +0000 | [diff] [blame] | 1374 | |
| 1375 | /* If the reference hdc is null, take the desktop dc */ |
| 1376 | if (hdc == 0) |
| 1377 | { |
| 1378 | hdc = CreateCompatibleDC(0); |
| 1379 | bDesktopDC = TRUE; |
| 1380 | } |
| 1381 | |
Alexandre Julliard | 67a9edb | 2008-02-05 17:35:40 +0100 | [diff] [blame] | 1382 | if (!(dc = get_dc_ptr( hdc ))) goto error; |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1383 | |
| 1384 | /* create Device Dependent Bitmap and add DIB pointer */ |
| 1385 | ret = CreateBitmap( dib->dsBm.bmWidth, dib->dsBm.bmHeight, 1, |
| 1386 | (bpp == 1) ? 1 : GetDeviceCaps(hdc, BITSPIXEL), NULL ); |
| 1387 | |
Alexandre Julliard | 5811a2c | 2009-01-28 16:20:56 +0100 | [diff] [blame^] | 1388 | if (ret && ((bmp = GDI_GetObjPtr(ret, OBJ_BITMAP)))) |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 1389 | { |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1390 | bmp->dib = dib; |
| 1391 | bmp->funcs = dc->funcs; |
Alexandre Julliard | f7ffbe4 | 2006-11-08 19:57:30 +0100 | [diff] [blame] | 1392 | /* create local copy of DIB palette */ |
| 1393 | if (bpp <= 8) DIB_CopyColorTable( dc, bmp, usage, bmi ); |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1394 | GDI_ReleaseObj( ret ); |
| 1395 | |
| 1396 | if (dc->funcs->pCreateDIBSection) |
| 1397 | { |
| 1398 | if (!dc->funcs->pCreateDIBSection(dc->physDev, ret, bmi, usage)) |
| 1399 | { |
| 1400 | DeleteObject( ret ); |
| 1401 | ret = 0; |
| 1402 | } |
| 1403 | } |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 1404 | } |
Ulrich Weigand | 4f85bad | 1999-02-09 15:30:22 +0000 | [diff] [blame] | 1405 | |
Alexandre Julliard | 67a9edb | 2008-02-05 17:35:40 +0100 | [diff] [blame] | 1406 | release_dc_ptr( dc ); |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1407 | if (bDesktopDC) DeleteDC( hdc ); |
| 1408 | if (ret && bits) *bits = dib->dsBm.bmBits; |
| 1409 | return ret; |
Stephane Lussier | 23259ce | 2000-07-11 22:04:44 +0000 | [diff] [blame] | 1410 | |
Alexandre Julliard | 9591466 | 2005-04-13 14:45:27 +0000 | [diff] [blame] | 1411 | error: |
| 1412 | if (bDesktopDC) DeleteDC( hdc ); |
| 1413 | if (section) UnmapViewOfFile( mapBits ); |
| 1414 | else if (!offset) VirtualFree( dib->dsBm.bmBits, 0, MEM_RELEASE ); |
| 1415 | HeapFree( GetProcessHeap(), 0, dib ); |
| 1416 | return 0; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 1417 | } |