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;
150 unsigned int optimize_for_speed
:1;
155 typedef struct RColor
{
163 typedef struct RHSVColor
{
164 unsigned short hue
; /* 0-359 */
165 unsigned char saturation
; /* 0-255 */
166 unsigned char value
; /* 0-255 */
171 typedef struct RPoint
{
176 typedef struct RSegment
{
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 */
202 * internal wrapper for XImage. Used for shm abstraction
204 typedef struct RXImage
{
207 /* Private data. Do not access */
209 XShmSegmentInfo info
;
215 /* image display modes */
217 RDitheredRendering
= 0,
218 RBestMatchRendering
= 1
222 /* smoothed scaling filter types */
233 /* note that not all operations are supported in all functions */
235 RClearOperation
, /* clear with 0 */
237 RNormalOperation
, /* same as combine */
244 RAbsoluteCoordinates
= 0,
245 RRelativeCoordinates
= 1
255 #define RBEV_SUNKEN RSunkenBevel
257 #define RBEV_RAISED RRaisedBevel
258 /* 1 pixel wide on top/left 2 on bottom/right */
259 #define RBEV_RAISED2 2
261 #define RBEV_RAISED3 3
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
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
);
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
);
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
,
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
);
334 Bool
RSaveImage(RImage
*image
, const char *filename
, const char *format
);
339 RImage
*RCloneImage(RImage
*image
);
341 RImage
*RGetSubImage(RImage
*image
, int x
, int y
, unsigned width
,
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
,
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
);
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
);
410 void RRGBtoHSV(const RColor
*color
, RHSVColor
*hsv
);
411 void RHSVtoRGB(const RHSVColor
*hsv
, RColor
*rgb
);
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
,
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
);
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
;
472 #endif /* __cplusplus */