gsbitmap.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* Copyright (C) 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: gsbitmap.h,v 1.2 2000/09/19 19:00:25 lpd Exp $ */
  16. /* Library "client" bitmap structures */
  17. #ifndef gsbitmap_INCLUDED
  18. #define gsbitmap_INCLUDED
  19. #include "gsstype.h" /* for extern_st */
  20. /*
  21. * The Ghostscript library stores all bitmaps bit-big-endian (i.e., the 0x80
  22. * bit of the first byte corresponds to x=0), as a sequence of bytes (i.e.,
  23. * you can't do word-oriented operations on them if you're on a
  24. * little-endian platform like the Intel 80x86 or VAX). The first scan line
  25. * corresponds to y=0 in whatever coordinate system is relevant.
  26. *
  27. * The structures defined here are for APIs that don't impose any alignment
  28. * restrictions on either the starting address or the raster (distance
  29. * between scan lines) of bitmap data. The structures defined in gxbitmap.h
  30. * do impose alignment restrictions, so that the library can use more
  31. * efficient algorithms; they are declared with identical contents to the
  32. * ones defined here, so that one can cast between them under appropriate
  33. * circumstances (aligned to unaligned is always safe; unaligned to
  34. * aligned is safe if one knows somehow that the data are actually aligned.)
  35. *
  36. * In this file we also provide structures that include depth information.
  37. * It probably was a design mistake not to include this information in the
  38. * gx structures as well.
  39. */
  40. /*
  41. * Drivers such as the X driver and the command list (band list) driver
  42. * benefit greatly by being able to cache bitmaps (tiles and characters)
  43. * and refer to them later. To help them recognize when a bitmap is the
  44. * same as one that they have seen before, the core code passes an optional
  45. * ID with the property that if two bitmaps have the same ID, they are
  46. * guaranteed to have the same contents. (The converse is *not* true,
  47. * however: two bitmaps may have different IDs and still be the same.)
  48. */
  49. typedef gs_id gs_bitmap_id;
  50. /* Define a special value to indicate "no identifier". */
  51. #define gs_no_bitmap_id gs_no_id
  52. /*
  53. * In its simplest form, the client bitmap structure does not specify a
  54. * depth, expecting it to be implicit in the context of use. In many cases
  55. * it is possible to guess this by comparing size.x and raster, but of
  56. * course code should not rely on this. See also gs_depth_bitmap below.
  57. * Requirements:
  58. * size.x > 0, size.y > 0
  59. * If size.y > 1,
  60. * raster >= (size.x * depth + 7) / 8
  61. */
  62. #define gs_bitmap_common(data_type) \
  63. data_type * data; /* pointer to the data */ \
  64. int raster; /* increment between scanlines, bytes */ \
  65. gs_int_point size; /* width and height */ \
  66. gs_bitmap_id id /* usually unused */
  67. typedef struct gs_bitmap_s {
  68. gs_bitmap_common(byte);
  69. } gs_bitmap;
  70. typedef struct gs_const_bitmap_s {
  71. gs_bitmap_common(const byte);
  72. } gs_const_bitmap;
  73. /*
  74. * For bitmaps used as halftone tiles, we may replicate the tile in
  75. * X and/or Y, but it is still valuable to know the true tile dimensions
  76. * (i.e., the dimensions prior to replication). Requirements:
  77. * size.x % rep_width = 0
  78. * size.y % rep_height = 0
  79. * Unaligned bitmaps are not very likely to be used as tiles (replicated),
  80. * since most of the library procedures that replicate tiles expect them
  81. * to be aligned.
  82. */
  83. #define gs_tile_bitmap_common(data_type) \
  84. gs_bitmap_common(data_type); \
  85. ushort rep_width, rep_height /* true size of tile */
  86. typedef struct gs_tile_bitmap_s {
  87. gs_tile_bitmap_common(byte);
  88. } gs_tile_bitmap;
  89. typedef struct gs_const_tile_bitmap_s {
  90. gs_tile_bitmap_common(const byte);
  91. } gs_const_tile_bitmap;
  92. /*
  93. * There is no "strip" version for client bitmaps, as the strip structure is
  94. * primarily used to efficiently store bitmaps rendered at an angle, and
  95. * there is little reason to do so with client bitmaps.
  96. *
  97. * For client bitmaps it is not always apparent from context what the intended
  98. * depth per sample value is. To provide for this, an extended version of the
  99. * bitmap structure is provided, that handles both variable depth and
  100. * interleaved color components. This structure is provided in both the
  101. * normal and tiled version.
  102. *
  103. * Extending this line of thinking, one could also add color space information
  104. * to a client bitmap structure. We have chosen not to do so, because color
  105. * space is almost always derived from context, and to provide such a feature
  106. * would involve additional memory-management complexity.
  107. */
  108. #define gs_depth_bitmap_common(data_type) \
  109. gs_bitmap_common(data_type); \
  110. byte pix_depth; /* bits per sample */ \
  111. byte num_comps /* number of interleaved components */ \
  112. typedef struct gs_depth_bitmap_s {
  113. gs_depth_bitmap_common(byte);
  114. } gs_depth_bitmap;
  115. typedef struct gs_const_depth_bitmap_s {
  116. gs_depth_bitmap_common(const byte);
  117. } gs_const_depth_bitmap;
  118. #define gs_tile_depth_bitmap_common(data_type) \
  119. gs_tile_bitmap_common(data_type); \
  120. byte pix_depth; /* bits per sample */ \
  121. byte num_comps /* number of interleaved components */ \
  122. typedef struct gs_tile_depth_bitmap_s {
  123. gs_tile_depth_bitmap_common(byte);
  124. } gs_tile_depth_bitmap;
  125. typedef struct gs_const_tile_depth_bitmap_s {
  126. gs_tile_depth_bitmap_common(const byte);
  127. } gs_const_tile_depth_bitmap;
  128. /*
  129. * For reasons that are no entirely clear, no memory management routines were
  130. * provided for the aligned bitmap structures provided in gxbitmap.h. Since
  131. * client bitmaps will, by nature, be created by different clients, so public
  132. * memory management procedures are provided. Note that the memory management
  133. * structure names retain the "gs_" prefix, to distinguish these structures
  134. * from those that may be provided for the gx_*_bitmap structures.
  135. *
  136. * For historical reasons of no particular validity (this was where the client
  137. * bitmap structure was first provided), the memory managment procedures for
  138. * client bitmap structures are included in gspcolor.c.
  139. */
  140. extern_st(st_gs_bitmap);
  141. extern_st(st_gs_tile_bitmap);
  142. extern_st(st_gs_depth_bitmap);
  143. extern_st(st_gs_tile_depth_bitmap);
  144. #define public_st_gs_bitmap() /* in gspcolor.c */ \
  145. gs_public_st_ptrs1( st_gs_bitmap, \
  146. gs_bitmap, \
  147. "client bitmap", \
  148. bitmap_enum_ptrs, \
  149. bitmap_reloc_ptrs, \
  150. data \
  151. )
  152. #define public_st_gs_tile_bitmap() /* in gspcolor.c */ \
  153. gs_public_st_suffix_add0_local( st_gs_tile_bitmap, \
  154. gs_tile_bitmap, \
  155. "client tile bitmap", \
  156. bitmap_enum_ptrs, \
  157. bitmap_reloc_ptrs, \
  158. st_gs_bitmap \
  159. )
  160. #define public_st_gs_depth_bitmap() /* in gspcolor.c */ \
  161. gs_public_st_suffix_add0_local( st_gs_depth_bitmap, \
  162. gs_depth_bitmap, \
  163. "client depth bitmap", \
  164. bitmap_enum_ptrs, \
  165. bitmap_reloc_ptrs, \
  166. st_gs_bitmap \
  167. )
  168. #define public_st_gs_tile_depth_bitmap()/* in gspcolor.c */ \
  169. gs_public_st_suffix_add0_local( st_gs_tile_depth_bitmap, \
  170. gs_tile_depth_bitmap, \
  171. "client tile_depth bitmap", \
  172. bitmap_enum_ptrs, \
  173. bitmap_reloc_ptrs, \
  174. st_gs_tile_bitmap \
  175. )
  176. #endif /* gsbitmap_INCLUDED */