home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / netpbma.zip / ppm / xim.h < prev    next >
C/C++ Source or Header  |  1993-10-04  |  6KB  |  122 lines

  1. /* xim.h - header file for Xim files
  2. **
  3. ** Taken from the X.V11R4 version of XimHeader.h:
  4. **
  5. ** Author: Philip R. Thompson
  6. ** Address:  phils@athena.mit.edu, 9-526 
  7. ** Note:  size of header should be 1024 (1K) bytes.
  8. ** $Header: /mit/phils/X/RCS/XimHeader.h,v 1.7 89/11/09 17:26:54 phils Exp Locker: phils $
  9. ** $Date: 89/11/09 17:26:54 $
  10. ** $Source: /mit/phils/X/RCS/XimHeader.h,v $
  11. */
  12.  
  13. #define IMAGE_VERSION    3
  14. #ifndef _BYTE
  15. typedef unsigned char  byte;
  16. #define _BYTE  1
  17. #endif
  18.  
  19. /* External ascii file format. */
  20. typedef struct ImageHeader {
  21.     char file_version[8];   /* header version */
  22.     char header_size[8];    /* Size of file header in bytes  */
  23.     char image_width[8];    /* Width of the raster image */
  24.     char image_height[8];   /* Height of the raster imgage */
  25.     char num_colors[8];     /* Actual number of entries in c_map */
  26.     char num_channels[3];   /* 0 or 1 = pixmap, 3 = RG&B buffers */
  27.     char bytes_per_line[5]; /* bytes per scanline */
  28.     char num_pictures[4];   /* Number of pictures in file */
  29.     char bits_per_channel[4]; /* usually 1 or 8 */
  30.     char alpha_channel[4];  /* Alpha channel flag */
  31.     char runlength[4];      /* Runlength encoded flag */
  32.     char author[48];        /* Name of who made it */
  33.     char date[32];          /* Date and time image was made */
  34.     char program[16];       /* Program that created this file */
  35.     char comment[96];       /* other viewing info. for this image */
  36.     unsigned char c_map[256][3]; /* RGB values of the pixmap indices */
  37. } ImageHeader, XimAsciiHeader;
  38.  
  39.  
  40. /* Internal binary format. */
  41. typedef struct Color {
  42.     byte pixel, red, grn, blu;
  43. } Color;
  44.  
  45. typedef struct XimImage {
  46.     int width;             /* width of the image in pixels */
  47.     int height;            /* height of the image in pixels */
  48.     unsigned datasize;     /* size of one channel of data */
  49.     short nchannels;     /* number data channels in image */
  50.     short bits_channel;  /* usually 1 or 8 */
  51.     short bytes_per_line; /* bytes to hold one scanline */
  52.     byte* data;            /* pixmap or red channel data */
  53.     byte* grn_data;        /* green channel data */
  54.     byte* blu_data;        /* blue  channel data */
  55.     byte* other;           /* other (alpha) data */
  56.     unsigned alpha_flag :1; /* alpha channel flag */
  57.     unsigned packed_flag:1; /* data packed in one chunk of memory */
  58.     unsigned runlen_flag:1; /* runlength encoded data flag */
  59.     unsigned : 0;           /* future flags, word alignment */
  60.     short tpics, npics;    /* number of images, total & left in file */
  61.     short ncolors;         /*   "    "  colors in the color table */
  62.     Color* colors;         /* colortable, one byte per r/g/b & pixel */
  63.     char* author;         /* author credit, copyright, etc */
  64.     char* date;           /* date image was made, grabbed, etc. */
  65.     char* program;        /* program used to make this */
  66.     short ncomments;       /* number of comments strings */
  67.     char** comments;      /* pointers to null terminated strings */
  68.     char* offset;         /* original offset in machine memory */
  69.     float chroma_red[2];   /* x, y image chromacity coords */
  70.     float chroma_grn[2];
  71.     float chroma_blu[2];
  72.     float chroma_wht[2];
  73.     float gamma;           /* image storage gamma */
  74. } XimImage;
  75.  
  76. /* Future external ascii variable length header - under review. */
  77. #if (VERSION == 4)
  78. typedef struct XimAsciiHeader {
  79.     char file_version[4];   /* header version */
  80.     char header_size[8];    /* Size of file header (fixed part only) */
  81.     char image_height[8];   /* Height of the raster imgage in pixels */
  82.     char image_width[8];    /* Width of the raster image in pixels */
  83.     char bytes_line[8];     /* Actual # of bytes separating scanlines */
  84.     char bits_channel[4];   /* Bits per channel (usually 1 or 8) */
  85.     char num_channels[4];   /* 1 = pixmap, 3 = RG&B buffers */
  86.     char alpha_channel[2];  /* Alpha channel flag */
  87.     char num_colors[4];     /* Number of entries in c_map (if any) */
  88.     char num_pictures[4];   /* Number of images in file */
  89.     char runlength_flag[2]; /* Runlength encoded flag */
  90.     char future_flags[8];
  91.     char author[48];        /* Name of who made it, from passwd entry */
  92.     char date[32];          /* Unix format date */
  93.     char program[32];       /* Program that created this */
  94.     char gamma[12];         /* image storage gamma */
  95.     char chroma_red[24];    /* image red primary chromaticity coords. */
  96.     char chroma_grn[24];    /*   "   green "          "         "     */
  97.     char chroma_blu[24];    /*   "   blue  "          "         "     */
  98.     char chroma_wht[24];    /*   "   white point      "         "     */
  99.     char comment_length[8]  /* Total length of comments */
  100.     /* char* comment;           Null separated comments  */
  101.     /* unsigned char c_map[];   RGB Colortable, (ncolors * 3 bytes) */
  102. }  XimAsciiHeader;
  103. #endif /*VERSION 4*/
  104.  
  105. #ifndef rnd
  106. #define rnd(x)  ((int)((float)(x) + 0.5)) /* round a float to an int */
  107. #endif
  108.  
  109. /* Note:
  110. * - All data is in char's in order to maintain easily portability
  111. *   across machines, and some human readibility.
  112. * - Images may be stored as pixmaps (8 bits/pixel) or as seperate
  113. *   red, green, blue channel data (24+ bits/pixel).
  114. * - An alpha channel is optional and is found after every num_channels
  115. *   of data.
  116. * - Pixmaps or RGB (and alpha) channel data are stored respectively
  117. *   after the header.
  118. * - If num_channels = 1, a pixmap is assumed and the colormap in the
  119. *   header is used.
  120. * - Data size = image_width * image_height.
  121. */
  122.