forgot this
[wmaker-crm.git] / wrlib / wraster.h
bloba5d8a53d7b08093950defb98867076068484f38e
1 /*
2 * Raster graphics library
3 *
4 * Copyright (c) 1997-2002 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.21 */
43 #define WRASTER_HEADER_VERSION 21
46 #include <X11/Xlib.h>
47 #include <X11/Xutil.h>
49 #ifdef XSHM
50 #include <X11/extensions/XShm.h>
51 #endif
54 #ifdef __cplusplus
55 extern "C" {
56 #endif /* __cplusplus */
58 /* RBestMatchRendering or RDitheredRendering */
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 /* filter type for smoothed scaling */
77 #define RC_ScalingFilter (1<<6)
79 /* standard colormap usage */
80 #define RC_StandardColormap (1<<7)
87 /* std colormap usage/creation modes */
88 enum {
89 RUseStdColormap, /* default. fallbacks to RIgnore.. if
90 there is none defined */
91 RCreateStdColormap,
92 RIgnoreStdColormap
97 typedef struct RContextAttributes {
98 int flags;
99 int render_mode;
100 int colors_per_channel; /* for PseudoColor */
101 float rgamma; /* gamma correction for red, */
102 float ggamma; /* green, */
103 float bgamma; /* and blue */
104 VisualID visualid; /* visual ID to use */
105 int use_shared_memory; /* True of False */
106 int scaling_filter;
107 int standard_colormap_mode; /* what to do with std cma */
108 } RContextAttributes;
112 * describes a screen in terms of depth, visual, number of colors
113 * we can use, if we should do dithering, and what colors to use for
114 * dithering.
116 typedef struct RContext {
117 Display *dpy;
118 int screen_number;
119 Colormap cmap;
121 RContextAttributes *attribs;
123 GC copy_gc;
125 Visual *visual;
126 int depth;
127 Window drawable; /* window to pass for XCreatePixmap().*/
128 /* generally = root */
129 int vclass;
131 unsigned long black;
132 unsigned long white;
134 int red_offset; /* only used in 24bpp */
135 int green_offset;
136 int blue_offset;
138 /* only used for pseudocolor and grayscale */
140 XStandardColormap *std_rgb_map; /* standard RGB colormap */
141 XStandardColormap *std_gray_map; /* standard grayscale colormap */
143 int ncolors; /* total number of colors we can use */
144 XColor *colors; /* internal colormap */
145 unsigned long *pixels; /* RContext->colors[].pixel */
147 struct {
148 unsigned int use_shared_pixmap:1;
149 unsigned int optimize_for_speed:1;
150 } flags;
152 struct RHermesData *hermes_data; /* handle for Hermes stuff */
153 } RContext;
156 typedef struct RColor {
157 unsigned char red;
158 unsigned char green;
159 unsigned char blue;
160 unsigned char alpha;
161 } RColor;
164 typedef struct RHSVColor {
165 unsigned short hue; /* 0-359 */
166 unsigned char saturation; /* 0-255 */
167 unsigned char value; /* 0-255 */
168 } RHSVColor;
172 typedef struct RPoint {
173 int x, y;
174 } RPoint;
177 typedef struct RSegment {
178 int x1, y1, x2, y2;
179 } RSegment;
183 /* image formats */
184 enum RImageFormat {
185 RRGBFormat,
186 RRGBAFormat
191 * internal 24bit+alpha image representation
193 typedef struct RImage {
194 unsigned char *data; /* image data RGBA or RGB */
195 int width, height; /* size of the image */
196 enum RImageFormat format;
197 RColor background; /* background color */
198 int refCount;
199 } RImage;
203 * internal wrapper for XImage. Used for shm abstraction
205 typedef struct RXImage {
206 XImage *image;
208 /* Private data. Do not access */
209 #ifdef XSHM
210 XShmSegmentInfo info;
211 char is_shared;
212 #endif
213 } RXImage;
216 /* image display modes */
217 enum {
218 RDitheredRendering = 0,
219 RBestMatchRendering = 1
223 /* smoothed scaling filter types */
224 enum {
225 RBoxFilter,
226 RTriangleFilter,
227 RBellFilter,
228 RBSplineFilter,
229 RLanczos3Filter,
230 RMitchellFilter
234 /* note that not all operations are supported in all functions */
235 enum {
236 RClearOperation, /* clear with 0 */
237 RCopyOperation,
238 RNormalOperation, /* same as combine */
239 RAddOperation,
240 RSubtractOperation
244 enum {
245 RAbsoluteCoordinates = 0,
246 RRelativeCoordinates = 1
250 enum {
251 RSunkenBevel = -1,
252 RNoBevel = 0,
253 RRaisedBevel = 1
255 /* bw compat */
256 #define RBEV_SUNKEN RSunkenBevel
257 /* 1 pixel wide */
258 #define RBEV_RAISED RRaisedBevel
259 /* 1 pixel wide on top/left 2 on bottom/right */
260 #define RBEV_RAISED2 2
261 /* 2 pixel width */
262 #define RBEV_RAISED3 3
264 enum {
265 RHorizontalGradient = 2,
266 RVerticalGradient = 3,
267 RDiagonalGradient = 4
269 /* for backwards compatibility */
270 #define RGRD_HORIZONTAL RHorizontalGradient
271 #define RGRD_VERTICAL RVerticalGradient
272 #define RGRD_DIAGONAL RDiagonalGradient
276 /* error codes */
277 #define RERR_NONE 0
278 #define RERR_OPEN 1 /* cant open file */
279 #define RERR_READ 2 /* error reading from file */
280 #define RERR_WRITE 3 /* error writing to file */
281 #define RERR_NOMEMORY 4 /* out of memory */
282 #define RERR_NOCOLOR 5 /* out of color cells */
283 #define RERR_BADIMAGEFILE 6 /* image file is corrupted or invalid */
284 #define RERR_BADFORMAT 7 /* image file format is unknown */
285 #define RERR_BADINDEX 8 /* no such image index in file */
287 #define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
288 #define RERR_STDCMAPFAIL 17 /* failed to created std colormap */
290 #define RERR_XERROR 127 /* internal X error */
291 #define RERR_INTERNAL 128 /* should not happen */
295 * Returns a NULL terminated array of strings containing the
296 * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
297 * Do not free the returned data.
299 char **RSupportedFileFormats(void);
302 char *RGetImageFileFormat(char *file);
305 * Xlib contexts
307 RContext *RCreateContext(Display *dpy, int screen_number,
308 RContextAttributes *attribs);
310 void RDestroyContext(RContext *context);
312 Bool RGetClosestXColor(RContext *context, RColor *color, XColor *retColor);
315 * RImage creation
317 RImage *RCreateImage(unsigned width, unsigned height, int alpha);
319 RImage *RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask);
321 RImage *RCreateImageFromDrawable(RContext *context, Drawable drawable,
322 Pixmap mask);
324 RImage *RLoadImage(RContext *context, char *file, int index);
326 RImage* RRetainImage(RImage *image);
328 void RReleaseImage(RImage *image);
330 /* Obsoleted function. Use RReleaseImage() instead. This was kept only to
331 * allow a smoother transition and to avoid breaking existing programs, but
332 * it will be removed in a future release. Right now is just an alias to
333 * RReleaseImage(). Do _NOT_ use RDestroyImage() anymore in your programs.
334 * Being an alias to RReleaseImage() this function no longer actually
335 * destroys the image, unless the image is no longer retained in some other
336 * place.
338 void RDestroyImage(RImage *image);
340 RImage *RGetImageFromXPMData(RContext *context, char **xpmData);
343 * RImage storing
345 Bool RSaveImage(RImage *image, char *filename, char *format);
348 * Area manipulation
350 RImage *RCloneImage(RImage *image);
352 RImage *RGetSubImage(RImage *image, int x, int y, unsigned width,
353 unsigned height);
355 void RCombineImageWithColor(RImage *image, RColor *color);
357 void RCombineImages(RImage *image, RImage *src);
359 void RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
360 unsigned height, int dx, int dy);
362 void RCombineImagesWithOpaqueness(RImage *image, RImage *src, int opaqueness);
364 void RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
365 unsigned width, unsigned height, int dx, int dy,
366 int opaqueness);
368 RImage *RScaleImage(RImage *image, unsigned new_width, unsigned new_height);
370 RImage *RSmoothScaleImage(RImage *src, unsigned new_width,
371 unsigned new_height);
373 RImage *RRotateImage(RImage *image, float angle);
376 RImage *RMakeTiledImage(RImage *tile, unsigned width, unsigned height);
378 RImage* RMakeCenteredImage(RImage *image, unsigned width, unsigned height,
379 RColor *color);
382 * Drawing
384 Bool RGetPixel(RImage *image, int x, int y, RColor *color);
386 void RPutPixel(RImage *image, int x, int y, RColor *color);
388 void ROperatePixel(RImage *image, int operation, int x, int y, RColor *color);
390 void RPutPixels(RImage *image, RPoint *points, int npoints, int mode,
391 RColor *color);
393 void ROperatePixels(RImage *image, int operation, RPoint *points,
394 int npoints, int mode, RColor *color);
396 int RDrawLine(RImage *image, int x0, int y0, int x1, int y1, RColor *color);
398 int ROperateLine(RImage *image, int operation, int x0, int y0, int x1, int y1,
399 RColor *color);
401 void RDrawLines(RImage *image, RPoint *points, int npoints, int mode,
402 RColor *color);
404 void ROperateLines(RImage *image, int operation, RPoint *points, int npoints,
405 int mode, RColor *color);
407 void RDrawSegments(RImage *image, RSegment *segs, int nsegs, RColor *color);
409 void ROperateSegments(RImage *image, int operation, RSegment *segs, int nsegs,
410 RColor *color);
413 * Color convertion
415 void RRGBtoHSV(RColor *color, RHSVColor *hsv);
416 void RHSVtoRGB(RHSVColor *hsv, RColor *rgb);
419 * Painting
421 void RClearImage(RImage *image, RColor *color);
423 void RFillImage(RImage *image, RColor *color);
425 void RBevelImage(RImage *image, int bevel_type);
427 RImage *RRenderGradient(unsigned width, unsigned height, RColor *from,
428 RColor *to, int style);
431 RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor **colors,
432 int style);
435 RImage *RRenderInterwovenGradient(unsigned width, unsigned height,
436 RColor colors1[2], int thickness1,
437 RColor colors2[2], int thickness2);
441 * Convertion into X Pixmaps
443 int RConvertImage(RContext *context, RImage *image, Pixmap *pixmap);
445 int RConvertImageMask(RContext *context, RImage *image, Pixmap *pixmap,
446 Pixmap *mask, int threshold);
450 * misc. utilities
452 RXImage *RCreateXImage(RContext *context, int depth,
453 unsigned width, unsigned height);
455 RXImage *RGetXImage(RContext *context, Drawable d, int x, int y,
456 unsigned width, unsigned height);
458 void RDestroyXImage(RContext *context, RXImage *ximage);
460 void RPutXImage(RContext *context, Drawable d, GC gc, RXImage *ximage,
461 int src_x, int src_y, int dest_x, int dest_y,
462 unsigned width, unsigned height);
464 /* do not free the returned string! */
465 const char *RMessageForError(int errorCode);
467 int RBlurImage(RImage *image);
469 /****** Global Variables *******/
471 extern int RErrorCode;
473 #ifdef __cplusplus
475 #endif /* __cplusplus */
477 #endif