1 /***********************************************************************/ 2 /* Open Visualization Data Explorer */ 3 /* (C) Copyright IBM Corp. 1989,1999 */ 4 /* ALL RIGHTS RESERVED */ 5 /* This code licensed under the */ 6 /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */ 7 /***********************************************************************/ 8 /* 9 * $Header: /src/master/dx/src/exec/dxmods/_rw_image.h,v 1.8 2005/02/01 00:36:23 davidt Exp $ 10 */ 11 12 #include <dxconfig.h> 13 14 #ifndef __RW_IMAGE_H_ 15 #define __RW_IMAGE_H_ 16 17 /* 18 * This file contains basic support for reading/writing images. 19 * We define enumerated image types, the tables entries that define 20 * an image format, some helper routines (and much much more...). 21 */ 22 #include <stdio.h> 23 24 #define MAX_IMAGE_NAMELEN 512 25 #define MAX_IMAGE_PATHLEN 2048 26 27 #define COLORTYPE_FLOAT "DXFloat" 28 #define COLORTYPE_BYTE "DXByte" 29 #define COLORTYPE_DELAYED "DXDelayedColor" 30 #define COLORTYPE_UNSPEC "DXInherent" 31 32 #define DELAYED_NO 0 33 #define DELAYED_YES 1 34 #define DELAYED_UNSPEC 2 35 36 /* 37 * Define the various image types. 38 * No entries of type 0, please. This is the libsvs error code. 39 */ 40 41 typedef enum imagetype { 42 img_typ_illegal = -1, 43 /* img_typ_error = 0 - A place holder so 0 is not used */ 44 img_typ_rgb = 1, 45 img_typ_r_g_b = 2, 46 img_typ_fb = 3, 47 img_typ_tiff = 4, 48 img_typ_ps_color = 5, 49 img_typ_eps_color = 6, 50 img_typ_ps_gray = 7, 51 img_typ_eps_gray = 8, 52 img_typ_gif = 9, 53 img_typ_yuv = 10, 54 img_typ_miff = 11, 55 img_typ_im = 12 56 } ImageType; 57 58 /* 59 * Bits that should be used in the 'flags' field of the image_info structure. 60 */ 61 /* Image format supported by DASD */ 62 #define ADASD_OK 0x1 63 /* Image format only supported on DASD */ 64 #define ADASD_ONLY 0x2 65 /* 66 * The image format supports appendable files. That is, we don't modify 67 * the file name (_dxf_BuildImageFileName()), when a frame number is specified. 68 */ 69 #define APPENDABLE_FILES 0x4 70 71 /* 72 * The format supports piping to stdout and will use the pipe if provied 73 * in RWImageArgs.pipe. 74 */ 75 #define PIPEABLE_OUTPUT 0x8 76 77 /* 78 * Define the arguments that are passed to the image writing functions 79 * via the following typedefs. 80 * Arguments: 81 * 1) Field - the field containing the image (possibly a 82 * series, but not composite) to write. 83 * 2) char* - the filename (without extension) to use when writing 84 * the image file. 85 * 3) ImageType - this is somewhat redundant but specifies the 86 * image type that is to be written out. 87 * 4) int - indicates the frame to be (over)written on the output 88 * file. This may not be supported for each format. 89 * 5) int - a flag that if true, indicates that the output file is 90 * to be written on the disk array device. 91 * 6) FILE* - if non-zero a pipe opened by WriteImage that should be 92 * written to by the format specific methods. 93 * 94 */ 95 /* Structure used to pass arguments to read/write routines. */ 96 typedef struct { 97 Field image; 98 char *basename; 99 char *extension; 100 ImageType imgtyp; 101 Class imgclass; 102 int startframe; 103 int adasd; 104 char *format; /* The format specified to WriteImage */ 105 char *compression; /* The compression of the format */ 106 unsigned int quality; /* compression level */ 107 unsigned int reduction; /* Amount to reduce while writing */ 108 float gamma; 109 FILE *pipe; 110 } RWImageArgs; 111 /* Function type that does the write work */ 112 typedef Error (*ImageWriteFunction)(RWImageArgs *iargs); 113 114 /* 115 * The following structure is used to help define supported image types. 116 */ 117 typedef struct { 118 /* 119 * What type of Image is this record for (tiff, rgb ...) 120 * This tag is used as a search key in ImageTable[]. 121 */ 122 ImageType type; 123 /* 124 * The number of files needed to support this type of file, usually 125 * just 1, but when more than 1 the 'extenstions' field should 126 * contain a list of sequentially ordered extensions. 127 */ 128 int files; 129 /* 130 * A colon separated character string indicating the recognized 131 * A (possibly colon separated) character string indicating the 132 * recognized format specifiers for this image type 133 * (i.e. "ps:ps-color"). 134 */ 135 char *formats; 136 /* 137 * A (possibly colon separated) character string indicating allowed 138 * extensions for this image type (i.e. "r:g:b"). Also, see the 139 * comment for the 'files' field. 140 */ 141 char *extensions; 142 /* 143 * Any extra information that may be needed. 144 */ 145 int flags; 146 /* 147 * A function that can write this image format to disk. 148 */ 149 ImageWriteFunction write; 150 /* 151 * A function that can read this image format from disk. 152 */ 153 ImageWriteFunction read; 154 } ImageInfo; 155 156 157 /* 158 * Get 'flags' field from the entry in ImageTable[] with image type 'type' 159 */ 160 ImageInfo *_dxf_ImageInfoFromType(ImageType type); 161 162 /* 163 * Determine the image type from a format specifier (i.e. "rgb", "r+g+b"...) 164 * 'format' is searched for in ImageTable[] and if found the corresponding 165 * 'type' field is returned. 166 */ 167 ImageInfo *_dxf_ImageInfoFromFormat(char *format); 168 169 /* 170 * Determine the image type from a filename (i.e. "image.rgb", "image.fp"...) 171 * The extension (the part after the last '.') is searched for in 172 * the 'extensions' field of the ImageTable[] entries and if found the 173 * corresponding 'type' field is returned. 174 */ 175 ImageInfo *_dxf_ImageInfoFromFileName ( char *basename); 176 177 /* 178 * Remove the extension (last part of filename after '.') if it is an 179 * extension for the given image type. 180 */ 181 void _dxf_RemoveImageExtension(char *name, ImageType type); 182 183 /* 184 * Extract the extension (last part of filename after '.') if it is an 185 * extension for the given image type. 186 */ 187 char * 188 _dxf_ExtractImageExtension ( char *name, ImageType type, 189 char *ext, int ext_size ); 190 191 /* 192 * Get the 'member'th image of series. Assert that dimensions match 193 * a un-partition the image if it is composite. 194 */ 195 Field _dxf_GetFlatSeriesImage(Series image, int member, 196 int width, int height, int *created); 197 198 199 200 /* 201 * Remove the last dotted part from a filename. 202 */ 203 char * _dxf_RemoveExtension ( char *extended ); 204 205 /*-------------------- Begin _rgb_image.c ----------------------------------*/ 206 207 SizeData *_dxf_ReadImageSizesADASD ( char *name, SizeData *sd ); 208 char *_dxf_BuildImageFileName ( char *, int, char *, ImageType, int, int); 209 char *_dxf_ReplaceImageFileExtension ( char*, int, char*, ImageType, char*); 210 211 /* 212 * The following are routines to write specific image formats to disk. 213 */ 214 /* Write an image in "fb" format, see _rgb_image.c */ 215 Error _dxf_write_fb(RWImageArgs *iargs); 216 217 /* Write an image in "rgb" format, see _rgb_image.c */ 218 Error _dxf_write_rgb(RWImageArgs *iargs); 219 220 /* Write an image in "r+g+b" format, see _rgb_image.c */ 221 Error _dxf_write_r_g_b(RWImageArgs *iargs); 222 223 Error _dxf_write_yuv(RWImageArgs *iargs); 224 225 /* 226 * Read/write the 'size' files associated with "rgb", "r+g+b" format 227 * Until we make ReadImage run off of ImageTable[] like WriteImage 228 * does, these need to be declared external (readimage.m references them). 229 */ 230 SizeData *_dxf_ReadSizeFile ( char *name, SizeData *sd ); 231 Error _dxf_WriteSizeFile ( char *name, SizeData sd ); 232 233 /*-------------------- End _rgb_image.c ----------------------------------*/ 234 235 /*-------------------- Begin _tiff.c ----------------------------------*/ 236 237 char * _dxf_BuildTIFFReadFileName 238 ( char *buf, int bufl, char *basename, char *fullname, int framenum, 239 int *numeric, int *selection ); 240 241 SizeData * _dxf_ReadImageSizesTIFF 242 ( char *name, int startframe, SizeData *data, int *use_numerics, 243 int ext_sel, int *multiples ); 244 245 Field _dxf_InputTIFF 246 (int width, int height, char *name, int relframe, int delayed, char * colortype); 247 248 /* Write an image in "tiff" format, see _tiff.c */ 249 Error _dxf_write_tiff(RWImageArgs *iargs); 250 251 /*-------------------- End _tiff.c ----------------------------------*/ 252 253 /*-------------------- Begin _gif.c ----------------------------------*/ 254 255 char * _dxf_BuildGIFReadFileName 256 ( char *buf, int bufl, char *basename, char *fullname, int framenum, 257 int *numeric, int *selection ); 258 259 SizeData * _dxf_ReadImageSizesGIF 260 ( char *name, int startframe, SizeData *data, int *use_numerics, 261 int ext_sel, int *multiples ); 262 263 Field _dxf_InputGIF 264 (int width, int height, char *name, int relframe, int delayed, char *colortype); 265 266 /* Write an image in "gif" format, see _gif.c */ 267 Error _dxf_write_gif(RWImageArgs *iargs); 268 269 /*-------------------- End _gif.c ----------------------------------*/ 270 271 /*-------------------- Begin _im_image.c ----------------------------------*/ 272 Error _dxf_write_im(RWImageArgs *iargs); 273 274 char * _dxf_BuildIMReadFileName 275 ( char *buf, int bufl, char *basename, char *fullname, 276 char *extension, int framenum, int *numeric ); 277 278 SizeData * _dxf_ReadImageSizesIM 279 ( char *name, int startframe, SizeData *data, int *use_numerics, 280 int *multiples ); 281 282 Field _dxf_InputIM( int width, int height, char *name, int relframe, 283 int delayed, char *colortype ); 284 285 int _dxf_ValidImageExtensionIM( char *ext ); 286 287 /*-------------------- End _im_image.c ----------------------------------*/ 288 /*-------------------- Begin _ps.c ----------------------------------*/ 289 290 /* Write a color image in PostScript format */ 291 Error _dxf_write_ps_color(RWImageArgs *iargs); 292 293 /* Write a gray image in PostScript format */ 294 Error _dxf_write_ps_gray(RWImageArgs *iargs); 295 296 /* Write a color image in Encapsulated PostScript format */ 297 Error _dxf_write_eps_color(RWImageArgs *iargs); 298 299 /* Write a gray image in Encapsulated PostScript format */ 300 Error _dxf_write_eps_gray(RWImageArgs *iargs); 301 302 Error _dxf_write_miff(RWImageArgs *iargs); 303 SizeData * _dxf_ReadImageSizesMIFF 304 ( char *name, int startframe, SizeData *data, int *use_numerics, 305 int ext_sel, int *multiples ); 306 307 Field _dxf_InputMIFF 308 (FILE **fh, int width, int height, char *name, int relframe, int delayed, char *colortype); 309 /*-------------------- End _ps.c ----------------------------------*/ 310 311 Error _dxf_make_gamma_table(ubyte *gamma_table, float gamma); 312 313 #endif /* __RW_IMAGE_H_ */ 314