wmaker: Replaced local 'extern' definition of wPreferences by proper header usage
[wmaker-crm.git] / wrlib / wraster.h
blobb5e360ea4bd9887dee1e788a02ab7705f6544767
1 /*
2 * Raster graphics library
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
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., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
23 * Environment variables:
25 * WRASTER_GAMMA <rgamma>/<ggamma>/<bgamma>
26 * gamma correction value. Must be greater than 0
27 * Only for PseudoColor visuals.
29 * Default:
30 * WRASTER_GAMMA 1/1/1
33 * If you want a specific value for a screen, append the screen number
34 * preceded by a hash to the variable name as in
35 * WRASTER_GAMMA#1
36 * for screen number 1
39 #ifndef RLRASTER_H_
40 #define RLRASTER_H_
43 /* version of the header for the library */
44 #define WRASTER_HEADER_VERSION 22
47 #include <X11/Xlib.h>
48 #include <X11/Xutil.h>
50 #ifdef XSHM
51 #include <X11/extensions/XShm.h>
52 #endif
55 #ifdef __cplusplus
56 extern "C" {
57 #endif /* __cplusplus */
59 /* RBestMatchRendering or RDitheredRendering */
60 #define RC_RenderMode (1<<0)
62 /* number of colors per channel for colormap in PseudoColor mode */
63 #define RC_ColorsPerChannel (1<<1)
65 /* do gamma correction */
66 #define RC_GammaCorrection (1<<2)
68 /* visual id to use */
69 #define RC_VisualID (1<<3)
71 /* shared memory usage */
72 #define RC_UseSharedMemory (1<<4)
74 /* use default instead of best visual */
75 #define RC_DefaultVisual (1<<5)
77 /* filter type for smoothed scaling */
78 #define RC_ScalingFilter (1<<6)
80 /* standard colormap usage */
81 #define RC_StandardColormap (1<<7)
88 /* std colormap usage/creation modes */
89 enum {
90 RUseStdColormap, /* default. fallbacks to RIgnore.. if
91 there is none defined */
92 RCreateStdColormap,
93 RIgnoreStdColormap
98 typedef struct RContextAttributes {
99 int flags;
100 int render_mode;
101 int colors_per_channel; /* for PseudoColor */
102 float rgamma; /* gamma correction for red, */
103 float ggamma; /* green, */
104 float bgamma; /* and blue */
105 VisualID visualid; /* visual ID to use */
106 int use_shared_memory; /* True of False */
107 int scaling_filter;
108 int standard_colormap_mode; /* what to do with std cma */
109 } RContextAttributes;
113 * describes a screen in terms of depth, visual, number of colors
114 * we can use, if we should do dithering, and what colors to use for
115 * dithering.
117 typedef struct RContext {
118 Display *dpy;
119 int screen_number;
120 Colormap cmap;
122 RContextAttributes *attribs;
124 GC copy_gc;
126 Visual *visual;
127 int depth;
128 Window drawable; /* window to pass for XCreatePixmap().*/
129 /* generally = root */
130 int vclass;
132 unsigned long black;
133 unsigned long white;
135 int red_offset; /* only used in 24bpp */
136 int green_offset;
137 int blue_offset;
139 /* only used for pseudocolor and grayscale */
141 XStandardColormap *std_rgb_map; /* standard RGB colormap */
142 XStandardColormap *std_gray_map; /* standard grayscale colormap */
144 int ncolors; /* total number of colors we can use */
145 XColor *colors; /* internal colormap */
146 unsigned long *pixels; /* RContext->colors[].pixel */
148 struct {
149 unsigned int use_shared_pixmap:1;
150 unsigned int optimize_for_speed:1;
151 } flags;
152 } RContext;
155 typedef struct RColor {
156 unsigned char red;
157 unsigned char green;
158 unsigned char blue;
159 unsigned char alpha;
160 } RColor;
163 typedef struct RHSVColor {
164 unsigned short hue; /* 0-359 */
165 unsigned char saturation; /* 0-255 */
166 unsigned char value; /* 0-255 */
167 } RHSVColor;
171 typedef struct RPoint {
172 int x, y;
173 } RPoint;
176 typedef struct RSegment {
177 int x1, y1, x2, y2;
178 } RSegment;
182 /* image formats */
183 enum RImageFormat {
184 RRGBFormat,
185 RRGBAFormat
190 * internal 24bit+alpha image representation
192 typedef struct RImage {
193 unsigned char *data; /* image data RGBA or RGB */
194 int width, height; /* size of the image */
195 enum RImageFormat format;
196 RColor background; /* background color */
197 int refCount;
198 } RImage;
202 * internal wrapper for XImage. Used for shm abstraction
204 typedef struct RXImage {
205 XImage *image;
207 /* Private data. Do not access */
208 #ifdef XSHM
209 XShmSegmentInfo info;
210 char is_shared;
211 #endif
212 } RXImage;
215 /* image display modes */
216 enum {
217 RDitheredRendering = 0,
218 RBestMatchRendering = 1
222 /* smoothed scaling filter types */
223 enum {
224 RBoxFilter,
225 RTriangleFilter,
226 RBellFilter,
227 RBSplineFilter,
228 RLanczos3Filter,
229 RMitchellFilter
233 /* note that not all operations are supported in all functions */
234 enum {
235 RClearOperation, /* clear with 0 */
236 RCopyOperation,
237 RNormalOperation, /* same as combine */
238 RAddOperation,
239 RSubtractOperation
243 enum {
244 RAbsoluteCoordinates = 0,
245 RRelativeCoordinates = 1
249 enum {
250 RSunkenBevel = -1,
251 RNoBevel = 0,
252 RRaisedBevel = 1
254 /* bw compat */
255 #define RBEV_SUNKEN RSunkenBevel
256 /* 1 pixel wide */
257 #define RBEV_RAISED RRaisedBevel
258 /* 1 pixel wide on top/left 2 on bottom/right */
259 #define RBEV_RAISED2 2
260 /* 2 pixel width */
261 #define RBEV_RAISED3 3
263 enum {
264 RHorizontalGradient = 2,
265 RVerticalGradient = 3,
266 RDiagonalGradient = 4
268 /* for backwards compatibility */
269 #define RGRD_HORIZONTAL RHorizontalGradient
270 #define RGRD_VERTICAL RVerticalGradient
271 #define RGRD_DIAGONAL RDiagonalGradient
275 /* error codes */
276 #define RERR_NONE 0
277 #define RERR_OPEN 1 /* cant open file */
278 #define RERR_READ 2 /* error reading from file */
279 #define RERR_WRITE 3 /* error writing to file */
280 #define RERR_NOMEMORY 4 /* out of memory */
281 #define RERR_NOCOLOR 5 /* out of color cells */
282 #define RERR_BADIMAGEFILE 6 /* image file is corrupted or invalid */
283 #define RERR_BADFORMAT 7 /* image file format is unknown */
284 #define RERR_BADINDEX 8 /* no such image index in file */
286 #define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
287 #define RERR_STDCMAPFAIL 17 /* failed to created std colormap */
289 #define RERR_XERROR 127 /* internal X error */
290 #define RERR_INTERNAL 128 /* should not happen */
294 * Returns a NULL terminated array of strings containing the
295 * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
296 * Do not free the returned data.
298 char **RSupportedFileFormats(void);
301 char *RGetImageFileFormat(const char *file);
304 * Xlib contexts
306 RContext *RCreateContext(Display *dpy, int screen_number,
307 const RContextAttributes *attribs);
309 void RDestroyContext(RContext *context);
311 Bool RGetClosestXColor(RContext *context, const RColor *color, XColor *retColor);
314 * RImage creation
316 RImage *RCreateImage(unsigned width, unsigned height, int alpha);
318 RImage *RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask);
320 RImage *RCreateImageFromDrawable(RContext *context, Drawable drawable,
321 Pixmap mask);
323 RImage *RLoadImage(RContext *context, const char *file, int index);
325 RImage* RRetainImage(RImage *image);
327 void RReleaseImage(RImage *image);
329 RImage *RGetImageFromXPMData(RContext *context, char **xpmData);
332 * RImage storing
334 Bool RSaveImage(RImage *image, const char *filename, const char *format);
337 * Area manipulation
339 RImage *RCloneImage(RImage *image);
341 RImage *RGetSubImage(RImage *image, int x, int y, unsigned width,
342 unsigned height);
344 void RCombineImageWithColor(RImage *image, const RColor *color);
346 void RCombineImages(RImage *image, RImage *src);
348 void RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
349 unsigned height, int dx, int dy);
351 void RCopyArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
352 unsigned height, int dx, int dy);
354 void RCombineImagesWithOpaqueness(RImage *image, RImage *src, int opaqueness);
356 void RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
357 unsigned width, unsigned height, int dx, int dy,
358 int opaqueness);
360 void RCombineAlpha(unsigned char *d, unsigned char *s, int s_has_alpha,
361 int width, int height, int dwi, int swi, int opacity);
363 RImage *RScaleImage(RImage *image, unsigned new_width, unsigned new_height);
365 RImage *RSmoothScaleImage(RImage *src, unsigned new_width,
366 unsigned new_height);
368 RImage *RRotateImage(RImage *image, float angle);
371 RImage *RMakeTiledImage(RImage *tile, unsigned width, unsigned height);
373 RImage* RMakeCenteredImage(RImage *image, unsigned width, unsigned height,
374 const RColor *color);
377 * Drawing
379 Bool RGetPixel(RImage *image, int x, int y, RColor *color);
381 void RPutPixel(RImage *image, int x, int y, const RColor *color);
383 void ROperatePixel(RImage *image, int operation, int x, int y, const RColor *color);
385 void RPutPixels(RImage *image, const RPoint *points, int npoints, int mode,
386 const RColor *color);
388 void ROperatePixels(RImage *image, int operation, const RPoint *points,
389 int npoints, int mode, const RColor *color);
391 int RDrawLine(RImage *image, int x0, int y0, int x1, int y1, const RColor *color);
393 int ROperateLine(RImage *image, int operation, int x0, int y0, int x1, int y1,
394 const RColor *color);
396 void RDrawLines(RImage *image, const RPoint *points, int npoints, int mode,
397 const RColor *color);
399 void ROperateLines(RImage *image, int operation, const RPoint *points, int npoints,
400 int mode, const RColor *color);
402 void RDrawSegments(RImage *image, const RSegment *segs, int nsegs, const RColor *color);
404 void ROperateSegments(RImage *image, int operation, const RSegment *segs, int nsegs,
405 const RColor *color);
408 * Color convertion
410 void RRGBtoHSV(const RColor *color, RHSVColor *hsv);
411 void RHSVtoRGB(const RHSVColor *hsv, RColor *rgb);
414 * Painting
416 void RClearImage(RImage *image, const RColor *color);
418 void RLightImage(RImage *image, const RColor *color);
420 void RFillImage(RImage *image, const RColor *color);
422 void RBevelImage(RImage *image, int bevel_type);
424 RImage *RRenderGradient(unsigned width, unsigned height, const RColor *from,
425 const RColor *to, int style);
428 RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor **colors,
429 int style);
432 RImage *RRenderInterwovenGradient(unsigned width, unsigned height,
433 RColor colors1[2], int thickness1,
434 RColor colors2[2], int thickness2);
438 * Convertion into X Pixmaps
440 int RConvertImage(RContext *context, RImage *image, Pixmap *pixmap);
442 int RConvertImageMask(RContext *context, RImage *image, Pixmap *pixmap,
443 Pixmap *mask, int threshold);
447 * misc. utilities
449 RXImage *RCreateXImage(RContext *context, int depth,
450 unsigned width, unsigned height);
452 RXImage *RGetXImage(RContext *context, Drawable d, int x, int y,
453 unsigned width, unsigned height);
455 void RDestroyXImage(RContext *context, RXImage *ximage);
457 void RPutXImage(RContext *context, Drawable d, GC gc, RXImage *ximage,
458 int src_x, int src_y, int dest_x, int dest_y,
459 unsigned width, unsigned height);
461 /* do not free the returned string! */
462 const char *RMessageForError(int errorCode);
464 int RBlurImage(RImage *image);
466 /****** Global Variables *******/
468 extern int RErrorCode;
470 #ifdef __cplusplus
472 #endif /* __cplusplus */
474 #endif