Blame converter/other/rast.h

Packit 78deda
/* rast.h - header file for Sun raster files
Packit 78deda
**
Packit 78deda
** The format of a Sun raster file is as follows.  First, a struct
Packit 78deda
** rasterfile.  Note the 32-bit magic number at the beginning; this
Packit 78deda
** identifies the file type and lets you figure out whether you need
Packit 78deda
** to do little-endian / big-endian byte-swapping or not.  (The PBMPLUS
Packit 78deda
** implementation does not do byte-swapping; instead, it reads all
Packit 78deda
** multi-byte values a byte at a time.)
Packit 78deda
**
Packit 78deda
** After the struct is an optional colormap.  If ras_maptype is RMT_NONE,
Packit 78deda
** no map is present; if it's RMT_EQUAL_RGB then the map consists of
Packit 78deda
** three unsigned-char arrays ras_maplength long, one each for r g and b.
Packit 78deda
** I don't know what RMT_RAW means.  Black and white bitmaps are stored
Packit 78deda
** as ras_maptype == RMT_NONE and ras_depth == 1, with the bits stored
Packit 78deda
** eight to a byte MSB first.
Packit 78deda
**
Packit 78deda
** Finally comes the image data.  If ras_type is RT_OLD or RT_STANDARD,
Packit 78deda
** the data is just plain old uncompressed bytes, padded out to a multiple
Packit 78deda
** of 16 bits in each row.  If ras_type is RT_BYTE_ENCODED, a run-length
Packit 78deda
** compression scheme is used: an escape-byte of 128 indicates a run;
Packit 78deda
** the next byte is a count, and the one after that is the byte to be
Packit 78deda
** replicated.  The one exception to this is if the count is 1; then
Packit 78deda
** there is no third byte in the packet, it means to put a single 128
Packit 78deda
** in the data stream.
Packit 78deda
*/
Packit 78deda
Packit 78deda
#ifndef RAST_H_INCLUDED
Packit 78deda
#define RAST_H_INCLUDED
Packit 78deda
Packit 78deda
#define PIX_ERR		-1
Packit 78deda
Packit 78deda
struct rasterfile {
Packit 78deda
    long ras_magic;
Packit 78deda
#define	RAS_MAGIC	0x59a66a95
Packit 78deda
    long ras_width;
Packit 78deda
    long ras_height;
Packit 78deda
    long ras_depth;
Packit 78deda
    long ras_length;
Packit 78deda
    long ras_type;
Packit 78deda
#define RT_OLD		0	/* Raw pixrect image in 68000 byte order */
Packit 78deda
#define RT_STANDARD	1	/* Raw pixrect image in 68000 byte order */
Packit 78deda
#define RT_BYTE_ENCODED	2	/* Run-length compression of bytes */
Packit 78deda
#define RT_FORMAT_RGB	3	/* XRGB or RGB instead of XBGR or BGR */
Packit 78deda
#define RT_FORMAT_TIFF	4	/* tiff <-> standard rasterfile */
Packit 78deda
#define RT_FORMAT_IFF	5	/* iff (TAAC format) <-> standard rasterfile */
Packit 78deda
#define RT_EXPERIMENTAL 0xffff	/* Reserved for testing */
Packit 78deda
    long ras_maptype;
Packit 78deda
#define RMT_NONE	0
Packit 78deda
#define RMT_EQUAL_RGB	1
Packit 78deda
#define RMT_RAW		2
Packit 78deda
    long ras_maplength;
Packit 78deda
};
Packit 78deda
Packit 78deda
struct pixrectops {
Packit 78deda
    int	(*pro_rop)();
Packit 78deda
    int	(*pro_stencil)();
Packit 78deda
    int	(*pro_batchrop)();
Packit 78deda
    int	(*pro_nop)();
Packit 78deda
    int	(*pro_destroy)();
Packit 78deda
    int	(*pro_get)();
Packit 78deda
    int	(*pro_put)();
Packit 78deda
    int	(*pro_vector)();
Packit 78deda
    struct pixrect* (*pro_region)();
Packit 78deda
    int	(*pro_putcolormap)();
Packit 78deda
    int	(*pro_getcolormap)();
Packit 78deda
    int	(*pro_putattributes)();
Packit 78deda
    int	(*pro_getattributes)();
Packit 78deda
};
Packit 78deda
Packit 78deda
struct pr_size {
Packit 78deda
    int x, y;
Packit 78deda
};
Packit 78deda
Packit 78deda
struct pr_pos {
Packit 78deda
    int x, y;
Packit 78deda
};
Packit 78deda
Packit 78deda
struct pixrect {
Packit 78deda
    struct pixrectops* pr_ops;
Packit 78deda
    struct pr_size pr_size;
Packit 78deda
    int pr_depth;
Packit 78deda
    struct mpr_data* pr_data;	/* work-alike only handles memory pixrects */
Packit 78deda
};
Packit 78deda
Packit 78deda
struct mpr_data {
Packit 78deda
    int md_linebytes;
Packit 78deda
    unsigned char* md_image;	/* note, byte not short -- avoid pr_flip() */
Packit 78deda
    struct pr_pos md_offset;
Packit 78deda
    short md_primary;
Packit 78deda
    short md_flags;
Packit 78deda
};
Packit 78deda
Packit 78deda
typedef struct {
Packit 78deda
    int type;
Packit 78deda
    int length;
Packit 78deda
    unsigned char* map[3];
Packit 78deda
} colormap_t;
Packit 78deda
Packit 78deda
/* And the routine definitions. */
Packit 78deda
Packit 78deda
struct pixrect *
Packit 78deda
mem_create(int const w,
Packit 78deda
           int const h,
Packit 78deda
           int const depth);
Packit 78deda
Packit 78deda
void
Packit 78deda
mem_free(struct pixrect * const p);
Packit 78deda
Packit 78deda
int
Packit 78deda
pr_dump(struct pixrect * const p,
Packit 78deda
        FILE *           const out,
Packit 78deda
        colormap_t *     const colormap,
Packit 78deda
        int              const type,
Packit 78deda
        int              const copy_flag);
Packit 78deda
Packit 78deda
int
Packit 78deda
pr_load_header(FILE *              const in,
Packit 78deda
               struct rasterfile * const hP);
Packit 78deda
Packit 78deda
int
Packit 78deda
pr_load_colormap(FILE *              const in,
Packit 78deda
                 struct rasterfile * const hP,
Packit 78deda
                 colormap_t *        const colormap);
Packit 78deda
Packit 78deda
struct pixrect *
Packit 78deda
pr_load_image(FILE *              const in,
Packit 78deda
              struct rasterfile * const hP,
Packit 78deda
              colormap_t *        const colormap);
Packit 78deda
Packit 78deda
#endif