gdevmem.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /* Copyright (C) 1991, 2000 Aladdin Enterprises. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  4. distributor accepts any responsibility for the consequences of using it, or
  5. for whether it serves any particular purpose or works at all, unless he or
  6. she says so in writing. Refer to the Aladdin Free Public License (the
  7. "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. in a plain ASCII text file named PUBLIC. The License grants you the right
  10. to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. conditions described in the License. Among other things, the License
  12. requires that the copyright notice and this notice be preserved on all
  13. copies.
  14. */
  15. /*$Id: gdevmem.h,v 1.3 2000/09/19 19:00:14 lpd Exp $ */
  16. /* Private definitions for memory devices. */
  17. #ifndef gdevmem_INCLUDED
  18. # define gdevmem_INCLUDED
  19. #include "gxbitops.h"
  20. /*
  21. The representation for a "memory" device is simply a
  22. contiguous bitmap stored in something like the PostScript
  23. representation, i.e., each scan line (in left-to-right order), padded
  24. to a multiple of bitmap_align_mod bytes, followed immediately by
  25. the next one.
  26. The representation of strings in the interpreter limits
  27. the size of a string to 64K-1 bytes, which means we can't simply use
  28. a string for the contents of a memory device.
  29. We get around this problem by making the client read out the
  30. contents of a memory device bitmap in pieces.
  31. On 80x86 PCs running in 16-bit mode, there may be no way to
  32. obtain a contiguous block of storage larger than 64K bytes,
  33. which typically isn't big enough for a full-screen bitmap.
  34. We take the following compromise position: if the PC is running in
  35. native mode (pseudo-segmenting), we limit the bitmap to 64K;
  36. if the PC is running in protected mode (e.g., under MS Windows),
  37. we assume that blocks larger than 64K have sequential segment numbers,
  38. and that the client arranges things so that an individual scan line,
  39. the scan line pointer table, and any single call on a drawing routine
  40. do not cross a segment boundary.
  41. Even though the scan lines are stored contiguously, we store a table
  42. of their base addresses, because indexing into it is faster than
  43. the multiplication that would otherwise be needed.
  44. */
  45. /*
  46. * Macros for scan line access.
  47. * x_to_byte is different for each number of bits per pixel.
  48. * Note that these macros depend on the definition of chunk:
  49. * each procedure that uses the scanning macros should #define
  50. * (not typedef) chunk as either uint or byte.
  51. */
  52. #define declare_scan_ptr(ptr)\
  53. DECLARE_SCAN_PTR_VARS(ptr, chunk *, draster)
  54. #define DECLARE_SCAN_PTR_VARS(ptr, ptype, draster)\
  55. register ptype ptr;\
  56. uint draster
  57. #define setup_rect(ptr)\
  58. SETUP_RECT_VARS(ptr, chunk *, draster)
  59. #define SETUP_RECT_VARS(ptr, ptype, draster)\
  60. draster = mdev->raster;\
  61. ptr = (ptype)(scan_line_base(mdev, y) +\
  62. (x_to_byte(x) & -chunk_align_bytes))
  63. /* ------ Generic macros ------ */
  64. /* Macro for declaring the essential device procedures. */
  65. dev_proc_get_initial_matrix(mem_get_initial_matrix);
  66. dev_proc_close_device(mem_close);
  67. #define declare_mem_map_procs(map_rgb_color, map_color_rgb)\
  68. private dev_proc_map_rgb_color(map_rgb_color);\
  69. private dev_proc_map_color_rgb(map_color_rgb)
  70. #define declare_mem_procs(copy_mono, copy_color, fill_rectangle)\
  71. private dev_proc_copy_mono(copy_mono);\
  72. private dev_proc_copy_color(copy_color);\
  73. private dev_proc_fill_rectangle(fill_rectangle)
  74. /*
  75. * We define one relatively low-usage drawing procedure that is common to
  76. * all memory devices so that we have a reliable way to implement
  77. * gs_is_memory_device. It is equivalent to gx_default_draw_thin_line.
  78. */
  79. dev_proc_draw_thin_line(mem_draw_thin_line);
  80. /* The following are used for all except planar or word-oriented devices. */
  81. dev_proc_open_device(mem_open);
  82. dev_proc_get_bits_rectangle(mem_get_bits_rectangle);
  83. /* The following are for word-oriented devices. */
  84. #if arch_is_big_endian
  85. # define mem_word_get_bits_rectangle mem_get_bits_rectangle
  86. #else
  87. dev_proc_get_bits_rectangle(mem_word_get_bits_rectangle);
  88. #endif
  89. /* The following are used for the non-true-color devices. */
  90. dev_proc_map_rgb_color(mem_mapped_map_rgb_color);
  91. dev_proc_map_color_rgb(mem_mapped_map_color_rgb);
  92. /* Default implementation */
  93. dev_proc_strip_copy_rop(mem_default_strip_copy_rop);
  94. /*
  95. * Macro for generating the device descriptor.
  96. * Various compilers have problems with the obvious definition
  97. * for max_value, namely:
  98. * (depth >= 8 ? 255 : (1 << depth) - 1)
  99. * I tried changing (1 << depth) to (1 << (depth & 15)) to forestall bogus
  100. * error messages about invalid shift counts, but the H-P compiler chokes
  101. * on this. Since the only values of depth we ever plan to support are
  102. * powers of 2 (and 24), we just go ahead and enumerate them.
  103. */
  104. #define max_value_gray(rgb_depth, gray_depth)\
  105. (gray_depth ? (1 << gray_depth) - 1 : max_value_rgb(rgb_depth, 0))
  106. #define max_value_rgb(rgb_depth, gray_depth)\
  107. (rgb_depth >= 8 ? 255 : rgb_depth == 4 ? 15 : rgb_depth == 2 ? 3 :\
  108. rgb_depth == 1 ? 1 : (1 << gray_depth) - 1)
  109. #define mem_full_alpha_device(name, rgb_depth, gray_depth, open, map_rgb_color, map_color_rgb, copy_mono, copy_color, fill_rectangle, map_cmyk_color, copy_alpha, strip_tile_rectangle, strip_copy_rop, get_bits_rectangle)\
  110. { std_device_dci_body(gx_device_memory, 0, name,\
  111. 0, 0, 72, 72,\
  112. (rgb_depth ? 3 : 0) + (gray_depth ? 1 : 0), /* num_components */\
  113. rgb_depth + gray_depth, /* depth */\
  114. max_value_gray(rgb_depth, gray_depth), /* max_gray */\
  115. max_value_rgb(rgb_depth, gray_depth), /* max_color */\
  116. max_value_gray(rgb_depth, gray_depth) + 1, /* dither_grays */\
  117. max_value_rgb(rgb_depth, gray_depth) + 1 /* dither_colors */\
  118. ),\
  119. { open, /* differs */\
  120. mem_get_initial_matrix,\
  121. gx_default_sync_output,\
  122. gx_default_output_page,\
  123. mem_close,\
  124. map_rgb_color, /* differs */\
  125. map_color_rgb, /* differs */\
  126. fill_rectangle, /* differs */\
  127. gx_default_tile_rectangle,\
  128. copy_mono, /* differs */\
  129. copy_color, /* differs */\
  130. gx_default_draw_line,\
  131. gx_default_get_bits,\
  132. gx_default_get_params,\
  133. gx_default_put_params,\
  134. map_cmyk_color, /* differs */\
  135. gx_forward_get_xfont_procs,\
  136. gx_forward_get_xfont_device,\
  137. gx_default_map_rgb_alpha_color,\
  138. gx_forward_get_page_device,\
  139. gx_default_get_alpha_bits, /* default is no alpha */\
  140. copy_alpha, /* differs */\
  141. gx_default_get_band,\
  142. gx_default_copy_rop,\
  143. gx_default_fill_path,\
  144. gx_default_stroke_path,\
  145. gx_default_fill_mask,\
  146. gx_default_fill_trapezoid,\
  147. gx_default_fill_parallelogram,\
  148. gx_default_fill_triangle,\
  149. mem_draw_thin_line, /* see above */\
  150. gx_default_begin_image,\
  151. gx_default_image_data,\
  152. gx_default_end_image,\
  153. strip_tile_rectangle, /* differs */\
  154. strip_copy_rop, /* differs */\
  155. gx_default_get_clipping_box,\
  156. gx_default_begin_typed_image,\
  157. get_bits_rectangle, /* differs */\
  158. gx_default_map_color_rgb_alpha,\
  159. gx_default_create_compositor,\
  160. gx_default_get_hardware_params,\
  161. gx_default_text_begin,\
  162. gx_default_finish_copydevice\
  163. },\
  164. 0, /* target */\
  165. mem_device_init_private /* see gxdevmem.h */\
  166. }
  167. #define mem_full_device(name, rgb_depth, gray_depth, open, map_rgb_color, map_color_rgb, copy_mono, copy_color, fill_rectangle, map_cmyk_color, strip_tile_rectangle, strip_copy_rop, get_bits_rectangle)\
  168. mem_full_alpha_device(name, rgb_depth, gray_depth, open, map_rgb_color,\
  169. map_color_rgb, copy_mono, copy_color, fill_rectangle,\
  170. map_cmyk_color, gx_default_copy_alpha,\
  171. strip_tile_rectangle, strip_copy_rop,\
  172. get_bits_rectangle)
  173. #define mem_device(name, rgb_depth, gray_depth, map_rgb_color, map_color_rgb, copy_mono, copy_color, fill_rectangle, strip_copy_rop)\
  174. mem_full_device(name, rgb_depth, gray_depth, mem_open, map_rgb_color,\
  175. map_color_rgb, copy_mono, copy_color, fill_rectangle,\
  176. gx_default_map_cmyk_color, gx_default_strip_tile_rectangle,\
  177. strip_copy_rop, mem_get_bits_rectangle)
  178. /* Swap a rectangle of bytes, for converting between word- and */
  179. /* byte-oriented representation. */
  180. void mem_swap_byte_rect(P6(byte *, uint, int, int, int, bool));
  181. /* Copy a rectangle of bytes from a source to a destination. */
  182. #define mem_copy_byte_rect(mdev, base, sourcex, sraster, x, y, w, h)\
  183. bytes_copy_rectangle(scan_line_base(mdev, y) + x_to_byte(x),\
  184. (mdev)->raster,\
  185. base + x_to_byte(sourcex), sraster,\
  186. x_to_byte(w), h)
  187. /* ------ Implementations ------ */
  188. extern const gx_device_memory mem_mono_device;
  189. extern const gx_device_memory mem_mapped2_device;
  190. extern const gx_device_memory mem_mapped4_device;
  191. extern const gx_device_memory mem_mapped8_device;
  192. extern const gx_device_memory mem_true16_device;
  193. extern const gx_device_memory mem_true24_device;
  194. extern const gx_device_memory mem_true32_device;
  195. extern const gx_device_memory mem_planar_device;
  196. /*
  197. * We declare the RasterOp implementation procedures here because they are
  198. * referenced in several implementation modules.
  199. */
  200. dev_proc_strip_copy_rop(mem_mono_strip_copy_rop);
  201. dev_proc_strip_copy_rop(mem_gray_strip_copy_rop);
  202. dev_proc_strip_copy_rop(mem_gray8_rgb24_strip_copy_rop);
  203. #if arch_is_big_endian
  204. # define mem_mono_word_device mem_mono_device
  205. # define mem_mapped2_word_device mem_mapped2_device
  206. # define mem_mapped4_word_device mem_mapped4_device
  207. # define mem_mapped8_word_device mem_mapped8_device
  208. # define mem_true24_word_device mem_true24_device
  209. # define mem_true32_word_device mem_true32_device
  210. #else
  211. extern const gx_device_memory mem_mono_word_device;
  212. extern const gx_device_memory mem_mapped2_word_device;
  213. extern const gx_device_memory mem_mapped4_word_device;
  214. extern const gx_device_memory mem_mapped8_word_device;
  215. extern const gx_device_memory mem_true24_word_device;
  216. extern const gx_device_memory mem_true32_word_device;
  217. #endif
  218. /* Provide standard palettes for 1-bit devices. */
  219. extern const gs_const_string mem_mono_b_w_palette; /* black=1, white=0 */
  220. extern const gs_const_string mem_mono_w_b_palette; /* black=0, white=1 */
  221. #endif /* gdevmem_INCLUDED */