xref: /plan9/sys/src/cmd/gs/src/gxbitfmt.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1997, 1998 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: gxbitfmt.h,v 1.5 2002/08/22 07:12:29 henrys Exp $ */
18 /* Definitions for bitmap storage formats */
19 
20 #ifndef gxbitfmt_INCLUDED
21 #  define gxbitfmt_INCLUDED
22 
23 /*
24  * Several operations, such as the get_bits_rectangle driver procedure, can
25  * take and/or produce data in a flexible variety of formats; the ability to
26  * describe how bitmap data is stored is useful in other contexts as well.
27  * We define bitmap storage formats using a bit mask: this allows a
28  * procedure to ask for, or offer to provide, data in more than one format.
29  */
30 
31 typedef ulong gx_bitmap_format_t;
32 
33     /*
34      * Define the supported color space alternatives.
35      */
36 
37 #define GB_COLORS_NATIVE (1L<<0)  /* native representation (DevicePixel) */
38 #define GB_COLORS_GRAY   (1L<<1)  /* DeviceGray */
39 #define GB_COLORS_RGB    (1L<<2)  /* DeviceRGB */
40 #define GB_COLORS_CMYK   (1L<<3)  /* DeviceCMYK */
41 
42 #define GB_COLORS_STANDARD_ALL\
43   (GB_COLORS_GRAY | GB_COLORS_RGB | GB_COLORS_CMYK)
44 #define GB_COLORS_ALL\
45   (GB_COLORS_NATIVE | GB_COLORS_STANDARD_ALL)
46 #define GB_COLORS_NAMES\
47   "colors_native", "colors_Gray", "colors_RGB", "colors_CMYK"
48 
49     /*
50      * Define whether alpha information is included.  For GB_COLORS_NATIVE,
51      * all values other than GB_ALPHA_NONE are equivalent.
52      */
53 
54 #define GB_ALPHA_NONE  (1L<<4)  /* no alpha */
55 #define GB_ALPHA_FIRST (1L<<5)  /* include alpha as first component */
56 #define GB_ALPHA_LAST  (1L<<6)  /* include alpha as last component */
57   /*unused*/           /*(1L<<7)*/
58 
59 #define GB_ALPHA_ALL\
60   (GB_ALPHA_NONE | GB_ALPHA_FIRST | GB_ALPHA_LAST)
61 #define GB_ALPHA_NAMES\
62   "alpha_none", "alpha_first", "alpha_last", "?alpha_unused?"
63 
64     /*
65      * Define the supported depths per component for GB_COLORS_STANDARD.
66      * For GB_COLORS_NATIVE with planar packing, it is the client's
67      * responsibility to know how the device divides up the bits of the
68      * pixel.
69      */
70 
71 #define GB_DEPTH_1  (1L<<8)
72 #define GB_DEPTH_2  (1L<<9)
73 #define GB_DEPTH_4  (1L<<10)
74 #define GB_DEPTH_8  (1L<<11)
75 #define GB_DEPTH_12 (1L<<12)
76 #define GB_DEPTH_16 (1L<<13)
77   /*unused1*/       /*(1L<<14)*/
78   /*unused2*/       /*(1L<<15)*/
79 
80 #define GB_DEPTH_ALL\
81   (GB_DEPTH_1 | GB_DEPTH_2 | GB_DEPTH_4 | GB_DEPTH_8 |\
82    GB_DEPTH_12 | GB_DEPTH_16)
83 #define GB_DEPTH_NAMES\
84   "depth_1", "depth_2", "depth_4", "depth_8",\
85   "depth_12", "depth_16", "?depth_unused1?", "?depth_unused2?"
86 
87 /* Find the maximum depth of an options mask. */
88 #define GB_OPTIONS_MAX_DEPTH(opt)\
89 "\
90 \000\001\002\002\004\004\004\004\010\010\010\010\010\010\010\010\
91 \014\014\014\014\014\014\014\014\014\014\014\014\014\014\014\014\
92 \020\020\020\020\020\020\020\020\020\020\020\020\020\020\020\020\
93 \020\020\020\020\020\020\020\020\020\020\020\020\020\020\020\020\
94 "[((opt) >> 8) & 0x3f]
95 /* Find the depth of an options mask with exactly 1 bit set. */
96 #define GB_OPTIONS_DEPTH(opt)\
97   ((((opt) >> 8) & 0xf) |\
98    "\000\000\014\020"[((opt) >> 12) & 3])
99 
100     /*
101      * Define the supported packing formats.  Currently, GB_PACKING_PLANAR is
102      * only partially supported, and GB_PACKING_BIT_PLANAR is hardly supported
103      * at all.
104      */
105 
106 #define GB_PACKING_CHUNKY     (1L<<16)
107 #define GB_PACKING_PLANAR     (1L<<17)  /* 1 plane per component */
108 #define GB_PACKING_BIT_PLANAR (1L<<18)  /* 1 plane per bit */
109 
110 #define GB_PACKING_ALL\
111   (GB_PACKING_CHUNKY | GB_PACKING_PLANAR | GB_PACKING_BIT_PLANAR)
112 #define GB_PACKING_NAMES\
113   "packing_chunky", "packing_planar", "packing_bit_planar"
114 
115     /*
116      * Define whether to return a subset of the planes.  With planar packing
117      * formats, if this is set, only those planes that had non-zero data
118      * pointers originally will be returned (either by copying or by
119      * pointer).  With chunky packing, if this is set, only an undefined
120      * subset of the returned bits may be valid.
121      */
122 
123 #define GB_SELECT_PLANES  (1L<<19)
124 #define GB_SELECT_ALL\
125   (GB_SELECT_PLANES)
126 #define GB_SELECT_NAMES\
127   "select_planes"
128 
129     /*
130      * Define the possible methods of returning data.
131      */
132 
133 #define GB_RETURN_COPY    (1L<<20)  /* copy to client's buffer */
134 #define GB_RETURN_POINTER (1L<<21)  /* return pointers to data */
135 
136 #define GB_RETURN_ALL\
137   (GB_RETURN_COPY | GB_RETURN_POINTER)
138 #define GB_RETURN_NAMES\
139   "return_copy", "return_pointer"
140 
141     /*
142      * Define the allowable alignments.  This is only relevant for
143      * GB_RETURN_POINTER: for GB_RETURN_COPY, any alignment is
144      * acceptable.
145      */
146 
147 #define GB_ALIGN_STANDARD (1L<<22)  /* require standard bitmap alignment */
148 #define GB_ALIGN_ANY      (1L<<23)  /* any alignment is acceptable */
149 
150 #define GB_ALIGN_ALL\
151   (GB_ALIGN_ANY | GB_ALIGN_STANDARD)
152 #define GB_ALIGN_NAMES\
153   "align_standard", "align_any"
154 
155     /*
156      * Define the allowable X offsets.  GB_OFFSET_ANY is only relevant for
157      * GB_RETURN_POINTER: for GB_RETURN_COPY, clients must specify
158      * the offset so they know how much space to allocate.
159      */
160 
161 #define GB_OFFSET_0         (1L<<24)  /* no offsetting */
162 #define GB_OFFSET_SPECIFIED (1L<<25)  /* client-specified offset */
163 #define GB_OFFSET_ANY       (1L<<26)  /* any offset is acceptable */
164 				/* (for GB_RETURN_POINTER only) */
165   /*unused*/                /*(1L<<27)*/
166 
167 #define GB_OFFSET_ALL\
168   (GB_OFFSET_0 | GB_OFFSET_SPECIFIED | GB_OFFSET_ANY)
169 #define GB_OFFSET_NAMES\
170   "offset_0", "offset_specified", "offset_any", "?offset_unused?"
171 
172     /*
173      * Define the allowable rasters.  GB_RASTER_ANY is only relevant for
174      * GB_RETURN_POINTER, for the same reason as GB_OFFSET_ANY.
175      * Note also that if GB_ALIGN_STANDARD and GB_RASTER_SPECIFIED are
176      * both chosen and more than one scan line is being transferred,
177      * the raster value must also be aligned (i.e., 0 mod align_bitmap_mod).
178      * Implementors are not required to check this.
179      */
180 
181     /*
182      * Standard raster is bitmap_raster(dev->width) for return_ptr,
183      * bitmap_raster(x_offset + width) for return_copy,
184      * padding per alignment.
185      */
186 #define GB_RASTER_STANDARD  (1L<<28)
187 #define GB_RASTER_SPECIFIED (1L<<29)  /* any client-specified raster */
188 #define GB_RASTER_ANY       (1L<<30)  /* any raster is acceptable (for */
189 				/* GB_RETURN_POINTER only) */
190 
191 #define GB_RASTER_ALL\
192   (GB_RASTER_STANDARD | GB_RASTER_SPECIFIED | GB_RASTER_ANY)
193 #define GB_RASTER_NAMES\
194   "raster_standard", "raster_specified", "raster_any"
195 
196 /* Define names for debugging printout. */
197 #define GX_BITMAP_FORMAT_NAMES\
198   GB_COLORS_NAMES, GB_ALPHA_NAMES, GB_DEPTH_NAMES, GB_PACKING_NAMES,\
199   GB_SELECT_NAMES, GB_RETURN_NAMES, GB_ALIGN_NAMES, GB_OFFSET_NAMES,\
200   GB_RASTER_NAMES
201 
202 #endif /* gxbitfmt_INCLUDED */
203