3 * Raster graphics library
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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: 0.11 */
44 #define WRASTER_HEADER_VERSION 11
52 #include <X11/Xutil.h>
55 #include <X11/extensions/XShm.h>
58 /* RM_MATCH or RM_DITHER */
59 #define RC_RenderMode (1<<0)
61 /* number of colors per channel for colormap in PseudoColor mode */
62 #define RC_ColorsPerChannel (1<<1)
64 /* do gamma correction */
65 #define RC_GammaCorrection (1<<2)
67 /* visual id to use */
68 #define RC_VisualID (1<<3)
70 /* shared memory usage */
71 #define RC_UseSharedMemory (1<<4)
73 /* use default instead of best visual */
74 #define RC_DefaultVisual (1<<5)
76 typedef struct RContextAttributes
{
79 int colors_per_channel
; /* for PseudoColor */
80 float rgamma
; /* gamma correction for red, */
81 float ggamma
; /* green, */
82 float bgamma
; /* and blue */
83 VisualID visualid
; /* visual ID to use */
84 int use_shared_memory
; /* True of False */
89 * describes a screen in terms of depth, visual, number of colors
90 * we can use, if we should do dithering, and what colors to use for
93 typedef struct RContext
{
98 RContextAttributes
*attribs
;
104 Window drawable
; /* window to pass for XCreatePixmap(). */
105 /* generally = root */
111 int red_offset
; /* only used in 24bpp */
115 /* only used for pseudocolor and grayscale */
117 XStandardColormap
*std_rgb_map
; /* standard RGB colormap */
118 XStandardColormap
*std_gray_map
; /* standard grayscale colormap */
120 int ncolors
; /* total number of colors we can use */
121 XColor
*colors
; /* internal colormap */
124 unsigned int use_shared_pixmap
:1;
129 typedef struct RColor
{
137 typedef struct RHSVColor
{
138 unsigned short hue
; /* 0-359 */
139 unsigned char saturation
; /* 0-255 */
140 unsigned char value
; /* 0-255 */
145 typedef struct RPoint
{
150 typedef struct RSegment
{
156 * internal 24bit+alpha image representation
158 typedef struct RImage
{
159 unsigned width
, height
; /* size of the image */
160 RColor background
; /* background color */
161 unsigned char *data
[4]; /* image data (R,G,B,A) */
166 * internal wrapper for XImage. Used for shm abstraction
168 typedef struct RXImage
{
171 /* Private data. Do not access */
173 XShmSegmentInfo info
;
179 /* note that not all operations are supported in all functions */
181 RClearOperation
, /* clear with 0 */
183 RNormalOperation
, /* same as combine */
189 /* image display modes */
191 RDitheredRendering
= 0,
192 RBestMatchRendering
= 1
196 #define RM_DITHER RDitheredRendering
197 #define RM_MATCH RBestMatchRendering
200 RAbsoluteCoordinates
= 0,
201 RRelativeCoordinates
= 1
211 #define RBEV_SUNKEN RSunkenBevel
213 #define RBEV_RAISED RRaisedBevel
214 /* 1 pixel wide on top/left 2 on bottom/right */
215 #define RBEV_RAISED2 2
217 #define RBEV_RAISED3 3
220 RHorizontalGradient
= 2,
221 RVerticalGradient
= 3,
222 RDiagonalGradient
= 4
225 /* for backwards compatibility */
226 #define RGRD_HORIZONTAL RHorizontalGradient
227 #define RGRD_VERTICAL RVerticalGradient
228 #define RGRD_DIAGONAL RDiagonalGradient
234 #define RERR_OPEN 1 /* cant open file */
235 #define RERR_READ 2 /* error reading from file */
236 #define RERR_WRITE 3 /* error writing to file */
237 #define RERR_NOMEMORY 4 /* out of memory */
238 #define RERR_NOCOLOR 5 /* out of color cells */
239 #define RERR_BADIMAGEFILE 6 /* image file is corrupted or invalid */
240 #define RERR_BADFORMAT 7 /* image file format is unknown */
241 #define RERR_BADINDEX 8 /* no such image index in file */
243 #define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
245 #define RERR_XERROR 127 /* internal X error */
246 #define RERR_INTERNAL 128 /* should not happen */
250 * Returns a NULL terminated array of strings containing the
251 * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
253 char **RSupportedFileFormats(void);
255 void RFreeStringList(char **list
);
260 RContext
*RCreateContext(Display
* dpy
, int screen_number
,
261 RContextAttributes
* attribs
);
263 void RDestroyContext(RContext
* context
);
265 Bool
RGetClosestXColor(RContext
* context
, RColor
* color
, XColor
* retColor
);
270 RImage
*RCreateImage(unsigned width
, unsigned height
, int alpha
);
272 RImage
*RCreateImageFromXImage(RContext
* context
, XImage
* image
, XImage
* mask
);
274 RImage
*RCreateImageFromDrawable(RContext
* context
, Drawable drawable
,
277 RImage
*RLoadImage(RContext
* context
, char *file
, int index
);
280 void RDestroyImage(RImage
* image
);
282 RImage
*RGetImageFromXPMData(RContext
* context
, char **data
);
287 Bool
RSaveImage(RImage
* image
, char *filename
, char *format
);
292 RImage
*RCloneImage(RImage
* image
);
294 RImage
*RGetSubImage(RImage
* image
, int x
, int y
, unsigned width
,
297 void RCombineImageWithColor(RImage
* image
, RColor
* color
);
299 void RCombineImages(RImage
* image
, RImage
* src
);
301 void RCombineArea(RImage
* image
, RImage
* src
, int sx
, int sy
, unsigned width
,
302 unsigned height
, int dx
, int dy
);
304 void RCombineImagesWithOpaqueness(RImage
* image
, RImage
* src
, int opaqueness
);
306 void RCombineAreaWithOpaqueness(RImage
* image
, RImage
* src
, int sx
, int sy
,
307 unsigned width
, unsigned height
, int dx
, int dy
,
310 RImage
*RScaleImage(RImage
* image
, unsigned new_width
, unsigned new_height
);
312 RImage
*RMakeTiledImage(RImage
* tile
, unsigned width
, unsigned height
);
314 RImage
*RMakeCenteredImage(RImage
* image
, unsigned width
, unsigned height
,
320 Bool
RGetPixel(RImage
* image
, int x
, int y
, RColor
* color
);
322 void RPutPixel(RImage
* image
, int x
, int y
, RColor
* color
);
324 void ROperatePixel(RImage
* image
, int operation
, int x
, int y
, RColor
* color
);
326 void RPutPixels(RImage
* image
, RPoint
* points
, int npoints
, int mode
,
329 void ROperatePixels(RImage
* image
, int operation
, RPoint
* points
,
330 int npoints
, int mode
, RColor
* color
);
332 int RDrawLine(RImage
* image
, int x0
, int y0
, int x1
, int y1
, RColor
* color
);
334 int ROperateLine(RImage
* image
, int operation
, int x0
, int y0
, int x1
, int y1
,
337 void RDrawLines(RImage
* image
, RPoint
* points
, int npoints
, int mode
,
340 void ROperateLines(RImage
* image
, int operation
, RPoint
* points
, int npoints
,
341 int mode
, RColor
* color
);
343 void RDrawSegments(RImage
* image
, RSegment
* segs
, int nsegs
, RColor
* color
);
345 void ROperateSegments(RImage
* image
, int operation
, RSegment
* segs
, int nsegs
,
351 void RRGBtoHSV(RColor
* color
, RHSVColor
* hsv
);
352 void RHSVtoRGB(RHSVColor
* hsv
, RColor
* rgb
);
357 void RClearImage(RImage
* image
, RColor
* color
);
359 void RBevelImage(RImage
* image
, int bevel_type
);
361 RImage
*RRenderGradient(unsigned width
, unsigned height
, RColor
* from
,
362 RColor
* to
, int style
);
365 RImage
*RRenderMultiGradient(unsigned width
, unsigned height
, RColor
** colors
,
369 * Convertion into X Pixmaps
371 int RConvertImage(RContext
* context
, RImage
* image
, Pixmap
* pixmap
);
373 int RConvertImageMask(RContext
* context
, RImage
* image
, Pixmap
* pixmap
,
374 Pixmap
* mask
, int threshold
);
380 RXImage
*RCreateXImage(RContext
* context
, int depth
,
381 unsigned width
, unsigned height
);
383 void RDestroyXImage(RContext
* context
, RXImage
* ximage
);
385 void RPutXImage(RContext
* context
, Drawable d
, GC gc
, RXImage
* ximage
,
386 int src_x
, int src_y
, int dest_x
, int dest_y
,
387 unsigned width
, unsigned height
);
389 /* do not free the returned string! */
390 const char *RMessageForError(int errorCode
);
392 int RBlurImage(RImage
* image
);
394 /****** Global Variables *******/
396 extern int RErrorCode
;