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,
23 * Environment variables:
25 * WRASTER_GAMMA <rgamma>/<ggamma>/<bgamma>
26 * gamma correction value. Must be greater than 0
27 * Only for PseudoColor visuals.
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
43 /* version of the header for the library */
44 #define WRASTER_HEADER_VERSION 22
48 #include <X11/Xutil.h>
51 #include <X11/extensions/XShm.h>
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 */
90 RUseStdColormap
, /* default. fallbacks to RIgnore.. if
91 there is none defined */
98 typedef struct RContextAttributes
{
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 */
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
117 typedef struct RContext
{
122 RContextAttributes
*attribs
;
128 Window drawable
; /* window to pass for XCreatePixmap().*/
129 /* generally = root */
135 int red_offset
; /* only used in 24bpp */
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 */
149 unsigned int use_shared_pixmap
:1;
154 typedef struct RColor
{
162 typedef struct RHSVColor
{
163 unsigned short hue
; /* 0-359 */
164 unsigned char saturation
; /* 0-255 */
165 unsigned char value
; /* 0-255 */
170 typedef struct RPoint
{
175 typedef struct RSegment
{
189 * internal 24bit+alpha image representation
191 typedef struct RImage
{
192 unsigned char *data
; /* image data RGBA or RGB */
193 int width
, height
; /* size of the image */
194 enum RImageFormat format
;
195 RColor background
; /* background color */
201 * internal wrapper for XImage. Used for shm abstraction
203 typedef struct RXImage
{
206 /* Private data. Do not access */
208 XShmSegmentInfo info
;
214 /* image display modes */
216 RDitheredRendering
= 0,
217 RBestMatchRendering
= 1
221 /* smoothed scaling filter types */
232 /* note that not all operations are supported in all functions */
234 RClearOperation
, /* clear with 0 */
236 RNormalOperation
, /* same as combine */
243 RAbsoluteCoordinates
= 0,
244 RRelativeCoordinates
= 1
254 #define RBEV_SUNKEN RSunkenBevel
256 #define RBEV_RAISED RRaisedBevel
257 /* 1 pixel wide on top/left 2 on bottom/right */
258 #define RBEV_RAISED2 2
260 #define RBEV_RAISED3 3
263 RHorizontalGradient
= 2,
264 RVerticalGradient
= 3,
265 RDiagonalGradient
= 4
267 /* for backwards compatibility */
268 #define RGRD_HORIZONTAL RHorizontalGradient
269 #define RGRD_VERTICAL RVerticalGradient
270 #define RGRD_DIAGONAL RDiagonalGradient
276 #define RERR_OPEN 1 /* cant open file */
277 #define RERR_READ 2 /* error reading from file */
278 #define RERR_WRITE 3 /* error writing to file */
279 #define RERR_NOMEMORY 4 /* out of memory */
280 #define RERR_NOCOLOR 5 /* out of color cells */
281 #define RERR_BADIMAGEFILE 6 /* image file is corrupted or invalid */
282 #define RERR_BADFORMAT 7 /* image file format is unknown */
283 #define RERR_BADINDEX 8 /* no such image index in file */
285 #define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
286 #define RERR_STDCMAPFAIL 17 /* failed to created std colormap */
288 #define RERR_XERROR 127 /* internal X error */
289 #define RERR_INTERNAL 128 /* should not happen */
293 * Cleaning before application exit
295 void RShutdown(void);
298 * Returns a NULL terminated array of strings containing the
299 * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
300 * Do not free the returned data.
302 char **RSupportedFileFormats(void);
305 char *RGetImageFileFormat(const char *file
);
310 RContext
*RCreateContext(Display
*dpy
, int screen_number
,
311 const RContextAttributes
*attribs
);
313 void RDestroyContext(RContext
*context
);
315 Bool
RGetClosestXColor(RContext
*context
, const RColor
*color
, XColor
*retColor
);
320 RImage
*RCreateImage(unsigned width
, unsigned height
, int alpha
);
322 RImage
*RCreateImageFromXImage(RContext
*context
, XImage
*image
, XImage
*mask
);
324 RImage
*RCreateImageFromDrawable(RContext
*context
, Drawable drawable
,
327 RImage
*RLoadImage(RContext
*context
, const char *file
, int index
);
329 RImage
* RRetainImage(RImage
*image
);
331 void RReleaseImage(RImage
*image
);
333 RImage
*RGetImageFromXPMData(RContext
*context
, char **xpmData
);
338 Bool
RSaveImage(RImage
*image
, const char *filename
, const char *format
);
343 RImage
*RCloneImage(RImage
*image
);
345 RImage
*RGetSubImage(RImage
*image
, int x
, int y
, unsigned width
,
348 void RCombineImageWithColor(RImage
*image
, const RColor
*color
);
350 void RCombineImages(RImage
*image
, RImage
*src
);
352 void RCombineArea(RImage
*image
, RImage
*src
, int sx
, int sy
, unsigned width
,
353 unsigned height
, int dx
, int dy
);
355 void RCopyArea(RImage
*image
, RImage
*src
, int sx
, int sy
, unsigned width
,
356 unsigned height
, int dx
, int dy
);
358 void RCombineImagesWithOpaqueness(RImage
*image
, RImage
*src
, int opaqueness
);
360 void RCombineAreaWithOpaqueness(RImage
*image
, RImage
*src
, int sx
, int sy
,
361 unsigned width
, unsigned height
, int dx
, int dy
,
364 void RCombineAlpha(unsigned char *d
, unsigned char *s
, int s_has_alpha
,
365 int width
, int height
, int dwi
, int swi
, int opacity
);
367 RImage
*RScaleImage(RImage
*image
, unsigned new_width
, unsigned new_height
);
369 RImage
*RSmoothScaleImage(RImage
*src
, unsigned new_width
,
370 unsigned new_height
);
372 RImage
*RRotateImage(RImage
*image
, float angle
);
374 RImage
*RVerticalFlipImage(RImage
*image
);
376 RImage
*RHorizontalFlipImage(RImage
*image
);
378 RImage
*RMakeTiledImage(RImage
*tile
, unsigned width
, unsigned height
);
380 RImage
* RMakeCenteredImage(RImage
*image
, unsigned width
, unsigned height
,
381 const RColor
*color
);
386 Bool
RGetPixel(RImage
*image
, int x
, int y
, RColor
*color
);
388 void RPutPixel(RImage
*image
, int x
, int y
, const RColor
*color
);
390 void ROperatePixel(RImage
*image
, int operation
, int x
, int y
, const RColor
*color
);
392 void RPutPixels(RImage
*image
, const RPoint
*points
, int npoints
, int mode
,
393 const RColor
*color
);
395 void ROperatePixels(RImage
*image
, int operation
, const RPoint
*points
,
396 int npoints
, int mode
, const RColor
*color
);
398 int RDrawLine(RImage
*image
, int x0
, int y0
, int x1
, int y1
, const RColor
*color
);
400 int ROperateLine(RImage
*image
, int operation
, int x0
, int y0
, int x1
, int y1
,
401 const RColor
*color
);
403 void RDrawLines(RImage
*image
, const RPoint
*points
, int npoints
, int mode
,
404 const RColor
*color
);
406 void ROperateLines(RImage
*image
, int operation
, const RPoint
*points
, int npoints
,
407 int mode
, const RColor
*color
);
409 void ROperateRectangle(RImage
*image
, int operation
, int x0
, int y0
, int x1
, int y1
, const RColor
*color
);
411 void RDrawSegments(RImage
*image
, const RSegment
*segs
, int nsegs
, const RColor
*color
);
413 void ROperateSegments(RImage
*image
, int operation
, const RSegment
*segs
, int nsegs
,
414 const RColor
*color
);
419 void RRGBtoHSV(const RColor
*color
, RHSVColor
*hsv
);
420 void RHSVtoRGB(const RHSVColor
*hsv
, RColor
*rgb
);
425 void RClearImage(RImage
*image
, const RColor
*color
);
427 void RLightImage(RImage
*image
, const RColor
*color
);
429 void RFillImage(RImage
*image
, const RColor
*color
);
431 void RBevelImage(RImage
*image
, int bevel_type
);
433 RImage
*RRenderGradient(unsigned width
, unsigned height
, const RColor
*from
,
434 const RColor
*to
, int style
);
437 RImage
*RRenderMultiGradient(unsigned width
, unsigned height
, RColor
**colors
,
441 RImage
*RRenderInterwovenGradient(unsigned width
, unsigned height
,
442 RColor colors1
[2], int thickness1
,
443 RColor colors2
[2], int thickness2
);
447 * Convertion into X Pixmaps
449 int RConvertImage(RContext
*context
, RImage
*image
, Pixmap
*pixmap
);
451 int RConvertImageMask(RContext
*context
, RImage
*image
, Pixmap
*pixmap
,
452 Pixmap
*mask
, int threshold
);
458 RXImage
*RCreateXImage(RContext
*context
, int depth
,
459 unsigned width
, unsigned height
);
461 RXImage
*RGetXImage(RContext
*context
, Drawable d
, int x
, int y
,
462 unsigned width
, unsigned height
);
464 void RDestroyXImage(RContext
*context
, RXImage
*ximage
);
466 void RPutXImage(RContext
*context
, Drawable d
, GC gc
, RXImage
*ximage
,
467 int src_x
, int src_y
, int dest_x
, int dest_y
,
468 unsigned width
, unsigned height
);
470 /* do not free the returned string! */
471 const char *RMessageForError(int errorCode
);
473 int RBlurImage(RImage
*image
);
475 /****** Global Variables *******/
477 extern int RErrorCode
;
481 #endif /* __cplusplus */