Small bug fix, and updated for some #defines that were removed.
[wmaker-crm.git] / wrlib / wraster.h
bloba370283255fe8f4fbd43e47dee8d0fc060482210
1 /*
2 * Raster graphics library
3 *
4 * Copyright (c) 1997, 1998, 1999 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.15 */
43 #define WRASTER_HEADER_VERSION 15
46 #include <X11/Xlib.h>
47 #include <X11/Xutil.h>
49 #ifdef XSHM
50 #include <X11/extensions/XShm.h>
51 #endif
53 /* RBestMatchRendering or RDitheredRendering */
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 /* filter type for smoothed scaling */
72 #define RC_ScalingFilter (1<<6)
74 #ifdef __cplusplus
75 extern "C" {
76 #endif /* __cplusplus */
78 typedef struct RContextAttributes {
79 int flags;
80 int render_mode;
81 int colors_per_channel; /* for PseudoColor */
82 float rgamma; /* gamma correction for red, */
83 float ggamma; /* green, */
84 float bgamma; /* and blue */
85 VisualID visualid; /* visual ID to use */
86 int use_shared_memory; /* True of False */
87 int scaling_filter;
88 } RContextAttributes;
92 * describes a screen in terms of depth, visual, number of colors
93 * we can use, if we should do dithering, and what colors to use for
94 * dithering.
96 typedef struct RContext {
97 Display *dpy;
98 int screen_number;
99 Colormap cmap;
101 RContextAttributes *attribs;
103 GC copy_gc;
105 Visual *visual;
106 int depth;
107 Window drawable; /* window to pass for XCreatePixmap().*/
108 /* generally = root */
109 int vclass;
111 unsigned long black;
112 unsigned long white;
114 int red_offset; /* only used in 24bpp */
115 int green_offset;
116 int blue_offset;
118 /* only used for pseudocolor and grayscale */
120 XStandardColormap *std_rgb_map; /* standard RGB colormap */
121 XStandardColormap *std_gray_map; /* standard grayscale colormap */
123 int ncolors; /* total number of colors we can use */
124 XColor *colors; /* internal colormap */
126 struct {
127 unsigned int use_shared_pixmap:1;
128 } flags;
129 } RContext;
132 typedef struct RColor {
133 unsigned char red;
134 unsigned char green;
135 unsigned char blue;
136 unsigned char alpha;
137 } RColor;
140 typedef struct RHSVColor {
141 unsigned short hue; /* 0-359 */
142 unsigned char saturation; /* 0-255 */
143 unsigned char value; /* 0-255 */
144 } RHSVColor;
148 typedef struct RPoint {
149 int x, y;
150 } RPoint;
153 typedef struct RSegment {
154 int x1, y1, x2, y2;
155 } RSegment;
159 * internal 24bit+alpha image representation
161 typedef struct RImage {
162 unsigned width, height; /* size of the image */
163 RColor background; /* background color */
164 unsigned char *data[4]; /* image data (R,G,B,A) */
165 } RImage;
169 * internal wrapper for XImage. Used for shm abstraction
171 typedef struct RXImage {
172 XImage *image;
174 /* Private data. Do not access */
175 #ifdef XSHM
176 XShmSegmentInfo info;
177 char is_shared;
178 #endif
179 } RXImage;
183 /* image display modes */
184 enum {
185 RDitheredRendering = 0,
186 RBestMatchRendering = 1
190 /* smoothed scaling filter types */
191 enum {
192 RBoxFilter,
193 RTriangleFilter,
194 RBellFilter,
195 RBSplineFilter,
196 RLanczos3Filter,
197 RMitchellFilter
201 /* note that not all operations are supported in all functions */
202 enum {
203 RClearOperation, /* clear with 0 */
204 RCopyOperation,
205 RNormalOperation, /* same as combine */
206 RAddOperation,
207 RSubtractOperation
211 enum {
212 RAbsoluteCoordinates = 0,
213 RRelativeCoordinates = 1
217 enum {
218 RSunkenBevel = -1,
219 RNoBevel = 0,
220 RRaisedBevel = 1
222 /* bw compat */
223 #define RBEV_SUNKEN RSunkenBevel
224 /* 1 pixel wide */
225 #define RBEV_RAISED RRaisedBevel
226 /* 1 pixel wide on top/left 2 on bottom/right */
227 #define RBEV_RAISED2 2
228 /* 2 pixel width */
229 #define RBEV_RAISED3 3
231 enum {
232 RHorizontalGradient = 2,
233 RVerticalGradient = 3,
234 RDiagonalGradient = 4
236 /* for backwards compatibility */
237 #define RGRD_HORIZONTAL RHorizontalGradient
238 #define RGRD_VERTICAL RVerticalGradient
239 #define RGRD_DIAGONAL RDiagonalGradient
243 /* error codes */
244 #define RERR_NONE 0
245 #define RERR_OPEN 1 /* cant open file */
246 #define RERR_READ 2 /* error reading from file */
247 #define RERR_WRITE 3 /* error writing to file */
248 #define RERR_NOMEMORY 4 /* out of memory */
249 #define RERR_NOCOLOR 5 /* out of color cells */
250 #define RERR_BADIMAGEFILE 6 /* image file is corrupted or invalid */
251 #define RERR_BADFORMAT 7 /* image file format is unknown */
252 #define RERR_BADINDEX 8 /* no such image index in file */
254 #define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
256 #define RERR_XERROR 127 /* internal X error */
257 #define RERR_INTERNAL 128 /* should not happen */
261 * Returns a NULL terminated array of strings containing the
262 * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
263 * Do not free the returned data.
265 char **RSupportedFileFormats(void);
268 char *RGetImageFileFormat(char *file);
271 * Xlib contexts
273 RContext *RCreateContext(Display *dpy, int screen_number,
274 RContextAttributes *attribs);
276 void RDestroyContext(RContext *context);
278 Bool RGetClosestXColor(RContext *context, RColor *color, XColor *retColor);
281 * RImage creation
283 RImage *RCreateImage(unsigned width, unsigned height, int alpha);
285 RImage *RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask);
287 RImage *RCreateImageFromDrawable(RContext *context, Drawable drawable,
288 Pixmap mask);
290 RImage *RLoadImage(RContext *context, char *file, int index);
293 void RDestroyImage(RImage *image);
295 RImage *RGetImageFromXPMData(RContext *context, char **data);
298 * RImage storing
300 Bool RSaveImage(RImage *image, char *filename, char *format);
303 * Area manipulation
305 RImage *RCloneImage(RImage *image);
307 RImage *RGetSubImage(RImage *image, int x, int y, unsigned width,
308 unsigned height);
310 void RCombineImageWithColor(RImage *image, RColor *color);
312 void RCombineImages(RImage *image, RImage *src);
314 void RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
315 unsigned height, int dx, int dy);
317 void RCombineImagesWithOpaqueness(RImage *image, RImage *src, int opaqueness);
319 void RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
320 unsigned width, unsigned height, int dx, int dy,
321 int opaqueness);
323 RImage *RScaleImage(RImage *image, unsigned new_width, unsigned new_height);
325 RImage *RSmoothScaleImage(RImage *src, unsigned new_width,
326 unsigned new_height);
328 RImage *RMakeTiledImage(RImage *tile, unsigned width, unsigned height);
330 RImage* RMakeCenteredImage(RImage *image, unsigned width, unsigned height,
331 RColor *color);
334 * Drawing
336 Bool RGetPixel(RImage *image, int x, int y, RColor *color);
338 void RPutPixel(RImage *image, int x, int y, RColor *color);
340 void ROperatePixel(RImage *image, int operation, int x, int y, RColor *color);
342 void RPutPixels(RImage *image, RPoint *points, int npoints, int mode,
343 RColor *color);
345 void ROperatePixels(RImage *image, int operation, RPoint *points,
346 int npoints, int mode, RColor *color);
348 int RDrawLine(RImage *image, int x0, int y0, int x1, int y1, RColor *color);
350 int ROperateLine(RImage *image, int operation, int x0, int y0, int x1, int y1,
351 RColor *color);
353 void RDrawLines(RImage *image, RPoint *points, int npoints, int mode,
354 RColor *color);
356 void ROperateLines(RImage *image, int operation, RPoint *points, int npoints,
357 int mode, RColor *color);
359 void RDrawSegments(RImage *image, RSegment *segs, int nsegs, RColor *color);
361 void ROperateSegments(RImage *image, int operation, RSegment *segs, int nsegs,
362 RColor *color);
365 * Color convertion
367 void RRGBtoHSV(RColor *color, RHSVColor *hsv);
368 void RHSVtoRGB(RHSVColor *hsv, RColor *rgb);
371 * Painting
373 void RClearImage(RImage *image, RColor *color);
375 void RBevelImage(RImage *image, int bevel_type);
377 RImage *RRenderGradient(unsigned width, unsigned height, RColor *from,
378 RColor *to, int style);
381 RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor **colors,
382 int style);
387 * Convertion into X Pixmaps
389 int RConvertImage(RContext *context, RImage *image, Pixmap *pixmap);
391 int RConvertImageMask(RContext *context, RImage *image, Pixmap *pixmap,
392 Pixmap *mask, int threshold);
396 * misc. utilities
398 RXImage *RCreateXImage(RContext *context, int depth,
399 unsigned width, unsigned height);
401 RXImage *RGetXImage(RContext *context, Drawable d, int x, int y,
402 unsigned width, unsigned height);
404 void RDestroyXImage(RContext *context, RXImage *ximage);
406 void RPutXImage(RContext *context, Drawable d, GC gc, RXImage *ximage,
407 int src_x, int src_y, int dest_x, int dest_y,
408 unsigned width, unsigned height);
410 /* do not free the returned string! */
411 const char *RMessageForError(int errorCode);
413 int RBlurImage(RImage *image);
415 /****** Global Variables *******/
417 extern int RErrorCode;
419 #ifdef __cplusplus
421 #endif /* __cplusplus */
423 #endif