2 * Raster graphics library
4 * Copyright (c) 1997, 1998, 1999 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., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Environment variables:
24 * WRASTER_GAMMA <rgamma>/<ggamma>/<bgamma>
25 * gamma correction value. Must be greater than 0
26 * Only for PseudoColor visuals.
32 * If you want a specific value for a screen, append the screen number
33 * preceded by a hash to the variable name as in
42 /* version of the header for the library: 0.15 */
43 #define WRASTER_HEADER_VERSION 15
47 #include <X11/Xutil.h>
50 #include <X11/extensions/XShm.h>
53 /* RBestMatchRendering or RDitheredRendering */
54 #define RC_RenderMode (1<<0)
56 /* number of colors per channel for colormap in PseudoColor mode */
57 #define RC_ColorsPerChannel (1<<1)
59 /* do gamma correction */
60 #define RC_GammaCorrection (1<<2)
62 /* visual id to use */
63 #define RC_VisualID (1<<3)
65 /* shared memory usage */
66 #define RC_UseSharedMemory (1<<4)
68 /* use default instead of best visual */
69 #define RC_DefaultVisual (1<<5)
71 /* filter type for smoothed scaling */
72 #define RC_ScalingFilter (1<<6)
76 #endif /* __cplusplus */
78 typedef struct RContextAttributes
{
81 int colors_per_channel
; /* for PseudoColor */
82 float rgamma
; /* gamma correction for red, */
83 float ggamma
; /* green, */
84 float bgamma
; /* and blue */
85 VisualID visualid
; /* visual ID to use */
86 int use_shared_memory
; /* True of False */
92 * describes a screen in terms of depth, visual, number of colors
93 * we can use, if we should do dithering, and what colors to use for
96 typedef struct RContext
{
101 RContextAttributes
*attribs
;
107 Window drawable
; /* window to pass for XCreatePixmap().*/
108 /* generally = root */
114 int red_offset
; /* only used in 24bpp */
118 /* only used for pseudocolor and grayscale */
120 XStandardColormap
*std_rgb_map
; /* standard RGB colormap */
121 XStandardColormap
*std_gray_map
; /* standard grayscale colormap */
123 int ncolors
; /* total number of colors we can use */
124 XColor
*colors
; /* internal colormap */
127 unsigned int use_shared_pixmap
:1;
132 typedef struct RColor
{
140 typedef struct RHSVColor
{
141 unsigned short hue
; /* 0-359 */
142 unsigned char saturation
; /* 0-255 */
143 unsigned char value
; /* 0-255 */
148 typedef struct RPoint
{
153 typedef struct RSegment
{
159 * internal 24bit+alpha image representation
161 typedef struct RImage
{
162 unsigned width
, height
; /* size of the image */
163 RColor background
; /* background color */
164 unsigned char *data
[4]; /* image data (R,G,B,A) */
169 * internal wrapper for XImage. Used for shm abstraction
171 typedef struct RXImage
{
174 /* Private data. Do not access */
176 XShmSegmentInfo info
;
183 /* image display modes */
185 RDitheredRendering
= 0,
186 RBestMatchRendering
= 1
190 /* smoothed scaling filter types */
201 /* note that not all operations are supported in all functions */
203 RClearOperation
, /* clear with 0 */
205 RNormalOperation
, /* same as combine */
212 RAbsoluteCoordinates
= 0,
213 RRelativeCoordinates
= 1
223 #define RBEV_SUNKEN RSunkenBevel
225 #define RBEV_RAISED RRaisedBevel
226 /* 1 pixel wide on top/left 2 on bottom/right */
227 #define RBEV_RAISED2 2
229 #define RBEV_RAISED3 3
232 RHorizontalGradient
= 2,
233 RVerticalGradient
= 3,
234 RDiagonalGradient
= 4
236 /* for backwards compatibility */
237 #define RGRD_HORIZONTAL RHorizontalGradient
238 #define RGRD_VERTICAL RVerticalGradient
239 #define RGRD_DIAGONAL RDiagonalGradient
245 #define RERR_OPEN 1 /* cant open file */
246 #define RERR_READ 2 /* error reading from file */
247 #define RERR_WRITE 3 /* error writing to file */
248 #define RERR_NOMEMORY 4 /* out of memory */
249 #define RERR_NOCOLOR 5 /* out of color cells */
250 #define RERR_BADIMAGEFILE 6 /* image file is corrupted or invalid */
251 #define RERR_BADFORMAT 7 /* image file format is unknown */
252 #define RERR_BADINDEX 8 /* no such image index in file */
254 #define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
256 #define RERR_XERROR 127 /* internal X error */
257 #define RERR_INTERNAL 128 /* should not happen */
261 * Returns a NULL terminated array of strings containing the
262 * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
263 * Do not free the returned data.
265 char **RSupportedFileFormats(void);
268 char *RGetImageFileFormat(char *file
);
273 RContext
*RCreateContext(Display
*dpy
, int screen_number
,
274 RContextAttributes
*attribs
);
276 void RDestroyContext(RContext
*context
);
278 Bool
RGetClosestXColor(RContext
*context
, RColor
*color
, XColor
*retColor
);
283 RImage
*RCreateImage(unsigned width
, unsigned height
, int alpha
);
285 RImage
*RCreateImageFromXImage(RContext
*context
, XImage
*image
, XImage
*mask
);
287 RImage
*RCreateImageFromDrawable(RContext
*context
, Drawable drawable
,
290 RImage
*RLoadImage(RContext
*context
, char *file
, int index
);
293 void RDestroyImage(RImage
*image
);
295 RImage
*RGetImageFromXPMData(RContext
*context
, char **data
);
300 Bool
RSaveImage(RImage
*image
, char *filename
, char *format
);
305 RImage
*RCloneImage(RImage
*image
);
307 RImage
*RGetSubImage(RImage
*image
, int x
, int y
, unsigned width
,
310 void RCombineImageWithColor(RImage
*image
, RColor
*color
);
312 void RCombineImages(RImage
*image
, RImage
*src
);
314 void RCombineArea(RImage
*image
, RImage
*src
, int sx
, int sy
, unsigned width
,
315 unsigned height
, int dx
, int dy
);
317 void RCombineImagesWithOpaqueness(RImage
*image
, RImage
*src
, int opaqueness
);
319 void RCombineAreaWithOpaqueness(RImage
*image
, RImage
*src
, int sx
, int sy
,
320 unsigned width
, unsigned height
, int dx
, int dy
,
323 RImage
*RScaleImage(RImage
*image
, unsigned new_width
, unsigned new_height
);
325 RImage
*RSmoothScaleImage(RImage
*src
, unsigned new_width
,
326 unsigned new_height
);
328 RImage
*RMakeTiledImage(RImage
*tile
, unsigned width
, unsigned height
);
330 RImage
* RMakeCenteredImage(RImage
*image
, unsigned width
, unsigned height
,
336 Bool
RGetPixel(RImage
*image
, int x
, int y
, RColor
*color
);
338 void RPutPixel(RImage
*image
, int x
, int y
, RColor
*color
);
340 void ROperatePixel(RImage
*image
, int operation
, int x
, int y
, RColor
*color
);
342 void RPutPixels(RImage
*image
, RPoint
*points
, int npoints
, int mode
,
345 void ROperatePixels(RImage
*image
, int operation
, RPoint
*points
,
346 int npoints
, int mode
, RColor
*color
);
348 int RDrawLine(RImage
*image
, int x0
, int y0
, int x1
, int y1
, RColor
*color
);
350 int ROperateLine(RImage
*image
, int operation
, int x0
, int y0
, int x1
, int y1
,
353 void RDrawLines(RImage
*image
, RPoint
*points
, int npoints
, int mode
,
356 void ROperateLines(RImage
*image
, int operation
, RPoint
*points
, int npoints
,
357 int mode
, RColor
*color
);
359 void RDrawSegments(RImage
*image
, RSegment
*segs
, int nsegs
, RColor
*color
);
361 void ROperateSegments(RImage
*image
, int operation
, RSegment
*segs
, int nsegs
,
367 void RRGBtoHSV(RColor
*color
, RHSVColor
*hsv
);
368 void RHSVtoRGB(RHSVColor
*hsv
, RColor
*rgb
);
373 void RClearImage(RImage
*image
, RColor
*color
);
375 void RBevelImage(RImage
*image
, int bevel_type
);
377 RImage
*RRenderGradient(unsigned width
, unsigned height
, RColor
*from
,
378 RColor
*to
, int style
);
381 RImage
*RRenderMultiGradient(unsigned width
, unsigned height
, RColor
**colors
,
387 * Convertion into X Pixmaps
389 int RConvertImage(RContext
*context
, RImage
*image
, Pixmap
*pixmap
);
391 int RConvertImageMask(RContext
*context
, RImage
*image
, Pixmap
*pixmap
,
392 Pixmap
*mask
, int threshold
);
398 RXImage
*RCreateXImage(RContext
*context
, int depth
,
399 unsigned width
, unsigned height
);
401 RXImage
*RGetXImage(RContext
*context
, Drawable d
, int x
, int y
,
402 unsigned width
, unsigned height
);
404 void RDestroyXImage(RContext
*context
, RXImage
*ximage
);
406 void RPutXImage(RContext
*context
, Drawable d
, GC gc
, RXImage
*ximage
,
407 int src_x
, int src_y
, int dest_x
, int dest_y
,
408 unsigned width
, unsigned height
);
410 /* do not free the returned string! */
411 const char *RMessageForError(int errorCode
);
413 int RBlurImage(RImage
*image
);
415 /****** Global Variables *******/
417 extern int RErrorCode
;
421 #endif /* __cplusplus */