1 /* 2 * bltImage.h -- 3 * 4 * Copyright 1993-1998 Lucent Technologies, Inc. 5 * 6 * Permission to use, copy, modify, and distribute this software and 7 * its documentation for any purpose and without fee is hereby 8 * granted, provided that the above copyright notice appear in all 9 * copies and that both that the copyright notice and warranty 10 * disclaimer appear in supporting documentation, and that the names 11 * of Lucent Technologies any of their entities not be used in 12 * advertising or publicity pertaining to distribution of the software 13 * without specific, written prior permission. 14 * 15 * Lucent Technologies disclaims all warranties with regard to this 16 * software, including all implied warranties of merchantability and 17 * fitness. In no event shall Lucent Technologies be liable for any 18 * special, indirect or consequential damages or any damages 19 * whatsoever resulting from loss of use, data or profits, whether in 20 * an action of contract, negligence or other tortuous action, arising 21 * out of or in connection with the use or performance of this 22 * software. 23 */ 24 25 #include <X11/Xutil.h> 26 #ifndef WIN32 27 #include <X11/Xproto.h> 28 #endif 29 30 #ifndef _BLT_IMAGE_H 31 #define _BLT_IMAGE_H 32 33 #define DIV255(i) ((((i) + 1) + (((i) + 1) >> 8) ) >> 8) 34 35 #define GAMMA (1.0) 36 37 #define ROTATE_0 0 38 #define ROTATE_90 1 39 #define ROTATE_180 2 40 #define ROTATE_270 3 41 42 /* 43 *---------------------------------------------------------------------- 44 * 45 * Pix32 -- 46 * 47 * A union representing either a pixel as a RGB triplet or a 48 * single word value. 49 * 50 *---------------------------------------------------------------------- 51 */ 52 typedef union { 53 unsigned int value; /* Lookup table address */ 54 struct RGBA { 55 unsigned char red; /* Red intensity 0..255 */ 56 unsigned char green; /* Green intensity 0.255 */ 57 unsigned char blue; /* Blue intensity 0..255 */ 58 unsigned char alpha; /* Alpha-channel for compositing. 0..255 */ 59 } rgba; 60 unsigned char channel[4]; 61 } Pix32; 62 63 #define Red rgba.red 64 #define Blue rgba.blue 65 #define Green rgba.green 66 #define Alpha rgba.alpha 67 68 69 typedef struct { 70 XColor exact, best; 71 double error; 72 unsigned int freq; 73 int allocated; 74 int index; 75 } ColorInfo; 76 77 /* 78 *---------------------------------------------------------------------- 79 * 80 * ColorTable -- 81 * 82 * For colormap-ed visuals, this structure contains color lookup 83 * information needed to translate RGB triplets to pixel indices. 84 * 85 * This structure isn't needed for TrueColor or Monochrome visuals. 86 * 87 * DirectColor: 88 * Pixel values for each color channel 89 * StaticColor, PsuedoColor, StaticGray, and GrayScale: 90 * Red represents the 8-bit color. Green and Blue pixel 91 * values are unused. 92 * 93 *---------------------------------------------------------------------- 94 */ 95 typedef struct ColorTableStruct { 96 double outputGamma; /* Gamma correction value */ 97 Display *display; /* Display of colortable. Used to free 98 * colors allocated. */ 99 XVisualInfo visualInfo; /* Visual information for window displaying 100 * the image. */ 101 Colormap colorMap; /* Colormap used. This may be the default 102 * colormap, or an allocated private map. */ 103 int flags; 104 unsigned int red[256], green[256], blue[256]; 105 106 /* Array of allocated pixels in colormap */ 107 ColorInfo colorInfo[256]; 108 ColorInfo *sortedColors[256]; 109 110 int nUsedColors, nFreeColors; 111 int nPixels; /* Number of colors in the quantized image */ 112 unsigned long int pixelValues[256]; 113 114 unsigned int *lut; /* Color lookup table. Used to collect 115 * frequencies of colors and later 116 * colormap indices */ 117 } *ColorTable; 118 119 #define PRIVATE_COLORMAP 1 120 #define RGBIndex(r,g,b) (((r)<<10) + ((r)<<6) + (r) + ((g) << 5) + (g) + (b)) 121 122 /* 123 *---------------------------------------------------------------------- 124 * 125 * Blt_ColorImage -- 126 * 127 * The structure below represents a color image. Each pixel 128 * occupies a 32-bit word of memory: one byte for each of the 129 * red, green, and blue color intensities, and another for 130 * alpha-channel image compositing (e.g. transparency). 131 * 132 *---------------------------------------------------------------------- 133 */ 134 typedef struct ColorImage { 135 int width, height; /* Dimensions of the image */ 136 Pix32 *bits; /* Array of pixels representing the image. */ 137 } *Blt_ColorImage; 138 139 /* 140 * Blt_ColorImage is supposed to be an opaque type. 141 * Use the macros below to access its members. 142 */ 143 #define Blt_ColorImageHeight(c) ((c)->height) 144 #define Blt_ColorImageWidth(c) ((c)->width) 145 #define Blt_ColorImageBits(c) ((c)->bits) 146 #define Blt_ColorImagePixel(c, x, y) ((c)->bits + ((c)->width * (y)) + (x)) 147 148 /* 149 *---------------------------------------------------------------------- 150 * 151 * ResampleFilterProc -- 152 * 153 * A function implementing a 1-D filter. 154 * 155 *---------------------------------------------------------------------- 156 */ 157 typedef double (ResampleFilterProc) _ANSI_ARGS_((double value)); 158 159 /* 160 *---------------------------------------------------------------------- 161 * 162 * ResampleFilter -- 163 * 164 * Contains information about a 1-D filter (its support and 165 * the procedure implementing the filter). 166 * 167 *---------------------------------------------------------------------- 168 */ 169 typedef struct { 170 char *name; /* Name of the filter */ 171 ResampleFilterProc *proc; /* 1-D filter procedure. */ 172 double support; /* Width of 1-D filter */ 173 } ResampleFilter; 174 175 extern ResampleFilter *bltBoxFilterPtr; /* The ubiquitous box filter */ 176 177 178 /* 179 *---------------------------------------------------------------------- 180 * 181 * Filter2D -- 182 * 183 * Defines a convolution mask for a 2-D filter. Used to smooth or 184 * enhance images. 185 * 186 *---------------------------------------------------------------------- 187 */ 188 typedef struct { 189 double support; /* Radius of filter */ 190 double sum, scale; /* Sum of kernel */ 191 double *kernel; /* Array of values (malloc-ed) representing 192 * the discrete 2-D filter. */ 193 } Filter2D; 194 195 /* Prototypes of image routines */ 196 197 extern void Blt_ColorImageToGreyscale _ANSI_ARGS_((Blt_ColorImage image)); 198 199 extern void Blt_ColorImageToPhoto _ANSI_ARGS_((Blt_ColorImage image, 200 Tk_PhotoHandle photo)); 201 202 extern Pixmap Blt_ColorImageToPixmap _ANSI_ARGS_((Tcl_Interp *interp, 203 Tk_Window tkwin, Blt_ColorImage image, ColorTable *colorTablePtr)); 204 205 extern Blt_ColorImage Blt_ConvolveColorImage _ANSI_ARGS_(( 206 Blt_ColorImage srcImage, Filter2D *filter)); 207 208 extern Blt_ColorImage Blt_CreateColorImage _ANSI_ARGS_((int width,int height)); 209 210 extern Blt_ColorImage Blt_DrawableToColorImage _ANSI_ARGS_((Tk_Window tkwin, 211 Drawable drawable, int x, int y, int width, int height, 212 double inputGamma)); 213 214 extern int Blt_GetResampleFilter _ANSI_ARGS_((Tcl_Interp *interp, 215 char *filterName, ResampleFilter **filterPtrPtr)); 216 217 extern void Blt_FreeColorImage _ANSI_ARGS_((Blt_ColorImage image)); 218 219 #if HAVE_JPEG 220 extern Blt_ColorImage Blt_JPEGToColorImage _ANSI_ARGS_((Tcl_Interp *interp, 221 char *fileName)); 222 #endif 223 224 extern Blt_ColorImage Blt_PhotoToColorImage _ANSI_ARGS_(( 225 Tk_PhotoHandle photo)); 226 227 extern Blt_ColorImage Blt_PhotoRegionToColorImage _ANSI_ARGS_(( 228 Tk_PhotoHandle photo, int x, int y, int width, int height)); 229 230 extern int Blt_TransColorImage _ANSI_ARGS_((Blt_ColorImage src, 231 Blt_ColorImage dest, Pix32 *color, int alpha, int flags)); 232 233 extern int Blt_RecolorImage _ANSI_ARGS_((Blt_ColorImage src, 234 Blt_ColorImage dest, Pix32 *oldColor, Pix32 *newColor, int alpha)); 235 236 extern int Blt_MergeColorImage _ANSI_ARGS_((Blt_ColorImage src, 237 Blt_ColorImage src2, 238 Blt_ColorImage dest, double opacity, double opacity2, Pix32 *withColor)); 239 240 int Blt_ImageMergeInner _ANSI_ARGS_((Tcl_Interp *interp, char *srcName, char *src2Name, 241 char * destName, XColor *maskColor, int leaveMsg)); 242 243 extern int Blt_QuantizeColorImage _ANSI_ARGS_((Blt_ColorImage src, 244 Blt_ColorImage dest, int nColors)); 245 246 extern Blt_ColorImage Blt_ResampleColorImage _ANSI_ARGS_((Blt_ColorImage image, 247 int destWidth, int destHeight, ResampleFilter *horzFilterPtr, 248 ResampleFilter *vertFilterPtr)); 249 250 extern void Blt_ResamplePhoto _ANSI_ARGS_((Tk_PhotoHandle srcPhoto, 251 int x, int y, int width, int height, Tk_PhotoHandle destPhoto, 252 ResampleFilter *horzFilterPtr, ResampleFilter *vertFilterPtr)); 253 254 255 extern int Blt_BlurColorImage _ANSI_ARGS_(( 256 Tk_PhotoHandle srcPhoto, Tk_PhotoHandle dstPhoto, int radius)); 257 258 extern Blt_ColorImage Blt_ResizeColorImage _ANSI_ARGS_((Blt_ColorImage src, 259 int x, int y, int width, int height, int destWidth, int destHeight)); 260 261 extern Blt_ColorImage Blt_ResizeColorSubimage _ANSI_ARGS_((Blt_ColorImage src, 262 int x, int y, int width, int height, int destWidth, int destHeight)); 263 264 extern Blt_ColorImage Blt_RotateColorImage _ANSI_ARGS_((Blt_ColorImage image, 265 double theta)); 266 267 extern void Blt_ResizePhoto _ANSI_ARGS_((Tk_PhotoHandle srcPhoto, int x, int y, 268 int width, int height, Tk_PhotoHandle destPhoto)); 269 270 extern int Blt_SnapPhoto _ANSI_ARGS_((Tcl_Interp *interp, Tk_Window tkwin, 271 Drawable drawable, int x, int y, int width, int height, int destWidth, 272 int destHeight, char *photoName, double inputGamma)); 273 274 extern void Blt_ImageRegion _ANSI_ARGS_((Blt_ColorImage image, 275 Region2D *regionPtr)); 276 277 Blt_ColorImage Blt_CopyColorImage _ANSI_ARGS_(( Blt_ColorImage src)); 278 279 extern Region2D *Blt_ColorImageRegion _ANSI_ARGS_((Blt_ColorImage image, 280 Region2D *regionPtr)); 281 282 extern Region2D *Blt_SetRegion _ANSI_ARGS_((int x, int y, int width, 283 int height, Region2D *regionPtr)); 284 285 extern ColorTable Blt_CreateColorTable _ANSI_ARGS_((Tk_Window tkwin)); 286 287 extern ColorTable Blt_DirectColorTable _ANSI_ARGS_((Tcl_Interp *interp, 288 Tk_Window tkwin, Blt_ColorImage image)); 289 290 extern ColorTable Blt_PseudoColorTable _ANSI_ARGS_((Tcl_Interp *interp, 291 Tk_Window tkwin, Blt_ColorImage image)); 292 293 extern void Blt_FreeColorTable _ANSI_ARGS_((ColorTable colorTable)); 294 295 /* Missing routines from the Tk photo C API */ 296 297 extern int Tk_ImageIsDeleted _ANSI_ARGS_((Tk_Image tkImage)); 298 extern Tk_ImageMaster Tk_ImageGetMaster _ANSI_ARGS_((Tk_Image tkImage)); 299 extern Tk_ImageType *Tk_ImageGetType _ANSI_ARGS_((Tk_Image tkImage)); 300 extern Pixmap Tk_ImageGetPhotoPixmap _ANSI_ARGS_((Tk_Image photoImage)); 301 extern GC Tk_ImageGetPhotoGC _ANSI_ARGS_((Tk_Image photoImage)); 302 303 extern char *Blt_NameOfImage _ANSI_ARGS_((Tk_Image tkImage)); 304 extern Tk_Image Blt_CreateTemporaryImage _ANSI_ARGS_((Tcl_Interp *interp, 305 Tk_Window tkwin, ClientData clientData)); 306 extern int Blt_DestroyTemporaryImage _ANSI_ARGS_((Tcl_Interp *interp, 307 Tk_Image tkImage)); 308 309 extern GC Blt_GetBitmapGC _ANSI_ARGS_((Tk_Window tkwin)); 310 extern Pixmap Blt_PhotoImageMask _ANSI_ARGS_((Tk_Window tkwin, 311 Tk_PhotoImageBlock src)); 312 313 extern Pixmap Blt_RotateBitmap _ANSI_ARGS_((Tk_Window tkwin, Pixmap bitmap, 314 int width, int height, double theta, int *widthPtr, int *heightPtr)); 315 316 extern Pixmap Blt_ScaleBitmap _ANSI_ARGS_((Tk_Window tkwin, Pixmap srcBitmap, 317 int srcWidth, int srcHeight, int scaledWidth, int scaledHeight)); 318 319 extern Pixmap Blt_ScaleRotateBitmapRegion _ANSI_ARGS_((Tk_Window tkwin, 320 Pixmap srcBitmap, unsigned int srcWidth, unsigned int srcHeight, 321 int regionX, int regionY, unsigned int regionWidth, 322 unsigned int regionHeight, unsigned int virtWidth, 323 unsigned int virtHeight, double theta)); 324 325 typedef enum {MIRROR_X=1, MIRROR_Y=2, MIRROR_XY=3, MIRROR_TILE=4, MIRROR_OUTER=5, MIRROR_INNER=6} BltMirrorEnum; 326 327 extern int 328 Blt_ImageMirror(Tcl_Interp *interp, char *srcImg, char *dstImg, int flip, int halo); 329 330 331 #endif /*_BLT_IMAGE_H*/ 332