xref: /plan9/sys/src/cmd/gs/src/gxcindex.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1995, 1996, 1997, 1999 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: gxcindex.h,v 1.7 2005/06/20 08:59:23 igor Exp $ */
18 /* Define the device color index type and macros */
19 
20 #ifndef gxcindex_INCLUDED
21 #  define gxcindex_INCLUDED
22 
23 #include "gsbitops.h"		/* for sample_store macros */
24 
25 /*
26  * Define the maximum number of components in a device color.
27  * The minimum value is 4, to handle CMYK; the maximum value is
28  * arch_sizeof_color_index * 8, since for larger values, there aren't enough
29  * bits in a gx_color_index to have even 1 bit per component.
30  */
31 #define GX_DEVICE_COLOR_MAX_COMPONENTS 16
32 
33 /*
34  * We might change gx_color_index to a pointer or a structure in the
35  * future.  These disabled options help us assess how much disruption
36  * such a change might cause.
37  */
38 /*#define TEST_CINDEX_POINTER*/
39 /*#define TEST_CINDEX_STRUCT*/
40 
41 /*
42  * Internally, a (pure) device color is represented by opaque values of
43  * type gx_color_index, which are tied to the specific device.  The driver
44  * maps between these values and RGB[alpha] or CMYK values.  In this way,
45  * the driver can convert RGB values to its most natural color representation,
46  * and have the graphics library cache the result.
47  */
48 
49 #ifdef TEST_CINDEX_STRUCT
50 
51 /* Define the type for device color index (pixel value) data. */
52 typedef struct { ulong value[2]; } gx_color_index_data;
53 
54 #else  /* !TEST_CINDEX_STRUCT */
55 
56 /* Define the type for device color index (pixel value) data. */
57 #ifdef GX_COLOR_INDEX_TYPE
58 typedef GX_COLOR_INDEX_TYPE gx_color_index_data;
59 #else
60 typedef ulong gx_color_index_data;
61 #endif
62 
63 #endif /* (!)TEST_CINDEX_STRUCT */
64 
65 #ifdef TEST_CINDEX_POINTER
66 
67 /* Define the type for device color indices (pixel values). */
68 typedef gx_color_index_data * gx_color_index;
69 #define arch_sizeof_color_index arch_sizeof_ptr
70 
71 extern const gx_color_index_data gx_no_color_index_data;
72 #define gx_no_color_index_values (&gx_no_color_index_data)
73 #define gx_no_color_index (&gx_no_color_index_data)
74 
75 #else  /* !TEST_CINDEX_POINTER */
76 
77 #define arch_sizeof_color_index sizeof(gx_color_index_data)
78 
79 /* Define the type for device color indices (pixel values). */
80 typedef gx_color_index_data gx_color_index;
81 
82 /*
83  * Define the 'transparent' or 'undefined' color index.
84  */
85 #define gx_no_color_index_value (~0)	/* no cast -> can be used in #if */
86 /*
87  * There was a comment here about the SGI C compiler provided with Irix 5.2
88  * giving error messages.  I hope that was fixed when the value of gx_no_color_index
89  * was changed from (-1) to (~0).  If not then let us know.
90  */
91 #define gx_no_color_index ((gx_color_index)gx_no_color_index_value)
92 
93 #endif /* (!)TEST_CINDEX_POINTER */
94 
95 /*
96  * Define macros for accumulating a scan line of a colored image.
97  * The usage is as follows:
98  *	DECLARE_LINE_ACCUM(line, bpp, xo);
99  *	for ( x = xo; x < xe; ++x ) {
100  *	    << compute color at x >>
101  *          LINE_ACCUM(color, bpp);
102  *      }
103  * This code must be enclosed in { }, since DECLARE_LINE_ACCUM declares
104  * variables.  Supported values of bpp are 1, 2, 4, or n * 8, where n <= 8.
105  *
106  * Note that DECLARE_LINE_ACCUM declares the variables l_dptr, l_dbyte, and
107  * l_dbit.  Other code in the loop may use these variables.
108  */
109 #define DECLARE_LINE_ACCUM(line, bpp, xo)\
110 	sample_store_declare_setup(l_dptr, l_dbit, l_dbyte, line, 0, bpp)
111 #define LINE_ACCUM(color, bpp)\
112 	sample_store_next_any(color, l_dptr, l_dbit, bpp, l_dbyte)
113 #define LINE_ACCUM_SKIP(bpp)\
114 	sample_store_skip_next(l_dptr, l_dbit, bpp, l_dbyte)
115 #define LINE_ACCUM_STORE(bpp)\
116 	sample_store_flush(l_dptr, l_dbit, bpp, l_dbyte)
117 /*
118  * Declare additional macros for accumulating a scan line with copying
119  * to a device.  Note that DECLARE_LINE_ACCUM_COPY also declares l_xprev.
120  * LINE_ACCUM_COPY is called after the accumulation loop.
121  */
122 #define DECLARE_LINE_ACCUM_COPY(line, bpp, xo)\
123 	DECLARE_LINE_ACCUM(line, bpp, xo);\
124 	int l_xprev = (xo)
125 #define LINE_ACCUM_COPY(dev, line, bpp, xo, xe, raster, y)\
126 	if ( (xe) > l_xprev ) {\
127 	    int code;\
128 	    LINE_ACCUM_STORE(bpp);\
129 	    code = (*dev_proc(dev, copy_color))\
130 	      (dev, line, l_xprev - (xo), raster,\
131 	       gx_no_bitmap_id, l_xprev, y, (xe) - l_xprev, 1);\
132 	    if ( code < 0 )\
133 	      return code;\
134 	}
135 
136 #endif /* gxcindex_INCLUDED */
137