/*
*  Author: Philip R. Thompson
*  Address:  phils@athena.mit.edu, 9-532
*  $Header: /mit/crldev/src/xim/lib/RCS/xim.h,v 1.12 92/07/30 18:54:09 phils Exp Locker: phils $
*  $Date: 92/07/30 18:54:09 $
*  $Source: /mit/crldev/src/xim/lib/RCS/xim.h,v $
*  Copyright (c) 1989, 1990 Massachusetts Institute of Technology
*                1988, Philip R. Thompson (phils@athena.mit.edu)
*                Computer Resource Laboratory (CRL)
*                Dept. of Architecture and Planning
*                M.I.T., Rm 9-532
*                Cambridge, MA  02139
*   This  software and its documentation may be used, copied, modified,
*   and distributed for any purpose without fee, provided:
*       --  The above copyright notice appears in all copies.
*       --  This disclaimer appears in all source code copies.
*       --  The names of M.I.T. and the CRL are not used in advertising
*           or publicity pertaining to distribution of the software
*           without prior specific written permission from me or CRL.
*   I provide this software freely as a public service.  It is NOT
*   public domain nor a commercial product, and therefore is not subject
*   to an an implied warranty of merchantability or fitness for a
*   particular purpose.  I provide it as is, without warranty.
*
*   This software is furnished  only on the basis that any party who
*   receives it indemnifies and holds harmless the parties who furnish
*   it against any claims, demands, or liabilities connected with using
*   it, furnishing it to adatas, or providing it to a third party.
*/
#ifndef _XIMLIB_H_
#define _XIMLIB_H_
#if (!defined(lint) && !defined(SABER) && !defined(__GNUC__))
static char ximlib_rcsid[] =
"$Header: /mit/crldev/src/xim/lib/RCS/xim.h,v 1.12 92/07/30 18:54:09 phils Exp Locker: phils $";
#endif                          /* lint */

#include <stdio.h>
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <sys/types.h>
#include "ximcompat.h"

#define XIM_VERSION    3

#ifndef _BYTE_
typedef unsigned char byte;
#define _BYTE_
#endif


/* External ascii file format
*  Note:  size of header should be 1024 (1K) bytes.
*/
typedef struct ImageHeader {
    char file_version[8];       /* header version */
    char header_size[8];        /* Size of file header in bytes (1024) */
    char image_width[8];        /* Width of the raster image */
    char image_height[8];       /* Height of the raster imgage */
    char num_colors[4];         /* Actual number of entries in c_map */
    char greyscale[2];          /* Flag if no c_map needed */
    char flag[2];               /* Not used */
    char num_channels[3];       /* 0 or 1 = pixmap, 3 = RG&B buffers */
    char bytes_per_line[5];     /* bytes per scanline */
    char num_pictures[4];       /* Number of pictures in file */
    char bits_per_channel[4];   /* usually 1 or 8 */
    char alpha_channel[4];      /* Alpha channel flag */
    char runlength[4];          /* Runlength encoded flag */
    char author[48];            /* Name of who made it */
    char date[32];              /* Date and time image was made */
    char program[16];           /* Program that created this file */
    char comment[96];           /* adata viewing info. for this image */
    unsigned char c_map[256][3];/* RGB values of the pixmap indices */
} XimAsciiHeader;


/* Internal binary format
*/
typedef struct Color {
    byte red, grn, blu, pixel;
} Color;

typedef struct Xim {
    int width;                  /* width of the image in pixels */
    int height;                 /* height of the image in pixels */
    int bytes_line;             /* bytes to hold one scanline */
    unsigned datasize;          /* size of one channel of data */
    short nchannels;            /* data channels per pixel, usually 1
                                 * or3 */
    short bits_channel;         /* depth of a channel, usually 1 or 8 */
    byte *data;                 /* pixmap or red channel data */
    byte *gdata;                /* green channel data */
    byte *bdata;                /* blue  channel data */
    byte *adata;                /* adata (alpha) data */
    short ncolors;              /* number of colors in the color table */
    Color *colors;              /* colortable for pixmaps */
    short curr_pic, npics;      /* current & total file number of
                                 * images */
    unsigned alpha_flag:1;      /* alpha channel flag - "adata" is used */
    unsigned grey_flag:1;       /* is pixmap grey scaled */
    unsigned packed_flag:1;     /* is data packed in one chunk of
                                 * memory */
    unsigned runlen_flag:1;     /* is data compressed flag (not used) */
    unsigned:0;                 /* future flags space and word
                                 * alignment */
    char *author;               /* author credit, copyright, etc */
    char *date;                 /* date image was made, grabbed, etc. */
    char *program;              /* program used to make this */
    char *name;                 /* name of the image - usually filename */
    short ncomments;            /* number of comments strings */
    char **comments;            /* pointers to null terminated comments */
    char *offset;               /* original offset in memory when
                                 * packed */
    float gamma;                /* image storage gamma */
    float chroma_red[2];        /* x, y image chromacity coords */
    float chroma_grn[2];
    float chroma_blu[2];
    float chroma_wht[2];
} Xim;

#ifdef __STDC__
typedef void (*XimErrorHandler)(char*, va_list);
#else
typedef void (*XimErrorHandler)();
#endif

/* Future external ascii variable length header - under review
*/
#if (VERSION == 4)
typedef struct XimAsciiHeader {
    char file_version[4];       /* header version */
    char header_size[8];        /* Size of file header (fixed part
                                 * only) */
    char image_height[8];       /* Height of the raster imgage in
                                 * pixels */
    char image_width[8];        /* Width of the raster image in pixels */
    char bytes_line[8];         /* Actual # of bytes separating
                                 * scanlines */
    char bits_channel[4];       /* Bits per channel (usually 1 or 8) */
    char num_channels[4];       /* 1 = pixmap, 3 = RG&B buffers */
    char alpha_channel[2];      /* Alpha channel flag */
    char num_colors[4];         /* Number of entries in c_map (if any) */
    char num_pictures[4];       /* Number of images in file */
    char compress_flag[2];      /* Runlength encoded flag */
    char greyscale_flag[2];     /* Greyscale flag */
    char future_flags[4];
    char author[48];            /* Name of who made it, from passwd
                                 * entry */
    char date[32];              /* Unix format date */
    char program[32];           /* Program that created this */
    char gamma[12];             /* image storage gamma */
    char chroma_red[24];        /* image red primary chromaticity
                                 * coords. */
    char chroma_grn[24];        /* "   green "          "         "     */
    char chroma_blu[24];        /* "   blue  "          "         "     */
    char chroma_wht[24];        /* "   white point      "         "     */
    char comment_length[8]      /* Total length of all comments */
    /* char *comment;           Null separated comments  */
    /* byte c_map[];   RGB Colortable, (ncolors * 3 bytes) */
} XimAsciiHeader;
#endif                          /* VERSION 4 */


/* Note:
* - All external data is in char's in order to maintain easily
*   portability across machines and some human readibility.
* - Images may be stored as bitmaps (8 pixels/byte), pixmaps
*   (1 byte /pixel) or as seperate red, green, blue channel data
*   (3 bytes/pixel).
* - An alpha channel is optional and is found after every num_channels
*   of data.
* - Pixmaps or RG&B (and alpha) channel data are stored respectively
*   after the header.
* - If num_channels == 1 a pixmap is assumed and the colormap in the
*   header is used unless its greyscale.
* - Datasize is for one channel.
*/

/* important flags for fitting images to various visuals and
 * colormaps.
 */
typedef struct XimFlags {
    int colorDither;   /* use color dithering ? */
    int enhance;       /* edge enhance image ? */
    int movePixel;     /* map pixel values to xcolor values ? */
    int useNewCMap;    /* create / use the new colormap ? */
    short bitmap;      /* display as 1-bit pixmap ? */
} XimFlags;

#endif                          /* _XIMDEFS_H_ */

/*** end xim.h ***/
