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 24
48 #include <X11/Xutil.h>
51 #include <X11/extensions/XShm.h>
56 * Define some macro to provide attributes for the compiler
58 * These attributes help producing better code and/or detecting bugs, however not all compiler support them
59 * as they are not standard.
60 * Because we're a public API header, we can't count on autoconf to detect them for us, so we use that #if
61 * mechanism and define an internal macro appropriately. Please note that the macro are not considered being
62 * part of the public API.
64 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
65 #define __wrlib_deprecated(msg) __attribute__ ((deprecated(msg)))
67 #define __wrlib_deprecated(msg) __attribute__ ((deprecated))
69 #define __wrlib_deprecated(msg)
73 /* Apparently introduced in GCC 3.0.x */
74 /* Function returns newly allocated memory that does not alias any existing variable */
75 #define __wrlib_nonalias __attribute__ ((malloc))
77 #define __wrlib_nonalias
80 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
81 /* Apparently introduced in GCC 3.3.x */
82 /* The argument at index #i must not be NULL */
83 #define __wrlib_nonnull(...) __attribute__ ((nonnull(__VA_ARGS__)))
85 #define __wrlib_nonnull(argidx)
88 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
89 /* Apparently introduced in GCC 3.4.x */
90 /* The return value of this function *must* be checked/used */
91 #define __wrlib_useresult __attribute__ ((warn_unused_result))
93 #define __wrlib_useresult
99 #endif /* __cplusplus */
101 /* RBestMatchRendering or RDitheredRendering */
102 #define RC_RenderMode (1<<0)
104 /* number of colors per channel for colormap in PseudoColor mode */
105 #define RC_ColorsPerChannel (1<<1)
107 /* do gamma correction */
108 #define RC_GammaCorrection (1<<2)
110 /* visual id to use */
111 #define RC_VisualID (1<<3)
113 /* shared memory usage */
114 #define RC_UseSharedMemory (1<<4)
116 /* use default instead of best visual */
117 #define RC_DefaultVisual (1<<5)
119 /* filter type for smoothed scaling */
120 #define RC_ScalingFilter (1<<6)
122 /* standard colormap usage */
123 #define RC_StandardColormap (1<<7)
127 /* image display modes */
129 RDitheredRendering
= 0,
130 RBestMatchRendering
= 1
134 /* std colormap usage/creation modes */
136 RUseStdColormap
, /* default: fallbacks to RIgnore if there is none defined */
142 /* smoothed scaling filter types */
153 typedef struct RContextAttributes
{
155 RRenderingMode render_mode
;
156 int colors_per_channel
; /* for PseudoColor */
157 float rgamma
; /* gamma correction for red, */
158 float ggamma
; /* green, */
159 float bgamma
; /* and blue */
160 VisualID visualid
; /* visual ID to use */
161 int use_shared_memory
; /* True of False */
162 RScalingFilter scaling_filter
;
163 RStdColormapMode standard_colormap_mode
; /* what to do with std cma */
164 } RContextAttributes
;
168 * describes a screen in terms of depth, visual, number of colors
169 * we can use, if we should do dithering, and what colors to use for
172 typedef struct RContext
{
177 RContextAttributes
*attribs
;
183 Window drawable
; /* window to pass for XCreatePixmap().*/
184 /* generally = root */
190 int red_offset
; /* only used in 24bpp */
194 /* only used for pseudocolor and grayscale */
196 XStandardColormap
*std_rgb_map
; /* standard RGB colormap */
197 XStandardColormap
*std_gray_map
; /* standard grayscale colormap */
199 int ncolors
; /* total number of colors we can use */
200 XColor
*colors
; /* internal colormap */
201 unsigned long *pixels
; /* RContext->colors[].pixel */
204 unsigned int use_shared_pixmap
:1;
205 unsigned int optimize_for_speed
:1
206 __wrlib_deprecated("Flag optimize_for_speed in RContext is not used anymore "
207 "and will be removed in future version, please do not use");
212 typedef struct RColor
{
220 typedef struct RHSVColor
{
221 unsigned short hue
; /* 0-359 */
222 unsigned char saturation
; /* 0-255 */
223 unsigned char value
; /* 0-255 */
228 typedef struct RPoint
{
233 typedef struct RSegment
{
247 * internal 24bit+alpha image representation
249 typedef struct RImage
{
250 unsigned char *data
; /* image data RGBA or RGB */
251 int width
, height
; /* size of the image */
252 enum RImageFormat format
;
253 RColor background
; /* background color */
259 * internal wrapper for XImage. Used for shm abstraction
261 typedef struct RXImage
{
264 /* Private data. Do not access */
266 XShmSegmentInfo info
;
272 /* note that not all operations are supported in all functions */
274 RClearOperation
, /* clear with 0 */
276 RNormalOperation
, /* same as combine */
283 RAbsoluteCoordinates
= 0,
284 RRelativeCoordinates
= 1
294 #define RBEV_SUNKEN RSunkenBevel
296 #define RBEV_RAISED RRaisedBevel
297 /* 1 pixel wide on top/left 2 on bottom/right */
298 #define RBEV_RAISED2 2
300 #define RBEV_RAISED3 3
303 RHorizontalGradient
= 2,
304 RVerticalGradient
= 3,
305 RDiagonalGradient
= 4
307 /* for backwards compatibility */
308 #define RGRD_HORIZONTAL RHorizontalGradient
309 #define RGRD_VERTICAL RVerticalGradient
310 #define RGRD_DIAGONAL RDiagonalGradient
314 * How an image can be flipped, for RFlipImage
316 * Values are actually bit-mask which can be OR'd
318 #define RHorizontalFlip 0x0001
319 #define RVerticalFlip 0x0002
324 #define RERR_OPEN 1 /* cant open file */
325 #define RERR_READ 2 /* error reading from file */
326 #define RERR_WRITE 3 /* error writing to file */
327 #define RERR_NOMEMORY 4 /* out of memory */
328 #define RERR_NOCOLOR 5 /* out of color cells */
329 #define RERR_BADIMAGEFILE 6 /* image file is corrupted or invalid */
330 #define RERR_BADFORMAT 7 /* image file format is unknown */
331 #define RERR_BADINDEX 8 /* no such image index in file */
333 #define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
334 #define RERR_STDCMAPFAIL 17 /* failed to created std colormap */
336 #define RERR_XERROR 127 /* internal X error */
337 #define RERR_INTERNAL 128 /* should not happen */
341 * Cleaning before application exit
343 void RShutdown(void);
346 * Returns a NULL terminated array of strings containing the
347 * supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
348 * Do not free the returned data.
350 char **RSupportedFileFormats(void)
354 char *RGetImageFileFormat(const char *file
)
355 __wrlib_useresult
__wrlib_nonnull(1);
360 RContext
*RCreateContext(Display
*dpy
, int screen_number
,
361 const RContextAttributes
*attribs
)
362 __wrlib_useresult __wrlib_nonalias
__wrlib_nonnull(1);
364 void RDestroyContext(RContext
*context
);
366 Bool
RGetClosestXColor(RContext
*context
, const RColor
*color
, XColor
*retColor
)
367 __wrlib_nonnull(1, 2, 3);
372 RImage
*RCreateImage(unsigned width
, unsigned height
, int alpha
)
373 __wrlib_useresult __wrlib_nonalias
;
375 RImage
*RCreateImageFromXImage(RContext
*context
, XImage
*image
, XImage
*mask
)
376 __wrlib_useresult __wrlib_nonalias
__wrlib_nonnull(1, 2);
378 RImage
*RCreateImageFromDrawable(RContext
*context
, Drawable drawable
,
380 __wrlib_useresult __wrlib_nonalias
__wrlib_nonnull(1);
382 RImage
*RLoadImage(RContext
*context
, const char *file
, int index
)
383 __wrlib_useresult __wrlib_nonalias
__wrlib_nonnull(1, 2);
385 RImage
* RRetainImage(RImage
*image
);
387 void RReleaseImage(RImage
*image
)
390 RImage
*RGetImageFromXPMData(RContext
*context
, char **xpmData
)
391 __wrlib_useresult __wrlib_nonalias
__wrlib_nonnull(1, 2);
396 Bool
RSaveImage(RImage
*image
, const char *filename
, const char *format
)
397 __wrlib_nonnull(1, 2, 3);
402 RImage
*RCloneImage(RImage
*image
)
403 __wrlib_useresult __wrlib_nonalias
__wrlib_nonnull(1);
405 RImage
*RGetSubImage(RImage
*image
, int x
, int y
, unsigned width
,
407 __wrlib_useresult __wrlib_nonalias
__wrlib_nonnull(1);
409 void RCombineImageWithColor(RImage
*image
, const RColor
*color
)
410 __wrlib_nonnull(1, 2);
412 void RCombineImages(RImage
*image
, RImage
*src
)
413 __wrlib_nonnull(1, 2);
415 void RCombineArea(RImage
*image
, RImage
*src
, int sx
, int sy
, unsigned width
,
416 unsigned height
, int dx
, int dy
)
417 __wrlib_nonnull(1, 2);
419 void RCopyArea(RImage
*image
, RImage
*src
, int sx
, int sy
, unsigned width
,
420 unsigned height
, int dx
, int dy
)
421 __wrlib_nonnull(1, 2);
423 void RCombineImagesWithOpaqueness(RImage
*image
, RImage
*src
, int opaqueness
)
424 __wrlib_nonnull(1, 2);
426 void RCombineAreaWithOpaqueness(RImage
*image
, RImage
*src
, int sx
, int sy
,
427 unsigned width
, unsigned height
, int dx
, int dy
,
429 __wrlib_nonnull(1, 2);
431 void RCombineAlpha(unsigned char *d
, unsigned char *s
, int s_has_alpha
,
432 int width
, int height
, int dwi
, int swi
, int opacity
)
433 __wrlib_nonnull(1, 2);
435 RImage
*RScaleImage(RImage
*image
, unsigned new_width
, unsigned new_height
)
436 __wrlib_useresult __wrlib_nonalias
;
438 RImage
*RSmoothScaleImage(RImage
*src
, unsigned new_width
,
440 __wrlib_useresult __wrlib_nonalias
__wrlib_nonnull(1);
442 RImage
*RRotateImage(RImage
*image
, float angle
)
443 __wrlib_useresult __wrlib_nonalias
__wrlib_nonnull(1);
445 RImage
*RFlipImage(RImage
*image
, int mode
)
446 __wrlib_useresult __wrlib_nonalias
;
448 RImage
*RMakeTiledImage(RImage
*tile
, unsigned width
, unsigned height
)
449 __wrlib_useresult __wrlib_nonalias
__wrlib_nonnull(1);
451 RImage
* RMakeCenteredImage(RImage
*image
, unsigned width
, unsigned height
,
453 __wrlib_useresult __wrlib_nonalias
__wrlib_nonnull(1, 4);
458 Bool
RGetPixel(RImage
*image
, int x
, int y
, RColor
*color
)
459 __wrlib_nonnull(1, 4);
461 void RPutPixel(RImage
*image
, int x
, int y
, const RColor
*color
)
462 __wrlib_nonnull(1, 4);
464 void ROperatePixel(RImage
*image
, RPixelOperation operation
, int x
, int y
, const RColor
*color
)
465 __wrlib_nonnull(1, 5);
467 void RPutPixels(RImage
*image
, const RPoint
*points
, int npoints
, RCoordinatesMode mode
,
469 __wrlib_nonnull(1, 2, 5);
471 void ROperatePixels(RImage
*image
, RPixelOperation operation
, const RPoint
*points
,
472 int npoints
, RCoordinatesMode mode
, const RColor
*color
)
473 __wrlib_nonnull(1, 3, 6);
475 int RDrawLine(RImage
*image
, int x0
, int y0
, int x1
, int y1
, const RColor
*color
)
476 __wrlib_nonnull(1, 6);
478 int ROperateLine(RImage
*image
, RPixelOperation operation
, int x0
, int y0
, int x1
, int y1
,
480 __wrlib_nonnull(1, 7);
482 void RDrawLines(RImage
*image
, const RPoint
*points
, int npoints
, RCoordinatesMode mode
,
484 __wrlib_nonnull(1, 2, 5);
486 void ROperateLines(RImage
*image
, RPixelOperation operation
, const RPoint
*points
, int npoints
,
487 RCoordinatesMode mode
, const RColor
*color
)
488 __wrlib_nonnull(1, 3, 6);
490 void ROperateRectangle(RImage
*image
, RPixelOperation operation
, int x0
, int y0
, int x1
, int y1
, const RColor
*color
)
491 __wrlib_nonnull(1, 7);
493 void RDrawSegments(RImage
*image
, const RSegment
*segs
, int nsegs
, const RColor
*color
)
494 __wrlib_nonnull(1, 2, 4);
496 void ROperateSegments(RImage
*image
, RPixelOperation operation
, const RSegment
*segs
, int nsegs
,
498 __wrlib_nonnull(1, 3, 5);
503 void RRGBtoHSV(const RColor
*color
, RHSVColor
*hsv
)
504 __wrlib_nonnull(1, 2);
506 void RHSVtoRGB(const RHSVColor
*hsv
, RColor
*rgb
)
507 __wrlib_nonnull(1, 2);
512 void RClearImage(RImage
*image
, const RColor
*color
)
513 __wrlib_nonnull(1, 2);
515 void RLightImage(RImage
*image
, const RColor
*color
)
516 __wrlib_nonnull(1, 2);
518 void RFillImage(RImage
*image
, const RColor
*color
)
519 __wrlib_nonnull(1, 2);
521 void RBevelImage(RImage
*image
, int bevel_type
)
524 RImage
*RRenderGradient(unsigned width
, unsigned height
, const RColor
*from
,
525 const RColor
*to
, RGradientStyle style
)
526 __wrlib_nonalias __wrlib_useresult
__wrlib_nonnull(3, 4);
529 RImage
*RRenderMultiGradient(unsigned width
, unsigned height
, RColor
**colors
,
530 RGradientStyle style
)
531 __wrlib_nonalias __wrlib_useresult
__wrlib_nonnull(3);
534 RImage
*RRenderInterwovenGradient(unsigned width
, unsigned height
,
535 RColor colors1
[2], int thickness1
,
536 RColor colors2
[2], int thickness2
)
537 __wrlib_nonalias __wrlib_useresult
;
541 * Convertion into X Pixmaps
543 int RConvertImage(RContext
*context
, RImage
*image
, Pixmap
*pixmap
)
544 __wrlib_nonnull(1, 2, 3);
546 int RConvertImageMask(RContext
*context
, RImage
*image
, Pixmap
*pixmap
,
547 Pixmap
*mask
, int threshold
)
548 __wrlib_nonnull(1, 2, 3, 4);
554 RXImage
*RCreateXImage(RContext
*context
, int depth
,
555 unsigned width
, unsigned height
)
556 __wrlib_nonalias __wrlib_useresult
__wrlib_nonnull(1);
558 RXImage
*RGetXImage(RContext
*context
, Drawable d
, int x
, int y
,
559 unsigned width
, unsigned height
)
560 __wrlib_nonalias __wrlib_useresult
__wrlib_nonnull(1);
562 void RDestroyXImage(RContext
*context
, RXImage
*ximage
)
563 __wrlib_nonnull(1, 2);
565 void RPutXImage(RContext
*context
, Drawable d
, GC gc
, RXImage
*ximage
,
566 int src_x
, int src_y
, int dest_x
, int dest_y
,
567 unsigned width
, unsigned height
)
568 __wrlib_nonnull(1, 3);
570 /* do not free the returned string! */
571 const char *RMessageForError(int errorCode
)
574 int RBlurImage(RImage
*image
)
577 /****** Global Variables *******/
579 extern int RErrorCode
;
583 #endif /* __cplusplus */
586 * The definitions below are done for internal use only
587 * We undef them so users of the library may not misuse them
589 #undef __wrlib_deprecated
590 #undef __wrlib_nonalias
591 #undef __wrlib_nonnull
592 #undef __wrlib_useresult