[4] | 1 | /****************************************************************************** |
---|
| 2 | * SAGE - Scalable Adaptive Graphics Environment |
---|
| 3 | * |
---|
| 4 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
| 5 | * University of Illinois at Chicago |
---|
| 6 | * |
---|
| 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright |
---|
| 13 | * notice, this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above |
---|
| 15 | * copyright notice, this list of conditions and the following disclaimer |
---|
| 16 | * in the documentation and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the University of Illinois at Chicago nor |
---|
| 18 | * the names of its contributors may be used to endorse or promote |
---|
| 19 | * products derived from this software without specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
| 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
| 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
| 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
| 25 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
| 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
| 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
| 28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
| 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
| 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
| 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | * |
---|
| 33 | * Direct questions, comments etc about SAGE to http://www.evl.uic.edu/cavern/forum/ |
---|
| 34 | * |
---|
| 35 | *****************************************************************************/ |
---|
| 36 | |
---|
| 37 | /* |
---|
| 38 | * Copyright 1995, Silicon Graphics, Inc. |
---|
| 39 | * ALL RIGHTS RESERVED |
---|
| 40 | * |
---|
| 41 | * UNPUBLISHED -- Rights reserved under the copyright laws of the United |
---|
| 42 | * States. Use of a copyright notice is precautionary only and does not |
---|
| 43 | * imply publication or disclosure. |
---|
| 44 | * |
---|
| 45 | * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: |
---|
| 46 | * Use, duplication or disclosure by the Government is subject to restrictions |
---|
| 47 | * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights |
---|
| 48 | * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or |
---|
| 49 | * in similar or successor clauses in the FAR, or the DOD or NASA FAR |
---|
| 50 | * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., |
---|
| 51 | * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. |
---|
| 52 | * |
---|
| 53 | * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY |
---|
| 54 | * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, |
---|
| 55 | * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY |
---|
| 56 | * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON |
---|
| 57 | * GRAPHICS, INC. |
---|
| 58 | * |
---|
| 59 | * image.h |
---|
| 60 | * |
---|
| 61 | * $Revision: 1.2 $ |
---|
| 62 | * $Date: 2004/06/25 03:36:29 $ |
---|
| 63 | */ |
---|
| 64 | |
---|
| 65 | #ifndef __GL_IMAGE__ |
---|
| 66 | #define __GL_IMAGE__ |
---|
| 67 | |
---|
| 68 | /* |
---|
| 69 | * Defines for image files . . . . |
---|
| 70 | * |
---|
| 71 | * Paul Haeberli - 1984 |
---|
| 72 | * |
---|
| 73 | * Brutally hacked into a c++ wrapper by Dave Springer, 1988. |
---|
| 74 | * reworked for C jimh 1991. |
---|
| 75 | * |
---|
| 76 | */ |
---|
| 77 | |
---|
| 78 | #include <stdio.h> |
---|
| 79 | #include <sys/types.h> /* for ushort16 and uint32 */ |
---|
| 80 | |
---|
| 81 | #ifndef _IOREAD |
---|
| 82 | # define _IOREAD 0x01 |
---|
| 83 | #endif |
---|
| 84 | #ifndef _IOWRT |
---|
| 85 | # define _IOWRT 0x02 |
---|
| 86 | #endif |
---|
| 87 | #ifndef _IORW |
---|
| 88 | # define _IORW 0x04 |
---|
| 89 | #endif |
---|
| 90 | #ifndef _IOEOF |
---|
| 91 | # define _IOEOF 0x08 |
---|
| 92 | #endif |
---|
| 93 | #ifndef _IOERR |
---|
| 94 | # define _IOERR 0x10 |
---|
| 95 | #endif |
---|
| 96 | |
---|
| 97 | #ifdef __cplusplus |
---|
| 98 | extern "C" { |
---|
| 99 | #endif |
---|
| 100 | |
---|
| 101 | #ifdef sun |
---|
| 102 | typedef uint16_t IMushort; |
---|
| 103 | typedef uint32_t IMulong; |
---|
| 104 | #else |
---|
| 105 | typedef u_int16_t IMushort; |
---|
| 106 | typedef u_int32_t IMulong; |
---|
| 107 | #endif |
---|
| 108 | |
---|
| 109 | typedef struct { |
---|
| 110 | IMushort imagic; /* stuff saved on disk . . */ |
---|
| 111 | IMushort type; |
---|
| 112 | IMushort dim; |
---|
| 113 | IMushort xsize; |
---|
| 114 | IMushort ysize; |
---|
| 115 | IMushort zsize; |
---|
| 116 | IMulong min; |
---|
| 117 | IMulong max; |
---|
| 118 | IMulong wastebytes; |
---|
| 119 | char name[80]; |
---|
| 120 | IMulong colormap; |
---|
| 121 | |
---|
| 122 | int file; /* stuff used in core only */ |
---|
| 123 | IMushort flags; |
---|
| 124 | int16_t dorev; |
---|
| 125 | int16_t x; |
---|
| 126 | int16_t y; |
---|
| 127 | int16_t z; |
---|
| 128 | int16_t cnt; |
---|
| 129 | IMushort *ptr; |
---|
| 130 | IMushort *base; |
---|
| 131 | IMushort *tmpbuf; |
---|
| 132 | IMulong offset; |
---|
| 133 | IMulong rleend; /* for rle images */ |
---|
| 134 | IMulong *rowstart; /* for rle images */ |
---|
| 135 | IMulong *rowsize; /* for rle images */ |
---|
| 136 | } IMAGE; |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | typedef struct { |
---|
| 140 | IMushort type; |
---|
| 141 | IMulong colormap; |
---|
| 142 | int xsize, ysize; |
---|
| 143 | IMulong *rowstart; |
---|
| 144 | IMulong *rowsize; |
---|
| 145 | IMushort *pixels; |
---|
| 146 | } MEMIMAGE ; |
---|
| 147 | |
---|
| 148 | #define IMAGIC 0732 |
---|
| 149 | |
---|
| 150 | /* type of the image */ |
---|
| 151 | #define CM_NORMAL 0 |
---|
| 152 | #define CM_DITHERED 1 |
---|
| 153 | #define CM_SCREEN 2 |
---|
| 154 | #define CM_COLORMAP 3 |
---|
| 155 | |
---|
| 156 | #define TYPEMASK 0xff00 |
---|
| 157 | #define BPPMASK 0x00ff |
---|
| 158 | #define ITYPE_VERBATIM 0x0000 |
---|
| 159 | #define ITYPE_RLE 0x0100 |
---|
| 160 | #define ISRLE(type) (((type) & 0xff00) == ITYPE_RLE) |
---|
| 161 | #define ISVERBATIM(type) (((type) & 0xff00) == ITYPE_VERBATIM) |
---|
| 162 | #define BPP(type) ((type) & BPPMASK) |
---|
| 163 | #define RLE(bpp) (ITYPE_RLE | (bpp)) |
---|
| 164 | #define VERBATIM(bpp) (ITYPE_VERBATIM | (bpp)) |
---|
| 165 | #define IBUFSIZE(pixels) ((pixels+(pixels>>6))<<2) |
---|
| 166 | #define RLE_NOP 0x00 |
---|
| 167 | |
---|
| 168 | #define ierror(p) (((p)->flags&_IOERR)!=0) |
---|
| 169 | #define ifileno(p) ((p)->file) |
---|
| 170 | |
---|
| 171 | #ifdef PIXMACROS |
---|
| 172 | #define getpix(p) (--(p)->cnt>=0? *(p)->ptr++:ifilbuf(p)) |
---|
| 173 | #define putpix(p,x) (--(p)->cnt>=0? ((int)(*(p)->ptr++=(unsigned)(x))):iflsbuf(p,(unsigned)(x))) |
---|
| 174 | #endif |
---|
| 175 | |
---|
| 176 | extern int iclose(IMAGE* image); |
---|
| 177 | extern int iflush(IMAGE* image); |
---|
| 178 | extern int ifilbuf(IMAGE* image); |
---|
| 179 | extern int iflsbuf(IMAGE* image, IMushort c); |
---|
| 180 | extern MEMIMAGE *newimage(int xsize, int ysize, int colormap); |
---|
| 181 | extern void freeimage(MEMIMAGE* mimage); |
---|
| 182 | extern void drawimage(int xorg, int yorg, MEMIMAGE* mimage); |
---|
| 183 | extern MEMIMAGE *readimage(char* name); |
---|
| 184 | extern MEMIMAGE *readrleimage(char* name); |
---|
| 185 | extern void img_transtoscreen(unsigned short* buf, int n); |
---|
| 186 | extern void img_setpixelortho(void); |
---|
| 187 | extern void img_makexmap(int colormap); |
---|
| 188 | extern void isetname(IMAGE* image, char* name); |
---|
| 189 | extern void isetcolormap(IMAGE* image, int colormap); |
---|
| 190 | extern IMAGE *iopen(char* file, char* mode, ...); |
---|
| 191 | /* |
---|
| 192 | extern IMAGE *iopen(char* file, char* mode, unsigned int type, |
---|
| 193 | unsigned int dim, unsigned int xsize, |
---|
| 194 | unsigned int ysize, unsigned int zsize); |
---|
| 195 | */ |
---|
| 196 | extern IMAGE *fiopen(int f, char* mode, unsigned int type, |
---|
| 197 | unsigned int dim, unsigned int xsize, |
---|
| 198 | unsigned int ysize, unsigned int zsize); |
---|
| 199 | extern IMAGE *imgopen(int f, char* file, char* mode, unsigned int type, |
---|
| 200 | unsigned int dim, unsigned int xsize, |
---|
| 201 | unsigned int ysize, unsigned int zsize); |
---|
| 202 | extern unsigned short* ibufalloc(IMAGE* image); |
---|
| 203 | extern int reverse(IMulong lwrd); |
---|
| 204 | extern void cvtshorts(IMushort* buffer, int n); |
---|
| 205 | extern void cvtlongs(IMulong* buffer, int n); |
---|
| 206 | extern void cvtimage(IMAGE *buffer); |
---|
| 207 | extern IMushort getpix(IMAGE* image); |
---|
| 208 | extern IMushort putpix(IMAGE* image, IMushort pix); |
---|
| 209 | extern int img_seek(IMAGE* image, int y, int z); |
---|
| 210 | extern int img_write(IMAGE* image, char* buffer, long count); |
---|
| 211 | extern int img_read(IMAGE* image, char* buffer, long count); |
---|
| 212 | extern unsigned long img_optseek(IMAGE* image, unsigned long offset); |
---|
| 213 | extern int img_getrowsize(register IMAGE* image); |
---|
| 214 | extern void img_setrowsize(IMAGE* image, int cnt, int y, int z); |
---|
| 215 | extern int img_rle_compact(IMushort* expbuf, int ibpp, |
---|
| 216 | IMushort* rlebuf, int obpp, int cnt); |
---|
| 217 | extern void img_rle_expand(IMushort* rlebuf, int ibpp, |
---|
| 218 | IMushort* expbuf, int obpp); |
---|
| 219 | extern int putrow(IMAGE* image, IMushort* buffer, int y, int z); |
---|
| 220 | extern int getrow(IMAGE* image, IMushort* buffer, int y, int z); |
---|
| 221 | |
---|
| 222 | extern void i_errhdlr(char *fmt, ...); |
---|
| 223 | extern int img_badrow( IMAGE *image, int y, int z ); |
---|
| 224 | |
---|
| 225 | #ifdef __cplusplus |
---|
| 226 | } |
---|
| 227 | #endif |
---|
| 228 | |
---|
| 229 | #endif /* _GL_IMAGE */ |
---|