home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / GXCLDEV.H < prev    next >
C/C++ Source or Header  |  1994-07-27  |  5KB  |  131 lines

  1. /* Copyright (C) 1991, 1992, 1993, 1994 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gxcldev.h */
  20. /* Internal definitions for Ghostscript command lists. */
  21. #include "gxclist.h"
  22.  
  23. #define cdev ((gx_device_clist *)dev)
  24.  
  25. /* A command always consists of an operation followed by operands. */
  26. /* The operands are implicit in the procedural code. */
  27. /* Operands marked # are variable-size. */
  28. typedef enum {
  29.     cmd_op_misc = 0x00,        /* (see below) */
  30.       cmd_opv_end_run = 0x00,    /* (nothing) */
  31.       cmd_opv_set_tile_size = 0x01,    /* width#, height# */
  32.       cmd_opv_set_tile_phase = 0x02, /* x#, y# */
  33.       cmd_opv_set_tile_index = 0x03, /* index */
  34.       cmd_opv_set_tile_bits = 0x04,    /* index, <bits> */
  35.     cmd_op_set_color0 = 0x10,    /* color+2 in op byte | color# */
  36.     cmd_op_set_color1 = 0x20,    /* color+2 in op byte | color# */
  37.     cmd_op_delta_tile_bits = 0x30,    /* n-1 in op byte, n x <offset, bits> */
  38.     cmd_op_fill_rect = 0x40,    /* rect# */
  39.     cmd_op_fill_rect_short = 0x50,    /* dh in op byte,dx,dw | rect_short */
  40.     cmd_op_fill_rect_tiny = 0x60,    /* dw in op byte, rect_tiny */
  41.     cmd_op_tile_rect = 0x70,    /* rect# */
  42.     cmd_op_tile_rect_short = 0x80,    /* dh in op byte,dx,dw | rect_short */
  43.     cmd_op_tile_rect_tiny = 0x90,    /* dw in op byte, rect_tiny */
  44.     cmd_op_copy_mono = 0xa0,    /* (rect#, data_x#, raster# | */
  45.                     /*  d_x+1 in op byte, x#, y#, w, h), */
  46.                     /* <bits> */
  47.     cmd_op_copy_mono_rle = 0xb0,    /* rect#, data_x#, raster#, <bits> */
  48.     cmd_op_copy_color = 0xc0,    /* rect#, data_x#, raster#, <bits> */
  49.     cmd_op_end
  50. } gx_cmd_op;
  51.  
  52. #define cmd_op_name_strings\
  53.   "misc", "set_color_0", "set_color_1", "delta_tile_bits",\
  54.   "fill_rect", "fill_rect_short", "fill_rect_tiny", "tile_rect",\
  55.   "tile_rect_short", "tile_rect_tiny", "copy_mono", "copy_mono_rle",\
  56.   "copy_color", "?d0?", "?e0?", "?f0?"
  57.  
  58. #define cmd_misc_op_name_strings\
  59.   "end_run", "set_tile_size", "set_tile_phase", "set_tile_index",\
  60.   "set_tile_bits", "?05?", "?06?", "?07?",\
  61.   "?08?", "?09?", "?0a?", "?0b?",\
  62.   "?0c?", "?0d?", "?0e?", "?0f?"\
  63.  
  64. #ifdef DEBUG
  65. extern const char *cmd_op_names[16];
  66. extern const char *cmd_misc_op_names[16];
  67. #endif
  68.  
  69. /* Define the size of the largest command, not counting any bitmap. */
  70. #define cmd_tile_d 3            /* size of tile delta */
  71. /* The variable-size integer encoding is little-endian.  The low 7 bits */
  72. /* of each byte contain data; the top bit is 1 for all but the last byte. */
  73. #define cmd_max_intsize(siz)\
  74.   (((siz) * 8 + 6) / 7)
  75. #define cmd_largest_size\
  76.   max(1 + 6 * cmd_max_intsize(sizeof(int)) /* copy_mono */, 2 + 16 * cmd_tile_d    /* delta_tile 15 */)
  77.  
  78. /* Define command parameter structures. */
  79. typedef struct {
  80.     int x, y, width, height;
  81. } gx_cmd_rect;
  82. typedef struct {
  83.     byte dx, dwidth, dy, dheight;    /* dy and dheight are optional */
  84. } gx_cmd_rect_short;
  85. #define cmd_min_short (-128)
  86. #define cmd_max_short 127
  87. typedef struct {
  88.     unsigned dx : 4;
  89.     unsigned dy : 4;
  90. } gx_cmd_rect_tiny;
  91. #define cmd_min_tiny (-8)
  92. #define cmd_max_tiny 7
  93.  
  94. /* Define the prefix on each command run in the writing buffer. */
  95. typedef struct cmd_prefix_s cmd_prefix;
  96. struct cmd_prefix_s {
  97.     cmd_prefix *next;
  98.     uint size;
  99. };
  100.  
  101. /* Define the entries in the block file. */
  102. typedef struct cmd_block_s {
  103.     int band;
  104.     long pos;            /* starting position in cfile */
  105. } cmd_block;
  106.  
  107. /* Remember the current state of one band when writing or reading. */
  108. struct gx_clist_state_s {
  109.     gx_color_index color0, color1;    /* most recent colors */
  110.     tile_slot *tile;        /* most recent tile */
  111.     gs_int_point tile_phase;    /* most recent tile phase */
  112.     gx_cmd_rect rect;        /* most recent rectangle */
  113.     /* Following are only used when writing */
  114.     cmd_prefix *head, *tail;    /* list of commands for band */
  115. };
  116. static tile_slot no_tile = { ~0L };
  117.  
  118. /* The initial values for a band state */
  119. static const gx_clist_state cls_initial =
  120.    {    gx_no_color_index, gx_no_color_index, &no_tile,
  121.      { 0, 0 }, { 0, 0, 0, 0 },
  122.     0, 0
  123.    };
  124.  
  125. #define clist_write(f, str, len)\
  126.   fwrite(str, 1, len, f)
  127.  
  128. /* Define the size of the command buffer used for reading. */
  129. /* This is needed to split up very large copy_ operations. */
  130. #define cbuf_size 500
  131.