wrlib: add explicit type definition in API to allow compiler Type Checks (2/3)
[wmaker-crm.git] / wrlib / wraster.h
blob4bb1056a1c336d9772c088b69664e76bbb887fa8
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 USE_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)
85 /* image display modes */
86 typedef enum {
87 RDitheredRendering = 0,
88 RBestMatchRendering = 1
89 } RRenderingMode;
92 /* std colormap usage/creation modes */
93 typedef enum {
94 RUseStdColormap, /* default: fallbacks to RIgnore if there is none defined */
95 RCreateStdColormap,
96 RIgnoreStdColormap
97 } RStdColormapMode;
100 /* smoothed scaling filter types */
101 typedef enum {
102 RBoxFilter,
103 RTriangleFilter,
104 RBellFilter,
105 RBSplineFilter,
106 RLanczos3Filter,
107 RMitchellFilter
108 } RScalingFilter;
111 typedef struct RContextAttributes {
112 int flags;
113 RRenderingMode render_mode;
114 int colors_per_channel; /* for PseudoColor */
115 float rgamma; /* gamma correction for red, */
116 float ggamma; /* green, */
117 float bgamma; /* and blue */
118 VisualID visualid; /* visual ID to use */
119 int use_shared_memory; /* True of False */
120 RScalingFilter scaling_filter;
121 RStdColormapMode standard_colormap_mode; /* what to do with std cma */
122 } RContextAttributes;
126 * describes a screen in terms of depth, visual, number of colors
127 * we can use, if we should do dithering, and what colors to use for
128 * dithering.
130 typedef struct RContext {
131 Display *dpy;
132 int screen_number;
133 Colormap cmap;
135 RContextAttributes *attribs;
137 GC copy_gc;
139 Visual *visual;
140 int depth;
141 Window drawable; /* window to pass for XCreatePixmap().*/
142 /* generally = root */
143 int vclass;
145 unsigned long black;
146 unsigned long white;
148 int red_offset; /* only used in 24bpp */
149 int green_offset;
150 int blue_offset;
152 /* only used for pseudocolor and grayscale */
154 XStandardColormap *std_rgb_map; /* standard RGB colormap */
155 XStandardColormap *std_gray_map; /* standard grayscale colormap */
157 int ncolors; /* total number of colors we can use */
158 XColor *colors; /* internal colormap */
159 unsigned long *pixels; /* RContext->colors[].pixel */
161 struct {
162 unsigned int use_shared_pixmap:1;
163 } flags;
164 } RContext;
167 typedef struct RColor {
168 unsigned char red;
169 unsigned char green;
170 unsigned char blue;
171 unsigned char alpha;
172 } RColor;
175 typedef struct RHSVColor {
176 unsigned short hue; /* 0-359 */
177 unsigned char saturation; /* 0-255 */
178 unsigned char value; /* 0-255 */
179 } RHSVColor;
183 typedef struct RPoint {
184 int x, y;
185 } RPoint;
188 typedef struct RSegment {
189 int x1, y1, x2, y2;
190 } RSegment;
194 /* image formats */
195 enum RImageFormat {
196 RRGBFormat,
197 RRGBAFormat
202 * internal 24bit+alpha image representation
204 typedef struct RImage {
205 unsigned char *data; /* image data RGBA or RGB */
206 int width, height; /* size of the image */
207 enum RImageFormat format;
208 RColor background; /* background color */
209 int refCount;
210 } RImage;
214 * internal wrapper for XImage. Used for shm abstraction
216 typedef struct RXImage {
217 XImage *image;
219 /* Private data. Do not access */
220 #ifdef USE_XSHM
221 XShmSegmentInfo info;
222 char is_shared;
223 #endif
224 } RXImage;
227 /* note that not all operations are supported in all functions */
228 typedef enum {
229 RClearOperation, /* clear with 0 */
230 RCopyOperation,
231 RNormalOperation, /* same as combine */
232 RAddOperation,
233 RSubtractOperation
234 } RPixelOperation;
237 typedef enum {
238 RAbsoluteCoordinates = 0,
239 RRelativeCoordinates = 1
240 } RCoordinatesMode;
243 enum {
244 RSunkenBevel = -1,
245 RNoBevel = 0,
246 RRaisedBevel = 1
248 /* bw compat */
249 #define RBEV_SUNKEN RSunkenBevel
250 /* 1 pixel wide */
251 #define RBEV_RAISED RRaisedBevel
252 /* 1 pixel wide on top/left 2 on bottom/right */
253 #define RBEV_RAISED2 2
254 /* 2 pixel width */
255 #define RBEV_RAISED3 3
257 enum {
258 RHorizontalGradient = 2,
259 RVerticalGradient = 3,
260 RDiagonalGradient = 4
262 /* for backwards compatibility */
263 #define RGRD_HORIZONTAL RHorizontalGradient
264 #define RGRD_VERTICAL RVerticalGradient
265 #define RGRD_DIAGONAL RDiagonalGradient
269 /* error codes */
270 #define RERR_NONE 0
271 #define RERR_OPEN 1 /* cant open file */
272 #define RERR_READ 2 /* error reading from file */
273 #define RERR_WRITE 3 /* error writing to file */
274 #define RERR_NOMEMORY 4 /* out of memory */
275 #define RERR_NOCOLOR 5 /* out of color cells */
276 #define RERR_BADIMAGEFILE 6 /* image file is corrupted or invalid */
277 #define RERR_BADFORMAT 7 /* image file format is unknown */
278 #define RERR_BADINDEX 8 /* no such image index in file */
280 #define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
281 #define RERR_STDCMAPFAIL 17 /* failed to created std colormap */
283 #define RERR_XERROR 127 /* internal X error */
284 #define RERR_INTERNAL 128 /* should not happen */
288 * Cleaning before application exit
290 void RShutdown(void);
293 * Returns a NULL terminated array of strings containing the
294 * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
295 * Do not free the returned data.
297 char **RSupportedFileFormats(void);
300 char *RGetImageFileFormat(const char *file);
303 * Xlib contexts
305 RContext *RCreateContext(Display *dpy, int screen_number,
306 const RContextAttributes *attribs);
308 void RDestroyContext(RContext *context);
310 Bool RGetClosestXColor(RContext *context, const RColor *color, XColor *retColor);
313 * RImage creation
315 RImage *RCreateImage(unsigned width, unsigned height, int alpha);
317 RImage *RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask);
319 RImage *RCreateImageFromDrawable(RContext *context, Drawable drawable,
320 Pixmap mask);
322 RImage *RLoadImage(RContext *context, const char *file, int index);
324 RImage* RRetainImage(RImage *image);
326 void RReleaseImage(RImage *image);
328 RImage *RGetImageFromXPMData(RContext *context, char **xpmData);
331 * RImage storing
333 Bool RSaveImage(RImage *image, const char *filename, const char *format);
336 * Area manipulation
338 RImage *RCloneImage(RImage *image);
340 RImage *RGetSubImage(RImage *image, int x, int y, unsigned width,
341 unsigned height);
343 void RCombineImageWithColor(RImage *image, const RColor *color);
345 void RCombineImages(RImage *image, RImage *src);
347 void RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
348 unsigned height, int dx, int dy);
350 void RCopyArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
351 unsigned height, int dx, int dy);
353 void RCombineImagesWithOpaqueness(RImage *image, RImage *src, int opaqueness);
355 void RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
356 unsigned width, unsigned height, int dx, int dy,
357 int opaqueness);
359 void RCombineAlpha(unsigned char *d, unsigned char *s, int s_has_alpha,
360 int width, int height, int dwi, int swi, int opacity);
362 RImage *RScaleImage(RImage *image, unsigned new_width, unsigned new_height);
364 RImage *RSmoothScaleImage(RImage *src, unsigned new_width,
365 unsigned new_height);
367 RImage *RRotateImage(RImage *image, float angle);
369 RImage *RVerticalFlipImage(RImage *image);
371 RImage *RHorizontalFlipImage(RImage *image);
373 RImage *RMakeTiledImage(RImage *tile, unsigned width, unsigned height);
375 RImage* RMakeCenteredImage(RImage *image, unsigned width, unsigned height,
376 const RColor *color);
379 * Drawing
381 Bool RGetPixel(RImage *image, int x, int y, RColor *color);
383 void RPutPixel(RImage *image, int x, int y, const RColor *color);
385 void ROperatePixel(RImage *image, RPixelOperation operation, int x, int y, const RColor *color);
387 void RPutPixels(RImage *image, const RPoint *points, int npoints, RCoordinatesMode mode,
388 const RColor *color);
390 void ROperatePixels(RImage *image, RPixelOperation operation, const RPoint *points,
391 int npoints, RCoordinatesMode mode, const RColor *color);
393 int RDrawLine(RImage *image, int x0, int y0, int x1, int y1, const RColor *color);
395 int ROperateLine(RImage *image, RPixelOperation operation, int x0, int y0, int x1, int y1,
396 const RColor *color);
398 void RDrawLines(RImage *image, const RPoint *points, int npoints, RCoordinatesMode mode,
399 const RColor *color);
401 void ROperateLines(RImage *image, RPixelOperation operation, const RPoint *points, int npoints,
402 RCoordinatesMode mode, const RColor *color);
404 void ROperateRectangle(RImage *image, RPixelOperation operation, int x0, int y0, int x1, int y1, const RColor *color);
406 void RDrawSegments(RImage *image, const RSegment *segs, int nsegs, const RColor *color);
408 void ROperateSegments(RImage *image, RPixelOperation operation, const RSegment *segs, int nsegs,
409 const RColor *color);
412 * Color convertion
414 void RRGBtoHSV(const RColor *color, RHSVColor *hsv);
415 void RHSVtoRGB(const RHSVColor *hsv, RColor *rgb);
418 * Painting
420 void RClearImage(RImage *image, const RColor *color);
422 void RLightImage(RImage *image, const RColor *color);
424 void RFillImage(RImage *image, const RColor *color);
426 void RBevelImage(RImage *image, int bevel_type);
428 RImage *RRenderGradient(unsigned width, unsigned height, const RColor *from,
429 const RColor *to, int style);
432 RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor **colors,
433 int style);
436 RImage *RRenderInterwovenGradient(unsigned width, unsigned height,
437 RColor colors1[2], int thickness1,
438 RColor colors2[2], int thickness2);
442 * Convertion into X Pixmaps
444 int RConvertImage(RContext *context, RImage *image, Pixmap *pixmap);
446 int RConvertImageMask(RContext *context, RImage *image, Pixmap *pixmap,
447 Pixmap *mask, int threshold);
451 * misc. utilities
453 RXImage *RCreateXImage(RContext *context, int depth,
454 unsigned width, unsigned height);
456 RXImage *RGetXImage(RContext *context, Drawable d, int x, int y,
457 unsigned width, unsigned height);
459 void RDestroyXImage(RContext *context, RXImage *ximage);
461 void RPutXImage(RContext *context, Drawable d, GC gc, RXImage *ximage,
462 int src_x, int src_y, int dest_x, int dest_y,
463 unsigned width, unsigned height);
465 /* do not free the returned string! */
466 const char *RMessageForError(int errorCode);
468 int RBlurImage(RImage *image);
470 /****** Global Variables *******/
472 extern int RErrorCode;
474 #ifdef __cplusplus
476 #endif /* __cplusplus */
478 #endif