home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / gnu / gs-2.6.1.4-src.lha / src / amiga / gs-2.6.1.4 / stream.h < prev    next >
C/C++ Source or Header  |  1994-01-27  |  12KB  |  333 lines

  1. /* Copyright (C) 1989, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* stream.h */
  20. /* Definitions for Ghostscript stream package */
  21. /* Requires stdio.h */
  22.  
  23. /*
  24.  * Note that the stream package works with bytes, not chars.
  25.  * This is to ensure unsigned representation on all systems.
  26.  * A stream currently can only be read or written, not both.
  27.  * Note also that the read procedure returns an int,
  28.  * not a char or a byte, so we can use negative values for EOFC and ERRC.
  29.  * We distinguish "data" from "signal" results (EOFC, ERRC) with a macro:
  30.  */
  31.  
  32. #define char_is_data(c) ((c) >= 0)
  33. #define char_is_signal(c) ((c) < 0)
  34. typedef struct stream_s stream;
  35.  
  36. /*
  37.  * We cast EOFC and ERRC to int explicitly, because some compilers
  38.  * don't do this if the other arm of a conditional is a byte.
  39.  * Clients should use char_is_data and char_is_signal (see above)
  40.  * to test for exceptional results.
  41.  */
  42. #define EOFC ((int)(-1))
  43. #define ERRC ((int)(-2))
  44. /****** ERRC IS NOT RECOGNIZED EVERYWHERE YET ******/
  45.  
  46. /* ------ Define the "virtual" stream procedures ------ */
  47.  
  48. typedef struct {
  49.  
  50.         /* Store # available for reading. */
  51.         /* Return 0 if OK, ERRC if error or not implemented. */
  52.     int (*available)(P2(stream *, long *));
  53.  
  54.         /* Set position. */
  55.         /* Return 0 if OK, ERRC if error or not implemented. */
  56.     int (*seek)(P2(stream *, long));
  57.  
  58.         /* Flush buffered data. */
  59.         /* Return 0 if OK, ERRC if error. */
  60.     int (*flush)(P1(stream *));
  61.  
  62.         /* Flush data (if writing) & close stream. */
  63.         /* Return 0 if OK, ERRC if error. */
  64.     int (*close)(P1(stream *));
  65.  
  66.         /* Refill buffer (setting endptr) and reset cptr. */
  67.         /* Return ERRC if not implemented; */
  68.         /* otherwise, set end_status appropriately and return 0. */
  69.     int (*read_buf)(P1(stream *));
  70.  
  71.         /* Write buffer and reset cptr. */
  72.         /* Return 0 if OK, ERRC if error or not implemented. */
  73.     int (*write_buf)(P1(stream *));
  74.  
  75. } stream_procs;
  76.  
  77. /* ------ Structs for specialized streams -- see below. ------ */
  78.  
  79. typedef struct CCITTFax_state_s {
  80.     /* The following are set before initialization. */
  81.     int Uncompressed;    /* boolean */
  82.     int K;
  83.     int EndOfLine;        /* boolean */
  84.     int EncodedByteAlign;    /* boolean */
  85.     int Columns;
  86.     int Rows;
  87.     int EndOfBlock;        /* boolean */
  88.     int BlackIs1;        /* boolean */
  89.     int DamagedRowsBeforeError;
  90.     int FirstBitLowOrder;    /* boolean */
  91.     uint raster;
  92.     /* The following are updated dynamically. */
  93.     int k_left;        /* number of next rows to encode in 2-D */
  94.                 /* (only if K > 0) */
  95.     int cbit;        /* bits left to fill in current decoded */
  96.                 /* byte at *cptr (0..7, input only) */
  97.     uint prev_pos;        /* position of previous line in buffer */
  98.     int rows_left;        /* number of rows left (input only) */
  99.     /* The following are input-only and not used yet. */
  100.     int uncomp_run;        /* non-0 iff we are in an uncompressed */
  101.                 /* run straddling a scan line (-1 if white, */
  102.                 /* 1 if black) */
  103.     int uncomp_left;    /* # of bits left in the run */
  104.     int uncomp_exit;    /* non-0 iff this is an exit run */
  105.                 /* (-1 if next run white, 1 if black) */
  106. } CCITTFax_state;
  107.  
  108. /****** STUB ******/
  109. struct dct_color_params_s;
  110. typedef struct DCT_state_s {
  111.     /* The following are set before initialization. */
  112.     int Columns;
  113.     int Rows;
  114.     int Colors;
  115.     float QFactor;
  116.     struct dct_color_params_s *params;    /* params[Colors] */
  117.     int ColorTransform;    /* 0 or 1 */    
  118. } DCT_state;
  119.  
  120. struct lzw_decode_table_s;
  121. struct lzw_encode_table_s;
  122. typedef struct LZW_state_s {
  123.     /* The following are set at initialization. */
  124.     int enhanced;            /* if true, use Aladdin's */
  125.                     /* enhanced compression algorithm */
  126.     /* The following are updated dynamically. */
  127.     struct lzw_decode_table_s *decode_table;    /* decoding table */
  128.     struct lzw_encode_table_s *encode_table;    /* encoding table */
  129.     uint next_code;            /* next code to be assigned */
  130.     int code_size;            /* current # of bits per code */
  131.     int prev_code;            /* previous code recognized */
  132.                     /* or assigned */
  133. } LZW_state;
  134.  
  135. typedef struct SubFile_state_s {
  136.     ulong count;        /* # of EODs to scan over */
  137.     const byte *eod_string;
  138.     uint string_size;
  139.     uint match;        /* # of matched chars preceding end of buffer */
  140. } SubFile_state;
  141.  
  142. /* ------ The actual stream structure ------ */
  143.  
  144. struct file_device_s;
  145.  
  146. struct stream_s {
  147.     byte *cptr;            /* pointer to last byte */
  148.                     /* read or written */
  149.     byte *endptr;            /* pointer to last byte */
  150.                     /* containing data for reading, */
  151.                     /* or to be filled for writing */
  152.     byte *cbuf;            /* base of buffer */
  153.     uint bsize;            /* size of buffer, 0 if closed */
  154.     uint cbsize;            /* size of buffer */
  155.     uint modes;            /* (not byte, to keep alignment) */
  156. #define s_mode_read 1
  157. #define s_mode_write 2
  158. #define s_mode_seek 4
  159. #define s_mode_append 8            /* (s_mode_write also set) */
  160. #define s_is_valid(s) ((s)->modes != 0)
  161. #define s_is_reading(s) (((s)->modes & s_mode_read) != 0)
  162. #define s_is_writing(s) (((s)->modes & s_mode_write) != 0)
  163. #define s_can_seek(s) (((s)->modes & s_mode_seek) != 0)
  164.     int end_status;            /* EOFC if at EOF when buffer */
  165.                     /* becomes empty, ERRC if error */
  166.     long position;            /* file position of beginning of */
  167.                     /* buffer */
  168.     stream_procs procs;
  169.     int num_format;            /* format for Level 2 */
  170.                     /* encoded number reader */
  171.                     /* (only used locally) */
  172.     stream *strm;            /* the underlying stream, non-zero */
  173.                     /* iff this is a filter stream */
  174.     int strm_is_temp;        /* if true, strm is a temporary */
  175.                     /* stream and should be freed */
  176.                     /* when this stream is closed */
  177.     ushort read_id;            /* "unique" serial # for detecting */
  178.                     /* references to closed streams */
  179.                     /* and for validating read access */
  180.     ushort write_id;        /* ditto to validate write access */
  181.     int inline_temp;        /* temporary for inline access */
  182.                     /* (see spgetc_inline below) */
  183.     /*
  184.      * If were were able to program in a real object-oriented style, 
  185.      * the remaining data would be per-subclass.  It's just too much
  186.      * of a nuisance to do this in C, so we allocate space for the
  187.      * private data of ALL subclasses.
  188.      */
  189.     /* The following are for file streams. */
  190.     struct file_device_s *fdev;    /* the file device */
  191.     FILE *file;            /* file handle for C library */
  192.     int (*save_close)(P1(stream *));    /* save original close proc */
  193.     stream *prev, *next;        /* keep track of all files */
  194.     /*
  195.      * The remaining members are only for filters.
  196.      * We simply allocate space for the simple ones,
  197.      * and only bother with a union for the complex ones.
  198.      */
  199.     /* The following is used by several decoding filters. */
  200.     int odd;            /* odd digit */
  201.     /* The following is for RunLengthEncode. */
  202.     ulong record_size;
  203.     /* The following is for RunLengthEncode and PFBDecode. */
  204.     ulong record_left;        /* bytes left in current record */
  205.     /* The following are for PFBDecode. */
  206.     int record_type;
  207.     int binary_to_hex;
  208.     /* The following are for eexecDecode. */
  209.     ushort cstate;            /* encryption state */
  210.     ushort _skip;            /* (keep int alignment) */
  211.     int binary;            /* true=binary, false=hex */
  212.     /* The following are for bit-oriented filters */
  213.     /* (see sbits.h for more details.) */
  214.     uint bits;        /* most recent bits of input or */
  215.                 /* current bits of output */
  216.     int bits_left;        /* # of valid low bits (input) or */
  217.                 /* unused low bits (output) in above */
  218.     int reverse_bits;    /* if true, reverse bit order */
  219.     /* The following are for various filters. */
  220.     union {
  221.         CCITTFax_state cf;
  222.         DCT_state dct;
  223.         LZW_state lzw;
  224.         SubFile_state sf;
  225.     } state;
  226. };
  227.  
  228. /* Initialize the checking IDs of a stream. */
  229. #define s_init_id