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

  1. /* rast.h - header file for Sun raster files
  2. **
  3. ** The format of a Sun raster file is as follows.  First, a struct
  4. ** rasterfile.  Note the 32-bit magic number at the beginning; this
  5. ** identifies the file type and lets you figure out whether you need
  6. ** to do little-endian / big-endian byte-swapping or not.  (The PBMPLUS
  7. ** implementation does not do byte-swapping; instead, it reads all
  8. ** multi-byte values a byte at a time.)
  9. **
  10. ** After the struct is an optional colormap.  If ras_maptype is RMT_NONE,
  11. ** no map is present; if it's RMT_EQUAL_RGB then the map consists of
  12. ** three unsigned-char arrays ras_maplength long, one each for r g and b.
  13. ** I don't know what RMT_RAW means.  Black and white bitmaps are stored
  14. ** as ras_maptype == RMT_NONE and ras_depth == 1, with the bits stored
  15. ** eight to a byte MSB first.
  16. **
  17. ** Finally comes the image data.  If ras_type is RT_OLD or RT_STANDARD,
  18. ** the data is just plain old uncompressed bytes, padded out to a multiple
  19. ** of 16 bits in each row.  If ras_type is RT_BYTE_ENCODED, a run-length
  20. ** compression scheme is used: an escape-byte of 128 indicates a run;
  21. ** the next byte is a count, and the one after that is the byte to be
  22. ** replicated.  The one exception to this is if the count is 1; then
  23. ** there is no third byte in the packet, it means to put a single 128
  24. ** in the data stream.
  25. */
  26.  
  27. #ifndef _RAST_H_
  28. #define _RAST_H_
  29.  
  30. #define PIX_ERR        -1
  31.  
  32. struct rasterfile {
  33.     long ras_magic;
  34. #define    RAS_MAGIC    0x59a66a95
  35.     long ras_width;
  36.     long ras_height;
  37.     long ras_depth;
  38.     long ras_length;
  39.     long ras_type;
  40. #define RT_OLD        0    /* Raw pixrect image in 68000 byte order */
  41. #define RT_STANDARD    1    /* Raw pixrect image in 68000 byte order */
  42. #define RT_BYTE_ENCODED    2    /* Run-length compression of bytes */
  43. #define RT_FORMAT_RGB    3    /* XRGB or RGB instead of XBGR or BGR */
  44. #define RT_FORMAT_TIFF    4    /* tiff <-> standard rasterfile */
  45. #define RT_FORMAT_IFF    5    /* iff (TAAC format) <-> standard rasterfile */
  46. #define RT_EXPERIMENTAL 0xffff    /* Reserved for testing */
  47.     long ras_maptype;
  48. #define RMT_NONE    0
  49. #define RMT_EQUAL_RGB    1
  50. #define RMT_RAW        2
  51.     long ras_maplength;
  52.     };
  53.  
  54. struct pixrectops {
  55.     int    (*pro_rop)();
  56.     int    (*pro_stencil)();
  57.     int    (*pro_batchrop)();
  58.     int    (*pro_nop)();
  59.     int    (*pro_destroy)();
  60.     int    (*pro_get)();
  61.     int    (*pro_put)();
  62.     int    (*pro_vector)();
  63.     struct pixrect* (*pro_region)();
  64.     int    (*pro_putcolormap)();
  65.     int    (*pro_getcolormap)();
  66.     int    (*pro_putattributes)();
  67.     int    (*pro_getattributes)();
  68.     };
  69.  
  70. struct pr_size {
  71.     int x, y;
  72.     };
  73. struct pr_pos {
  74.     int x, y;
  75.     };
  76.  
  77. struct pixrect {
  78.     struct pixrectops* pr_ops;
  79.     struct pr_size pr_size;
  80.     int pr_depth;
  81.     struct mpr_data* pr_data;    /* work-alike only handles memory pixrects */
  82.     };
  83.  
  84. struct mpr_data {
  85.     int md_linebytes;
  86.     unsigned char* md_image;    /* note, byte not short -- avoid pr_flip() */
  87.     struct pr_pos md_offset;
  88.     short md_primary;
  89.     short md_flags;
  90.     };
  91.  
  92. typedef struct {
  93.     int type;
  94.     int length;
  95.     unsigned char* map[3];
  96.     } colormap_t;
  97.  
  98. /* And the routine definitions. */
  99.  
  100. struct pixrect* mem_create ARGS(( int w, int h, int depth ));
  101. void mem_free ARGS(( struct pixrect* p ));
  102.  
  103. int pr_dump ARGS(( struct pixrect* p, FILE* out, colormap_t* colormap, int type, int copy_flag ));
  104.  
  105. int pr_load_header ARGS(( FILE* in, struct rasterfile* hP ));
  106.  
  107. int pr_load_colormap ARGS(( FILE* in, struct rasterfile* hP, colormap_t* colormap ));
  108.  
  109. struct pixrect* pr_load_image ARGS(( FILE* in, struct rasterfile* hP, colormap_t* colormap ));
  110.  
  111. #endif /*_RAST_H_*/
  112.