2 |
- |
1 |
/* Copyright (C) 1994 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: gdev8bcm.h,v 1.5 2002/06/16 07:25:26 lpd Exp $ */
|
|
|
18 |
/* 8-bit color map support */
|
|
|
19 |
/* Requires gxdevice.h (for gx_color_value) */
|
|
|
20 |
|
|
|
21 |
#ifndef gdev8bcm_INCLUDED
|
|
|
22 |
# define gdev8bcm_INCLUDED
|
|
|
23 |
|
|
|
24 |
/*
|
|
|
25 |
* The MS-DOS, MS Windows, and X Windows drivers all use (at least on
|
|
|
26 |
* some platforms) an 8-bit color map in which some fraction is reserved
|
|
|
27 |
* for a pre-allocated cube and some or all of the remainder is
|
|
|
28 |
* allocated dynamically. Since looking up colors in this map can be
|
|
|
29 |
* a major performance bottleneck, we provide an efficient implementation
|
|
|
30 |
* that can be shared among drivers.
|
|
|
31 |
*
|
|
|
32 |
* As a performance compromise, we only look up the top 5 bits of the
|
|
|
33 |
* RGB value in the color map. This compromises color quality very little,
|
|
|
34 |
* and allows substantial optimizations.
|
|
|
35 |
*/
|
|
|
36 |
|
|
|
37 |
#define gx_8bit_map_size 323
|
|
|
38 |
#define gx_8bit_map_spreader 123 /* approx. 323 - (1.618 * 323) */
|
|
|
39 |
typedef struct gx_8bit_map_entry_s {
|
|
|
40 |
ushort rgb; /* key = 0rrrrrgggggbbbbb */
|
|
|
41 |
#define gx_8bit_no_rgb ((ushort)0xffff)
|
|
|
42 |
#define gx_8bit_rgb_key(r, g, b)\
|
|
|
43 |
(((r >> (gx_color_value_bits - 5)) << 10) +\
|
|
|
44 |
((g >> (gx_color_value_bits - 5)) << 5) +\
|
|
|
45 |
(b >> (gx_color_value_bits - 5)))
|
|
|
46 |
short index; /* value */
|
|
|
47 |
} gx_8bit_map_entry;
|
|
|
48 |
typedef struct gx_8bit_color_map_s {
|
|
|
49 |
int count; /* # of occupied entries */
|
|
|
50 |
int max_count; /* max # of occupied entries */
|
|
|
51 |
gx_8bit_map_entry map[gx_8bit_map_size + 1];
|
|
|
52 |
} gx_8bit_color_map;
|
|
|
53 |
|
|
|
54 |
/* Initialize an 8-bit color map. */
|
|
|
55 |
void gx_8bit_map_init(gx_8bit_color_map *, int);
|
|
|
56 |
|
|
|
57 |
/* Look up a color in an 8-bit color map. */
|
|
|
58 |
/* Return -1 if not found. */
|
|
|
59 |
int gx_8bit_map_rgb_color(const gx_8bit_color_map *, gx_color_value,
|
|
|
60 |
gx_color_value, gx_color_value);
|
|
|
61 |
|
|
|
62 |
/* Test whether an 8-bit color map has room for more entries. */
|
|
|
63 |
#define gx_8bit_map_is_full(pcm)\
|
|
|
64 |
((pcm)->count == (pcm)->max_count)
|
|
|
65 |
|
|
|
66 |
/* Add a color to an 8-bit color map. */
|
|
|
67 |
/* Return -1 if the map is full. */
|
|
|
68 |
int gx_8bit_add_rgb_color(gx_8bit_color_map *, gx_color_value,
|
|
|
69 |
gx_color_value, gx_color_value);
|
|
|
70 |
|
|
|
71 |
#endif /* gdev8bcm_INCLUDED */
|