Update for 0.51.0
[wmaker-crm.git] / wrlib / wraster.h
blob4ece24e56db4dbd83cd1fab780ea296e59372ad0
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.11 */
43 #define WRASTER_HEADER_VERSION 11
46 #include <X11/Xlib.h>
47 #include <X11/Xutil.h>
49 #ifdef XSHM
50 #include <X11/extensions/XShm.h>
51 #endif
53 /* RM_MATCH or RM_DITHER */
54 #define RC_RenderMode (1<<0)
56 /* number of colors per channel for colormap in PseudoColor mode */
57 #define RC_ColorsPerChannel (1<<1)
59 /* do gamma correction */
60 #define RC_GammaCorrection (1<<2)
62 /* visual id to use */
63 #define RC_VisualID (1<<3)
65 /* shared memory usage */
66 #define RC_UseSharedMemory (1<<4)
68 /* use default instead of best visual */
69 #define RC_DefaultVisual (1<<5)
71 typedef struct RContextAttributes {
72 int flags;
73 int render_mode;
74 int colors_per_channel; /* for PseudoColor */
75 float rgamma; /* gamma correction for red, */
76 float ggamma; /* green, */
77 float bgamma; /* and blue */
78 VisualID visualid; /* visual ID to use */
79 int use_shared_memory; /* True of False */
80 } RContextAttributes;
84 * describes a screen in terms of depth, visual, number of colors
85 * we can use, if we should do dithering, and what colors to use for
86 * dithering.
88 typedef struct RContext {
89 Display *dpy;
90 int screen_number;
91 Colormap cmap;
93 RContextAttributes *attribs;
95 GC copy_gc;
97 Visual *visual;
98 int depth;
99 Window drawable; /* window to pass for XCreatePixmap().*/
100 /* generally = root */
101 int vclass;
103 unsigned long black;
104 unsigned long white;
106 int red_offset; /* only used in 24bpp */
107 int green_offset;
108 int blue_offset;
110 /* only used for pseudocolor and grayscale */
112 XStandardColormap *std_rgb_map; /* standard RGB colormap */
113 XStandardColormap *std_gray_map; /* standard grayscale colormap */
115 int ncolors; /* total number of colors we can use */
116 XColor *colors; /* internal colormap */
118 struct {
119 unsigned int use_shared_pixmap:1;
120 } flags;
121 } RContext;
124 typedef struct RColor {
125 unsigned char red;
126 unsigned char green;
127 unsigned char blue;
128 unsigned char alpha;
129 } RColor;
132 typedef struct RHSVColor {
133 unsigned short hue; /* 0-359 */
134 unsigned char saturation; /* 0-255 */
135 unsigned char value; /* 0-255 */
136 } RHSVColor;
140 typedef struct RPoint {
141 int x, y;
142 } RPoint;
145 typedef struct RSegment {
146 int x1, y1, x2, y2;
147 } RSegment;
151 * internal 24bit+alpha image representation
153 typedef struct RImage {
154 unsigned width, height; /* size of the image */
155 RColor background; /* background color */
156 unsigned char *data[4]; /* image data (R,G,B,A) */
157 } RImage;
161 * internal wrapper for XImage. Used for shm abstraction
163 typedef struct RXImage {
164 XImage *image;
166 /* Private data. Do not access */
167 #ifdef XSHM
168 XShmSegmentInfo info;
169 char is_shared;
170 #endif
171 } RXImage;
174 /* note that not all operations are supported in all functions */
175 enum {
176 RClearOperation, /* clear with 0 */
177 RCopyOperation,
178 RNormalOperation, /* same as combine */
179 RAddOperation,
180 RSubtractOperation
184 /* image display modes */
185 enum {
186 RDitheredRendering = 0,
187 RBestMatchRendering = 1
190 /* bw compat */
191 #define RM_DITHER RDitheredRendering
192 #define RM_MATCH RBestMatchRendering
194 enum {
195 RAbsoluteCoordinates = 0,
196 RRelativeCoordinates = 1
200 enum {
201 RSunkenBevel = -1,
202 RRaisedBevel = 1
204 /* bw compat */
205 #define RBEV_SUNKEN RSunkenBevel
206 /* 1 pixel wide */
207 #define RBEV_RAISED RRaisedBevel
208 /* 1 pixel wide on top/left 2 on bottom/right */
209 #define RBEV_RAISED2 2
210 /* 2 pixel width */
211 #define RBEV_RAISED3 3
213 enum {
214 RHorizontalGradient = 2,
215 RVerticalGradient = 3,
216 RDiagonalGradient = 4
218 /* for backwards compatibility */
219 #define RGRD_HORIZONTAL RHorizontalGradient
220 #define RGRD_VERTICAL RVerticalGradient
221 #define RGRD_DIAGONAL RDiagonalGradient
225 /* error codes */
226 #define RERR_NONE 0
227 #define RERR_OPEN 1 /* cant open file */
228 #define RERR_READ 2 /* error reading from file */
229 #define RERR_WRITE 3 /* error writing to file */
230 #define RERR_NOMEMORY 4 /* out of memory */
231 #define RERR_NOCOLOR 5 /* out of color cells */
232 #define RERR_BADIMAGEFILE 6 /* image file is corrupted or invalid */
233 #define RERR_BADFORMAT 7 /* image file format is unknown */
234 #define RERR_BADINDEX 8 /* no such image index in file */
236 #define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
238 #define RERR_XERROR 127 /* internal X error */
239 #define RERR_INTERNAL 128 /* should not happen */
243 * Returns a NULL terminated array of strings containing the
244 * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
246 char **RSupportedFileFormats(void);
248 void RFreeStringList(char **list);
251 * Xlib contexts
253 RContext *RCreateContext(Display *dpy, int screen_number,
254 RContextAttributes *attribs);
256 void RDestroyContext(RContext *context);
258 Bool RGetClosestXColor(RContext *context, RColor *color, XColor *retColor);
261 * RImage creation
263 RImage *RCreateImage(unsigned width, unsigned height, int alpha);
265 RImage *RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask);
267 RImage *RCreateImageFromDrawable(RContext *context, Drawable drawable,
268 Pixmap mask);
270 RImage *RLoadImage(RContext *context, char *file, int index);
273 void RDestroyImage(RImage *image);
275 RImage *RGetImageFromXPMData(RContext *context, char **data);
278 * RImage storing
280 Bool RSaveImage(RImage *image, char *filename, char *format);
283 * Area manipulation
285 RImage *RCloneImage(RImage *image);
287 RImage *RGetSubImage(RImage *image, int x, int y, unsigned width,
288 unsigned height);
290 void RCombineImageWithColor(RImage *image, RColor *color);
292 void RCombineImages(RImage *image, RImage *src);
294 void RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
295 unsigned height, int dx, int dy);
297 void RCombineImagesWithOpaqueness(RImage *image, RImage *src, int opaqueness);
299 void RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
300 unsigned width, unsigned height, int dx, int dy,
301 int opaqueness);
303 RImage *RScaleImage(RImage *image, unsigned new_width, unsigned new_height);
305 RImage *RMakeTiledImage(RImage *tile, unsigned width, unsigned height);
307 RImage* RMakeCenteredImage(RImage *image, unsigned width, unsigned height,
308 RColor *color);
311 * Drawing
313 Bool RGetPixel(RImage *image, int x, int y, RColor *color);
315 void RPutPixel(RImage *image, int x, int y, RColor *color);
317 void ROperatePixel(RImage *image, int operation, int x, int y, RColor *color);
319 void RPutPixels(RImage *image, RPoint *points, int npoints, int mode,
320 RColor *color);
322 void ROperatePixels(RImage *image, int operation, RPoint *points,
323 int npoints, int mode, RColor *color);
325 int RDrawLine(RImage *image, int x0, int y0, int x1, int y1, RColor *color);
327 int ROperateLine(RImage *image, int operation, int x0, int y0, int x1, int y1,
328 RColor *color);
330 void RDrawLines(RImage *image, RPoint *points, int npoints, int mode,
331 RColor *color);
333 void ROperateLines(RImage *image, int operation, RPoint *points, int npoints,
334 int mode, RColor *color);
336 void RDrawSegments(RImage *image, RSegment *segs, int nsegs, RColor *color);
338 void ROperateSegments(RImage *image, int operation, RSegment *segs, int nsegs,
339 RColor *color);
342 * Color convertion
344 void RRGBtoHSV(RColor *color, RHSVColor *hsv);
345 void RHSVtoRGB(RHSVColor *hsv, RColor *rgb);
348 * Painting
350 void RClearImage(RImage *image, RColor *color);
352 void RBevelImage(RImage *image, int bevel_type);
354 RImage *RRenderGradient(unsigned width, unsigned height, RColor *from,
355 RColor *to, int style);
358 RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor **colors,
359 int style);
364 * Convertion into X Pixmaps
366 int RConvertImage(RContext *context, RImage *image, Pixmap *pixmap);
368 int RConvertImageMask(RContext *context, RImage *image, Pixmap *pixmap,
369 Pixmap *mask, int threshold);
373 * misc. utilities
375 RXImage *RCreateXImage(RContext *context, int depth,
376 unsigned width, unsigned height);
378 void RDestroyXImage(RContext *context, RXImage *ximage);
380 void RPutXImage(RContext *context, Drawable d, GC gc, RXImage *ximage,
381 int src_x, int src_y, int dest_x, int dest_y,
382 unsigned width, unsigned height);
384 /* do not free the returned string! */
385 const char *RMessageForError(int errorCode);
387 int RBlurImage(RImage *image);
389 /****** Global Variables *******/
391 extern int RErrorCode;
393 #endif