Updating to version 0.20.2
[wmaker-crm.git] / wrlib / wraster.h
blob252284b9fd6a2cfe4c42625d33abfc3bf2c4f06b
1 /*
2 * Raster graphics library
3 *
4 * Copyright (c) 1997, 1998 Alfredo K. Kojima
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
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 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Environment variables:
24 * WRASTER_GAMMA <rgamma>/<ggamma>/<bgamma>
25 * gamma correction value. Must be greater than 0
26 * Only for PseudoColor visuals.
28 * Default:
29 * WRASTER_GAMMA 1/1/1
32 * If you want a specific value for a screen, append the screen number
33 * preceded by a hash to the variable name as in
34 * WRASTER_GAMMA#1
35 * for screen number 1
38 #ifndef RLRASTER_H_
39 #define RLRASTER_H_
42 /* version of the header for the library: 0.10 */
43 #define WRASTER_HEADER_VERSION 10
45 #ifdef HAVE_ALLOCA_H
46 #include <alloca.h>
47 #endif
50 #include <X11/Xlib.h>
51 #include <X11/Xutil.h>
53 #ifdef XSHM
54 #include <X11/extensions/XShm.h>
55 #endif
57 /* RM_MATCH or RM_DITHER */
58 #define RC_RenderMode (1<<0)
60 /* number of colors per channel for colormap in PseudoColor mode */
61 #define RC_ColorsPerChannel (1<<1)
63 /* do gamma correction */
64 #define RC_GammaCorrection (1<<2)
66 /* visual id to use */
67 #define RC_VisualID (1<<3)
69 /* shared memory usage */
70 #define RC_UseSharedMemory (1<<4)
72 /* use default instead of best visual */
73 #define RC_DefaultVisual (1<<5)
75 typedef struct RContextAttributes {
76 int flags;
77 int render_mode;
78 int colors_per_channel; /* for PseudoColor */
79 float rgamma; /* gamma correction for red, */
80 float ggamma; /* green, */
81 float bgamma; /* and blue */
82 VisualID visualid; /* visual ID to use */
83 int use_shared_memory; /* True of False */
84 } RContextAttributes;
88 * describes a screen in terms of depth, visual, number of colors
89 * we can use, if we should do dithering, and what colors to use for
90 * dithering.
92 typedef struct RContext {
93 Display *dpy;
94 int screen_number;
95 Colormap cmap;
97 RContextAttributes *attribs;
99 GC copy_gc;
101 Visual *visual;
102 int depth;
103 Window drawable; /* window to pass for XCreatePixmap().*/
104 /* generally = root */
105 int vclass;
107 unsigned long black;
108 unsigned long white;
110 int red_offset; /* only used in 24bpp */
111 int green_offset;
112 int blue_offset;
114 /* only used for pseudocolor and grayscale */
115 int ncolors; /* total number of colors we can use */
116 XColor *colors; /* internal colormap */
117 } RContext;
120 typedef struct RColor {
121 unsigned char red;
122 unsigned char green;
123 unsigned char blue;
124 unsigned char alpha;
125 } RColor;
128 typedef struct RHSVColor {
129 unsigned short hue; /* 0-359 */
130 unsigned char saturation; /* 0-255 */
131 unsigned char value; /* 0-255 */
132 } RHSVColor;
136 typedef struct RPoint {
137 int x, y;
138 } RPoint;
141 typedef struct RSegment {
142 int x1, y1, x2, y2;
143 } RSegment;
147 * internal 24bit+alpha image representation
149 typedef struct RImage {
150 unsigned width, height; /* size of the image */
151 RColor background; /* background color */
152 unsigned char *data[4]; /* image data (R,G,B,A) */
153 } RImage;
157 * internal wrapper for XImage. Used for shm abstraction
159 typedef struct RXImage {
160 XImage *image;
162 /* Private data. Do not access */
163 #ifdef XSHM
164 XShmSegmentInfo info;
165 char is_shared;
166 #endif
167 } RXImage;
170 /* note that not all operations are supported in all functions */
171 enum {
172 RClearOperation, /* clear with 0 */
173 RCopyOperation,
174 RNormalOperation, /* same as combine */
175 RAddOperation,
176 RSubtractOperation
180 /* image display modes */
181 enum {
182 RDitheredRendering = 0,
183 RBestMatchRendering = 1
186 /* bw compat */
187 #define RM_DITHER RDitheredRendering
188 #define RM_MATCH RBestMatchRendering
190 enum {
191 RAbsoluteCoordinates = 0,
192 RRelativeCoordinates = 1
196 enum {
197 RSunkenBevel = -1,
198 RRaisedBevel = 1
200 /* bw compat */
201 #define RBEV_SUNKEN RSunkenBevel
202 /* 1 pixel wide */
203 #define RBEV_RAISED RRaisedBevel
204 /* 1 pixel wide on top/left 2 on bottom/right */
205 #define RBEV_RAISED2 2
206 /* 2 pixel width */
207 #define RBEV_RAISED3 3
209 enum {
210 RHorizontalGradient = 2,
211 RVerticalGradient = 3,
212 RDiagonalGradient = 4
214 /* for backwards compatibility */
215 #define RGRD_HORIZONTAL RHorizontalGradient
216 #define RGRD_VERTICAL RVerticalGradient
217 #define RGRD_DIAGONAL RDiagonalGradient
221 /* error codes */
222 #define RERR_NONE 0
223 #define RERR_OPEN 1 /* cant open file */
224 #define RERR_READ 2 /* error reading from file */
225 #define RERR_WRITE 3 /* error writing to file */
226 #define RERR_NOMEMORY 4 /* out of memory */
227 #define RERR_NOCOLOR 5 /* out of color cells */
228 #define RERR_BADIMAGEFILE 6 /* image file is corrupted or invalid */
229 #define RERR_BADFORMAT 7 /* image file format is unknown */
230 #define RERR_BADINDEX 8 /* no such image index in file */
232 #define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
234 #define RERR_XERROR 127 /* internal X error */
235 #define RERR_INTERNAL 128 /* should not happen */
239 * Returns a NULL terminated array of strings containing the
240 * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
242 char **RSupportedFileFormats(void);
244 void RFreeStringList(char **list);
247 * Xlib contexts
249 RContext *RCreateContext(Display *dpy, int screen_number,
250 RContextAttributes *attribs);
252 void RDestroyContext(RContext *context);
254 Bool RGetClosestXColor(RContext *context, RColor *color, XColor *retColor);
257 * RImage creation
259 RImage *RCreateImage(unsigned width, unsigned height, int alpha);
261 RImage *RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask);
263 RImage *RCreateImageFromDrawable(RContext *context, Drawable drawable,
264 Pixmap mask);
266 RImage *RLoadImage(RContext *context, char *file, int index);
269 void RDestroyImage(RImage *image);
271 RImage *RGetImageFromXPMData(RContext *context, char **data);
274 * RImage storing
276 Bool RSaveImage(RImage *image, char *filename, char *format);
279 * Area manipulation
281 RImage *RCloneImage(RImage *image);
283 RImage *RGetSubImage(RImage *image, int x, int y, unsigned width,
284 unsigned height);
286 void RCombineImageWithColor(RImage *image, RColor *color);
288 void RCombineImages(RImage *image, RImage *src);
290 void RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
291 unsigned height, int dx, int dy);
293 void RCombineImagesWithOpaqueness(RImage *image, RImage *src, int opaqueness);
295 void RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
296 unsigned width, unsigned height, int dx, int dy,
297 int opaqueness);
299 RImage *RScaleImage(RImage *image, unsigned new_width, unsigned new_height);
301 RImage *RMakeTiledImage(RImage *tile, unsigned width, unsigned height);
303 RImage* RMakeCenteredImage(RImage *image, unsigned width, unsigned height,
304 RColor *color);
307 * Drawing
309 Bool RGetPixel(RImage *image, int x, int y, RColor *color);
311 void RPutPixel(RImage *image, int x, int y, RColor *color);
313 void ROperatePixel(RImage *image, int operation, int x, int y, RColor *color);
315 void RPutPixels(RImage *image, RPoint *points, int npoints, int mode,
316 RColor *color);
318 void ROperatePixels(RImage *image, int operation, RPoint *points,
319 int npoints, int mode, RColor *color);
321 int RDrawLine(RImage *image, int x0, int y0, int x1, int y1, RColor *color);
323 int ROperateLine(RImage *image, int operation, int x0, int y0, int x1, int y1,
324 RColor *color);
326 void RDrawLines(RImage *image, RPoint *points, int npoints, int mode,
327 RColor *color);
329 void ROperateLines(RImage *image, int operation, RPoint *points, int npoints,
330 int mode, RColor *color);
332 void RDrawSegments(RImage *image, RSegment *segs, int nsegs, RColor *color);
334 void ROperateSegments(RImage *image, int operation, RSegment *segs, int nsegs,
335 RColor *color);
338 * Color convertion
340 void RRGBtoHSV(RColor *color, RHSVColor *hsv);
341 void RHSVtoRGB(RHSVColor *hsv, RColor *rgb);
344 * Painting
346 void RClearImage(RImage *image, RColor *color);
348 void RBevelImage(RImage *image, int bevel_type);
350 RImage *RRenderGradient(unsigned width, unsigned height, RColor *from,
351 RColor *to, int style);
354 RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor **colors,
355 int style);
358 * Convertion into X Pixmaps
360 int RConvertImage(RContext *context, RImage *image, Pixmap *pixmap);
362 int RConvertImageMask(RContext *context, RImage *image, Pixmap *pixmap,
363 Pixmap *mask, int threshold);
367 * misc. utilities
369 RXImage *RCreateXImage(RContext *context, int depth,
370 unsigned width, unsigned height);
372 void RDestroyXImage(RContext *context, RXImage *ximage);
374 void RPutXImage(RContext *context, Drawable d, GC gc, RXImage *ximage,
375 int src_x, int src_y, int dest_x, int dest_y,
376 unsigned width, unsigned height);
378 /* do not free the returned string! */
379 const char *RMessageForError(int errorCode);
382 /****** Global Variables *******/
384 extern int RErrorCode;
386 #endif