wmmoonclock: Bump to version 1.29.
[dockapps.git] / wmglobe / src / wraster.h
blob0e42af56abdaf982d7f8a3a550298f22d935c711
2 /*
3 * Raster graphics library
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Environment variables:
25 * WRASTER_GAMMA <rgamma>/<ggamma>/<bgamma>
26 * gamma correction value. Must be greater than 0
27 * Only for PseudoColor visuals.
29 * Default:
30 * WRASTER_GAMMA 1/1/1
33 * If you want a specific value for a screen, append the screen number
34 * preceded by a hash to the variable name as in
35 * WRASTER_GAMMA#1
36 * for screen number 1
39 #ifndef RLRASTER_H_
40 #define RLRASTER_H_
43 /* version of the header for the library: 0.11 */
44 #define WRASTER_HEADER_VERSION 11
46 #ifdef HAVE_ALLOCA_H
47 #include <alloca.h>
48 #endif
51 #include <X11/Xlib.h>
52 #include <X11/Xutil.h>
54 #ifdef XSHM
55 #include <X11/extensions/XShm.h>
56 #endif
58 /* RM_MATCH or RM_DITHER */
59 #define RC_RenderMode (1<<0)
61 /* number of colors per channel for colormap in PseudoColor mode */
62 #define RC_ColorsPerChannel (1<<1)
64 /* do gamma correction */
65 #define RC_GammaCorrection (1<<2)
67 /* visual id to use */
68 #define RC_VisualID (1<<3)
70 /* shared memory usage */
71 #define RC_UseSharedMemory (1<<4)
73 /* use default instead of best visual */
74 #define RC_DefaultVisual (1<<5)
76 typedef struct RContextAttributes {
77 int flags;
78 int render_mode;
79 int colors_per_channel; /* for PseudoColor */
80 float rgamma; /* gamma correction for red, */
81 float ggamma; /* green, */
82 float bgamma; /* and blue */
83 VisualID visualid; /* visual ID to use */
84 int use_shared_memory; /* True of False */
85 } RContextAttributes;
89 * describes a screen in terms of depth, visual, number of colors
90 * we can use, if we should do dithering, and what colors to use for
91 * dithering.
93 typedef struct RContext {
94 Display *dpy;
95 int screen_number;
96 Colormap cmap;
98 RContextAttributes *attribs;
100 GC copy_gc;
102 Visual *visual;
103 int depth;
104 Window drawable; /* window to pass for XCreatePixmap(). */
105 /* generally = root */
106 int vclass;
108 unsigned long black;
109 unsigned long white;
111 int red_offset; /* only used in 24bpp */
112 int green_offset;
113 int blue_offset;
115 /* only used for pseudocolor and grayscale */
117 XStandardColormap *std_rgb_map; /* standard RGB colormap */
118 XStandardColormap *std_gray_map; /* standard grayscale colormap */
120 int ncolors; /* total number of colors we can use */
121 XColor *colors; /* internal colormap */
123 struct {
124 unsigned int use_shared_pixmap:1;
125 } flags;
126 } RContext;
129 typedef struct RColor {
130 unsigned char red;
131 unsigned char green;
132 unsigned char blue;
133 unsigned char alpha;
134 } RColor;
137 typedef struct RHSVColor {
138 unsigned short hue; /* 0-359 */
139 unsigned char saturation; /* 0-255 */
140 unsigned char value; /* 0-255 */
141 } RHSVColor;
145 typedef struct RPoint {
146 int x, y;
147 } RPoint;
150 typedef struct RSegment {
151 int x1, y1, x2, y2;
152 } RSegment;
156 * internal 24bit+alpha image representation
158 typedef struct RImage {
159 unsigned width, height; /* size of the image */
160 RColor background; /* background color */
161 unsigned char *data[4]; /* image data (R,G,B,A) */
162 } RImage;
166 * internal wrapper for XImage. Used for shm abstraction
168 typedef struct RXImage {
169 XImage *image;
171 /* Private data. Do not access */
172 #ifdef XSHM
173 XShmSegmentInfo info;
174 char is_shared;
175 #endif
176 } RXImage;
179 /* note that not all operations are supported in all functions */
180 enum {
181 RClearOperation, /* clear with 0 */
182 RCopyOperation,
183 RNormalOperation, /* same as combine */
184 RAddOperation,
185 RSubtractOperation
189 /* image display modes */
190 enum {
191 RDitheredRendering = 0,
192 RBestMatchRendering = 1
195 /* bw compat */
196 #define RM_DITHER RDitheredRendering
197 #define RM_MATCH RBestMatchRendering
199 enum {
200 RAbsoluteCoordinates = 0,
201 RRelativeCoordinates = 1
205 enum {
206 RSunkenBevel = -1,
207 RRaisedBevel = 1
210 /* bw compat */
211 #define RBEV_SUNKEN RSunkenBevel
212 /* 1 pixel wide */
213 #define RBEV_RAISED RRaisedBevel
214 /* 1 pixel wide on top/left 2 on bottom/right */
215 #define RBEV_RAISED2 2
216 /* 2 pixel width */
217 #define RBEV_RAISED3 3
219 enum {
220 RHorizontalGradient = 2,
221 RVerticalGradient = 3,
222 RDiagonalGradient = 4
225 /* for backwards compatibility */
226 #define RGRD_HORIZONTAL RHorizontalGradient
227 #define RGRD_VERTICAL RVerticalGradient
228 #define RGRD_DIAGONAL RDiagonalGradient
232 /* error codes */
233 #define RERR_NONE 0
234 #define RERR_OPEN 1 /* cant open file */
235 #define RERR_READ 2 /* error reading from file */
236 #define RERR_WRITE 3 /* error writing to file */
237 #define RERR_NOMEMORY 4 /* out of memory */
238 #define RERR_NOCOLOR 5 /* out of color cells */
239 #define RERR_BADIMAGEFILE 6 /* image file is corrupted or invalid */
240 #define RERR_BADFORMAT 7 /* image file format is unknown */
241 #define RERR_BADINDEX 8 /* no such image index in file */
243 #define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
245 #define RERR_XERROR 127 /* internal X error */
246 #define RERR_INTERNAL 128 /* should not happen */
250 * Returns a NULL terminated array of strings containing the
251 * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
253 char **RSupportedFileFormats(void);
255 void RFreeStringList(char **list);
258 * Xlib contexts
260 RContext *RCreateContext(Display * dpy, int screen_number,
261 RContextAttributes * attribs);
263 void RDestroyContext(RContext * context);
265 Bool RGetClosestXColor(RContext * context, RColor * color, XColor * retColor);
268 * RImage creation
270 RImage *RCreateImage(unsigned width, unsigned height, int alpha);
272 RImage *RCreateImageFromXImage(RContext * context, XImage * image, XImage * mask);
274 RImage *RCreateImageFromDrawable(RContext * context, Drawable drawable,
275 Pixmap mask);
277 RImage *RLoadImage(RContext * context, char *file, int index);
280 void RDestroyImage(RImage * image);
282 RImage *RGetImageFromXPMData(RContext * context, char **data);
285 * RImage storing
287 Bool RSaveImage(RImage * image, char *filename, char *format);
290 * Area manipulation
292 RImage *RCloneImage(RImage * image);
294 RImage *RGetSubImage(RImage * image, int x, int y, unsigned width,
295 unsigned height);
297 void RCombineImageWithColor(RImage * image, RColor * color);
299 void RCombineImages(RImage * image, RImage * src);
301 void RCombineArea(RImage * image, RImage * src, int sx, int sy, unsigned width,
302 unsigned height, int dx, int dy);
304 void RCombineImagesWithOpaqueness(RImage * image, RImage * src, int opaqueness);
306 void RCombineAreaWithOpaqueness(RImage * image, RImage * src, int sx, int sy,
307 unsigned width, unsigned height, int dx, int dy,
308 int opaqueness);
310 RImage *RScaleImage(RImage * image, unsigned new_width, unsigned new_height);
312 RImage *RMakeTiledImage(RImage * tile, unsigned width, unsigned height);
314 RImage *RMakeCenteredImage(RImage * image, unsigned width, unsigned height,
315 RColor * color);
318 * Drawing
320 Bool RGetPixel(RImage * image, int x, int y, RColor * color);
322 void RPutPixel(RImage * image, int x, int y, RColor * color);
324 void ROperatePixel(RImage * image, int operation, int x, int y, RColor * color);
326 void RPutPixels(RImage * image, RPoint * points, int npoints, int mode,
327 RColor * color);
329 void ROperatePixels(RImage * image, int operation, RPoint * points,
330 int npoints, int mode, RColor * color);
332 int RDrawLine(RImage * image, int x0, int y0, int x1, int y1, RColor * color);
334 int ROperateLine(RImage * image, int operation, int x0, int y0, int x1, int y1,
335 RColor * color);
337 void RDrawLines(RImage * image, RPoint * points, int npoints, int mode,
338 RColor * color);
340 void ROperateLines(RImage * image, int operation, RPoint * points, int npoints,
341 int mode, RColor * color);
343 void RDrawSegments(RImage * image, RSegment * segs, int nsegs, RColor * color);
345 void ROperateSegments(RImage * image, int operation, RSegment * segs, int nsegs,
346 RColor * color);
349 * Color convertion
351 void RRGBtoHSV(RColor * color, RHSVColor * hsv);
352 void RHSVtoRGB(RHSVColor * hsv, RColor * rgb);
355 * Painting
357 void RClearImage(RImage * image, RColor * color);
359 void RBevelImage(RImage * image, int bevel_type);
361 RImage *RRenderGradient(unsigned width, unsigned height, RColor * from,
362 RColor * to, int style);
365 RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor ** colors,
366 int style);
369 * Convertion into X Pixmaps
371 int RConvertImage(RContext * context, RImage * image, Pixmap * pixmap);
373 int RConvertImageMask(RContext * context, RImage * image, Pixmap * pixmap,
374 Pixmap * mask, int threshold);
378 * misc. utilities
380 RXImage *RCreateXImage(RContext * context, int depth,
381 unsigned width, unsigned height);
383 void RDestroyXImage(RContext * context, RXImage * ximage);
385 void RPutXImage(RContext * context, Drawable d, GC gc, RXImage * ximage,
386 int src_x, int src_y, int dest_x, int dest_y,
387 unsigned width, unsigned height);
389 /* do not free the returned string! */
390 const char *RMessageForError(int errorCode);
392 int RBlurImage(RImage * image);
394 /****** Global Variables *******/
396 extern int RErrorCode;
398 #endif