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.8 */
43 #define WRASTER_HEADER_VERSION 8
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 XShmSegmentInfo info
;
168 /* note that not all operations are supported in all functions */
170 RClearOperation
, /* clear with 0 */
172 RNormalOperation
, /* same as combine */
178 /* image display modes */
180 RDitheredRendering
= 0,
181 RBestMatchRendering
= 1
185 #define RM_DITHER RDitheredRendering
186 #define RM_MATCH RBestMatchRendering
189 RAbsoluteCoordinates
= 0,
190 RRelativeCoordinates
= 1
199 #define RBEV_SUNKEN RSunkenBevel
201 #define RBEV_RAISED RRaisedBevel
202 /* 1 pixel wide on top/left 2 on bottom/right */
203 #define RBEV_RAISED2 2
205 #define RBEV_RAISED3 3
208 RHorizontalGradient
= 2,
209 RVerticalGradient
= 3,
210 RDiagonalGradient
= 4
212 /* for backwards compatibility */
213 #define RGRD_HORIZONTAL RHorizontalGradient
214 #define RGRD_VERTICAL RVerticalGradient
215 #define RGRD_DIAGONAL RDiagonalGradient
221 * Returns a NULL terminated array of strings containing the
222 * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
224 char **RSupportedFileFormats(void);
226 void RFreeStringList(char **list
);
231 RContext
*RCreateContext(Display
*dpy
, int screen_number
,
232 RContextAttributes
*attribs
);
235 Bool
RGetClosestXColor(RContext
*context
, RColor
*color
, XColor
*retColor
);
240 RImage
*RCreateImage(unsigned width
, unsigned height
, int alpha
);
242 RImage
*RCreateImageFromXImage(RContext
*context
, XImage
*image
, XImage
*mask
);
244 RImage
*RCreateImageFromDrawable(RContext
*context
, Drawable drawable
,
247 RImage
*RLoadImage(RContext
*context
, char *file
, int index
);
250 void RDestroyImage(RImage
*image
);
252 RImage
*RGetImageFromXPMData(RContext
*context
, char **data
);
258 RImage
*RCloneImage(RImage
*image
);
260 RImage
*RGetSubImage(RImage
*image
, int x
, int y
, unsigned width
,
263 void RCombineImageWithColor(RImage
*image
, RColor
*color
);
265 void RCombineImages(RImage
*image
, RImage
*src
);
267 void RCombineArea(RImage
*image
, RImage
*src
, int sx
, int sy
, unsigned width
,
268 unsigned height
, int dx
, int dy
);
270 void RCombineImagesWithOpaqueness(RImage
*image
, RImage
*src
, int opaqueness
);
272 void RCombineAreaWithOpaqueness(RImage
*image
, RImage
*src
, int sx
, int sy
,
273 unsigned width
, unsigned height
, int dx
, int dy
,
276 RImage
*RScaleImage(RImage
*image
, unsigned new_width
, unsigned new_height
);
278 RImage
*RMakeTiledImage(RImage
*tile
, unsigned width
, unsigned height
);
280 RImage
* RMakeCenteredImage(RImage
*image
, unsigned width
, unsigned height
,
286 Bool
RGetPixel(RImage
*image
, int x
, int y
, RColor
*color
);
288 void RPutPixel(RImage
*image
, int x
, int y
, RColor
*color
);
290 void ROperatePixel(RImage
*image
, int operation
, int x
, int y
, RColor
*color
);
292 void RPutPixels(RImage
*image
, RPoint
*points
, int npoints
, int mode
,
295 void ROperatePixels(RImage
*image
, int operation
, RPoint
*points
,
296 int npoints
, int mode
, RColor
*color
);
298 int RDrawLine(RImage
*image
, int x0
, int y0
, int x1
, int y1
, RColor
*color
);
300 int ROperateLine(RImage
*image
, int operation
, int x0
, int y0
, int x1
, int y1
,
303 void RDrawLines(RImage
*image
, RPoint
*points
, int npoints
, int mode
,
306 void ROperateLines(RImage
*image
, int operation
, RPoint
*points
, int npoints
,
307 int mode
, RColor
*color
);
309 void RDrawSegments(RImage
*image
, RSegment
*segs
, int nsegs
, RColor
*color
);
311 void ROperateSegments(RImage
*image
, int operation
, RSegment
*segs
, int nsegs
,
317 void RRGBtoHSV(RColor
*color
, RHSVColor
*hsv
);
318 void RHSVtoRGB(RHSVColor
*hsv
, RColor
*rgb
);
323 int RClearImage(RImage
*image
, RColor
*color
);
325 int RBevelImage(RImage
*image
, int bevel_type
);
327 RImage
*RRenderGradient(unsigned width
, unsigned height
, RColor
*from
,
328 RColor
*to
, int style
);
331 RImage
*RRenderMultiGradient(unsigned width
, unsigned height
, RColor
**colors
,
335 * Convertion into X Pixmaps
337 int RConvertImage(RContext
*context
, RImage
*image
, Pixmap
*pixmap
);
339 int RConvertImageMask(RContext
*context
, RImage
*image
, Pixmap
*pixmap
,
340 Pixmap
*mask
, int threshold
);
346 RXImage
*RCreateXImage(RContext
*context
, int depth
,
347 unsigned width
, unsigned height
);
349 void RDestroyXImage(RContext
*context
, RXImage
*ximage
);
351 void RPutXImage(RContext
*context
, Drawable d
, GC gc
, RXImage
*ximage
,
352 int src_x
, int src_y
, int dest_x
, int dest_y
,
353 unsigned width
, unsigned height
);
356 /****** Global Variables *******/
359 * Where error strings are stored
361 extern char RErrorString
[];