Initial revision
[wmaker-crm.git] / wrlib / wraster.h
blobb86d5e28a2d84d30db2ad8830dd622486d902bdf
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.8 */
43 #define WRASTER_HEADER_VERSION 8
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;
161 #ifdef XSHM
162 XShmSegmentInfo info;
163 int is_shared;
164 #endif
165 } RXImage;
168 /* note that not all operations are supported in all functions */
169 enum {
170 RClearOperation, /* clear with 0 */
171 RCopyOperation,
172 RNormalOperation, /* same as combine */
173 RAddOperation,
174 RSubtractOperation
178 /* image display modes */
179 enum {
180 RDitheredRendering = 0,
181 RBestMatchRendering = 1
184 /* bw compat */
185 #define RM_DITHER RDitheredRendering
186 #define RM_MATCH RBestMatchRendering
188 enum {
189 RAbsoluteCoordinates = 0,
190 RRelativeCoordinates = 1
194 enum {
195 RSunkenBevel = -1,
196 RRaisedBevel = 1
198 /* bw compat */
199 #define RBEV_SUNKEN RSunkenBevel
200 /* 1 pixel wide */
201 #define RBEV_RAISED RRaisedBevel
202 /* 1 pixel wide on top/left 2 on bottom/right */
203 #define RBEV_RAISED2 2
204 /* 2 pixel width */
205 #define RBEV_RAISED3 3
207 enum {
208 RHorizontalGradient = 2,
209 RVerticalGradient = 3,
210 RDiagonalGradient = 4
212 /* for backwards compatibility */
213 #define RGRD_HORIZONTAL RHorizontalGradient
214 #define RGRD_VERTICAL RVerticalGradient
215 #define RGRD_DIAGONAL RDiagonalGradient
221 * Returns a NULL terminated array of strings containing the
222 * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
224 char **RSupportedFileFormats(void);
226 void RFreeStringList(char **list);
229 * Xlib contexts
231 RContext *RCreateContext(Display *dpy, int screen_number,
232 RContextAttributes *attribs);
235 Bool RGetClosestXColor(RContext *context, RColor *color, XColor *retColor);
238 * RImage creation
240 RImage *RCreateImage(unsigned width, unsigned height, int alpha);
242 RImage *RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask);
244 RImage *RCreateImageFromDrawable(RContext *context, Drawable drawable,
245 Pixmap mask);
247 RImage *RLoadImage(RContext *context, char *file, int index);
250 void RDestroyImage(RImage *image);
252 RImage *RGetImageFromXPMData(RContext *context, char **data);
256 * Area manipulation
258 RImage *RCloneImage(RImage *image);
260 RImage *RGetSubImage(RImage *image, int x, int y, unsigned width,
261 unsigned height);
263 void RCombineImageWithColor(RImage *image, RColor *color);
265 void RCombineImages(RImage *image, RImage *src);
267 void RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
268 unsigned height, int dx, int dy);
270 void RCombineImagesWithOpaqueness(RImage *image, RImage *src, int opaqueness);
272 void RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
273 unsigned width, unsigned height, int dx, int dy,
274 int opaqueness);
276 RImage *RScaleImage(RImage *image, unsigned new_width, unsigned new_height);
278 RImage *RMakeTiledImage(RImage *tile, unsigned width, unsigned height);
280 RImage* RMakeCenteredImage(RImage *image, unsigned width, unsigned height,
281 RColor *color);
284 * Drawing
286 Bool RGetPixel(RImage *image, int x, int y, RColor *color);
288 void RPutPixel(RImage *image, int x, int y, RColor *color);
290 void ROperatePixel(RImage *image, int operation, int x, int y, RColor *color);
292 void RPutPixels(RImage *image, RPoint *points, int npoints, int mode,
293 RColor *color);
295 void ROperatePixels(RImage *image, int operation, RPoint *points,
296 int npoints, int mode, RColor *color);
298 int RDrawLine(RImage *image, int x0, int y0, int x1, int y1, RColor *color);
300 int ROperateLine(RImage *image, int operation, int x0, int y0, int x1, int y1,
301 RColor *color);
303 void RDrawLines(RImage *image, RPoint *points, int npoints, int mode,
304 RColor *color);
306 void ROperateLines(RImage *image, int operation, RPoint *points, int npoints,
307 int mode, RColor *color);
309 void RDrawSegments(RImage *image, RSegment *segs, int nsegs, RColor *color);
311 void ROperateSegments(RImage *image, int operation, RSegment *segs, int nsegs,
312 RColor *color);
315 * Color convertion
317 void RRGBtoHSV(RColor *color, RHSVColor *hsv);
318 void RHSVtoRGB(RHSVColor *hsv, RColor *rgb);
321 * Painting
323 int RClearImage(RImage *image, RColor *color);
325 int RBevelImage(RImage *image, int bevel_type);
327 RImage *RRenderGradient(unsigned width, unsigned height, RColor *from,
328 RColor *to, int style);
331 RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor **colors,
332 int style);
335 * Convertion into X Pixmaps
337 int RConvertImage(RContext *context, RImage *image, Pixmap *pixmap);
339 int RConvertImageMask(RContext *context, RImage *image, Pixmap *pixmap,
340 Pixmap *mask, int threshold);
344 * misc. utilities
346 RXImage *RCreateXImage(RContext *context, int depth,
347 unsigned width, unsigned height);
349 void RDestroyXImage(RContext *context, RXImage *ximage);
351 void RPutXImage(RContext *context, Drawable d, GC gc, RXImage *ximage,
352 int src_x, int src_y, int dest_x, int dest_y,
353 unsigned width, unsigned height);
356 /****** Global Variables *******/
359 * Where error strings are stored
361 extern char RErrorString[];
364 #endif