gxbitmap.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* Copyright (C) 1989, 1993, 1996, 1997, 1998, 1999 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: gxbitmap.h,v 1.2 2000/09/19 19:00:33 lpd Exp $ */
  16. /* Definitions for stored bitmaps for Ghostscript */
  17. #ifndef gxbitmap_INCLUDED
  18. # define gxbitmap_INCLUDED
  19. #include "gstypes.h" /* for gs_id */
  20. #include "gsbitmap.h"
  21. /* Define the gx version of a bitmap identifier. */
  22. typedef gs_bitmap_id gx_bitmap_id;
  23. /* Define the gx version of the "no identifier" value. */
  24. #define gx_no_bitmap_id gs_no_bitmap_id
  25. /*
  26. * For gx_bitmap data, each scan line must start on a `word' (long)
  27. * boundary, and hence is padded to a word boundary, although this should
  28. * rarely be of concern, since the raster and width are specified
  29. * individually.
  30. */
  31. /* We assume arch_align_long_mod is 1-4 or 8. */
  32. #if arch_align_long_mod <= 4
  33. # define log2_align_bitmap_mod 2
  34. #else
  35. #if arch_align_long_mod == 8
  36. # define log2_align_bitmap_mod 3
  37. #endif
  38. #endif
  39. #define align_bitmap_mod (1 << log2_align_bitmap_mod)
  40. #define bitmap_raster(width_bits)\
  41. ((uint)((((width_bits) + (align_bitmap_mod * 8 - 1))\
  42. >> (log2_align_bitmap_mod + 3)) << log2_align_bitmap_mod))
  43. /*
  44. * Define the gx analogue of the basic bitmap structure. Note that since
  45. * all scan lines must be aligned, the requirement on raster is:
  46. * If size.y > 1,
  47. * raster >= bitmap_raster(size.x * depth)
  48. * raster % align_bitmap_mod = 0
  49. */
  50. #define gx_bitmap_common(data_type) gs_bitmap_common(data_type)
  51. typedef struct gx_bitmap_s {
  52. gx_bitmap_common(byte);
  53. } gx_bitmap;
  54. typedef struct gx_const_bitmap_s {
  55. gx_bitmap_common(const byte);
  56. } gx_const_bitmap;
  57. /*
  58. * Define the gx analogue of the tile bitmap structure. Note that if
  59. * shift != 0 (for strip bitmaps, see below), size.y and rep_height
  60. * mean something slightly different: see below for details.
  61. */
  62. #define gx_tile_bitmap_common(data_type) gs_tile_bitmap_common(data_type)
  63. typedef struct gx_tile_bitmap_s {
  64. gx_tile_bitmap_common(byte);
  65. } gx_tile_bitmap;
  66. typedef struct gx_const_tile_bitmap_s {
  67. gx_tile_bitmap_common(const byte);
  68. } gx_const_tile_bitmap;
  69. /*
  70. * For halftones at arbitrary angles, we provide for storing the halftone
  71. * data as a strip that must be shifted in X for different values of Y. For
  72. * an ordinary (non-shifted) halftone that has a repetition width of W and a
  73. * repetition height of H, the pixel at coordinate (X,Y) corresponds to
  74. * halftone pixel (X mod W, Y mod H), ignoring phase; for a strip halftone
  75. * with strip shift S and strip height H, the pixel at (X,Y) corresponds to
  76. * halftone pixel ((X + S * floor(Y/H)) mod W, Y mod H). In other words,
  77. * each Y increment of H shifts the strip left by S pixels.
  78. *
  79. * As for non-shifted tiles, a strip bitmap may include multiple copies
  80. * in X or Y to reduce loop overhead. In this case, we must distinguish:
  81. * - The height of an individual strip, which is the same as
  82. * the height of the bitmap being replicated (rep_height, H);
  83. * - The height of the entire bitmap (size.y).
  84. * Similarly, we must distinguish:
  85. * - The shift per strip (rep_shift, S);
  86. * - The shift for the entire bitmap (shift).
  87. * Note that shift = (rep_shift * size.y / rep_height) mod rep_width,
  88. * so the shift member of the structure is only an accelerator. It is,
  89. * however, an important one, since it indicates whether the overall
  90. * bitmap requires shifting or not.
  91. *
  92. * Note that for shifted tiles, size.y is the size of the stored bitmap
  93. * (1 or more strips), and NOT the height of the actual tile. The latter
  94. * is not stored in the structure at all: it can be computed as H * W /
  95. * gcd(S, W).
  96. *
  97. * If the bitmap consists of a multiple of W / gcd(S, W) copies in Y, the
  98. * effective shift is zero, reducing it to a tile. For simplicity, we
  99. * require that if shift is non-zero, the bitmap height be less than H * W /
  100. * gcd(S, W). I.e., we don't allow strip bitmaps that are large enough to
  101. * include a complete tile but that don't include an integral number of
  102. * tiles. Requirements:
  103. * rep_shift < rep_width
  104. * shift = (rep_shift * (size.y / rep_height)) % rep_width
  105. */
  106. #define gx_strip_bitmap_common(data_type)\
  107. gx_tile_bitmap_common(data_type);\
  108. ushort rep_shift;\
  109. ushort shift
  110. typedef struct gx_strip_bitmap_s {
  111. gx_strip_bitmap_common(byte);
  112. } gx_strip_bitmap;
  113. typedef struct gx_const_strip_bitmap_s {
  114. gx_strip_bitmap_common(const byte);
  115. } gx_const_strip_bitmap;
  116. extern_st(st_gx_strip_bitmap);
  117. #define public_st_gx_strip_bitmap() /* in gspcolor.c */\
  118. gs_public_st_suffix_add0_local(st_gx_strip_bitmap, gx_strip_bitmap,\
  119. "gx_strip_bitmap", bitmap_enum_ptrs, bitmap_reloc_ptrs,\
  120. st_gs_tile_bitmap)
  121. #define st_gx_strip_bitmap_max_ptrs 1
  122. #endif /* gxbitmap_INCLUDED */