/* Copyright (C) 1992 Aladdin Enterprises. All rights reserved.
Distributed by Free Software Foundation, Inc.
This file is part of Ghostscript.
Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing. Refer
to the Ghostscript General Public License for full details.
Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License. A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities. It should be in a file named COPYING. Among other
things, the copyright notice and this notice must be preserved on all
/* Support routines for PC color mapping */
#include "gsmatrix.h" /* for gxdevice.h */
#include "gdevpccm.h" /* interface */
/* Color mapping routines for EGA/VGA-style color. */
/* Colors are 4 bits: 8=intensity, 4=R, 2=G, 1=B. */
#define dgray 8 /* dark gray is not very usable */
pc_4bit_map_rgb_color(gx_device
*dev
, gx_color_value r
, gx_color_value g
,
#define c13 (gx_max_color_value / 3)
#define c23 (gx_max_color_value - c13)
{{black
,blue
,lblue
},{red
,magenta
,lmagenta
},{lred
,lmagenta
,lmagenta
}};
{{green
,cyan
,lcyan
},{brown
,white
,lcyan
},{yellow
,yellow
,lmagenta
}};
{{lgreen
,lgreen
,lcyan
},{lgreen
,lgreen
,lcyan
},{yellow
,yellow
,bwhite
}};
((g
>= c23
? g2
: g
>= c13
? g1
: g0
)
[r
>= c23
? 2 : r
>= c13
? 1 : 0]
[b
>= c23
? 2 : b
>= c13
? 1 : 0]);
pc_4bit_map_color_rgb(gx_device
*dev
, gx_color_index color
,
#define icolor (int)color
(icolor
& 8 ? gx_max_color_value
: gx_max_color_value
/ 3);
prgb
[0] = (icolor
& 4 ? one
: 0);
prgb
[1] = (icolor
& 2 ? one
: 0);
prgb
[2] = (icolor
& 1 ? one
: 0);
/* Color mapping routines for 8-bit color with a fixed palette */
/* (3 bits of R, 3 bits of G, 2 bits of B). */
pc_8bit_map_rgb_color(gx_device
*dev
, gx_color_value r
, gx_color_value g
,
{ return (gx_color_index
)
(((r
>> (gx_color_value_bits
- 3)) << 5) +
((g
>> (gx_color_value_bits
- 3)) << 2) +
((b
>> (gx_color_value_bits
- 2))));
pc_8bit_map_color_rgb(gx_device
*dev
, gx_color_index color
,
#define icolor (uint)color
prgb
[0] = ((icolor
>> 5) & 7) * (gx_max_color_value
/ 7);
prgb
[1] = ((icolor
>> 2) & 7) * (gx_max_color_value
/ 7);
prgb
[2] = (icolor
& 3) * (gx_max_color_value
/ 3);
/* Write a palette on a file. */
pc_write_palette(gx_device
*dev
, uint max_index
, FILE *file
)
for ( i
= 0; i
< max_index
; i
++ )
{ (*dev
->procs
->map_color_rgb
)(dev
, (gx_color_index
)i
, rgb
);
for ( c
= 0; c
< 3; c
++ )
{ byte b
= rgb
[c
] >> (gx_color_value_bits
- 8);