1 /* Copyright (C) 1995, 1996, 1997, 1999 artofcode LLC.  All rights reserved.
2 
3   This program is free software; you can redistribute it and/or modify it
4   under the terms of the GNU General Public License as published by the
5   Free Software Foundation; either version 2 of the License, or (at your
6   option) any later version.
7 
8   This program is distributed in the hope that it will be useful, but
9   WITHOUT ANY WARRANTY; without even the implied warranty of
10   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11   General Public License for more details.
12 
13   You should have received a copy of the GNU General Public License along
14   with this program; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA, 02111-1307.
16 
17 */
18 
19 /*$Id: gxcindex.h,v 1.2.6.1.2.1 2003/01/17 00:49:03 giles Exp $ */
20 /* Define the device color index type and macros */
21 
22 #ifndef gxcindex_INCLUDED
23 #  define gxcindex_INCLUDED
24 
25 #include "gsbitops.h"		/* for sample_store macros */
26 
27 /*
28  * Define the maximum number of components in a device color.
29  * The minimum value is 4, to handle CMYK; the maximum value is
30  * sizeof(gx_color_index) * 8, since for larger values, there aren't enough
31  * bits in a gx_color_index to have even 1 bit per component.
32  */
33 #define GX_DEVICE_COLOR_MAX_COMPONENTS 6
34 
35 /*
36  * We might change gx_color_index to a pointer or a structure in the
37  * future.  These disabled options help us assess how much disruption
38  * such a change might cause.
39  */
40 /*#define TEST_CINDEX_POINTER*/
41 /*#define TEST_CINDEX_STRUCT*/
42 
43 /*
44  * Internally, a (pure) device color is represented by opaque values of
45  * type gx_color_index, which are tied to the specific device.  The driver
46  * maps between these values and RGB[alpha] or CMYK values.  In this way,
47  * the driver can convert RGB values to its most natural color representation,
48  * and have the graphics library cache the result.
49  */
50 
51 #ifdef TEST_CINDEX_STRUCT
52 
53 /* Define the type for device color index (pixel value) data. */
54 typedef struct { ulong value[2]; } gx_color_index_data;
55 
56 #else  /* !TEST_CINDEX_STRUCT */
57 
58 /* Define the type for device color index (pixel value) data. */
59 typedef ulong gx_color_index_data;
60 
61 #endif /* (!)TEST_CINDEX_STRUCT */
62 
63 #ifdef TEST_CINDEX_POINTER
64 
65 /* Define the type for device color indices (pixel values). */
66 typedef gx_color_index_data * gx_color_index;
67 #define arch_sizeof_color_index arch_sizeof_ptr
68 
69 extern const gx_color_index_data gx_no_color_index_data;
70 #define gx_no_color_index_values (&gx_no_color_index_data)
71 #define gx_no_color_index (&gx_no_color_index_data)
72 
73 #else  /* !TEST_CINDEX_POINTER */
74 
75 /* Define the type for device color indices (pixel values). */
76 typedef gx_color_index_data gx_color_index;
77 #define arch_sizeof_color_index arch_sizeof_long
78 
79 /* Define the 'transparent' color index. */
80 #define gx_no_color_index_value (-1)	/* no cast -> can be used in #if */
81 
82 /* The SGI C compiler provided with Irix 5.2 gives error messages */
83 /* if we use the proper definition of gx_no_color_index: */
84 /*#define gx_no_color_index ((gx_color_index)gx_no_color_index_value) */
85 /* Instead, we must spell out the typedef: */
86 #define gx_no_color_index ((unsigned long)gx_no_color_index_value)
87 
88 #endif /* (!)TEST_CINDEX_POINTER */
89 
90 /*
91  * Define macros for accumulating a scan line of a colored image.
92  * The usage is as follows:
93  *	DECLARE_LINE_ACCUM(line, bpp, xo);
94  *	for ( x = xo; x < xe; ++x ) {
95  *	    << compute color at x >>
96  *          LINE_ACCUM(color, bpp);
97  *      }
98  * This code must be enclosed in { }, since DECLARE_LINE_ACCUM declares
99  * variables.  Supported values of bpp are 1, 2, 4, 8, 12, 16, 24, 32.
100  *
101  * Note that DECLARE_LINE_ACCUM declares the variables l_dptr, l_dbyte, and
102  * l_dbit.  Other code in the loop may use these variables.
103  */
104 #define DECLARE_LINE_ACCUM(line, bpp, xo)\
105 	sample_store_declare_setup(l_dptr, l_dbit, l_dbyte, line, 0, bpp)
106 #define LINE_ACCUM(color, bpp)\
107 	sample_store_next32(color, l_dptr, l_dbit, bpp, l_dbyte)
108 #define LINE_ACCUM_SKIP(bpp)\
109 	sample_store_skip_next(l_dptr, l_dbit, bpp, l_dbyte)
110 #define LINE_ACCUM_STORE(bpp)\
111 	sample_store_flush(l_dptr, l_dbit, bpp, l_dbyte)
112 /*
113  * Declare additional macros for accumulating a scan line with copying
114  * to a device.  Note that DECLARE_LINE_ACCUM_COPY also declares l_xprev.
115  * LINE_ACCUM_COPY is called after the accumulation loop.
116  */
117 #define DECLARE_LINE_ACCUM_COPY(line, bpp, xo)\
118 	DECLARE_LINE_ACCUM(line, bpp, xo);\
119 	int l_xprev = (xo)
120 #define LINE_ACCUM_COPY(dev, line, bpp, xo, xe, raster, y)\
121 	if ( (xe) > l_xprev ) {\
122 	    int code;\
123 	    LINE_ACCUM_STORE(bpp);\
124 	    code = (*dev_proc(dev, copy_color))\
125 	      (dev, line, l_xprev - (xo), raster,\
126 	       gx_no_bitmap_id, l_xprev, y, (xe) - l_xprev, 1);\
127 	    if ( code < 0 )\
128 	      return code;\
129 	}
130 
131 #endif /* gxcindex_INCLUDED */
132