2 * Raster graphics library
4 * Copyright (c) 1997, 1998 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.10 */
43 #define WRASTER_HEADER_VERSION 10
51 #include <X11/Xutil.h>
54 #include <X11/extensions/XShm.h>
57 /* RM_MATCH or RM_DITHER */
58 #define RC_RenderMode (1<<0)
60 /* number of colors per channel for colormap in PseudoColor mode */
61 #define RC_ColorsPerChannel (1<<1)
63 /* do gamma correction */
64 #define RC_GammaCorrection (1<<2)
66 /* visual id to use */
67 #define RC_VisualID (1<<3)
69 /* shared memory usage */
70 #define RC_UseSharedMemory (1<<4)
72 /* use default instead of best visual */
73 #define RC_DefaultVisual (1<<5)
75 typedef struct RContextAttributes
{
78 int colors_per_channel
; /* for PseudoColor */
79 float rgamma
; /* gamma correction for red, */
80 float ggamma
; /* green, */
81 float bgamma
; /* and blue */
82 VisualID visualid
; /* visual ID to use */
83 int use_shared_memory
; /* True of False */
88 * describes a screen in terms of depth, visual, number of colors
89 * we can use, if we should do dithering, and what colors to use for
92 typedef struct RContext
{
97 RContextAttributes
*attribs
;
103 Window drawable
; /* window to pass for XCreatePixmap().*/
104 /* generally = root */
110 int red_offset
; /* only used in 24bpp */
114 /* only used for pseudocolor and grayscale */
115 int ncolors
; /* total number of colors we can use */
116 XColor
*colors
; /* internal colormap */
120 typedef struct RColor
{
128 typedef struct RHSVColor
{
129 unsigned short hue
; /* 0-359 */
130 unsigned char saturation
; /* 0-255 */
131 unsigned char value
; /* 0-255 */
136 typedef struct RPoint
{
141 typedef struct RSegment
{
147 * internal 24bit+alpha image representation
149 typedef struct RImage
{
150 unsigned width
, height
; /* size of the image */
151 RColor background
; /* background color */
152 unsigned char *data
[4]; /* image data (R,G,B,A) */
157 * internal wrapper for XImage. Used for shm abstraction
159 typedef struct RXImage
{
162 /* Private data. Do not access */
164 XShmSegmentInfo info
;
170 /* note that not all operations are supported in all functions */
172 RClearOperation
, /* clear with 0 */
174 RNormalOperation
, /* same as combine */
180 /* image display modes */
182 RDitheredRendering
= 0,
183 RBestMatchRendering
= 1
187 #define RM_DITHER RDitheredRendering
188 #define RM_MATCH RBestMatchRendering
191 RAbsoluteCoordinates
= 0,
192 RRelativeCoordinates
= 1
201 #define RBEV_SUNKEN RSunkenBevel
203 #define RBEV_RAISED RRaisedBevel
204 /* 1 pixel wide on top/left 2 on bottom/right */
205 #define RBEV_RAISED2 2
207 #define RBEV_RAISED3 3
210 RHorizontalGradient
= 2,
211 RVerticalGradient
= 3,
212 RDiagonalGradient
= 4
214 /* for backwards compatibility */
215 #define RGRD_HORIZONTAL RHorizontalGradient
216 #define RGRD_VERTICAL RVerticalGradient
217 #define RGRD_DIAGONAL RDiagonalGradient
223 #define RERR_OPEN 1 /* cant open file */
224 #define RERR_READ 2 /* error reading from file */
225 #define RERR_WRITE 3 /* error writing to file */
226 #define RERR_NOMEMORY 4 /* out of memory */
227 #define RERR_NOCOLOR 5 /* out of color cells */
228 #define RERR_BADIMAGEFILE 6 /* image file is corrupted or invalid */
229 #define RERR_BADFORMAT 7 /* image file format is unknown */
230 #define RERR_BADINDEX 8 /* no such image index in file */
232 #define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
234 #define RERR_XERROR 127 /* internal X error */
235 #define RERR_INTERNAL 128 /* should not happen */
239 * Returns a NULL terminated array of strings containing the
240 * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
242 char **RSupportedFileFormats(void);
244 void RFreeStringList(char **list
);
249 RContext
*RCreateContext(Display
*dpy
, int screen_number
,
250 RContextAttributes
*attribs
);
252 void RDestroyContext(RContext
*context
);
254 Bool
RGetClosestXColor(RContext
*context
, RColor
*color
, XColor
*retColor
);
259 RImage
*RCreateImage(unsigned width
, unsigned height
, int alpha
);
261 RImage
*RCreateImageFromXImage(RContext
*context
, XImage
*image
, XImage
*mask
);
263 RImage
*RCreateImageFromDrawable(RContext
*context
, Drawable drawable
,
266 RImage
*RLoadImage(RContext
*context
, char *file
, int index
);
269 void RDestroyImage(RImage
*image
);
271 RImage
*RGetImageFromXPMData(RContext
*context
, char **data
);
276 Bool
RSaveImage(RImage
*image
, char *filename
, char *format
);
281 RImage
*RCloneImage(RImage
*image
);
283 RImage
*RGetSubImage(RImage
*image
, int x
, int y
, unsigned width
,
286 void RCombineImageWithColor(RImage
*image
, RColor
*color
);
288 void RCombineImages(RImage
*image
, RImage
*src
);
290 void RCombineArea(RImage
*image
, RImage
*src
, int sx
, int sy
, unsigned width
,
291 unsigned height
, int dx
, int dy
);
293 void RCombineImagesWithOpaqueness(RImage
*image
, RImage
*src
, int opaqueness
);
295 void RCombineAreaWithOpaqueness(RImage
*image
, RImage
*src
, int sx
, int sy
,
296 unsigned width
, unsigned height
, int dx
, int dy
,
299 RImage
*RScaleImage(RImage
*image
, unsigned new_width
, unsigned new_height
);
301 RImage
*RMakeTiledImage(RImage
*tile
, unsigned width
, unsigned height
);
303 RImage
* RMakeCenteredImage(RImage
*image
, unsigned width
, unsigned height
,
309 Bool
RGetPixel(RImage
*image
, int x
, int y
, RColor
*color
);
311 void RPutPixel(RImage
*image
, int x
, int y
, RColor
*color
);
313 void ROperatePixel(RImage
*image
, int operation
, int x
, int y
, RColor
*color
);
315 void RPutPixels(RImage
*image
, RPoint
*points
, int npoints
, int mode
,
318 void ROperatePixels(RImage
*image
, int operation
, RPoint
*points
,
319 int npoints
, int mode
, RColor
*color
);
321 int RDrawLine(RImage
*image
, int x0
, int y0
, int x1
, int y1
, RColor
*color
);
323 int ROperateLine(RImage
*image
, int operation
, int x0
, int y0
, int x1
, int y1
,
326 void RDrawLines(RImage
*image
, RPoint
*points
, int npoints
, int mode
,
329 void ROperateLines(RImage
*image
, int operation
, RPoint
*points
, int npoints
,
330 int mode
, RColor
*color
);
332 void RDrawSegments(RImage
*image
, RSegment
*segs
, int nsegs
, RColor
*color
);
334 void ROperateSegments(RImage
*image
, int operation
, RSegment
*segs
, int nsegs
,
340 void RRGBtoHSV(RColor
*color
, RHSVColor
*hsv
);
341 void RHSVtoRGB(RHSVColor
*hsv
, RColor
*rgb
);
346 void RClearImage(RImage
*image
, RColor
*color
);
348 void RBevelImage(RImage
*image
, int bevel_type
);
350 RImage
*RRenderGradient(unsigned width
, unsigned height
, RColor
*from
,
351 RColor
*to
, int style
);
354 RImage
*RRenderMultiGradient(unsigned width
, unsigned height
, RColor
**colors
,
358 * Convertion into X Pixmaps
360 int RConvertImage(RContext
*context
, RImage
*image
, Pixmap
*pixmap
);
362 int RConvertImageMask(RContext
*context
, RImage
*image
, Pixmap
*pixmap
,
363 Pixmap
*mask
, int threshold
);
369 RXImage
*RCreateXImage(RContext
*context
, int depth
,
370 unsigned width
, unsigned height
);
372 void RDestroyXImage(RContext
*context
, RXImage
*ximage
);
374 void RPutXImage(RContext
*context
, Drawable d
, GC gc
, RXImage
*ximage
,
375 int src_x
, int src_y
, int dest_x
, int dest_y
,
376 unsigned width
, unsigned height
);
378 /* do not free the returned string! */
379 const char *RMessageForError(int errorCode
);
382 /****** Global Variables *******/
384 extern int RErrorCode
;