Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * GDI bitmap objects |
| 3 | * |
| 4 | * Copyright 1993 Alexandre Julliard |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 5 | * 1998 Huw D M Davies |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 6 | */ |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 7 | |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 8 | #include <stdlib.h> |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 9 | #include <string.h> |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 10 | |
| 11 | #include "wine/winbase16.h" |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 12 | #include "gdi.h" |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 13 | #include "bitmap.h" |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 14 | #include "heap.h" |
Alexandre Julliard | 06c275a | 1999-05-02 14:32:27 +0000 | [diff] [blame] | 15 | #include "debugtools.h" |
Patrik Stridvall | 8d8703c | 1999-02-04 14:05:38 +0000 | [diff] [blame] | 16 | #include "wine/winuser16.h" |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 17 | |
Alexandre Julliard | 946a444 | 2000-07-30 13:50:27 +0000 | [diff] [blame] | 18 | DEFAULT_DEBUG_CHANNEL(bitmap); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 19 | |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 20 | BITMAP_DRIVER *BITMAP_Driver = NULL; |
| 21 | |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 22 | |
| 23 | /*********************************************************************** |
Huw D M Davies | 8261736 | 1998-11-01 16:35:42 +0000 | [diff] [blame] | 24 | * BITMAP_GetWidthBytes |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 25 | * |
Huw D M Davies | 8261736 | 1998-11-01 16:35:42 +0000 | [diff] [blame] | 26 | * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB |
| 27 | * data. |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 28 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 29 | INT BITMAP_GetWidthBytes( INT bmWidth, INT bpp ) |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 30 | { |
| 31 | switch(bpp) |
| 32 | { |
| 33 | case 1: |
| 34 | return 2 * ((bmWidth+15) >> 4); |
| 35 | |
| 36 | case 24: |
| 37 | bmWidth *= 3; /* fall through */ |
| 38 | case 8: |
| 39 | return bmWidth + (bmWidth & 1); |
| 40 | |
| 41 | case 32: |
| 42 | return bmWidth * 4; |
| 43 | |
| 44 | case 16: |
| 45 | case 15: |
| 46 | return bmWidth * 2; |
| 47 | |
| 48 | case 4: |
| 49 | return 2 * ((bmWidth+3) >> 2); |
| 50 | |
| 51 | default: |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 52 | WARN("Unknown depth %d, please report.\n", bpp ); |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 53 | } |
| 54 | return -1; |
| 55 | } |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 56 | |
| 57 | /*********************************************************************** |
Ulrich Weigand | 71f7a46 | 1998-10-11 19:13:52 +0000 | [diff] [blame] | 58 | * CreateUserBitmap16 (GDI.407) |
| 59 | */ |
| 60 | HBITMAP16 WINAPI CreateUserBitmap16( INT16 width, INT16 height, UINT16 planes, |
| 61 | UINT16 bpp, LPCVOID bits ) |
| 62 | { |
| 63 | return CreateBitmap16( width, height, planes, bpp, bits ); |
| 64 | } |
| 65 | |
| 66 | /*********************************************************************** |
| 67 | * CreateUserDiscardableBitmap16 (GDI.409) |
| 68 | */ |
| 69 | HBITMAP16 WINAPI CreateUserDiscardableBitmap16( WORD dummy, |
| 70 | INT16 width, INT16 height ) |
| 71 | { |
Alexandre Julliard | 946a444 | 2000-07-30 13:50:27 +0000 | [diff] [blame] | 72 | HDC hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL ); |
| 73 | HBITMAP16 ret = CreateCompatibleBitmap16( hdc, width, height ); |
| 74 | DeleteDC( hdc ); |
| 75 | return ret; |
Ulrich Weigand | 71f7a46 | 1998-10-11 19:13:52 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | |
Ulrich Weigand | 71f7a46 | 1998-10-11 19:13:52 +0000 | [diff] [blame] | 79 | /*********************************************************************** |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 80 | * CreateBitmap16 (GDI.48) |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 81 | * CreateBitmap16 (DISPLAY.48) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 82 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 83 | HBITMAP16 WINAPI CreateBitmap16( INT16 width, INT16 height, UINT16 planes, |
| 84 | UINT16 bpp, LPCVOID bits ) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 85 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 86 | return CreateBitmap( width, height, planes, bpp, bits ); |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 90 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 91 | * CreateBitmap [GDI32.@] Creates a bitmap with the specified info |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 92 | * |
| 93 | * PARAMS |
| 94 | * width [I] bitmap width |
| 95 | * height [I] bitmap height |
| 96 | * planes [I] Number of color planes |
| 97 | * bpp [I] Number of bits to identify a color |
| 98 | * bits [I] Pointer to array containing color data |
| 99 | * |
| 100 | * RETURNS |
| 101 | * Success: Handle to bitmap |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 102 | * Failure: 0 |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 103 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 104 | HBITMAP WINAPI CreateBitmap( INT width, INT height, UINT planes, |
| 105 | UINT bpp, LPCVOID bits ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 106 | { |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 107 | BITMAPOBJ *bmp; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 108 | HBITMAP hbitmap; |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 109 | |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 110 | planes = (BYTE)planes; |
| 111 | bpp = (BYTE)bpp; |
| 112 | |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 113 | |
| 114 | /* Check parameters */ |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 115 | if (!height || !width) return 0; |
| 116 | if (planes != 1) { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 117 | FIXME("planes = %d\n", planes); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 118 | return 0; |
| 119 | } |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 120 | if (height < 0) height = -height; |
| 121 | if (width < 0) width = -width; |
| 122 | |
| 123 | /* Create the BITMAPOBJ */ |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 124 | if (!(bmp = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC, &hbitmap ))) return 0; |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 125 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 126 | TRACE("%dx%d, %d colors returning %08x\n", width, height, |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 127 | 1 << (planes*bpp), hbitmap); |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 128 | |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 129 | bmp->size.cx = 0; |
| 130 | bmp->size.cy = 0; |
| 131 | bmp->bitmap.bmType = 0; |
Huw D M Davies | 8261736 | 1998-11-01 16:35:42 +0000 | [diff] [blame] | 132 | bmp->bitmap.bmWidth = width; |
| 133 | bmp->bitmap.bmHeight = height; |
| 134 | bmp->bitmap.bmPlanes = planes; |
| 135 | bmp->bitmap.bmBitsPixel = bpp; |
| 136 | bmp->bitmap.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp ); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 137 | bmp->bitmap.bmBits = NULL; |
| 138 | |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 139 | bmp->funcs = NULL; |
| 140 | bmp->physBitmap = NULL; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 141 | bmp->dib = NULL; |
| 142 | |
| 143 | if (bits) /* Set bitmap bits */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 144 | SetBitmapBits( hbitmap, height * bmp->bitmap.bmWidthBytes, |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 145 | bits ); |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 146 | GDI_ReleaseObj( hbitmap ); |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 147 | return hbitmap; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | |
| 151 | /*********************************************************************** |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 152 | * CreateCompatibleBitmap16 (GDI.51) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 153 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 154 | HBITMAP16 WINAPI CreateCompatibleBitmap16(HDC16 hdc, INT16 width, INT16 height) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 155 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 156 | return CreateCompatibleBitmap( hdc, width, height ); |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 160 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 161 | * CreateCompatibleBitmap [GDI32.@] Creates a bitmap compatible with the DC |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 162 | * |
| 163 | * PARAMS |
| 164 | * hdc [I] Handle to device context |
| 165 | * width [I] Width of bitmap |
| 166 | * height [I] Height of bitmap |
| 167 | * |
| 168 | * RETURNS |
| 169 | * Success: Handle to bitmap |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 170 | * Failure: 0 |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 171 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 172 | HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 173 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 174 | HBITMAP hbmpRet = 0; |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 175 | DC *dc; |
| 176 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 177 | TRACE("(%04x,%d,%d) = \n", hdc, width, height ); |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 178 | if (!(dc = DC_GetDCPtr( hdc ))) return 0; |
NF Stevens | 16f0dfb | 1999-01-01 18:45:03 +0000 | [diff] [blame] | 179 | if ((width >= 0x10000) || (height >= 0x10000)) { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 180 | FIXME("got bad width %d or height %d, please look for reason\n", |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 181 | width, height ); |
Huw D M Davies | d6a91b7 | 1998-12-02 10:29:04 +0000 | [diff] [blame] | 182 | } else { |
Eric Pouech | 7990b7c | 1999-06-07 17:46:39 +0000 | [diff] [blame] | 183 | /* MS doc says if width or height is 0, return 1-by-1 pixel, monochrome bitmap */ |
| 184 | if (!width || !height) |
| 185 | hbmpRet = CreateBitmap( 1, 1, 1, 1, NULL ); |
| 186 | else |
Alexandre Julliard | 2239abb | 2000-11-05 02:05:07 +0000 | [diff] [blame] | 187 | hbmpRet = CreateBitmap( width, height, 1, dc->bitsPerPixel, NULL ); |
Huw D M Davies | d6a91b7 | 1998-12-02 10:29:04 +0000 | [diff] [blame] | 188 | if(dc->funcs->pCreateBitmap) |
| 189 | dc->funcs->pCreateBitmap( hbmpRet ); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 190 | } |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 191 | TRACE("\t\t%04x\n", hbmpRet); |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 192 | GDI_ReleaseObj(hdc); |
Alexandre Julliard | 1e9ac79 | 1996-06-06 18:38:27 +0000 | [diff] [blame] | 193 | return hbmpRet; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | |
| 197 | /*********************************************************************** |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 198 | * CreateBitmapIndirect16 (GDI.49) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 199 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 200 | HBITMAP16 WINAPI CreateBitmapIndirect16( const BITMAP16 * bmp ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 201 | { |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 202 | return CreateBitmap16( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes, |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 203 | bmp->bmBitsPixel, MapSL( bmp->bmBits ) ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 207 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 208 | * CreateBitmapIndirect [GDI32.@] Creates a bitmap with the specifies info |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 209 | * |
| 210 | * RETURNS |
| 211 | * Success: Handle to bitmap |
| 212 | * Failure: NULL |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 213 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 214 | HBITMAP WINAPI CreateBitmapIndirect( |
| 215 | const BITMAP * bmp) /* [in] Pointer to the bitmap data */ |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 216 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 217 | return CreateBitmap( bmp->bmWidth, bmp->bmHeight, bmp->bmPlanes, |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 218 | bmp->bmBitsPixel, bmp->bmBits ); |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | |
| 222 | /*********************************************************************** |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 223 | * GetBitmapBits16 (GDI.74) |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 224 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 225 | LONG WINAPI GetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPVOID buffer ) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 226 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 227 | return GetBitmapBits( hbitmap, count, buffer ); |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | |
| 231 | /*********************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 232 | * GetBitmapBits [GDI32.@] Copies bitmap bits of bitmap to buffer |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 233 | * |
| 234 | * RETURNS |
| 235 | * Success: Number of bytes copied |
| 236 | * Failure: 0 |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 237 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 238 | LONG WINAPI GetBitmapBits( |
| 239 | HBITMAP hbitmap, /* [in] Handle to bitmap */ |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 240 | LONG count, /* [in] Number of bytes to copy */ |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 241 | LPVOID bits) /* [out] Pointer to buffer to receive bits */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 242 | { |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 243 | BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); |
| 244 | LONG height, ret; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 245 | |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 246 | if (!bmp) return 0; |
Pascal Lessard | 8903e53 | 1999-05-22 10:39:00 +0000 | [diff] [blame] | 247 | |
| 248 | /* If the bits vector is null, the function should return the read size */ |
| 249 | if(bits == NULL) |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 250 | { |
| 251 | ret = bmp->bitmap.bmWidthBytes * bmp->bitmap.bmHeight; |
| 252 | goto done; |
| 253 | } |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 254 | |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 255 | if (count < 0) { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 256 | WARN("(%ld): Negative number of bytes passed???\n", count ); |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 257 | count = -count; |
| 258 | } |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 259 | |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 260 | /* Only get entire lines */ |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 261 | height = count / bmp->bitmap.bmWidthBytes; |
| 262 | if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 263 | count = height * bmp->bitmap.bmWidthBytes; |
Uwe Bonnes | 1f43de3 | 1998-11-07 12:25:18 +0000 | [diff] [blame] | 264 | if (count == 0) |
| 265 | { |
Francois Gouget | 05fc3cd | 2001-01-22 02:22:26 +0000 | [diff] [blame] | 266 | WARN("Less than one entire line requested\n"); |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 267 | ret = 0; |
| 268 | goto done; |
Uwe Bonnes | 1f43de3 | 1998-11-07 12:25:18 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 271 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 272 | TRACE("(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n", |
| 273 | hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, |
| 274 | 1 << bmp->bitmap.bmBitsPixel, height ); |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 275 | |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 276 | if(bmp->funcs) { |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 277 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 278 | TRACE("Calling device specific BitmapBits\n"); |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 279 | if(bmp->funcs->pBitmapBits) |
| 280 | ret = bmp->funcs->pBitmapBits(hbitmap, bits, count, DDB_GET); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 281 | else { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 282 | ERR("BitmapBits == NULL??\n"); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 283 | ret = 0; |
| 284 | } |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 285 | |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 286 | } else { |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 287 | |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 288 | if(!bmp->bitmap.bmBits) { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 289 | WARN("Bitmap is empty\n"); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 290 | ret = 0; |
| 291 | } else { |
| 292 | memcpy(bits, bmp->bitmap.bmBits, count); |
| 293 | ret = count; |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 294 | } |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 295 | |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 296 | } |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 297 | done: |
| 298 | GDI_ReleaseObj( hbitmap ); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 299 | return ret; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | |
| 303 | /*********************************************************************** |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 304 | * SetBitmapBits16 (GDI.106) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 305 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 306 | LONG WINAPI SetBitmapBits16( HBITMAP16 hbitmap, LONG count, LPCVOID buffer ) |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 307 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 308 | return SetBitmapBits( hbitmap, count, buffer ); |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 312 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 313 | * SetBitmapBits [GDI32.@] Sets bits of color data for a bitmap |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 314 | * |
| 315 | * RETURNS |
| 316 | * Success: Number of bytes used in setting the bitmap bits |
| 317 | * Failure: 0 |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 318 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 319 | LONG WINAPI SetBitmapBits( |
| 320 | HBITMAP hbitmap, /* [in] Handle to bitmap */ |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 321 | LONG count, /* [in] Number of bytes in bitmap array */ |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 322 | LPCVOID bits) /* [in] Address of array with bitmap bits */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 323 | { |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 324 | BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); |
| 325 | LONG height, ret; |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 326 | |
Pascal Lessard | 8903e53 | 1999-05-22 10:39:00 +0000 | [diff] [blame] | 327 | if ((!bmp) || (!bits)) |
| 328 | return 0; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 329 | |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 330 | if (count < 0) { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 331 | WARN("(%ld): Negative number of bytes passed???\n", count ); |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 332 | count = -count; |
| 333 | } |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 334 | |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 335 | /* Only get entire lines */ |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 336 | height = count / bmp->bitmap.bmWidthBytes; |
| 337 | if (height > bmp->bitmap.bmHeight) height = bmp->bitmap.bmHeight; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 338 | count = height * bmp->bitmap.bmWidthBytes; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 339 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 340 | TRACE("(%08x, %ld, %p) %dx%d %d colors fetched height: %ld\n", |
| 341 | hbitmap, count, bits, bmp->bitmap.bmWidth, bmp->bitmap.bmHeight, |
| 342 | 1 << bmp->bitmap.bmBitsPixel, height ); |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 343 | |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 344 | if(bmp->funcs) { |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 345 | |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 346 | TRACE("Calling device specific BitmapBits\n"); |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 347 | if(bmp->funcs->pBitmapBits) |
| 348 | ret = bmp->funcs->pBitmapBits(hbitmap, (void *) bits, count, DDB_SET); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 349 | else { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 350 | ERR("BitmapBits == NULL??\n"); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 351 | ret = 0; |
| 352 | } |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 353 | |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 354 | } else { |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 355 | |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 356 | if(!bmp->bitmap.bmBits) /* Alloc enough for entire bitmap */ |
| 357 | bmp->bitmap.bmBits = HeapAlloc( GetProcessHeap(), 0, count ); |
| 358 | if(!bmp->bitmap.bmBits) { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 359 | WARN("Unable to allocate bit buffer\n"); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 360 | ret = 0; |
| 361 | } else { |
| 362 | memcpy(bmp->bitmap.bmBits, bits, count); |
| 363 | ret = count; |
| 364 | } |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 367 | GDI_ReleaseObj( hbitmap ); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 368 | return ret; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 369 | } |
| 370 | |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 371 | /********************************************************************** |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 372 | * BITMAP_CopyBitmap |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 373 | * |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 374 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 375 | HBITMAP BITMAP_CopyBitmap(HBITMAP hbitmap) |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 376 | { |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 377 | BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 378 | HBITMAP res = 0; |
| 379 | BITMAP bm; |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 380 | |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 381 | if(!bmp) return 0; |
| 382 | |
| 383 | bm = bmp->bitmap; |
| 384 | bm.bmBits = NULL; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 385 | res = CreateBitmapIndirect(&bm); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 386 | |
| 387 | if(res) { |
| 388 | char *buf = HeapAlloc( GetProcessHeap(), 0, bm.bmWidthBytes * |
| 389 | bm.bmHeight ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 390 | GetBitmapBits (hbitmap, bm.bmWidthBytes * bm.bmHeight, buf); |
| 391 | SetBitmapBits (res, bm.bmWidthBytes * bm.bmHeight, buf); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 392 | HeapFree( GetProcessHeap(), 0, buf ); |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 393 | } |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 394 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 395 | GDI_ReleaseObj( hbitmap ); |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 396 | return res; |
| 397 | } |
| 398 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 399 | /*********************************************************************** |
Alexandre Julliard | 7cbe657 | 1995-01-09 18:21:16 +0000 | [diff] [blame] | 400 | * BITMAP_DeleteObject |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 401 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 402 | BOOL BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bmp ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 403 | { |
Alexandre Julliard | a08e2cf | 2000-03-28 13:37:50 +0000 | [diff] [blame] | 404 | if (bmp->funcs && bmp->funcs->pDeleteObject) |
| 405 | bmp->funcs->pDeleteObject( hbitmap ); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 406 | |
| 407 | if( bmp->bitmap.bmBits ) |
| 408 | HeapFree( GetProcessHeap(), 0, bmp->bitmap.bmBits ); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 409 | |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 410 | DIB_DeleteDIBSection( bmp ); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 411 | |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 412 | return GDI_FreeObject( hbitmap, bmp ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | |
| 416 | /*********************************************************************** |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 417 | * BITMAP_GetObject16 |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 418 | */ |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 419 | INT16 BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 420 | { |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 421 | if (bmp->dib) |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 422 | { |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 423 | if ( count <= sizeof(BITMAP16) ) |
| 424 | { |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 425 | BITMAP *bmp32 = &bmp->dib->dsBm; |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 426 | BITMAP16 bmp16; |
| 427 | bmp16.bmType = bmp32->bmType; |
| 428 | bmp16.bmWidth = bmp32->bmWidth; |
| 429 | bmp16.bmHeight = bmp32->bmHeight; |
| 430 | bmp16.bmWidthBytes = bmp32->bmWidthBytes; |
| 431 | bmp16.bmPlanes = bmp32->bmPlanes; |
| 432 | bmp16.bmBitsPixel = bmp32->bmBitsPixel; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 433 | bmp16.bmBits = (SEGPTR)0; |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 434 | memcpy( buffer, &bmp16, count ); |
| 435 | return count; |
| 436 | } |
| 437 | else |
| 438 | { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 439 | FIXME("not implemented for DIBs: count %d\n", count); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 440 | return 0; |
| 441 | } |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 442 | } |
| 443 | else |
| 444 | { |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 445 | BITMAP16 bmp16; |
| 446 | bmp16.bmType = bmp->bitmap.bmType; |
| 447 | bmp16.bmWidth = bmp->bitmap.bmWidth; |
| 448 | bmp16.bmHeight = bmp->bitmap.bmHeight; |
| 449 | bmp16.bmWidthBytes = bmp->bitmap.bmWidthBytes; |
| 450 | bmp16.bmPlanes = bmp->bitmap.bmPlanes; |
| 451 | bmp16.bmBitsPixel = bmp->bitmap.bmBitsPixel; |
| 452 | bmp16.bmBits = (SEGPTR)0; |
| 453 | if (count > sizeof(bmp16)) count = sizeof(bmp16); |
| 454 | memcpy( buffer, &bmp16, count ); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 455 | return count; |
| 456 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 457 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 458 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 459 | |
| 460 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 461 | * BITMAP_GetObject |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 462 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 463 | INT BITMAP_GetObject( BITMAPOBJ * bmp, INT count, LPVOID buffer ) |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 464 | { |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 465 | if (bmp->dib) |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 466 | { |
| 467 | if (count < sizeof(DIBSECTION)) |
| 468 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 469 | if (count > sizeof(BITMAP)) count = sizeof(BITMAP); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 470 | } |
| 471 | else |
| 472 | { |
| 473 | if (count > sizeof(DIBSECTION)) count = sizeof(DIBSECTION); |
| 474 | } |
| 475 | |
Patrik Stridvall | b87fe2e | 1999-04-01 08:16:08 +0000 | [diff] [blame] | 476 | memcpy( buffer, bmp->dib, count ); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 477 | return count; |
| 478 | } |
| 479 | else |
| 480 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 481 | if (count > sizeof(BITMAP)) count = sizeof(BITMAP); |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 482 | memcpy( buffer, &bmp->bitmap, count ); |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 483 | return count; |
| 484 | } |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | |
Alexandre Julliard | 36ca136 | 1994-06-02 22:38:20 +0000 | [diff] [blame] | 488 | /*********************************************************************** |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 489 | * CreateDiscardableBitmap16 (GDI.156) |
Alexandre Julliard | 36ca136 | 1994-06-02 22:38:20 +0000 | [diff] [blame] | 490 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 491 | HBITMAP16 WINAPI CreateDiscardableBitmap16( HDC16 hdc, INT16 width, |
| 492 | INT16 height ) |
Alexandre Julliard | 36ca136 | 1994-06-02 22:38:20 +0000 | [diff] [blame] | 493 | { |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 494 | return CreateCompatibleBitmap16( hdc, width, height ); |
| 495 | } |
| 496 | |
| 497 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 498 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 499 | * CreateDiscardableBitmap [GDI32.@] Creates a discardable bitmap |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 500 | * |
| 501 | * RETURNS |
| 502 | * Success: Handle to bitmap |
| 503 | * Failure: NULL |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 504 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 505 | HBITMAP WINAPI CreateDiscardableBitmap( |
| 506 | HDC hdc, /* [in] Handle to device context */ |
| 507 | INT width, /* [in] Bitmap width */ |
| 508 | INT height) /* [in] Bitmap height */ |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 509 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 510 | return CreateCompatibleBitmap( hdc, width, height ); |
Alexandre Julliard | 36ca136 | 1994-06-02 22:38:20 +0000 | [diff] [blame] | 511 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 512 | |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 513 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 514 | /*********************************************************************** |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 515 | * GetBitmapDimensionEx16 (GDI.468) |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 516 | * |
| 517 | * NOTES |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 518 | * Can this call GetBitmapDimensionEx? |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 519 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 520 | BOOL16 WINAPI GetBitmapDimensionEx16( HBITMAP16 hbitmap, LPSIZE16 size ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 521 | { |
| 522 | BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); |
| 523 | if (!bmp) return FALSE; |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 524 | size->cx = bmp->size.cx; |
| 525 | size->cy = bmp->size.cy; |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 526 | GDI_ReleaseObj( hbitmap ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 527 | return TRUE; |
| 528 | } |
| 529 | |
| 530 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 531 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 532 | * GetBitmapDimensionEx [GDI32.@] Retrieves dimensions of a bitmap |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 533 | * |
| 534 | * RETURNS |
| 535 | * Success: TRUE |
| 536 | * Failure: FALSE |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 537 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 538 | BOOL WINAPI GetBitmapDimensionEx( |
| 539 | HBITMAP hbitmap, /* [in] Handle to bitmap */ |
| 540 | LPSIZE size) /* [out] Address of struct receiving dimensions */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 541 | { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 542 | BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); |
| 543 | if (!bmp) return FALSE; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 544 | *size = bmp->size; |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 545 | GDI_ReleaseObj( hbitmap ); |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 546 | return TRUE; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 547 | } |
| 548 | |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 549 | |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 550 | /*********************************************************************** |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 551 | * GetBitmapDimension (GDI.162) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 552 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 553 | DWORD WINAPI GetBitmapDimension16( HBITMAP16 hbitmap ) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 554 | { |
| 555 | SIZE16 size; |
| 556 | if (!GetBitmapDimensionEx16( hbitmap, &size )) return 0; |
| 557 | return MAKELONG( size.cx, size.cy ); |
| 558 | } |
| 559 | |
| 560 | |
| 561 | /*********************************************************************** |
| 562 | * SetBitmapDimensionEx16 (GDI.478) |
| 563 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 564 | BOOL16 WINAPI SetBitmapDimensionEx16( HBITMAP16 hbitmap, INT16 x, INT16 y, |
| 565 | LPSIZE16 prevSize ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 566 | { |
| 567 | BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); |
| 568 | if (!bmp) return FALSE; |
Alexandre Julliard | 982a223 | 2000-12-13 20:20:09 +0000 | [diff] [blame] | 569 | if (prevSize) |
| 570 | { |
| 571 | prevSize->cx = bmp->size.cx; |
| 572 | prevSize->cy = bmp->size.cy; |
| 573 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 574 | bmp->size.cx = x; |
| 575 | bmp->size.cy = y; |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 576 | GDI_ReleaseObj( hbitmap ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 577 | return TRUE; |
| 578 | } |
| 579 | |
| 580 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 581 | /****************************************************************************** |
Patrik Stridvall | d0a4177 | 2001-02-14 23:11:17 +0000 | [diff] [blame] | 582 | * SetBitmapDimensionEx [GDI32.@] Assignes dimensions to a bitmap |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 583 | * |
| 584 | * RETURNS |
| 585 | * Success: TRUE |
| 586 | * Failure: FALSE |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 587 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 588 | BOOL WINAPI SetBitmapDimensionEx( |
| 589 | HBITMAP hbitmap, /* [in] Handle to bitmap */ |
| 590 | INT x, /* [in] Bitmap width */ |
| 591 | INT y, /* [in] Bitmap height */ |
| 592 | LPSIZE prevSize) /* [out] Address of structure for orig dims */ |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 593 | { |
| 594 | BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC ); |
| 595 | if (!bmp) return FALSE; |
Huw D M Davies | 87f87bf | 1998-10-28 09:53:53 +0000 | [diff] [blame] | 596 | if (prevSize) *prevSize = bmp->size; |
| 597 | bmp->size.cx = x; |
| 598 | bmp->size.cy = y; |
Alexandre Julliard | 2a2321b | 2000-08-19 21:38:55 +0000 | [diff] [blame] | 599 | GDI_ReleaseObj( hbitmap ); |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 600 | return TRUE; |
| 601 | } |
| 602 | |
| 603 | |
| 604 | /*********************************************************************** |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 605 | * SetBitmapDimension (GDI.163) |
| 606 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 607 | DWORD WINAPI SetBitmapDimension16( HBITMAP16 hbitmap, INT16 x, INT16 y ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 608 | { |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 609 | SIZE16 size; |
| 610 | if (!SetBitmapDimensionEx16( hbitmap, x, y, &size )) return 0; |
| 611 | return MAKELONG( size.cx, size.cy ); |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 612 | } |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 613 | |