core/vil/file_formats/vil_viffheader.h
Go to the documentation of this file.
00001 #ifndef vil_viffheader_h_
00002 #define vil_viffheader_h_
00003 /*
00004 * Copyright 1990, 1991, 1992 (c) Khoral Research, Inc.
00005 *
00006 * All rights reserved.
00007 *
00008 * The viff.h file is a plain ascii C include file.  It is a copy of the
00009 * file in KHOROS_HOME/include/viff.h, but with a less restrictive
00010 * copyright.  The purpose of this file is allow others to build in
00011 * interoperability to their software, without having to get a Khoros license to
00012 * distribute their software.   Redistribution of any other component of
00013 * Khoros still needs a separate license that is available via the Khoros
00014 * Consortium.
00015 *
00016 * For further information, contact:
00017 *
00018 * khoros-request@khoros.unm.edu
00019 *
00020 *----------------------------------------------------------------------
00021 *
00022 * Copyright 1990, University of New Mexico.  All rights reserved.
00023 *
00024 * Permission to copy, modify, and use this include file is hereby
00025 * granted, provided that this notice is retained thereon and
00026 * on all copies.  UNM makes no representations as too the sui-
00027 * tability and operability of this software for any purpose.
00028 * It is provided "as is" without express or implied warranty.
00029 *
00030 * UNM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00031 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
00032 * NESS.  IN NO EVENT SHALL UNM BE LIABLE FOR ANY SPECIAL,
00033 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY OTHER DAMAGES WHAT-
00034 * SOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
00035 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
00036 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PER-
00037 * FORMANCE OF THIS SOFTWARE.
00038 *
00039 *----------------------------------------------------------------------
00040 */
00041 
00042 /*
00043 file: viff.h
00044 
00045 contains:  Khoros Visualization/Image File Format.
00046            Design considerations included the need
00047            for portability, expandability and simplicity.
00048 
00049 written by: John Rasure
00050 
00051 date: 5/5/88
00052 
00053 modifications:  Scott R. Wilson 1/13/88
00054   Scott R. Wilson 5/3/88 - Version 2, Release 0
00055   Scott Wilson, John Rasure, Tom Sauer, and
00056   Mark Young:  2/18/89 - Version 3 Release 0
00057   Scott Wilson - Version 3.1
00058   Tom Sauer - 7/12/89 removed the #defines for
00059     location dimension
00060   Scott Wilson - Correct comment for
00061     subrow_size 5/9/90
00062   Scott Wilson - Deleted unneeded include of
00063     vdefines.h 18-Jan-91
00064 */
00065 
00066 #include <vxl_config.h> /* for vxl_uint_32 */
00067 
00068 
00069 /* this is a C header file. you cannot use // comments in it
00070 //:
00071 // \file
00072 // \brief  Khoros Visualization/Image File Format.
00073 // \author John Rassure
00074 // \date May 5, 1988
00075 //
00076 // \verbatim
00077 // ******************************************************************
00078 //  Khoros Visualization/Image File Format
00079 //
00080 //  A Khoros data file is organized as a 1Kbyte header
00081 //  followed by additional information.  The first two
00082 //  bytes of the header tell what kind of stuff the
00083 //  additional information is.  For Khoros image files,
00084 //  the additional information consists of the maps,
00085 //  the location data, and then the image or vector data.
00086 //
00087 //  There is a supporting document for this file called
00088 //  "The Khoros Visualization/Image File Format" that will help to
00089 //  explain the various fields, see $KHOROS_HOME/manual/viff_format.
00090 //
00091 //  The header fields where carefully selected to
00092 //  prevent contradictions between categories, i.e. they
00093 //  were chosen to be orthogonal to each other.  However,
00094 //  in several situations this causes the fields to supply
00095 //  redundant information.
00096 //
00097 //  Note that the structure contains pointers to the various
00098 //  chunks of data.  These will make sense ONLY when the
00099 //  data is in memory.
00100 //
00101 //  *imagedata - points to a sequence of images, an image is
00102 //  made up of bands, and the bands are in a sequence; or
00103 //  it can point to vectors, where the vector dimension is
00104 //  the number of bands.
00105 //
00106 //  *maps - points to a sequence of 2-dimensional maps, a map
00107 //  is organized as stacked columns.  A data value indexes map rows.
00108 //
00109 //  *location - points to bands of coordinate values, ie if
00110 //  two dimensional locations, then there would be a band
00111 //  of x's followed by a band of y's.
00112 //
00113 //  The Khoros convention for the image orientation is
00114 //  with the image origin in the upper left hand corner.
00115 //
00116 // ******************************************************************
00117 //
00118 // Modified 2010 for use with VXL for loading and saving viff images.
00119 // Derived from appropriately licensed copy found in archive of old
00120 // file formats stored in ./viffheader.h.original and found at
00121 // http://www.redwoodsoft.com/~dru/museum/gfx/gff/vendspec/viff/viff.h
00122 //
00123 // Ian Scott 15 Jan 2010
00124 // \endverbatim
00125 */
00126 
00127 
00128 #define VIFF_HEADERSIZE 1024
00129 
00130 
00131 enum vil_viff_data_storage
00132 {
00133   VFF_TYP_BIT= 0,       /* pixels are on or off (binary image)*/
00134 /* Note: This is an X11 XBitmap
00135    with bits packed into a byte and
00136    padded to a byte */
00137   VFF_TYP_1_BYTE=   1,  /* pixels are byte (unsigned char) */
00138   VFF_TYP_2_BYTE=   2,  /* pixels are two byte (short int) */
00139   VFF_TYP_4_BYTE=   4,  /* pixels are four byte (integer) */
00140   VFF_TYP_FLOAT=    5,  /* pixels are float (single precision)*/
00141   VFF_TYP_COMPLEX=  6,  /* pixels are complex float */
00142   VFF_TYP_DOUBLE=   9,  /* pixels are float (double precision)*/
00143   VFF_TYP_DCOMPLEX= 10 /* pixels are double complex */
00144 };
00145 
00146 /* image structure definition */
00147 
00148 struct vil_viff_xvimage  {
00149   vil_viff_xvimage(
00150     unsigned ncols, unsigned nrows,
00151     vil_viff_data_storage storage_type,
00152     unsigned num_data_bands);
00153 
00154   vil_viff_xvimage();
00155 
00156   /*  Administrative or file management information */
00157 
00158   char  identifier;  /* a magic number (XV_FILE_MAGIC_NUM) that tells
00159                         the world that this is an
00160                         Khoros file */
00161 
00162   char  file_type;  /* tells if this file is a VIFF file if equal to XV_FILE_TYPE_XVIFF*/
00163 
00164   char   release;  /* release number */
00165 
00166   char  version;  /* version number */
00167 
00168   char  machine_dep;  /* indicates peculiarities of */
00169   /* machine architecture */
00170 
00171   char    trash[3];  /* preserves word boundaries */
00172   /* groups of 4 bytes */
00173 
00174   char  comment[512];  /* text for image commentary */
00175 
00176   /* Things that specify the spatial properties of the image, pixel
00177      organization, and data storage arrangement.  */
00178 
00179   vxl_uint_32  row_size;  /* length of row in pixels,
00180                              i.e. number of columns */
00181 
00182   vxl_uint_32  col_size;  /* length of column in pixels,
00183                              i.e. number or rows */
00184 
00185   vxl_uint_32  subrow_size;    /* Length of subrows. This is useful
00186                                   when one wants pixel vectors to
00187                                   represent 2D objects (images).
00188                                   The size of each pixel "image"
00189                                   would be subrow_size (columns)
00190                                   by num_data_bands/subrow_size (rows).
00191                                   This field may be ignored except
00192                                   by routines that need the 2D
00193                                   interpretation. */
00194 
00195   /* The product of row_size and col_size is used to indicate
00196      the number of locations when the location type is explicit,
00197      the product also indicates the number of pixels in a band,
00198      or the number of vectors.  */
00199 
00200   vxl_sint_32  startx, starty;  /* subimage starting position (upper
00201                                    left hand corner), negative indicates
00202                                    that it is not a subimage */
00203 
00204   float   pixsizx, pixsizy;  /* Actual size of pixel at time of
00205                                 digitization in meters */
00206 
00207   vxl_uint_32  location_type;  /* implied or explicit location
00208                                   data  (implied locations are
00209                                   derived from row_size and
00210                                   col_size) */
00211 
00212   vxl_uint_32  location_dim;  /* explicit locations can be of
00213                                  any dimension  */
00214 
00215   vxl_uint_32  num_of_images;     /* number of images
00216                                      pointed to by *imagedata,
00217                                      do not confuse with number of
00218                                      bands */
00219 
00220   vxl_uint_32  num_data_bands;  /* Number of bands per data pixel,
00221                                    or number of bands per image, or
00222                                    dimension of vector data, or
00223                                    number of elements in a vector */
00224 
00225   vxl_uint_32  data_storage_type;  /* storage type for disk data */
00226 
00227   vxl_uint_32  data_encode_scheme; /* encoding scheme of disk data */
00228 
00229   /* Things that determine how the mapping (if any) of data bands is
00230      to be done to obtain the actual "image" or data.  */
00231 
00232   vxl_uint_32  map_scheme;   /* How mapping (if any) is to occur */
00233 
00234   vxl_uint_32  map_storage_type;/* Storage type of cells in the maps */
00235 
00236   vxl_uint_32  map_row_size; /* number of columns in map array */
00237 
00238   vxl_uint_32  map_col_size;  /* number of entries in map (rows) */
00239 
00240   vxl_uint_32  map_subrow_size; /* Length of subrows. This is useful
00241                                    when using the output vector from
00242                                    the map as a 2-D image, rather
00243                                    than just a vector. The size of
00244                                    the 2-D image would be:
00245                                    map_subrow_size (columns) by
00246                                    map_row_size/map_subrow_size
00247                                    (rows). This field may be ignored
00248                                    except by routines that need the 2D
00249                                    interpretation */
00250 
00251   vxl_uint_32  map_enable;  /* Tells if the disk data is valid
00252                                with or without being sent thru the
00253                                map. Some data MUST be mapped to be
00254                                valid. */
00255 
00256   vxl_uint_32  maps_per_cycle;  /* number of maps to constitue a "cycle"
00257                                    for VFF_MS_CYCLE */
00258 
00259   /* Specification of the particular color model in use when working with a
00260      color image. This just tells what the coordinate system and axis orientation
00261      of the color space is.  */
00262 
00263   vxl_uint_32  color_space_model;
00264 
00265   /* Extra fields for use by the user as needed. These are NOT SUPPORTED
00266      in any way, except for being read and written correctly with respect
00267      to machine dependencies.  */
00268 
00269   vxl_uint_32   ispare1,ispare2;  /* Spare long ints */
00270 
00271   float    fspare1,fspare2;  /* Spare floats */
00272 
00273   /* Pointers to the actual data - these are valid only when in memory! */
00274 
00275   char  reserve[VIFF_HEADERSIZE - (21*sizeof(vxl_sint_32))
00276     - (520*sizeof(char))
00277     - (2*sizeof(char *)) - (4*sizeof(float))
00278     - (sizeof(float *))];
00279   /* maximum header information is
00280      1024 bytes, what is not currently
00281      used is saved in reserve */
00282 
00283   char *maps;    /* a pointer to the maps, must be cast into
00284                     the proper type */
00285 
00286   float *location;  /* a pointer to the location data (for
00287                        explicit locations, each location is
00288                        paired with data pointed to by
00289                        *imagedata); all locations are
00290                        in float */
00291 
00292   char *imagedata;  /* a pointer to the input data (straight off
00293                        of disk), must be cast into the proper type */
00294 
00295 } ;
00296 
00297 
00298 #define XV_FILE_MAGIC_NUM  0xab    /* Khoros file identifier */
00299 #define XV_FILE_TYPE_XVIFF    1       /* indicates an image file */
00300 
00301 /* definitions for version number,
00302 char release; */
00303 #define XV_IMAGE_VER_NUM      3  /* Version 3 (3.1) */
00304 
00305 /* definitions for release number,
00306 char version; */
00307 #define XV_IMAGE_REL_NUM      1  /* Release 1   */
00308 
00309 /* definitions for subimage information,
00310 vxl_sint_32 startx, starty; */
00311 #define VFF_NOTSUB          ~0  /* a negative number indicates that
00312 the image is not a subimage  */
00313 
00314 /* definitions for machine dependencies,
00315 char machine_dep; */
00316 #define VFF_DEP_IEEEORDER  0x2  /* IEEE byte ordering */
00317 #define VFF_DEP_DECORDER   0x4  /* DEC (VAX) byte ordering */
00318 #define VFF_DEP_NSORDER    0x8  /* NS32000 byte ordering */
00319 #define VFF_DEP_CRAYORDER  0xA  /* Cray byte size and ordering */
00320 
00321 #define VFF_DEP_BIGENDIAN  VFF_DEP_IEEEORDER
00322 #define VFF_DEP_LITENDIAN  VFF_DEP_NSORDER
00323 
00324 /* definitions for data encoding scheme on disk - i.e. it may be
00325    compressed using RLE, or uncompressed (RAW).
00326    vxl_uint_32 data_encode_scheme; */
00327 #define VFF_DES_RAW       0  /* Raw - no compression */
00328 #define VFF_DES_COMPRESS  1  /* Compressed using ALZ */
00329 #define VFF_DES_RLE       2  /* Compressed using RLE */
00330 #define VFF_DES_TRANSFORM 3  /* Transform based compression */
00331 #define VFF_DES_CCITT     4  /* CCITT standard compression */
00332 #define VFF_DES_ADPCM     5  /* ADPCM compression */
00333 #define VFF_DES_GENERIC   6  /* User-specified compression */
00334 
00335 /* definitions for map data or cells storage type,
00336    vxl_uint_32 map_storage_type; */
00337 #define VFF_MAPTYP_NONE    0  /* No cell type is assigned  */
00338 #define VFF_MAPTYP_1_BYTE  1  /* cells are byte (unsigned char)    */
00339 #define VFF_MAPTYP_2_BYTE  2  /* cells are two byte (short int) */
00340 #define VFF_MAPTYP_4_BYTE  4  /* cells are four byte (integer) */
00341 #define VFF_MAPTYP_FLOAT   5  /* cells are float (single precision) */
00342 #define VFF_MAPTYP_COMPLEX 6  /* cells are complex FLOAT */
00343 #define VFF_MAPTYP_DOUBLE  7  /* cells are float (double precision) */
00344 
00345 /* definitions for mapping schemes, vxl_uint_32 map_scheme; */
00346 #define VFF_MS_NONE       0  /* No mapping is to be done, and no
00347                                 maps are to be stored. */
00348 #define VFF_MS_ONEPERBAND 1  /* Each data band has its own map */
00349 #define VFF_MS_CYCLE      2  /* An array of maps is selected in order
00350                                 by groups of maps_per_cycle, allowing
00351                                 "rotating the color map" */
00352 #define VFF_MS_SHARED     3  /* All data band share the same map */
00353 #define VFF_MS_GROUP      4  /* All data bands are "grouped"
00354                                 together to point into one map */
00355 
00356 /* definitions for enabling the map, vxl_uint_32 map_enable; */
00357 #define VFF_MAP_OPTIONAL  1  /* The data is valid without being
00358                                sent thru the color map. If a
00359                                map is defined, the data may
00360                                optionally be sent thru it. */
00361 #define  VFF_MAP_FORCE    2  /* The data MUST be sent thru the map
00362                                 to be interpreted */
00363 
00364 /* definitions for color map models, vxl_uint_32 color_space_model; */
00365 
00366 /*  the models use the following convention:
00367     ntsc: national television systems committee
00368     cie:  Commission Internationale de L'Eclairage
00369     ucs:  universal chromaticity scale
00370     RGB:  red band, green band, blue band
00371     CMY:  cyan band, magenta band, yellow band
00372     YIQ:  luminance, I and Q represent chrominance
00373     HSV:  hue, saturation, value
00374     IHS:  intensity, hue, saturation
00375     XYZ:
00376     UVW:
00377     SOW:
00378     Lab:
00379     Luv:
00380 
00381     For more information on how to interpret the combined meaning of the
00382     colorspace fields, see the document in $KHOROS_HOME/manual/viff_format,
00383     which contains detailed descriptions on the fields along with numerous
00384     examples of proper use.  */
00385 
00386 #define VFF_CM_NONE         0
00387 #define  VFF_CM_ntscRGB     1
00388 #define  VFF_CM_ntscCMY     2
00389 #define  VFF_CM_ntscYIQ     3
00390 #define  VFF_CM_HSV         4
00391 #define  VFF_CM_HLS         5
00392 #define  VFF_CM_IHS         6
00393 #define  VFF_CM_cieRGB      7
00394 #define  VFF_CM_cieXYZ      8
00395 #define  VFF_CM_cieUVW      9
00396 #define  VFF_CM_cieucsUVW  10
00397 #define  VFF_CM_cieucsSOW  11
00398 #define  VFF_CM_cieucsLab  12
00399 #define  VFF_CM_cieucsLuv  13
00400 #define  VFF_CM_GENERIC    14  /* the color space is user defined */
00401 #define  VFF_CM_genericRGB 15  /* an RGB image but not conforming
00402                                   to any standard */
00403 
00404 /* definitions for location type, vxl_uint_32 location_type; */
00405 #define  VFF_LOC_IMPLICIT  1  /*  The location of image pixels
00406                                   or vector data is given by using
00407                                   the implied 2D array given by
00408                                   row_size and col_size.  */
00409 #define  VFF_LOC_EXPLICIT  2  /*  The location of the image pixels
00410                                   or the vectors is explicit */
00411 
00412 
00413 #endif /* vil_viffheader_h_ */