wrlib: re-introduce the optimize_for_speed flag for binary compatibility
[wmaker-crm.git] / wrlib / wraster.h
blob992a8e95bcbe0377b7af6cf9a2bb6558d0908622
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
56 * Define some macro to provide attributes for the compiler
58 * These attributes help producing better code and/or detecting bugs, however not all compiler support them
59 * as they are not standard.
60 * Because we're a public API header, we can't count on autoconf to detect them for us, so we use that #if
61 * mechanism and define an internal macro appropriately. Please note that the macro are not considered being
62 * part of the public API.
64 #if __GNUC__ >= 3
65 #define __wrlib_deprecated(msg) __attribute__ ((deprecated(msg)))
66 #else
67 #define __wrlib_deprecated(msg)
68 #endif
71 #ifdef __cplusplus
72 extern "C" {
73 #endif /* __cplusplus */
75 /* RBestMatchRendering or RDitheredRendering */
76 #define RC_RenderMode (1<<0)
78 /* number of colors per channel for colormap in PseudoColor mode */
79 #define RC_ColorsPerChannel (1<<1)
81 /* do gamma correction */
82 #define RC_GammaCorrection (1<<2)
84 /* visual id to use */
85 #define RC_VisualID (1<<3)
87 /* shared memory usage */
88 #define RC_UseSharedMemory (1<<4)
90 /* use default instead of best visual */
91 #define RC_DefaultVisual (1<<5)
93 /* filter type for smoothed scaling */
94 #define RC_ScalingFilter (1<<6)
96 /* standard colormap usage */
97 #define RC_StandardColormap (1<<7)
101 /* image display modes */
102 typedef enum {
103 RDitheredRendering = 0,
104 RBestMatchRendering = 1
105 } RRenderingMode;
108 /* std colormap usage/creation modes */
109 typedef enum {
110 RUseStdColormap, /* default: fallbacks to RIgnore if there is none defined */
111 RCreateStdColormap,
112 RIgnoreStdColormap
113 } RStdColormapMode;
116 /* smoothed scaling filter types */
117 typedef enum {
118 RBoxFilter,
119 RTriangleFilter,
120 RBellFilter,
121 RBSplineFilter,
122 RLanczos3Filter,
123 RMitchellFilter
124 } RScalingFilter;
127 typedef struct RContextAttributes {
128 int flags;
129 RRenderingMode render_mode;
130 int colors_per_channel; /* for PseudoColor */
131 float rgamma; /* gamma correction for red, */
132 float ggamma; /* green, */
133 float bgamma; /* and blue */
134 VisualID visualid; /* visual ID to use */
135 int use_shared_memory; /* True of False */
136 RScalingFilter scaling_filter;
137 RStdColormapMode standard_colormap_mode; /* what to do with std cma */
138 } RContextAttributes;
142 * describes a screen in terms of depth, visual, number of colors
143 * we can use, if we should do dithering, and what colors to use for
144 * dithering.
146 typedef struct RContext {
147 Display *dpy;
148 int screen_number;
149 Colormap cmap;
151 RContextAttributes *attribs;
153 GC copy_gc;
155 Visual *visual;
156 int depth;
157 Window drawable; /* window to pass for XCreatePixmap().*/
158 /* generally = root */
159 int vclass;
161 unsigned long black;
162 unsigned long white;
164 int red_offset; /* only used in 24bpp */
165 int green_offset;
166 int blue_offset;
168 /* only used for pseudocolor and grayscale */
170 XStandardColormap *std_rgb_map; /* standard RGB colormap */
171 XStandardColormap *std_gray_map; /* standard grayscale colormap */
173 int ncolors; /* total number of colors we can use */
174 XColor *colors; /* internal colormap */
175 unsigned long *pixels; /* RContext->colors[].pixel */
177 struct {
178 unsigned int use_shared_pixmap:1;
179 unsigned int optimize_for_speed:1
180 __wrlib_deprecated("Flag optimize_for_speed in RContext is not used anymore "
181 "and will be removed in future version, please do not use");
182 } flags;
183 } RContext;
186 typedef struct RColor {
187 unsigned char red;
188 unsigned char green;
189 unsigned char blue;
190 unsigned char alpha;
191 } RColor;
194 typedef struct RHSVColor {
195 unsigned short hue; /* 0-359 */
196 unsigned char saturation; /* 0-255 */
197 unsigned char value; /* 0-255 */
198 } RHSVColor;
202 typedef struct RPoint {
203 int x, y;
204 } RPoint;
207 typedef struct RSegment {
208 int x1, y1, x2, y2;
209 } RSegment;
213 /* image formats */
214 enum RImageFormat {
215 RRGBFormat,
216 RRGBAFormat
221 * internal 24bit+alpha image representation
223 typedef struct RImage {
224 unsigned char *data; /* image data RGBA or RGB */
225 int width, height; /* size of the image */
226 enum RImageFormat format;
227 RColor background; /* background color */
228 int refCount;
229 } RImage;
233 * internal wrapper for XImage. Used for shm abstraction
235 typedef struct RXImage {
236 XImage *image;
238 /* Private data. Do not access */
239 #ifdef USE_XSHM
240 XShmSegmentInfo info;
241 char is_shared;
242 #endif
243 } RXImage;
246 /* note that not all operations are supported in all functions */
247 typedef enum {
248 RClearOperation, /* clear with 0 */
249 RCopyOperation,
250 RNormalOperation, /* same as combine */
251 RAddOperation,
252 RSubtractOperation
253 } RPixelOperation;
256 typedef enum {
257 RAbsoluteCoordinates = 0,
258 RRelativeCoordinates = 1
259 } RCoordinatesMode;
262 enum {
263 RSunkenBevel = -1,
264 RNoBevel = 0,
265 RRaisedBevel = 1
267 /* bw compat */
268 #define RBEV_SUNKEN RSunkenBevel
269 /* 1 pixel wide */
270 #define RBEV_RAISED RRaisedBevel
271 /* 1 pixel wide on top/left 2 on bottom/right */
272 #define RBEV_RAISED2 2
273 /* 2 pixel width */
274 #define RBEV_RAISED3 3
276 typedef enum {
277 RHorizontalGradient = 2,
278 RVerticalGradient = 3,
279 RDiagonalGradient = 4
280 } RGradientStyle;
281 /* for backwards compatibility */
282 #define RGRD_HORIZONTAL RHorizontalGradient
283 #define RGRD_VERTICAL RVerticalGradient
284 #define RGRD_DIAGONAL RDiagonalGradient
288 * How an image can be flipped, for RFlipImage
290 * Values are actually bit-mask which can be OR'd
292 #define RHorizontalFlip 0x0001
293 #define RVerticalFlip 0x0002
296 /* error codes */
297 #define RERR_NONE 0
298 #define RERR_OPEN 1 /* cant open file */
299 #define RERR_READ 2 /* error reading from file */
300 #define RERR_WRITE 3 /* error writing to file */
301 #define RERR_NOMEMORY 4 /* out of memory */
302 #define RERR_NOCOLOR 5 /* out of color cells */
303 #define RERR_BADIMAGEFILE 6 /* image file is corrupted or invalid */
304 #define RERR_BADFORMAT 7 /* image file format is unknown */
305 #define RERR_BADINDEX 8 /* no such image index in file */
307 #define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
308 #define RERR_STDCMAPFAIL 17 /* failed to created std colormap */
310 #define RERR_XERROR 127 /* internal X error */
311 #define RERR_INTERNAL 128 /* should not happen */
315 * Cleaning before application exit
317 void RShutdown(void);
320 * Returns a NULL terminated array of strings containing the
321 * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
322 * Do not free the returned data.
324 char **RSupportedFileFormats(void);
327 char *RGetImageFileFormat(const char *file);
330 * Xlib contexts
332 RContext *RCreateContext(Display *dpy, int screen_number,
333 const RContextAttributes *attribs);
335 void RDestroyContext(RContext *context);
337 Bool RGetClosestXColor(RContext *context, const RColor *color, XColor *retColor);
340 * RImage creation
342 RImage *RCreateImage(unsigned width, unsigned height, int alpha);
344 RImage *RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask);
346 RImage *RCreateImageFromDrawable(RContext *context, Drawable drawable,
347 Pixmap mask);
349 RImage *RLoadImage(RContext *context, const char *file, int index);
351 RImage* RRetainImage(RImage *image);
353 void RReleaseImage(RImage *image);
355 RImage *RGetImageFromXPMData(RContext *context, char **xpmData);
358 * RImage storing
360 Bool RSaveImage(RImage *image, const char *filename, const char *format);
363 * Area manipulation
365 RImage *RCloneImage(RImage *image);
367 RImage *RGetSubImage(RImage *image, int x, int y, unsigned width,
368 unsigned height);
370 void RCombineImageWithColor(RImage *image, const RColor *color);
372 void RCombineImages(RImage *image, RImage *src);
374 void RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
375 unsigned height, int dx, int dy);
377 void RCopyArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
378 unsigned height, int dx, int dy);
380 void RCombineImagesWithOpaqueness(RImage *image, RImage *src, int opaqueness);
382 void RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
383 unsigned width, unsigned height, int dx, int dy,
384 int opaqueness);
386 void RCombineAlpha(unsigned char *d, unsigned char *s, int s_has_alpha,
387 int width, int height, int dwi, int swi, int opacity);
389 RImage *RScaleImage(RImage *image, unsigned new_width, unsigned new_height);
391 RImage *RSmoothScaleImage(RImage *src, unsigned new_width,
392 unsigned new_height);
394 RImage *RRotateImage(RImage *image, float angle);
396 RImage *RFlipImage(RImage *image, int mode);
398 RImage *RMakeTiledImage(RImage *tile, unsigned width, unsigned height);
400 RImage* RMakeCenteredImage(RImage *image, unsigned width, unsigned height,
401 const RColor *color);
404 * Drawing
406 Bool RGetPixel(RImage *image, int x, int y, RColor *color);
408 void RPutPixel(RImage *image, int x, int y, const RColor *color);
410 void ROperatePixel(RImage *image, RPixelOperation operation, int x, int y, const RColor *color);
412 void RPutPixels(RImage *image, const RPoint *points, int npoints, RCoordinatesMode mode,
413 const RColor *color);
415 void ROperatePixels(RImage *image, RPixelOperation operation, const RPoint *points,
416 int npoints, RCoordinatesMode mode, const RColor *color);
418 int RDrawLine(RImage *image, int x0, int y0, int x1, int y1, const RColor *color);
420 int ROperateLine(RImage *image, RPixelOperation operation, int x0, int y0, int x1, int y1,
421 const RColor *color);
423 void RDrawLines(RImage *image, const RPoint *points, int npoints, RCoordinatesMode mode,
424 const RColor *color);
426 void ROperateLines(RImage *image, RPixelOperation operation, const RPoint *points, int npoints,
427 RCoordinatesMode mode, const RColor *color);
429 void ROperateRectangle(RImage *image, RPixelOperation operation, int x0, int y0, int x1, int y1, const RColor *color);
431 void RDrawSegments(RImage *image, const RSegment *segs, int nsegs, const RColor *color);
433 void ROperateSegments(RImage *image, RPixelOperation operation, const RSegment *segs, int nsegs,
434 const RColor *color);
437 * Color convertion
439 void RRGBtoHSV(const RColor *color, RHSVColor *hsv);
440 void RHSVtoRGB(const RHSVColor *hsv, RColor *rgb);
443 * Painting
445 void RClearImage(RImage *image, const RColor *color);
447 void RLightImage(RImage *image, const RColor *color);
449 void RFillImage(RImage *image, const RColor *color);
451 void RBevelImage(RImage *image, int bevel_type);
453 RImage *RRenderGradient(unsigned width, unsigned height, const RColor *from,
454 const RColor *to, RGradientStyle style);
457 RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor **colors,
458 RGradientStyle style);
461 RImage *RRenderInterwovenGradient(unsigned width, unsigned height,
462 RColor colors1[2], int thickness1,
463 RColor colors2[2], int thickness2);
467 * Convertion into X Pixmaps
469 int RConvertImage(RContext *context, RImage *image, Pixmap *pixmap);
471 int RConvertImageMask(RContext *context, RImage *image, Pixmap *pixmap,
472 Pixmap *mask, int threshold);
476 * misc. utilities
478 RXImage *RCreateXImage(RContext *context, int depth,
479 unsigned width, unsigned height);
481 RXImage *RGetXImage(RContext *context, Drawable d, int x, int y,
482 unsigned width, unsigned height);
484 void RDestroyXImage(RContext *context, RXImage *ximage);
486 void RPutXImage(RContext *context, Drawable d, GC gc, RXImage *ximage,
487 int src_x, int src_y, int dest_x, int dest_y,
488 unsigned width, unsigned height);
490 /* do not free the returned string! */
491 const char *RMessageForError(int errorCode);
493 int RBlurImage(RImage *image);
495 /****** Global Variables *******/
497 extern int RErrorCode;
499 #ifdef __cplusplus
501 #endif /* __cplusplus */
504 * The definitions below are done for internal use only
505 * We undef them so users of the library may not misuse them
507 #undef __wrlib_deprecated
509 #endif