|
/* $Header: /cvsroot/esrg/sfesrg/esrgpcpj/shared/tk_base/tkwinimage.c,v 1.1.1.1 2001/06/13 05:13:34 dtashley Exp $ */ |
|
|
|
|
|
/* |
|
|
* tkWinImage.c -- |
|
|
* |
|
|
* This file contains routines for manipulation full-color images. |
|
|
* |
|
|
* Copyright (c) 1995 Sun Microsystems, Inc. |
|
|
* |
|
|
* See the file "license.terms" for information on usage and redistribution |
|
|
* of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
|
|
* |
|
|
* RCS: @(#) $Id: tkwinimage.c,v 1.1.1.1 2001/06/13 05:13:34 dtashley Exp $ |
|
|
*/ |
|
|
|
|
|
#include "tkWinInt.h" |
|
|
|
|
|
static int DestroyImage _ANSI_ARGS_((XImage* data)); |
|
|
static unsigned long ImageGetPixel _ANSI_ARGS_((XImage *image, int x, int y)); |
|
|
static int PutPixel _ANSI_ARGS_((XImage *image, int x, int y, |
|
|
unsigned long pixel)); |
|
|
|
|
|
/* |
|
|
*---------------------------------------------------------------------- |
|
|
* |
|
|
* DestroyImage -- |
|
|
* |
|
|
* This is a trivial wrapper around ckfree to make it possible to |
|
|
* pass ckfree as a pointer. |
|
|
* |
|
|
* Results: |
|
|
* None. |
|
|
* |
|
|
* Side effects: |
|
|
* Deallocates the image. |
|
|
* |
|
|
*---------------------------------------------------------------------- |
|
|
*/ |
|
|
|
|
|
static int |
|
|
DestroyImage(imagePtr) |
|
|
XImage *imagePtr; /* image to free */ |
|
|
{ |
|
|
if (imagePtr) { |
|
|
if (imagePtr->data) { |
|
|
ckfree((char*)imagePtr->data); |
|
|
} |
|
|
ckfree((char*)imagePtr); |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
|
|
|
/* |
|
|
*---------------------------------------------------------------------- |
|
|
* |
|
|
* ImageGetPixel -- |
|
|
* |
|
|
* Get a single pixel from an image. |
|
|
* |
|
|
* Results: |
|
|
* Returns the 32 bit pixel value. |
|
|
* |
|
|
* Side effects: |
|
|
* None. |
|
|
* |
|
|
*---------------------------------------------------------------------- |
|
|
*/ |
|
|
|
|
|
static unsigned long |
|
|
ImageGetPixel(image, x, y) |
|
|
XImage *image; |
|
|
int x, y; |
|
|
{ |
|
|
unsigned long pixel = 0; |
|
|
unsigned char *srcPtr = &(image->data[(y * image->bytes_per_line) |
|
|
+ ((x * image->bits_per_pixel) / NBBY)]); |
|
|
|
|
|
switch (image->bits_per_pixel) { |
|
|
case 32: |
|
|
case 24: |
|
|
pixel = RGB(srcPtr[2], srcPtr[1], srcPtr[0]); |
|
|
break; |
|
|
case 16: |
|
|
pixel = RGB(((((WORD*)srcPtr)[0]) >> 7) & 0xf8, |
|
|
((((WORD*)srcPtr)[0]) >> 2) & 0xf8, |
|
|
((((WORD*)srcPtr)[0]) << 3) & 0xf8); |
|
|
break; |
|
|
case 8: |
|
|
pixel = srcPtr[0]; |
|
|
break; |
|
|
case 4: |
|
|
pixel = ((x%2) ? (*srcPtr) : ((*srcPtr) >> 4)) & 0x0f; |
|
|
break; |
|
|
case 1: |
|
|
pixel = ((*srcPtr) & (0x80 >> (x%8))) ? 1 : 0; |
|
|
break; |
|
|
} |
|
|
return pixel; |
|
|
} |
|
|
|
|
|
/* |
|
|
*---------------------------------------------------------------------- |
|
|
* |
|
|
* PutPixel -- |
|
|
* |
|
|
* Set a single pixel in an image. |
|
|
* |
|
|
* Results: |
|
|
* None. |
|
|
* |
|
|
* Side effects: |
|
|
* None. |
|
|
* |
|
|
*---------------------------------------------------------------------- |
|
|
*/ |
|
|
|
|
|
static int |
|
|
PutPixel(image, x, y, pixel) |
|
|
XImage *image; |
|
|
int x, y; |
|
|
unsigned long pixel; |
|
|
{ |
|
|
unsigned char *destPtr = &(image->data[(y * image->bytes_per_line) |
|
|
+ ((x * image->bits_per_pixel) / NBBY)]); |
|
|
|
|
|
switch (image->bits_per_pixel) { |
|
|
case 32: |
|
|
/* |
|
|
* Pixel is DWORD: 0x00BBGGRR |
|
|
*/ |
|
|
|
|
|
destPtr[3] = 0; |
|
|
case 24: |
|
|
/* |
|
|
* Pixel is triplet: 0xBBGGRR. |
|
|
*/ |
|
|
|
|
|
destPtr[0] = (unsigned char) GetBValue(pixel); |
|
|
destPtr[1] = (unsigned char) GetGValue(pixel); |
|
|
destPtr[2] = (unsigned char) GetRValue(pixel); |
|
|
break; |
|
|
case 16: |
|
|
/* |
|
|
* Pixel is WORD: 5-5-5 (R-G-B) |
|
|
*/ |
|
|
|
|
|
(*(WORD*)destPtr) = |
|
|
((GetRValue(pixel) & 0xf8) << 7) |
|
|
| ((GetGValue(pixel) & 0xf8) <<2) |
|
|
| ((GetBValue(pixel) & 0xf8) >> 3); |
|
|
break; |
|
|
case 8: |
|
|
/* |
|
|
* Pixel is 8-bit index into color table. |
|
|
*/ |
|
|
|
|
|
(*destPtr) = (unsigned char) pixel; |
|
|
break; |
|
|
case 4: |
|
|
/* |
|
|
* Pixel is 4-bit index in MSBFirst order. |
|
|
*/ |
|
|
if (x%2) { |
|
|
(*destPtr) = (unsigned char) (((*destPtr) & 0xf0) |
|
|
| (pixel & 0x0f)); |
|
|
} else { |
|
|
(*destPtr) = (unsigned char) (((*destPtr) & 0x0f) |
|
|
| ((pixel << 4) & 0xf0)); |
|
|
} |
|
|
break; |
|
|
case 1: { |
|
|
/* |
|
|
* Pixel is bit in MSBFirst order. |
|
|
*/ |
|
|
|
|
|
int mask = (0x80 >> (x%8)); |
|
|
if (pixel) { |
|
|
(*destPtr) |= mask; |
|
|
} else { |
|
|
(*destPtr) &= ~mask; |
|
|
} |
|
|
} |
|
|
break; |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
|
|
|
/* |
|
|
*---------------------------------------------------------------------- |
|
|
* |
|
|
* XCreateImage -- |
|
|
* |
|
|
* Allocates storage for a new XImage. |
|
|
* |
|
|
* Results: |
|
|
* Returns a newly allocated XImage. |
|
|
* |
|
|
* Side effects: |
|
|
* None. |
|
|
* |
|
|
*---------------------------------------------------------------------- |
|
|
*/ |
|
|
|
|
|
XImage * |
|
|
XCreateImage(display, visual, depth, format, offset, data, width, height, |
|
|
bitmap_pad, bytes_per_line) |
|
|
Display* display; |
|
|
Visual* visual; |
|
|
unsigned int depth; |
|
|
int format; |
|
|
int offset; |
|
|
char* data; |
|
|
unsigned int width; |
|
|
unsigned int height; |
|
|
int bitmap_pad; |
|
|
int bytes_per_line; |
|
|
{ |
|
|
XImage* imagePtr = (XImage *) ckalloc(sizeof(XImage)); |
|
|
imagePtr->width = width; |
|
|
imagePtr->height = height; |
|
|
imagePtr->xoffset = offset; |
|
|
imagePtr->format = format; |
|
|
imagePtr->data = data; |
|
|
imagePtr->byte_order = LSBFirst; |
|
|
imagePtr->bitmap_unit = 8; |
|
|
imagePtr->bitmap_bit_order = MSBFirst; |
|
|
imagePtr->bitmap_pad = bitmap_pad; |
|
|
imagePtr->bits_per_pixel = depth; |
|
|
imagePtr->depth = depth; |
|
|
|
|
|
/* |
|
|
* Under Windows, bitmap_pad must be on an LONG data-type boundary. |
|
|
*/ |
|
|
|
|
|
#define LONGBITS (sizeof(LONG) * 8) |
|
|
|
|
|
bitmap_pad = (bitmap_pad + LONGBITS - 1) / LONGBITS * LONGBITS; |
|
|
|
|
|
/* |
|
|
* Round to the nearest bitmap_pad boundary. |
|
|
*/ |
|
|
|
|
|
if (bytes_per_line) { |
|
|
imagePtr->bytes_per_line = bytes_per_line; |
|
|
} else { |
|
|
imagePtr->bytes_per_line = (((depth * width) |
|
|
+ (bitmap_pad - 1)) >> 3) & ~((bitmap_pad >> 3) - 1); |
|
|
} |
|
|
|
|
|
imagePtr->red_mask = 0; |
|
|
imagePtr->green_mask = 0; |
|
|
imagePtr->blue_mask = 0; |
|
|
|
|
|
imagePtr->f.put_pixel = PutPixel; |
|
|
imagePtr->f.get_pixel = ImageGetPixel; |
|
|
imagePtr->f.destroy_image = DestroyImage; |
|
|
imagePtr->f.create_image = NULL; |
|
|
imagePtr->f.sub_image = NULL; |
|
|
imagePtr->f.add_pixel = NULL; |
|
|
|
|
|
return imagePtr; |
|
|
} |
|
|
|
|
|
/* |
|
|
*---------------------------------------------------------------------- |
|
|
* |
|
|
* XGetImage -- |
|
|
* |
|
|
* This function copies data from a pixmap or window into an |
|
|
* XImage. |
|
|
* |
|
|
* Results: |
|
|
* Returns a newly allocated image containing the data from the |
|
|
* given rectangle of the given drawable. |
|
|
* |
|
|
* Side effects: |
|
|
* None. |
|
|
* |
|
|
*---------------------------------------------------------------------- |
|
|
*/ |
|
|
|
|
|
XImage * |
|
|
XGetImage(display, d, x, y, width, height, plane_mask, format) |
|
|
Display* display; |
|
|
Drawable d; |
|
|
int x; |
|
|
int y; |
|
|
unsigned int width; |
|
|
unsigned int height; |
|
|
unsigned long plane_mask; |
|
|
int format; |
|
|
{ |
|
|
TkWinDrawable *twdPtr = (TkWinDrawable *)d; |
|
|
XImage *imagePtr; |
|
|
HDC dc; |
|
|
char infoBuf[sizeof(BITMAPINFO) + sizeof(RGBQUAD)]; |
|
|
BITMAPINFO *infoPtr = (BITMAPINFO*)infoBuf; |
|
|
|
|
|
if ((twdPtr->type != TWD_BITMAP) || (twdPtr->bitmap.handle == NULL) |
|
|
|| (format != XYPixmap) || (plane_mask != 1)) { |
|
|
panic("XGetImage: not implemented"); |
|
|
} |
|
|
|
|
|
|
|
|
imagePtr = XCreateImage(display, NULL, 1, XYBitmap, 0, NULL, |
|
|
width, height, 32, 0); |
|
|
imagePtr->data = ckalloc(imagePtr->bytes_per_line * imagePtr->height); |
|
|
|
|
|
dc = GetDC(NULL); |
|
|
|
|
|
GetDIBits(dc, twdPtr->bitmap.handle, 0, height, NULL, |
|
|
infoPtr, DIB_RGB_COLORS); |
|
|
|
|
|
infoPtr->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
|
|
infoPtr->bmiHeader.biWidth = width; |
|
|
infoPtr->bmiHeader.biHeight = -(LONG)height; |
|
|
infoPtr->bmiHeader.biPlanes = 1; |
|
|
infoPtr->bmiHeader.biBitCount = 1; |
|
|
infoPtr->bmiHeader.biCompression = BI_RGB; |
|
|
infoPtr->bmiHeader.biCompression = 0; |
|
|
infoPtr->bmiHeader.biXPelsPerMeter = 0; |
|
|
infoPtr->bmiHeader.biYPelsPerMeter = 0; |
|
|
infoPtr->bmiHeader.biClrUsed = 0; |
|
|
infoPtr->bmiHeader.biClrImportant = 0; |
|
|
|
|
|
GetDIBits(dc, twdPtr->bitmap.handle, 0, height, imagePtr->data, |
|
|
infoPtr, DIB_RGB_COLORS); |
|
|
ReleaseDC(NULL, dc); |
|
|
|
|
|
return imagePtr; |
|
|
} |
|
|
|
|
|
|
|
|
/* $History: tkWinImage.c $ |
|
|
* |
|
|
* ***************** Version 1 ***************** |
|
|
* User: Dtashley Date: 1/02/01 Time: 3:15a |
|
|
* Created in $/IjuScripter, IjuConsole/Source/Tk Base |
|
|
* Initial check-in. |
|
|
*/ |
|
|
|
|
|
/* End of TKWINIMAGE.C */ |
|
1 |
|
/* $Header$ */ |
2 |
|
|
3 |
|
/* |
4 |
|
* tkWinImage.c -- |
5 |
|
* |
6 |
|
* This file contains routines for manipulation full-color images. |
7 |
|
* |
8 |
|
* Copyright (c) 1995 Sun Microsystems, Inc. |
9 |
|
* |
10 |
|
* See the file "license.terms" for information on usage and redistribution |
11 |
|
* of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
12 |
|
* |
13 |
|
* RCS: @(#) $Id: tkwinimage.c,v 1.1.1.1 2001/06/13 05:13:34 dtashley Exp $ |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "tkWinInt.h" |
17 |
|
|
18 |
|
static int DestroyImage _ANSI_ARGS_((XImage* data)); |
19 |
|
static unsigned long ImageGetPixel _ANSI_ARGS_((XImage *image, int x, int y)); |
20 |
|
static int PutPixel _ANSI_ARGS_((XImage *image, int x, int y, |
21 |
|
unsigned long pixel)); |
22 |
|
|
23 |
|
/* |
24 |
|
*---------------------------------------------------------------------- |
25 |
|
* |
26 |
|
* DestroyImage -- |
27 |
|
* |
28 |
|
* This is a trivial wrapper around ckfree to make it possible to |
29 |
|
* pass ckfree as a pointer. |
30 |
|
* |
31 |
|
* Results: |
32 |
|
* None. |
33 |
|
* |
34 |
|
* Side effects: |
35 |
|
* Deallocates the image. |
36 |
|
* |
37 |
|
*---------------------------------------------------------------------- |
38 |
|
*/ |
39 |
|
|
40 |
|
static int |
41 |
|
DestroyImage(imagePtr) |
42 |
|
XImage *imagePtr; /* image to free */ |
43 |
|
{ |
44 |
|
if (imagePtr) { |
45 |
|
if (imagePtr->data) { |
46 |
|
ckfree((char*)imagePtr->data); |
47 |
|
} |
48 |
|
ckfree((char*)imagePtr); |
49 |
|
} |
50 |
|
return 0; |
51 |
|
} |
52 |
|
|
53 |
|
/* |
54 |
|
*---------------------------------------------------------------------- |
55 |
|
* |
56 |
|
* ImageGetPixel -- |
57 |
|
* |
58 |
|
* Get a single pixel from an image. |
59 |
|
* |
60 |
|
* Results: |
61 |
|
* Returns the 32 bit pixel value. |
62 |
|
* |
63 |
|
* Side effects: |
64 |
|
* None. |
65 |
|
* |
66 |
|
*---------------------------------------------------------------------- |
67 |
|
*/ |
68 |
|
|
69 |
|
static unsigned long |
70 |
|
ImageGetPixel(image, x, y) |
71 |
|
XImage *image; |
72 |
|
int x, y; |
73 |
|
{ |
74 |
|
unsigned long pixel = 0; |
75 |
|
unsigned char *srcPtr = &(image->data[(y * image->bytes_per_line) |
76 |
|
+ ((x * image->bits_per_pixel) / NBBY)]); |
77 |
|
|
78 |
|
switch (image->bits_per_pixel) { |
79 |
|
case 32: |
80 |
|
case 24: |
81 |
|
pixel = RGB(srcPtr[2], srcPtr[1], srcPtr[0]); |
82 |
|
break; |
83 |
|
case 16: |
84 |
|
pixel = RGB(((((WORD*)srcPtr)[0]) >> 7) & 0xf8, |
85 |
|
((((WORD*)srcPtr)[0]) >> 2) & 0xf8, |
86 |
|
((((WORD*)srcPtr)[0]) << 3) & 0xf8); |
87 |
|
break; |
88 |
|
case 8: |
89 |
|
pixel = srcPtr[0]; |
90 |
|
break; |
91 |
|
case 4: |
92 |
|
pixel = ((x%2) ? (*srcPtr) : ((*srcPtr) >> 4)) & 0x0f; |
93 |
|
break; |
94 |
|
case 1: |
95 |
|
pixel = ((*srcPtr) & (0x80 >> (x%8))) ? 1 : 0; |
96 |
|
break; |
97 |
|
} |
98 |
|
return pixel; |
99 |
|
} |
100 |
|
|
101 |
|
/* |
102 |
|
*---------------------------------------------------------------------- |
103 |
|
* |
104 |
|
* PutPixel -- |
105 |
|
* |
106 |
|
* Set a single pixel in an image. |
107 |
|
* |
108 |
|
* Results: |
109 |
|
* None. |
110 |
|
* |
111 |
|
* Side effects: |
112 |
|
* None. |
113 |
|
* |
114 |
|
*---------------------------------------------------------------------- |
115 |
|
*/ |
116 |
|
|
117 |
|
static int |
118 |
|
PutPixel(image, x, y, pixel) |
119 |
|
XImage *image; |
120 |
|
int x, y; |
121 |
|
unsigned long pixel; |
122 |
|
{ |
123 |
|
unsigned char *destPtr = &(image->data[(y * image->bytes_per_line) |
124 |
|
+ ((x * image->bits_per_pixel) / NBBY)]); |
125 |
|
|
126 |
|
switch (image->bits_per_pixel) { |
127 |
|
case 32: |
128 |
|
/* |
129 |
|
* Pixel is DWORD: 0x00BBGGRR |
130 |
|
*/ |
131 |
|
|
132 |
|
destPtr[3] = 0; |
133 |
|
case 24: |
134 |
|
/* |
135 |
|
* Pixel is triplet: 0xBBGGRR. |
136 |
|
*/ |
137 |
|
|
138 |
|
destPtr[0] = (unsigned char) GetBValue(pixel); |
139 |
|
destPtr[1] = (unsigned char) GetGValue(pixel); |
140 |
|
destPtr[2] = (unsigned char) GetRValue(pixel); |
141 |
|
break; |
142 |
|
case 16: |
143 |
|
/* |
144 |
|
* Pixel is WORD: 5-5-5 (R-G-B) |
145 |
|
*/ |
146 |
|
|
147 |
|
(*(WORD*)destPtr) = |
148 |
|
((GetRValue(pixel) & 0xf8) << 7) |
149 |
|
| ((GetGValue(pixel) & 0xf8) <<2) |
150 |
|
| ((GetBValue(pixel) & 0xf8) >> 3); |
151 |
|
break; |
152 |
|
case 8: |
153 |
|
/* |
154 |
|
* Pixel is 8-bit index into color table. |
155 |
|
*/ |
156 |
|
|
157 |
|
(*destPtr) = (unsigned char) pixel; |
158 |
|
break; |
159 |
|
case 4: |
160 |
|
/* |
161 |
|
* Pixel is 4-bit index in MSBFirst order. |
162 |
|
*/ |
163 |
|
if (x%2) { |
164 |
|
(*destPtr) = (unsigned char) (((*destPtr) & 0xf0) |
165 |
|
| (pixel & 0x0f)); |
166 |
|
} else { |
167 |
|
(*destPtr) = (unsigned char) (((*destPtr) & 0x0f) |
168 |
|
| ((pixel << 4) & 0xf0)); |
169 |
|
} |
170 |
|
break; |
171 |
|
case 1: { |
172 |
|
/* |
173 |
|
* Pixel is bit in MSBFirst order. |
174 |
|
*/ |
175 |
|
|
176 |
|
int mask = (0x80 >> (x%8)); |
177 |
|
if (pixel) { |
178 |
|
(*destPtr) |= mask; |
179 |
|
} else { |
180 |
|
(*destPtr) &= ~mask; |
181 |
|
} |
182 |
|
} |
183 |
|
break; |
184 |
|
} |
185 |
|
return 0; |
186 |
|
} |
187 |
|
|
188 |
|
/* |
189 |
|
*---------------------------------------------------------------------- |
190 |
|
* |
191 |
|
* XCreateImage -- |
192 |
|
* |
193 |
|
* Allocates storage for a new XImage. |
194 |
|
* |
195 |
|
* Results: |
196 |
|
* Returns a newly allocated XImage. |
197 |
|
* |
198 |
|
* Side effects: |
199 |
|
* None. |
200 |
|
* |
201 |
|
*---------------------------------------------------------------------- |
202 |
|
*/ |
203 |
|
|
204 |
|
XImage * |
205 |
|
XCreateImage(display, visual, depth, format, offset, data, width, height, |
206 |
|
bitmap_pad, bytes_per_line) |
207 |
|
Display* display; |
208 |
|
Visual* visual; |
209 |
|
unsigned int depth; |
210 |
|
int format; |
211 |
|
int offset; |
212 |
|
char* data; |
213 |
|
unsigned int width; |
214 |
|
unsigned int height; |
215 |
|
int bitmap_pad; |
216 |
|
int bytes_per_line; |
217 |
|
{ |
218 |
|
XImage* imagePtr = (XImage *) ckalloc(sizeof(XImage)); |
219 |
|
imagePtr->width = width; |
220 |
|
imagePtr->height = height; |
221 |
|
imagePtr->xoffset = offset; |
222 |
|
imagePtr->format = format; |
223 |
|
imagePtr->data = data; |
224 |
|
imagePtr->byte_order = LSBFirst; |
225 |
|
imagePtr->bitmap_unit = 8; |
226 |
|
imagePtr->bitmap_bit_order = MSBFirst; |
227 |
|
imagePtr->bitmap_pad = bitmap_pad; |
228 |
|
imagePtr->bits_per_pixel = depth; |
229 |
|
imagePtr->depth = depth; |
230 |
|
|
231 |
|
/* |
232 |
|
* Under Windows, bitmap_pad must be on an LONG data-type boundary. |
233 |
|
*/ |
234 |
|
|
235 |
|
#define LONGBITS (sizeof(LONG) * 8) |
236 |
|
|
237 |
|
bitmap_pad = (bitmap_pad + LONGBITS - 1) / LONGBITS * LONGBITS; |
238 |
|
|
239 |
|
/* |
240 |
|
* Round to the nearest bitmap_pad boundary. |
241 |
|
*/ |
242 |
|
|
243 |
|
if (bytes_per_line) { |
244 |
|
imagePtr->bytes_per_line = bytes_per_line; |
245 |
|
} else { |
246 |
|
imagePtr->bytes_per_line = (((depth * width) |
247 |
|
+ (bitmap_pad - 1)) >> 3) & ~((bitmap_pad >> 3) - 1); |
248 |
|
} |
249 |
|
|
250 |
|
imagePtr->red_mask = 0; |
251 |
|
imagePtr->green_mask = 0; |
252 |
|
imagePtr->blue_mask = 0; |
253 |
|
|
254 |
|
imagePtr->f.put_pixel = PutPixel; |
255 |
|
imagePtr->f.get_pixel = ImageGetPixel; |
256 |
|
imagePtr->f.destroy_image = DestroyImage; |
257 |
|
imagePtr->f.create_image = NULL; |
258 |
|
imagePtr->f.sub_image = NULL; |
259 |
|
imagePtr->f.add_pixel = NULL; |
260 |
|
|
261 |
|
return imagePtr; |
262 |
|
} |
263 |
|
|
264 |
|
/* |
265 |
|
*---------------------------------------------------------------------- |
266 |
|
* |
267 |
|
* XGetImage -- |
268 |
|
* |
269 |
|
* This function copies data from a pixmap or window into an |
270 |
|
* XImage. |
271 |
|
* |
272 |
|
* Results: |
273 |
|
* Returns a newly allocated image containing the data from the |
274 |
|
* given rectangle of the given drawable. |
275 |
|
* |
276 |
|
* Side effects: |
277 |
|
* None. |
278 |
|
* |
279 |
|
*---------------------------------------------------------------------- |
280 |
|
*/ |
281 |
|
|
282 |
|
XImage * |
283 |
|
XGetImage(display, d, x, y, width, height, plane_mask, format) |
284 |
|
Display* display; |
285 |
|
Drawable d; |
286 |
|
int x; |
287 |
|
int y; |
288 |
|
unsigned int width; |
289 |
|
unsigned int height; |
290 |
|
unsigned long plane_mask; |
291 |
|
int format; |
292 |
|
{ |
293 |
|
TkWinDrawable *twdPtr = (TkWinDrawable *)d; |
294 |
|
XImage *imagePtr; |
295 |
|
HDC dc; |
296 |
|
char infoBuf[sizeof(BITMAPINFO) + sizeof(RGBQUAD)]; |
297 |
|
BITMAPINFO *infoPtr = (BITMAPINFO*)infoBuf; |
298 |
|
|
299 |
|
if ((twdPtr->type != TWD_BITMAP) || (twdPtr->bitmap.handle == NULL) |
300 |
|
|| (format != XYPixmap) || (plane_mask != 1)) { |
301 |
|
panic("XGetImage: not implemented"); |
302 |
|
} |
303 |
|
|
304 |
|
|
305 |
|
imagePtr = XCreateImage(display, NULL, 1, XYBitmap, 0, NULL, |
306 |
|
width, height, 32, 0); |
307 |
|
imagePtr->data = ckalloc(imagePtr->bytes_per_line * imagePtr->height); |
308 |
|
|
309 |
|
dc = GetDC(NULL); |
310 |
|
|
311 |
|
GetDIBits(dc, twdPtr->bitmap.handle, 0, height, NULL, |
312 |
|
infoPtr, DIB_RGB_COLORS); |
313 |
|
|
314 |
|
infoPtr->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
315 |
|
infoPtr->bmiHeader.biWidth = width; |
316 |
|
infoPtr->bmiHeader.biHeight = -(LONG)height; |
317 |
|
infoPtr->bmiHeader.biPlanes = 1; |
318 |
|
infoPtr->bmiHeader.biBitCount = 1; |
319 |
|
infoPtr->bmiHeader.biCompression = BI_RGB; |
320 |
|
infoPtr->bmiHeader.biCompression = 0; |
321 |
|
infoPtr->bmiHeader.biXPelsPerMeter = 0; |
322 |
|
infoPtr->bmiHeader.biYPelsPerMeter = 0; |
323 |
|
infoPtr->bmiHeader.biClrUsed = 0; |
324 |
|
infoPtr->bmiHeader.biClrImportant = 0; |
325 |
|
|
326 |
|
GetDIBits(dc, twdPtr->bitmap.handle, 0, height, imagePtr->data, |
327 |
|
infoPtr, DIB_RGB_COLORS); |
328 |
|
ReleaseDC(NULL, dc); |
329 |
|
|
330 |
|
return imagePtr; |
331 |
|
} |
332 |
|
|
333 |
|
/* End of tkwinimage.c */ |