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)
85 /* image display modes */
87 RDitheredRendering
= 0,
88 RBestMatchRendering
= 1
92 /* std colormap usage/creation modes */
94 RUseStdColormap
, /* default: fallbacks to RIgnore if there is none defined */
100 /* smoothed scaling filter types */
111 typedef struct RContextAttributes
{
113 RRenderingMode render_mode
;
114 int colors_per_channel
; /* for PseudoColor */
115 float rgamma
; /* gamma correction for red, */
116 float ggamma
; /* green, */
117 float bgamma
; /* and blue */
118 VisualID visualid
; /* visual ID to use */
119 int use_shared_memory
; /* True of False */
120 RScalingFilter scaling_filter
;
121 RStdColormapMode standard_colormap_mode
; /* what to do with std cma */
122 } RContextAttributes
;
126 * describes a screen in terms of depth, visual, number of colors
127 * we can use, if we should do dithering, and what colors to use for
130 typedef struct RContext
{
135 RContextAttributes
*attribs
;
141 Window drawable
; /* window to pass for XCreatePixmap().*/
142 /* generally = root */
148 int red_offset
; /* only used in 24bpp */
152 /* only used for pseudocolor and grayscale */
154 XStandardColormap
*std_rgb_map
; /* standard RGB colormap */
155 XStandardColormap
*std_gray_map
; /* standard grayscale colormap */
157 int ncolors
; /* total number of colors we can use */
158 XColor
*colors
; /* internal colormap */
159 unsigned long *pixels
; /* RContext->colors[].pixel */
162 unsigned int use_shared_pixmap
:1;
167 typedef struct RColor
{
175 typedef struct RHSVColor
{
176 unsigned short hue
; /* 0-359 */
177 unsigned char saturation
; /* 0-255 */
178 unsigned char value
; /* 0-255 */
183 typedef struct RPoint
{
188 typedef struct RSegment
{
202 * internal 24bit+alpha image representation
204 typedef struct RImage
{
205 unsigned char *data
; /* image data RGBA or RGB */
206 int width
, height
; /* size of the image */
207 enum RImageFormat format
;
208 RColor background
; /* background color */
214 * internal wrapper for XImage. Used for shm abstraction
216 typedef struct RXImage
{
219 /* Private data. Do not access */
221 XShmSegmentInfo info
;
227 /* note that not all operations are supported in all functions */
229 RClearOperation
, /* clear with 0 */
231 RNormalOperation
, /* same as combine */
238 RAbsoluteCoordinates
= 0,
239 RRelativeCoordinates
= 1
249 #define RBEV_SUNKEN RSunkenBevel
251 #define RBEV_RAISED RRaisedBevel
252 /* 1 pixel wide on top/left 2 on bottom/right */
253 #define RBEV_RAISED2 2
255 #define RBEV_RAISED3 3
258 RHorizontalGradient
= 2,
259 RVerticalGradient
= 3,
260 RDiagonalGradient
= 4
262 /* for backwards compatibility */
263 #define RGRD_HORIZONTAL RHorizontalGradient
264 #define RGRD_VERTICAL RVerticalGradient
265 #define RGRD_DIAGONAL RDiagonalGradient
269 * How an image can be flipped, for RFlipImage
271 * Values are actually bit-mask which can be OR'd
273 #define RHorizontalFlip 0x0001
274 #define RVerticalFlip 0x0002
279 #define RERR_OPEN 1 /* cant open file */
280 #define RERR_READ 2 /* error reading from file */
281 #define RERR_WRITE 3 /* error writing to file */
282 #define RERR_NOMEMORY 4 /* out of memory */
283 #define RERR_NOCOLOR 5 /* out of color cells */
284 #define RERR_BADIMAGEFILE 6 /* image file is corrupted or invalid */
285 #define RERR_BADFORMAT 7 /* image file format is unknown */
286 #define RERR_BADINDEX 8 /* no such image index in file */
288 #define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
289 #define RERR_STDCMAPFAIL 17 /* failed to created std colormap */
291 #define RERR_XERROR 127 /* internal X error */
292 #define RERR_INTERNAL 128 /* should not happen */
296 * Cleaning before application exit
298 void RShutdown(void);
301 * Returns a NULL terminated array of strings containing the
302 * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
303 * Do not free the returned data.
305 char **RSupportedFileFormats(void);
308 char *RGetImageFileFormat(const char *file
);
313 RContext
*RCreateContext(Display
*dpy
, int screen_number
,
314 const RContextAttributes
*attribs
);
316 void RDestroyContext(RContext
*context
);
318 Bool
RGetClosestXColor(RContext
*context
, const RColor
*color
, XColor
*retColor
);
323 RImage
*RCreateImage(unsigned width
, unsigned height
, int alpha
);
325 RImage
*RCreateImageFromXImage(RContext
*context
, XImage
*image
, XImage
*mask
);
327 RImage
*RCreateImageFromDrawable(RContext
*context
, Drawable drawable
,
330 RImage
*RLoadImage(RContext
*context
, const char *file
, int index
);
332 RImage
* RRetainImage(RImage
*image
);
334 void RReleaseImage(RImage
*image
);
336 RImage
*RGetImageFromXPMData(RContext
*context
, char **xpmData
);
341 Bool
RSaveImage(RImage
*image
, const char *filename
, const char *format
);
346 RImage
*RCloneImage(RImage
*image
);
348 RImage
*RGetSubImage(RImage
*image
, int x
, int y
, unsigned width
,
351 void RCombineImageWithColor(RImage
*image
, const RColor
*color
);
353 void RCombineImages(RImage
*image
, RImage
*src
);
355 void RCombineArea(RImage
*image
, RImage
*src
, int sx
, int sy
, unsigned width
,
356 unsigned height
, int dx
, int dy
);
358 void RCopyArea(RImage
*image
, RImage
*src
, int sx
, int sy
, unsigned width
,
359 unsigned height
, int dx
, int dy
);
361 void RCombineImagesWithOpaqueness(RImage
*image
, RImage
*src
, int opaqueness
);
363 void RCombineAreaWithOpaqueness(RImage
*image
, RImage
*src
, int sx
, int sy
,
364 unsigned width
, unsigned height
, int dx
, int dy
,
367 void RCombineAlpha(unsigned char *d
, unsigned char *s
, int s_has_alpha
,
368 int width
, int height
, int dwi
, int swi
, int opacity
);
370 RImage
*RScaleImage(RImage
*image
, unsigned new_width
, unsigned new_height
);
372 RImage
*RSmoothScaleImage(RImage
*src
, unsigned new_width
,
373 unsigned new_height
);
375 RImage
*RRotateImage(RImage
*image
, float angle
);
377 RImage
*RFlipImage(RImage
*image
, int mode
);
379 RImage
*RMakeTiledImage(RImage
*tile
, unsigned width
, unsigned height
);
381 RImage
* RMakeCenteredImage(RImage
*image
, unsigned width
, unsigned height
,
382 const RColor
*color
);
387 Bool
RGetPixel(RImage
*image
, int x
, int y
, RColor
*color
);
389 void RPutPixel(RImage
*image
, int x
, int y
, const RColor
*color
);
391 void ROperatePixel(RImage
*image
, RPixelOperation operation
, int x
, int y
, const RColor
*color
);
393 void RPutPixels(RImage
*image
, const RPoint
*points
, int npoints
, RCoordinatesMode mode
,
394 const RColor
*color
);
396 void ROperatePixels(RImage
*image
, RPixelOperation operation
, const RPoint
*points
,
397 int npoints
, RCoordinatesMode mode
, const RColor
*color
);
399 int RDrawLine(RImage
*image
, int x0
, int y0
, int x1
, int y1
, const RColor
*color
);
401 int ROperateLine(RImage
*image
, RPixelOperation operation
, int x0
, int y0
, int x1
, int y1
,
402 const RColor
*color
);
404 void RDrawLines(RImage
*image
, const RPoint
*points
, int npoints
, RCoordinatesMode mode
,
405 const RColor
*color
);
407 void ROperateLines(RImage
*image
, RPixelOperation operation
, const RPoint
*points
, int npoints
,
408 RCoordinatesMode mode
, const RColor
*color
);
410 void ROperateRectangle(RImage
*image
, RPixelOperation operation
, int x0
, int y0
, int x1
, int y1
, const RColor
*color
);
412 void RDrawSegments(RImage
*image
, const RSegment
*segs
, int nsegs
, const RColor
*color
);
414 void ROperateSegments(RImage
*image
, RPixelOperation operation
, const RSegment
*segs
, int nsegs
,
415 const RColor
*color
);
420 void RRGBtoHSV(const RColor
*color
, RHSVColor
*hsv
);
421 void RHSVtoRGB(const RHSVColor
*hsv
, RColor
*rgb
);
426 void RClearImage(RImage
*image
, const RColor
*color
);
428 void RLightImage(RImage
*image
, const RColor
*color
);
430 void RFillImage(RImage
*image
, const RColor
*color
);
432 void RBevelImage(RImage
*image
, int bevel_type
);
434 RImage
*RRenderGradient(unsigned width
, unsigned height
, const RColor
*from
,
435 const RColor
*to
, RGradientStyle style
);
438 RImage
*RRenderMultiGradient(unsigned width
, unsigned height
, RColor
**colors
,
439 RGradientStyle style
);
442 RImage
*RRenderInterwovenGradient(unsigned width
, unsigned height
,
443 RColor colors1
[2], int thickness1
,
444 RColor colors2
[2], int thickness2
);
448 * Convertion into X Pixmaps
450 int RConvertImage(RContext
*context
, RImage
*image
, Pixmap
*pixmap
);
452 int RConvertImageMask(RContext
*context
, RImage
*image
, Pixmap
*pixmap
,
453 Pixmap
*mask
, int threshold
);
459 RXImage
*RCreateXImage(RContext
*context
, int depth
,
460 unsigned width
, unsigned height
);
462 RXImage
*RGetXImage(RContext
*context
, Drawable d
, int x
, int y
,
463 unsigned width
, unsigned height
);
465 void RDestroyXImage(RContext
*context
, RXImage
*ximage
);
467 void RPutXImage(RContext
*context
, Drawable d
, GC gc
, RXImage
*ximage
,
468 int src_x
, int src_y
, int dest_x
, int dest_y
,
469 unsigned width
, unsigned height
);
471 /* do not free the returned string! */
472 const char *RMessageForError(int errorCode
);
474 int RBlurImage(RImage
*image
);
476 /****** Global Variables *******/
478 extern int RErrorCode
;
482 #endif /* __cplusplus */