home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gs252src.zip / GS252 / GDEVMEM.H < prev    next >
C/C++ Source or Header  |  1992-09-19  |  8KB  |  191 lines

  1. /* Copyright (C) 1991, 1992 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* gdevmem.h */
  21. /* Private definitions for memory devices. */
  22.  
  23. /*
  24.    The representation for a "memory" device is simply a
  25.    contiguous bitmap stored in something like the PostScript
  26.    representation, i.e., each scan line (in left-to-right order), padded
  27.    to a byte or word boundary, followed immediately by the next one.
  28.  
  29.    The representation of strings in the Ghostscript interpreter limits
  30.    the size of a string to 64K-1 bytes, which means we can't simply use
  31.    a string for the contents of a memory device.
  32.    We get around this problem by making the client read out the
  33.    contents of a memory device bitmap in pieces.
  34.  
  35.    On PCs with segmented architectures, there is no way to
  36.    obtain a contiguous block of storage larger than 64K bytes,
  37.    which isn't big enough for a full-screen bitmap, even in monochrome.
  38.    If this ever becomes a problem, we will use a banded representation.
  39.  
  40.    Even though the scan lines are stored contiguously, we store a table
  41.    of their base addresses, because indexing into it is faster than
  42.    the multiplication that would otherwise be needed.
  43. */
  44.  
  45. /* ------ Generic macros ------ */
  46.  
  47. /* Macro for declaring the essential device procedures. */
  48. #define declare_mem_map_procs(map_rgb_color, map_color_rgb)\
  49.   private dev_proc_map_rgb_color(map_rgb_color);\
  50.   private dev_proc_map_color_rgb(map_color_rgb)
  51. #define declare_mem_procs(copy_mono, copy_color, fill_rectangle)\
  52.   private dev_proc_copy_mono(copy_mono);\
  53.   private dev_proc_copy_color(copy_color);\
  54.   private dev_proc_fill_rectangle(fill_rectangle)
  55.  
  56. /* Macro for generating the procedure record in the device descriptor */
  57. extern dev_proc_open_device(mem_open);
  58. extern dev_proc_get_initial_matrix(mem_get_initial_matrix);
  59. extern dev_proc_close_device(mem_close);
  60. extern dev_proc_get_bits(mem_get_bits);
  61. #define mem_procs(map_rgb_color, map_color_rgb, copy_mono, copy_color, fill_rectangle)\
  62. {    mem_open,\
  63.     mem_get_initial_matrix,\
  64.     gx_default_sync_output,\
  65.     gx_default_output_page,\
  66.     mem_close,\
  67.     map_rgb_color,            /* differs */\
  68.     map_color_rgb,            /* differs */\
  69.     fill_rectangle,            /* differs */\
  70.     gx_default_tile_rectangle,\
  71.     copy_mono,            /* differs */\
  72.     copy_color,            /* differs */\
  73.     gx_default_draw_line,\
  74.     mem_get_bits,\
  75.     gx_default_get_props,\
  76.     gx_default_put_props\
  77. }
  78.  
  79. /*
  80.  * Macro for generating the device descriptor.
  81.  * Various compilers have problems with the obvious definition
  82.  * for max_value, namely:
  83.  *    (depth >= 8 ? 255 : (1 << depth) - 1)
  84.  * I tried changing (1 << depth) to (1 << (depth & 15)) to forestall bogus
  85.  * error messages about invalid shift counts, but the H-P compiler chokes
  86.  * on this.  Since the only values of depth we ever plan to support are
  87.  * powers of 2 (and 24), we just go ahead and enumerate them.
  88.  */
  89. #define max_value(depth)\
  90.   (depth >= 8 ? 255 : depth == 4 ? 15 : depth == 2 ? 3 : 1)
  91. #define mem_device(name, depth, procs)\
  92. {    sizeof(gx_device_memory),\
  93.     &procs,            /* differs */\
  94.     name,            /* differs */\
  95.     0, 0,            /* x and y extent (filled in) */\
  96.     72, 72,            /* density (makes initclip come out right) */\
  97.     no_margins,        /* margins */\
  98.        {    (depth >= 4 ? 3 : 1),    /* num_components */\
  99.         depth,\
  100.         max_value(depth),    /* max_gray */\
  101.         max_value(depth),    /* max_rgb */\
  102.         max_value(depth) + 1,    /* dither_gray */\
  103.         max_value(depth) + 1,    /* dither_color */\
  104.        },\
  105.     0,            /* not open yet */\
  106.     identity_matrix_body,    /* initial matrix (filled in) */\
  107.     0,            /* raster (filled in) */\
  108.     (byte *)0,        /* base (filled in) */\
  109.     (byte **)0,        /* line_ptrs (filled in by mem_open) */\
  110.     0,            /* initial bytes_le (filled in by mem_open) */\
  111.     0,            /* invert (filled in for mono) */\
  112.     0, (byte *)0,        /* palette (filled in for color) */\
  113.     { 0, 0 }        /* alloc, free */\
  114. }
  115.  
  116. /* Macro for casting gx_device argument */
  117. #define mdev ((gx_device_memory *)dev)
  118.  
  119. /*
  120.  * Macros for processing bitmaps in the largest possible chunks.
  121.  * Bits within a byte are always stored big-endian;
  122.  * bytes are normally stored in the natural order for the platform,
  123.  * but the client can force them into big-endian order (which is required
  124.  * for the source of copy_mono) by calling gdev_mem_ensure_byte_order.
  125.  * (mem_get_bits swaps bytes if necessary.)
  126.  * Note that we use type uint for register variables holding a chunk:
  127.  * for this reason, the chunk size cannot be larger than uint.
  128.  */
  129. /*
  130.  * The clog2_bytes macro assumes that ints are 2 or 4 bytes in size:
  131.  * check this now.
  132.  */
  133. #if !(arch_sizeof_int == 2 || arch_sizeof_int == 4)
  134. #  error sizeof(int) must be 2 or 4 for correct operation.
  135. #endif
  136. /* Generic macros for chunk accessing. */
  137. #define cbytes(ct) ((int)sizeof(ct))    /* sizeof may be unsigned */
  138. #  define chunk_bytes cbytes(chunk)
  139. #define clog2_bytes(ct) ((int)sizeof(ct)>>1)    /* works for 1,2,4! */
  140. #  define chunk_log2_bytes clog2_bytes(chunk)
  141. #define cbits(ct) ((int)sizeof(ct)*8)    /* sizeof may be unsigned */
  142. #  define chunk_bits cbits(chunk)
  143. #define clog2_bits(ct) (clog2_bytes(ct)+3)
  144. #  define chunk_log2_bits clog2_bits(chunk)
  145. #define cbit_mask(ct) (cbits(ct)-1)
  146. #  define chunk_bit_mask cbit_mask(chunk)
  147. /*
  148.  * The obvious definition for cmask is:
  149.  *    #define cmask(ct) ((ct)~(ct)0)
  150.  * but this doesn't work on the VAX/VMS compiler, which fails to truncate
  151.  * the value to 16 bits when ct is ushort.
  152.  * Instead, we have to generate the mask with no extra 1-bits.
  153.  * We can't do this in the obvious way:
  154.  *    #define cmask(ct) ((1 << (sizeof(ct) * 8)) - 1)
  155.  * because some compilers won't allow a shift of 32 bits.  Instead,
  156.  * we have to do something really awkward:
  157.  */
  158. #define cmask(ct) ((ct) (((((ct)1 << (sizeof(ct)*8-2)) - 1) << 2) + 3))
  159. #  define chunk_all_bits cmask(chunk)
  160. /*
  161.  * The obvious definition for chi_bits is:
  162.  *    #define chi_bits(ct,n) (cmask(ct)-(cmask(ct)>>(n)))
  163.  * but this doesn't work on the DEC/MIPS compilers.
  164.  * Instead, we have to restrict chi_bits to only working for values of n
  165.  * between 0 and cbits(ct)-1, and use
  166.  */
  167. #define chi_bits(ct,n) (ct)(~(ct)1 << (cbits(ct)-1 - (n)))
  168. #  define chunk_hi_bits(n) chi_bits(chunk,n)
  169.  
  170. /* Define whether this is a machine where chunks are long, */
  171. /* but the machine can't shift a long by its full width. */
  172. #define arch_cant_shift_full_chunk\
  173.   (arch_is_big_endian && !arch_ints_are_short && !arch_can_shift_full_long)
  174.  
  175. /* Macros for scan line access. */
  176. /* x_to_byte is different for each number of bits per pixel. */
  177. /* Note that these macros depend on the definition of chunk: */
  178. /* each procedure that uses the scanning macros should #define */
  179. /* (not typedef) chunk as either uint or byte. */
  180. #define scan_line_base(dev,y) (dev->line_ptrs[y])
  181. #define declare_scan_ptr(ptr)   declare_scan_ptr_as(ptr, chunk *)
  182. #define declare_scan_ptr_as(ptr,ptype)\
  183.     register ptype ptr; uint draster
  184. #define inc_chunk_ptr(ptr,delta)\
  185.     ptr = (chunk *)((byte *)ptr + (delta))
  186. #define setup_rect(ptr)   setup_rect_as(ptr, chunk *)
  187. #define setup_rect_as(ptr,ptype)\
  188.     draster = mdev->raster;\
  189.     ptr = (ptype)(scan_line_base(mdev, y) +\
  190.         (x_to_byte(x) & -chunk_bytes))
  191.