xref: /plan9/sys/src/cmd/gs/src/gdevxcmp.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 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: gdevxcmp.h,v 1.4 2002/02/21 22:24:52 giles Exp $ */
18 /* X driver color mapping structure */
19 
20 #ifndef gdevxcmp_INCLUDED
21 #  define gdevxcmp_INCLUDED
22 
23 /*
24  * The structure defined in this file is used in only one place, in the
25  * gx_device_X structure defined in gdevx.h.  We define it as a separate
26  * structure because its function is logically separate from the rest of the
27  * X driver, and because this function (color mapping / management) accounts
28  * for the single largest piece of the driver.
29  */
30 
31 /* Define pixel value to RGB mapping */
32 typedef struct x11_rgb_s {
33     gx_color_value rgb[3];
34     bool defined;
35 } x11_rgb_t;
36 
37 /* Define dynamic color hash table structure */
38 typedef struct x11_color_s x11_color_t;
39 struct x11_color_s {
40     XColor color;
41     x11_color_t *next;
42 };
43 
44 /*
45  * Define X color values.  Fortuitously, these are the same as Ghostscript
46  * color values; in gdevxcmp.c, we are pretty sloppy about aliasing the
47  * two.
48  */
49 typedef ushort X_color_value;
50 #define X_max_color_value 0xffff
51 
52 #if HaveStdCMap  /* Standard colormap stuff is only in X11R4 and later. */
53 
54 /* Define the structure for values computed from a standard cmap component. */
55 typedef struct x11_cmap_values_s {
56     int cv_shift;	/* 16 - log2(max_value + 1) */
57     X_color_value nearest[64]; /* [i] = i * 0xffff / max_value */
58     int pixel_shift;	/* log2(mult) */
59 } x11_cmap_values_t;
60 
61 #endif
62 
63 typedef struct x11_cman_s {
64 
65     /*
66      * num_rgb is the number of possible R/G/B values, i.e.,
67      * 1 << the bits_per_rgb of the X visual.
68      */
69     int num_rgb;
70 
71     /*
72      * color_mask is a mask that selects the high-order N bits of an
73      * X color value, where N may be the mask width for TrueColor or
74      * StaticGray and is bits_per_rgb for the other visual classes.
75      *
76      * match_mask is the mask used for comparing colors.  It may have
77      * fewer bits than color_mask if the device is not using halftones.
78      */
79     struct cmm_ {
80 	X_color_value red, green, blue;
81     } color_mask, match_mask;
82 
83 #if HaveStdCMap  /* Standard colormap stuff is only in X11R4 and later. */
84 
85     struct {
86 
87 	/*
88 	 * map is the X standard colormap for the display and screen,
89 	 * if one is available.
90 	 */
91 	XStandardColormap *map;
92 
93 	/*
94 	 * When possible, we precompute shift values and tables that replace
95 	 * some multiplies and divides.
96 	 */
97 	bool fast;
98 	x11_cmap_values_t red, green, blue;
99 
100 	/*
101 	 * If free_map is true, we allocated the map ourselves (to
102 	 * represent a TrueColor or Static Gray visual), and must free it
103 	 * when closing the device.
104 	 */
105 	bool free_map;
106 
107     } std_cmap;
108 
109 #endif /* HaveStdCmap */
110 
111     /*
112      * color_to_rgb is a reverse map from pixel values to RGB values.  It
113      * only maps pixels values up to 255: pixel values above this must go
114      * through the standard colormap or query the server.
115      */
116     struct cmc_ {
117 	int size;		/* min(1 << depth, 256) */
118 	x11_rgb_t *values;	/* [color_to_rgb.size] */
119     } color_to_rgb;
120 
121     /*
122      * For systems with writable colormaps and no suitable standard
123      * colormap, dither_ramp is a preallocated ramp or cube used for
124      * dithering.
125      */
126 #define CUBE_INDEX(r,g,b) (((r) * xdev->color_info.dither_colors + (g)) * \
127 				  xdev->color_info.dither_colors + (b))
128     x_pixel *dither_ramp;	/* [color_info.dither_colors^3] if color,
129 				   [color_info.dither_grays] if gray */
130 
131     /*
132      * For systems with writable colormaps, dynamic.colors is a chained
133      * hash table that maps RGB values (masked with color_mask) to
134      * pixel values.  Entries are added dynamically.
135      */
136     struct cmd_ {
137 	int size;
138 	x11_color_t **colors;	/* [size] */
139 	int shift;		/* 16 - log2(size) */
140 	int used;
141 	int max_used;
142     } dynamic;
143 
144 } x11_cman_t;
145 
146 #endif /* gdevxcmp_INCLUDED */
147