/*
 *  Raster graphics library
 * 
 *  Copyright (c) 1997 Alfredo K. Kojima
 * 
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *  
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *  
 *  You should have received a copy of the GNU Library General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 * Environment variables:
 * 
 * WRASTER_GAMMA <rgamma>/<ggamma>/<bgamma>
 * gamma correction value. Must be  greater than 0
 * Only for PseudoColor visuals.
 * 
 * Default:
 * WRASTER_GAMMA 1/1/1
 * 
 * 
 * If you want a specific value for a screen, append the screen number
 * preceded by a hash to the variable name as in
 * WRASTER_GAMMA#1
 * for screen number 1
 */

#ifndef RLRASTER_H_
#define RLRASTER_H_

#include <X11/Xlib.h>
#include <X11/Xutil.h>

/* RM_MATCH or RM_DITHER */
#define RC_RenderMode 		(1<<0)

/* number of colors per channel for colormap in PseudoColor mode */
#define RC_ColorsPerChannel	(1<<1)

/* do gamma correction */
#define RC_GammaCorrection	(1<<2)

/* visual id to use */
#define RC_VisualID		(1<<3)

typedef struct RContextAttributes {
    int flags;
    int render_mode;
    int colors_per_channel;	       /* for PseudoColor */
    float rgamma;		       /* gamma correction for red, */
    float ggamma;		       /* green, */
    float bgamma;		       /* and blue */
    VisualID visualid;		       /* visual ID to use */
} RContextAttributes;


/*
 * describes a screen in terms of depth, visual, number of colors
 * we can use, if we should do dithering, and what colors to use for
 * dithering.
 */
typedef struct RContext {
    Display *dpy;
    Colormap cmap;
    
    RContextAttributes *attribs;

    GC copy_gc;

    Visual *visual;
    int depth;
    Window drawable;		       /* window to pass for XCreatePixmap().*/
				       /* generally = root */
    int vclass;
    
    unsigned long black;
    unsigned long white;
    
    /* only used for pseudocolor and grayscale */
    int ncolors;		       /* total number of colors we can use */
    XColor *colors;		       /* internal colormap */
} RContext;


/* image display modes */
#define RM_DITHER	0
#define RM_MATCH	1



typedef struct RColor {
    unsigned char red, green, blue;
} RColor;


/*
 * internal 24bit+alpha image representation
 */
typedef struct RImage {
    int width, height;		       /* size of the image */
    RColor background;		       /* background color */
    unsigned char *data[4];	       /* image data (R,G,B,A) */
} RImage;



#define WBEV_SUNKEN	-1
/* 1 pixel wide */
#define WBEV_RAISED	1
/* 1 pixel wide on top/left 2 on bottom/right */
#define WBEV_RAISED2	2


#define WGRD_HORIZONTAL	2
#define WGRD_VERTICAL	3
#define WGRD_DIAGONAL	4

/* cpc == colors per channel for the dithering colormap */
RContext *RCreateContext(Display *dpy, int screen_number,
			 RContextAttributes *attribs);

RImage *RCreateImage(int width, int height, int alpha);

RImage *RCloneImage(RImage *image);

RImage *RGetSubImage(RImage *image, int x, int y, int width, int height);

RImage *RLoadImage(RContext *context, char *file, int index);

int RDestroyImage(RImage *image);

int RBevelImage(RImage *image, int bevel_type);

int RCombineImages(RImage *image, RImage *src);

int RCombineArea(RImage *image, RImage *src, int sx, int sy, int width,
		 int height, int dx, int dy);

RImage *RScaleImage(RImage *image, int new_width, int new_height);


RImage *RRenderGradient(int width, int height, RColor *from, RColor *to,
			int style);

int RConvertImage(RContext *context, RImage *image, Pixmap *pixmap);

int RConvertImageMask(RContext *context, RImage *image, Pixmap *pixmap,
		      Pixmap *mask, int threshold);


extern char RErrorString[];
#endif
