gdevmr2n.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* Copyright (C) 1995, 1996, 1997, 1998, 1999 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: gdevmr2n.c,v 1.4 2002/02/21 22:24:51 giles Exp $ */
  14. /* RasterOp implementation for 2- and 4-bit memory devices */
  15. #include "memory_.h"
  16. #include "gx.h"
  17. #include "gsbittab.h"
  18. #include "gserrors.h"
  19. #include "gsropt.h"
  20. #include "gxcindex.h"
  21. #include "gxdcolor.h"
  22. #include "gxdevice.h"
  23. #include "gxdevmem.h"
  24. #include "gxdevrop.h"
  25. #include "gdevmem.h"
  26. #include "gdevmrop.h"
  27. /* Calculate the X offset for a given Y value, */
  28. /* taking shift into account if necessary. */
  29. #define x_offset(px, ty, textures)\
  30. ((textures)->shift == 0 ? (px) :\
  31. (px) + (ty) / (textures)->rep_height * (textures)->rep_shift)
  32. /* ---------------- Fake RasterOp for 2- and 4-bit devices ---------------- */
  33. /*
  34. * Define patched versions of the driver procedures that may be called
  35. * by mem_mono_strip_copy_rop (see below). Currently we just punt to
  36. * the slow, general case; we could do a lot better.
  37. */
  38. private int
  39. mem_gray_rop_fill_rectangle(gx_device * dev, int x, int y, int w, int h,
  40. gx_color_index color)
  41. {
  42. return -1;
  43. }
  44. private int
  45. mem_gray_rop_copy_mono(gx_device * dev, const byte * data,
  46. int dx, int raster, gx_bitmap_id id,
  47. int x, int y, int w, int h,
  48. gx_color_index zero, gx_color_index one)
  49. {
  50. return -1;
  51. }
  52. private int
  53. mem_gray_rop_strip_tile_rectangle(gx_device * dev,
  54. const gx_strip_bitmap * tiles,
  55. int x, int y, int w, int h,
  56. gx_color_index color0, gx_color_index color1,
  57. int px, int py)
  58. {
  59. return -1;
  60. }
  61. int
  62. mem_gray_strip_copy_rop(gx_device * dev,
  63. const byte * sdata, int sourcex, uint sraster, gx_bitmap_id id,
  64. const gx_color_index * scolors,
  65. const gx_strip_bitmap * textures, const gx_color_index * tcolors,
  66. int x, int y, int width, int height,
  67. int phase_x, int phase_y, gs_logical_operation_t lop)
  68. {
  69. gx_color_index scolors2[2];
  70. const gx_color_index *real_scolors = scolors;
  71. gx_color_index tcolors2[2];
  72. const gx_color_index *real_tcolors = tcolors;
  73. gx_strip_bitmap texture2;
  74. const gx_strip_bitmap *real_texture = textures;
  75. long tdata;
  76. int depth = dev->color_info.depth;
  77. int log2_depth = depth >> 1; /* works for 2, 4 */
  78. gx_color_index max_pixel = (1 << depth) - 1;
  79. int code;
  80. #ifdef DEBUG
  81. if (gs_debug_c('b'))
  82. trace_copy_rop("mem_gray_strip_copy_rop",
  83. dev, sdata, sourcex, sraster,
  84. id, scolors, textures, tcolors,
  85. x, y, width, height, phase_x, phase_y, lop);
  86. #endif
  87. if (gx_device_has_color(dev) ||
  88. (lop & (lop_S_transparent | lop_T_transparent)) ||
  89. (scolors && /* must be (0,0) or (max,max) */
  90. ((scolors[0] | scolors[1]) != 0) &&
  91. ((scolors[0] & scolors[1]) != max_pixel)) ||
  92. (tcolors && (tcolors[0] != tcolors[1]))
  93. ) {
  94. /* We can't fake it: do it the slow, painful way. */
  95. return mem_default_strip_copy_rop(dev, sdata, sourcex, sraster, id,
  96. scolors, textures, tcolors,
  97. x, y, width, height,
  98. phase_x, phase_y, lop);
  99. }
  100. if (scolors) { /* Must be a solid color: see above. */
  101. scolors2[0] = scolors2[1] = scolors[0] & 1;
  102. real_scolors = scolors2;
  103. }
  104. if (textures) {
  105. texture2 = *textures;
  106. texture2.size.x <<= log2_depth;
  107. texture2.rep_width <<= log2_depth;
  108. texture2.shift <<= log2_depth;
  109. texture2.rep_shift <<= log2_depth;
  110. real_texture = &texture2;
  111. }
  112. if (tcolors) {
  113. /* For polybit textures with colors other than */
  114. /* all 0s or all 1s, fabricate the data. */
  115. if (tcolors[0] != 0 && tcolors[0] != max_pixel) {
  116. real_tcolors = 0;
  117. *(byte *) & tdata = (byte) tcolors[0] << (8 - depth);
  118. texture2.data = (byte *) & tdata;
  119. texture2.raster = align_bitmap_mod;
  120. texture2.size.x = texture2.rep_width = depth;
  121. texture2.size.y = texture2.rep_height = 1;
  122. texture2.id = gx_no_bitmap_id;
  123. texture2.shift = texture2.rep_shift = 0;
  124. real_texture = &texture2;
  125. } else {
  126. tcolors2[0] = tcolors2[1] = tcolors[0] & 1;
  127. real_tcolors = tcolors2;
  128. }
  129. }
  130. /*
  131. * mem_mono_strip_copy_rop may call fill_rectangle, copy_mono, or
  132. * strip_tile_rectangle for special cases. Patch those procedures
  133. * temporarily so they will either do the right thing or return
  134. * an error.
  135. */
  136. {
  137. dev_proc_fill_rectangle((*fill_rectangle)) =
  138. dev_proc(dev, fill_rectangle);
  139. dev_proc_copy_mono((*copy_mono)) =
  140. dev_proc(dev, copy_mono);
  141. dev_proc_strip_tile_rectangle((*strip_tile_rectangle)) =
  142. dev_proc(dev, strip_tile_rectangle);
  143. set_dev_proc(dev, fill_rectangle, mem_gray_rop_fill_rectangle);
  144. set_dev_proc(dev, copy_mono, mem_gray_rop_copy_mono);
  145. set_dev_proc(dev, strip_tile_rectangle,
  146. mem_gray_rop_strip_tile_rectangle);
  147. dev->width <<= log2_depth;
  148. code = mem_mono_strip_copy_rop(dev, sdata,
  149. (real_scolors == NULL ?
  150. sourcex << log2_depth : sourcex),
  151. sraster, id, real_scolors,
  152. real_texture, real_tcolors,
  153. x << log2_depth, y,
  154. width << log2_depth, height,
  155. phase_x << log2_depth, phase_y, lop);
  156. set_dev_proc(dev, fill_rectangle, fill_rectangle);
  157. set_dev_proc(dev, copy_mono, copy_mono);
  158. set_dev_proc(dev, strip_tile_rectangle, strip_tile_rectangle);
  159. dev->width >>= log2_depth;
  160. }
  161. /* If we punted, use the general procedure. */
  162. if (code < 0)
  163. return mem_default_strip_copy_rop(dev, sdata, sourcex, sraster, id,
  164. scolors, textures, tcolors,
  165. x, y, width, height,
  166. phase_x, phase_y, lop);
  167. return code;
  168. }