Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/tkImgPhoto.h @ 69:33d812a61356
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 17:55:14 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 69:33d812a61356 |
---|---|
1 /* | |
2 * tkImgPhoto.h -- | |
3 * | |
4 * Declarations for images of type "photo" for Tk. | |
5 * | |
6 * Copyright (c) 1994 The Australian National University. | |
7 * Copyright (c) 1994-1997 Sun Microsystems, Inc. | |
8 * Copyright (c) 2002-2008 Donal K. Fellows | |
9 * Copyright (c) 2003 ActiveState Corporation. | |
10 * | |
11 * See the file "license.terms" for information on usage and redistribution of | |
12 * this file, and for a DISCLAIMER OF ALL WARRANTIES. | |
13 * | |
14 * Author: Paul Mackerras (paulus@cs.anu.edu.au), | |
15 * Department of Computer Science, | |
16 * Australian National University. | |
17 */ | |
18 | |
19 #include "tkInt.h" | |
20 #ifdef _WIN32 | |
21 #include "tkWinInt.h" | |
22 #elif defined(__CYGWIN__) | |
23 #include "tkUnixInt.h" | |
24 #endif | |
25 | |
26 /* | |
27 * Forward declarations of the structures we define. | |
28 */ | |
29 | |
30 #define PhotoModel PhotoMaster | |
31 typedef struct ColorTableId ColorTableId; | |
32 typedef struct ColorTable ColorTable; | |
33 typedef struct PhotoInstance PhotoInstance; | |
34 typedef struct PhotoMaster PhotoMaster; | |
35 | |
36 /* | |
37 * A signed 8-bit integral type. If chars are unsigned and the compiler isn't | |
38 * an ANSI one, then we have to use short instead (which wastes space) to get | |
39 * signed behavior. | |
40 */ | |
41 | |
42 #if defined(__STDC__) || defined(_AIX) | |
43 typedef signed char schar; | |
44 #else | |
45 # ifndef __CHAR_UNSIGNED__ | |
46 typedef char schar; | |
47 # else | |
48 typedef short schar; | |
49 # endif | |
50 #endif | |
51 | |
52 /* | |
53 * An unsigned 32-bit integral type, used for pixel values. We use int rather | |
54 * than long here to accommodate those systems where longs are 64 bits. | |
55 */ | |
56 | |
57 typedef unsigned int pixel; | |
58 | |
59 /* | |
60 * The maximum number of pixels to transmit to the server in a single | |
61 * XPutImage call. | |
62 */ | |
63 | |
64 #define MAX_PIXELS 65536 | |
65 | |
66 /* | |
67 * The set of colors required to display a photo image in a window depends on: | |
68 * - the visual used by the window | |
69 * - the palette, which specifies how many levels of each primary color to | |
70 * use, and | |
71 * - the gamma value for the image. | |
72 * | |
73 * Pixel values allocated for specific colors are valid only for the colormap | |
74 * in which they were allocated. Sets of pixel values allocated for displaying | |
75 * photos are re-used in other windows if possible, that is, if the display, | |
76 * colormap, palette and gamma values match. A hash table is used to locate | |
77 * these sets of pixel values, using the following data structure as key: | |
78 */ | |
79 | |
80 struct ColorTableId { | |
81 Display *display; /* Qualifies the colormap resource ID. */ | |
82 Colormap colormap; /* Colormap that the windows are using. */ | |
83 double gamma; /* Gamma exponent value for images. */ | |
84 Tk_Uid palette; /* Specifies how many shades of each primary | |
85 * we want to allocate. */ | |
86 }; | |
87 | |
88 /* | |
89 * For a particular (display, colormap, palette, gamma) combination, a data | |
90 * structure of the following type is used to store the allocated pixel values | |
91 * and other information: | |
92 */ | |
93 | |
94 struct ColorTable { | |
95 ColorTableId id; /* Information used in selecting this color | |
96 * table. */ | |
97 int flags; /* See below. */ | |
98 int refCount; /* Number of instances using this map. */ | |
99 int liveRefCount; /* Number of instances which are actually in | |
100 * use, using this map. */ | |
101 int numColors; /* Number of colors allocated for this map. */ | |
102 | |
103 XVisualInfo visualInfo; /* Information about the visual for windows | |
104 * using this color table. */ | |
105 | |
106 pixel redValues[256]; /* Maps 8-bit values of red intensity to a | |
107 * pixel value or index in pixelMap. */ | |
108 pixel greenValues[256]; /* Ditto for green intensity. */ | |
109 pixel blueValues[256]; /* Ditto for blue intensity. */ | |
110 unsigned long *pixelMap; /* Actual pixel values allocated. */ | |
111 | |
112 unsigned char colorQuant[3][256]; | |
113 /* Maps 8-bit intensities to quantized | |
114 * intensities. The first index is 0 for red, | |
115 * 1 for green, 2 for blue. */ | |
116 }; | |
117 | |
118 /* | |
119 * Bit definitions for the flags field of a ColorTable. | |
120 * BLACK_AND_WHITE: 1 means only black and white colors are | |
121 * available. | |
122 * COLOR_WINDOW: 1 means a full 3-D color cube has been | |
123 * allocated. | |
124 * DISPOSE_PENDING: 1 means a call to DisposeColorTable has been | |
125 * scheduled as an idle handler, but it hasn't | |
126 * been invoked yet. | |
127 * MAP_COLORS: 1 means pixel values should be mapped through | |
128 * pixelMap. | |
129 */ | |
130 | |
131 #ifdef COLOR_WINDOW | |
132 #undef COLOR_WINDOW | |
133 #endif | |
134 | |
135 #define BLACK_AND_WHITE 1 | |
136 #define COLOR_WINDOW 2 | |
137 #define DISPOSE_PENDING 4 | |
138 #define MAP_COLORS 8 | |
139 | |
140 /* | |
141 * Definition of the data associated with each photo image model. | |
142 */ | |
143 | |
144 struct PhotoMaster { | |
145 Tk_ImageMaster tkMaster; /* Tk's token for image model. NULL means the | |
146 * image is being deleted. */ | |
147 Tcl_Interp *interp; /* Interpreter associated with the application | |
148 * using this image. */ | |
149 Tcl_Command imageCmd; /* Token for image command (used to delete it | |
150 * when the image goes away). NULL means the | |
151 * image command has already been deleted. */ | |
152 int flags; /* Sundry flags, defined below. */ | |
153 int width, height; /* Dimensions of image. */ | |
154 int userWidth, userHeight; /* User-declared image dimensions. */ | |
155 Tk_Uid palette; /* User-specified default palette for | |
156 * instances of this image. */ | |
157 double gamma; /* Display gamma value to correct for. */ | |
158 char *fileString; /* Name of file to read into image. */ | |
159 Tcl_Obj *dataString; /* Object to use as contents of image. */ | |
160 Tcl_Obj *format; /* User-specified format of data in image file | |
161 * or string value. */ | |
162 unsigned char *pix32; /* Local storage for 32-bit image. */ | |
163 int ditherX, ditherY; /* Location of first incorrectly dithered | |
164 * pixel in image. */ | |
165 TkRegion validRegion; /* Tk region indicating which parts of the | |
166 * image have valid image data. */ | |
167 PhotoInstance *instancePtr; /* First in the list of instances associated | |
168 * with this model. */ | |
169 }; | |
170 | |
171 /* | |
172 * Bit definitions for the flags field of a PhotoMaster. | |
173 * COLOR_IMAGE: 1 means that the image has different color | |
174 * components. | |
175 * IMAGE_CHANGED: 1 means that the instances of this image need | |
176 * to be redithered. | |
177 * COMPLEX_ALPHA: 1 means that the instances of this image have | |
178 * alpha values that aren't 0 or 255, and so need | |
179 * the copy-merge-replace renderer . | |
180 */ | |
181 | |
182 #define COLOR_IMAGE 1 | |
183 #define IMAGE_CHANGED 2 | |
184 #define COMPLEX_ALPHA 4 | |
185 | |
186 /* | |
187 * Flag to OR with the compositing rule to indicate that the source, despite | |
188 * having an alpha channel, has simple alpha. | |
189 */ | |
190 | |
191 #define SOURCE_IS_SIMPLE_ALPHA_PHOTO 0x10000000 | |
192 | |
193 /* | |
194 * The following data structure represents all of the instances of a photo | |
195 * image in windows on a given screen that are using the same colormap. | |
196 */ | |
197 | |
198 struct PhotoInstance { | |
199 PhotoMaster *masterPtr; /* Pointer to model for image. */ | |
200 Display *display; /* Display for windows using this instance. */ | |
201 Colormap colormap; /* The image may only be used in windows with | |
202 * this particular colormap. */ | |
203 PhotoInstance *nextPtr; /* Pointer to the next instance in the list of | |
204 * instances associated with this model. */ | |
205 int refCount; /* Number of instances using this structure. */ | |
206 Tk_Uid palette; /* Palette for these particular instances. */ | |
207 double gamma; /* Gamma value for these instances. */ | |
208 Tk_Uid defaultPalette; /* Default palette to use if a palette is not | |
209 * specified for the model. */ | |
210 ColorTable *colorTablePtr; /* Pointer to information about colors | |
211 * allocated for image display in windows like | |
212 * this one. */ | |
213 Pixmap pixels; /* X pixmap containing dithered image. */ | |
214 int width, height; /* Dimensions of the pixmap. */ | |
215 schar *error; /* Error image, used in dithering. */ | |
216 XImage *imagePtr; /* Image structure for converted pixels. */ | |
217 XVisualInfo visualInfo; /* Information about the visual that these | |
218 * windows are using. */ | |
219 GC gc; /* Graphics context for writing images to the | |
220 * pixmap. */ | |
221 }; | |
222 | |
223 /* | |
224 * Implementation of the Porter-Duff Source-Over compositing rule. | |
225 */ | |
226 | |
227 #define PD_SRC_OVER(srcColor, srcAlpha, dstColor, dstAlpha) \ | |
228 (srcColor*srcAlpha/255) + dstAlpha*(255-srcAlpha)/255*dstColor/255 | |
229 #define PD_SRC_OVER_ALPHA(srcAlpha, dstAlpha) \ | |
230 (srcAlpha + (255-srcAlpha)*dstAlpha/255) | |
231 | |
232 #undef MIN | |
233 #define MIN(a, b) ((a) < (b)? (a): (b)) | |
234 #undef MAX | |
235 #define MAX(a, b) ((a) > (b)? (a): (b)) | |
236 | |
237 /* | |
238 * Declarations of functions shared between the different parts of the | |
239 * photo image implementation. | |
240 */ | |
241 | |
242 MODULE_SCOPE void TkImgPhotoConfigureInstance( | |
243 PhotoInstance *instancePtr); | |
244 MODULE_SCOPE void TkImgDisposeInstance(ClientData clientData); | |
245 MODULE_SCOPE void TkImgPhotoInstanceSetSize(PhotoInstance *instancePtr); | |
246 MODULE_SCOPE ClientData TkImgPhotoGet(Tk_Window tkwin, ClientData clientData); | |
247 MODULE_SCOPE void TkImgDitherInstance(PhotoInstance *instancePtr, int x, | |
248 int y, int width, int height); | |
249 MODULE_SCOPE void TkImgPhotoDisplay(ClientData clientData, | |
250 Display *display, Drawable drawable, | |
251 int imageX, int imageY, int width, int height, | |
252 int drawableX, int drawableY); | |
253 MODULE_SCOPE void TkImgPhotoFree(ClientData clientData, | |
254 Display *display); | |
255 MODULE_SCOPE void TkImgResetDither(PhotoInstance *instancePtr); | |
256 | |
257 /* | |
258 * Local Variables: | |
259 * mode: c | |
260 * c-basic-offset: 4 | |
261 * fill-column: 78 | |
262 * End: | |
263 */ |