1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
4
This software is provided AS-IS with no warranty, either express or
7
This software is distributed under license and may not be copied, modified
8
or distributed except as expressly authorized under the terms of that
9
license. Refer to licensing information at http://www.artifex.com/
10
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
11
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
14
/* $Id: gdevxalt.c 8250 2007-09-25 13:31:24Z giles $ */
15
/* Alternative X Windows drivers for help in driver debugging */
16
#include "gx.h" /* for gx_bitmap; includes std.h */
24
#include "gsdevice.h" /* for gs_copydevice */
27
extern const gx_device_X gs_x11_device;
28
extern const gx_device_X gs_x11alpha_device;
31
* Define a forwarding device with a cache for the first 16 colors,
32
* which avoids all of the time-consuming color mapping calls for
33
* the black-and-white, 2-bit gray, and 1-bit CMYK devices defined here.
36
gx_device_forward_common;
37
gx_color_index color_cache[16];
39
* alt_map_color returns a value >= 0 if it maps directly to the final
40
* gx_color_index, or < 0 if it only sets RGB values.
42
dev_proc_map_color_rgb((*alt_map_color));
43
} gx_device_X_wrapper;
44
#define X_WRAPPER_DATA(amc_proc)\
45
/* gx_device_forward_common */\
48
/* gx_device_X_wrapper */\
51
gs_private_st_suffix_add0_final(st_device_X_wrapper, gx_device_X_wrapper,
52
"gx_device_X_wrapper", gdevx_wrapper_enum_ptrs, gdevx_wrapper_reloc_ptrs,
53
gx_device_finalize, st_device_forward);
55
/* ---------------- Generic procedures ---------------- */
57
/* Forward declarations */
58
static int get_dev_target(gx_device **, gx_device *);
60
static int get_target_info(gx_device *);
61
static gx_color_index x_alt_map_color(gx_device *, gx_color_index);
63
/* Clear the color mapping cache. */
65
x_clear_color_cache(gx_device /*gx_device_X_wrapper */ * dev)
67
gx_device_X_wrapper *xdev = (gx_device_X_wrapper *) dev;
70
for (i = 0; i < countof(xdev->color_cache); ++i)
71
xdev->color_cache[i] = gx_no_color_index;
72
gx_device_decache_colors(dev);
75
/* "Wrappers" for driver procedures */
78
x_wrap_open(gx_device * dev)
83
if ((code = get_dev_target(&tdev, dev)) < 0)
85
rcode = (*dev_proc(tdev, open_device)) (tdev);
89
code = get_target_info(dev);
90
return (code < 0 ? code : rcode);
94
x_forward_sync_output(gx_device * dev)
99
if ((code = get_dev_target(&tdev, dev)) < 0)
101
return (*dev_proc(tdev, sync_output)) (tdev);
105
x_forward_output_page(gx_device * dev, int num_copies, int flush)
110
if ((code = get_dev_target(&tdev, dev)) < 0)
112
return (*dev_proc(tdev, output_page)) (tdev, num_copies, flush);
116
x_wrap_close(gx_device * dev)
119
* The underlying x11 device will be closed and freed as soon as there
120
* are no more pointers to it, which normally occurs in the next
123
gx_device_set_target((gx_device_forward *)dev, NULL);
124
x_clear_color_cache(dev);
129
x_wrap_map_color_rgb(gx_device * dev, gx_color_index color,
130
gx_color_value prgb[3])
135
if ((code = get_dev_target(&tdev, dev)) < 0)
137
return (*dev_proc(tdev, map_color_rgb)) (tdev,
138
x_alt_map_color(dev, color),
143
x_wrap_fill_rectangle(gx_device * dev, int x, int y, int w, int h,
144
gx_color_index color)
149
if ((code = get_dev_target(&tdev, dev)) < 0)
151
return (*dev_proc(tdev, fill_rectangle)) (tdev, x, y, w, h,
152
x_alt_map_color(dev, color));
156
x_wrap_copy_mono(gx_device * dev,
157
const byte * base, int sourcex, int raster, gx_bitmap_id id,
158
int x, int y, int w, int h,
159
gx_color_index zero, gx_color_index one)
164
if ((code = get_dev_target(&tdev, dev)) < 0)
166
return (*dev_proc(tdev, copy_mono)) (tdev, base, sourcex, raster, id,
168
x_alt_map_color(dev, zero),
169
x_alt_map_color(dev, one));
174
x_wrap_copy_color(gx_device * dev, const byte * base, int sourcex,
175
int raster, gx_bitmap_id id, int x, int y, int w, int h)
179
#define mapped_bytes 480 /* must be a multiple of 3 & 4 */
180
int depth_bytes, source_bits;
181
int block_w, block_h;
183
byte mapped[mapped_bytes];
186
fit_copy(dev, base, sourcex, raster, id, x, y, w, h);
187
if ((code = get_dev_target(&tdev, dev)) < 0)
189
/* Device pixels must be an integral number of bytes. */
190
if (tdev->color_info.depth & 7)
191
return gx_default_copy_color(dev, base, sourcex, raster, id,
193
depth_bytes = tdev->color_info.depth >> 3;
194
source_bits = dev->color_info.depth;
196
int mapped_pixels = mapped_bytes / depth_bytes;
198
if (w > mapped_pixels >> 1)
199
block_w = min(w, mapped_pixels), block_h = 1;
201
block_w = w, block_h = mapped_pixels / w;
203
for (yblock = y; yblock < y + h; yblock += block_h)
204
for (xblock = x; xblock < x + w; xblock += block_w) {
206
int xend = min(xblock + block_w, x + w);
207
int yend = min(yblock + block_h, y + h);
211
for (ycur = yblock; ycur < yend; ++ycur)
212
for (xcur = xblock; xcur < xend; ++xcur) {
213
int sbit = (xcur - x + sourcex) * source_bits;
215
base[(ycur - y) * raster + (sbit >> 3)];
217
((sbyte << (sbit & 7)) & 0xff) >> (8 - source_bits);
218
gx_color_index cindex =
219
((gx_device_X_wrapper *) dev)->color_cache[spixel];
221
if (cindex == gx_no_color_index)
222
cindex = x_alt_map_color(dev, spixel);
223
switch (depth_bytes) {
225
*p++ = (byte) (cindex >> 24);
227
*p++ = (byte) (cindex >> 16);
229
*p++ = (byte) (cindex >> 8);
230
default /*case 1 */ :
231
*p++ = (byte) cindex;
234
code = (*dev_proc(tdev, copy_color))
235
(tdev, mapped, 0, (xend - xblock) * depth_bytes, gx_no_bitmap_id,
236
xblock, yblock, xend - xblock, yend - yblock);
245
x_forward_copy_color(gx_device * dev, const byte * base, int sourcex,
246
int raster, gx_bitmap_id id, int x, int y, int w, int h)
251
if ((code = get_dev_target(&tdev, dev)) < 0)
253
return (*dev_proc(tdev, copy_color)) (tdev, base, sourcex, raster, id,
258
x_forward_get_bits(gx_device * dev, int y, byte * str, byte ** actual_data)
263
if ((code = get_dev_target(&tdev, dev)) < 0)
265
return (*dev_proc(tdev, get_bits)) (tdev, y, str, actual_data);
269
x_wrap_get_bits(gx_device * dev, int y, byte * str, byte ** actual_data)
271
int depth = dev->color_info.depth;
277
gs_memory_t *mem = dev->memory;
281
gx_color_index pixel_in = gx_no_color_index;
283
* The following initialization is unnecessary: since no pixel has a
284
* value of gx_no_color_index, the test pixel != pixel_in will always
285
* succeed the first time through the loop below, so pixel_out will
286
* always be set before it is used. We initialize pixel_out solely to
287
* suppress bogus warning messages from certain compilers.
289
gx_color_index pixel_out = 0;
293
DECLARE_LINE_ACCUM(str, depth, 0);
295
if ((code = get_dev_target(&tdev, dev)) < 0)
298
sdepth = tdev->color_info.depth;
299
smask = (sdepth <= 8 ? (1 << sdepth) - 1 : 0xff);
300
dsize = (width * sdepth + 7) / 8;
301
row = gs_alloc_bytes(mem, dsize, "x_wrap_get_bits");
303
return_error(gs_error_VMerror);
304
code = (*dev_proc(tdev, get_bits)) (tdev, y, row, &base);
307
for (sbit = 0, xi = 0; xi < width; sbit += sdepth, ++xi) {
308
const byte *sptr = base + (sbit >> 3);
309
gx_color_index pixel;
310
gx_color_value rgb[3];
314
pixel = (*sptr >> (8 - sdepth - (sbit & 7))) & smask;
317
for (i = 0; i < sdepth; i += 8, ++sptr)
318
pixel = (pixel << 8) + *sptr;
320
if (pixel != pixel_in) {
321
(*dev_proc(tdev, map_color_rgb))(tdev, pixel, rgb);
323
if (dev->color_info.num_components <= 3)
324
pixel_out = (*dev_proc(dev, map_rgb_color))(dev, rgb);
326
/* Convert RGB to CMYK. */
327
gx_color_value c = gx_max_color_value - rgb[0];
328
gx_color_value m = gx_max_color_value - rgb[1];
329
gx_color_value y = gx_max_color_value - rgb[2];
330
gx_color_value k = (c < m ? min(c, y) : min(m, y));
332
gx_color_value cmyk[4];
333
cmyk[0] = c - k; cmyk[1] = m - k; cmyk[2] = y - k; cmyk[3] = k;
334
pixel_out = (*dev_proc(dev, map_cmyk_color))(dev, cmyk);
337
LINE_ACCUM(pixel_out, depth);
339
LINE_ACCUM_STORE(depth);
340
gx:gs_free_object(mem, row, "x_wrap_get_bits");
346
x_wrap_get_params(gx_device * dev, gs_param_list * plist)
349
/* We assume that a get_params call has no side effects.... */
350
gx_device_X save_dev;
354
if ((code = get_dev_target(&tdev, dev)) < 0)
356
save_dev = *(gx_device_X *) tdev;
358
tdev->color_info = dev->color_info;
359
tdev->dname = dev->dname;
360
ecode = (*dev_proc(tdev, get_params)) (tdev, plist);
361
*(gx_device_X *) tdev = save_dev;
366
x_wrap_put_params(gx_device * dev, gs_param_list * plist)
369
gx_device_color_info cinfo;
373
if ((code = get_dev_target(&tdev, dev)) < 0)
376
* put_params will choke if we simply feed it the output of
377
* get_params; we have to substitute color_info the same way.
379
cinfo = tdev->color_info;
381
tdev->color_info = dev->color_info;
382
tdev->dname = dev->dname;
383
rcode = (*dev_proc(tdev, put_params)) (tdev, plist);
384
tdev->color_info = cinfo;
388
code = get_target_info(dev);
389
return (code < 0 ? code : rcode);
392
/* Internal procedures */
394
/* Get the target, creating it if necessary. */
396
get_dev_target(gx_device ** ptdev, gx_device * dev)
398
gx_device *tdev = ((gx_device_forward *) dev)->target;
401
/* Create an X device instance. */
402
int code = gs_copydevice(&tdev, (const gx_device *)&gs_x11_device,
407
check_device_separable(tdev);
408
gx_device_fill_in_procs(tdev);
409
gx_device_set_target((gx_device_forward *)dev, tdev);
410
x_clear_color_cache(dev);
416
/* Copy parameters back from the target. */
418
get_target_info(gx_device * dev)
423
if ((code = get_dev_target(&tdev, dev)) < 0)
426
#define copy(m) dev->m = tdev->m;
427
#define copy2(m) copy(m[0]); copy(m[1])
428
#define copy4(m) copy2(m); copy(m[2]); copy(m[3])
434
copy(ImagingBBox_set);
436
copy2(MarginsHWResolution);
439
if (dev->color_info.num_components == 3) {
440
/* Leave the anti-aliasing information alone. */
441
gx_device_anti_alias_info aa;
443
aa = dev->color_info.anti_alias;
445
dev->color_info.anti_alias = aa;
452
x_clear_color_cache(dev);
456
/* Map a fake CMYK or black/white color to a real X color if necessary. */
457
static gx_color_index
458
x_alt_map_color(gx_device * dev, gx_color_index color)
460
gx_device_X_wrapper *xdev = (gx_device_X_wrapper *) dev;
462
gx_color_value rgb[3];
463
gx_color_index cindex;
467
if (color == gx_no_color_index)
470
cindex = ((gx_device_X_wrapper *) dev)->color_cache[color];
471
if (cindex != gx_no_color_index)
474
if ((code = get_dev_target(&tdev, dev)) < 0)
476
result = xdev->alt_map_color(dev, color, rgb);
480
cindex = dev_proc(tdev, map_rgb_color)(tdev, rgb);
482
((gx_device_X_wrapper *) dev)->color_cache[color] = cindex;
486
/* ---------------- CMYK procedures ---------------- */
488
/* Device procedures */
489
static dev_proc_open_device(x_cmyk_open);
490
static dev_proc_put_params(x_cmyk_put_params);
491
static dev_proc_map_cmyk_color(x_cmyk_map_cmyk_color);
492
/* Extended device procedures */
493
static dev_proc_map_color_rgb(x_cmyk_alt_map_color);
495
/* The device descriptor */
496
static const gx_device_procs x_cmyk_procs = {
498
gx_forward_get_initial_matrix,
499
x_forward_sync_output,
500
x_forward_output_page,
502
NULL, /* map_rgb_color */
503
x_wrap_map_color_rgb,
504
x_wrap_fill_rectangle,
505
gx_default_tile_rectangle,
508
gx_default_draw_line,
512
x_cmyk_map_cmyk_color,
513
gx_forward_get_xfont_procs,
514
gx_forward_get_xfont_device,
515
NULL, /* map_rgb_alpha_color */
516
gx_forward_get_page_device,
517
gx_forward_get_alpha_bits,
518
NULL /* copy_alpha */
521
/* The instances are public. */
522
const gx_device_X_wrapper gs_x11cmyk_device = {
523
std_device_dci_type_body(gx_device_X_wrapper, &x_cmyk_procs, "x11cmyk",
524
&st_device_X_wrapper,
525
FAKE_RES * 85 / 10, FAKE_RES * 11, /* x and y extent (nominal) */
526
FAKE_RES, FAKE_RES, /* x and y density (nominal) */
528
X_WRAPPER_DATA(x_cmyk_alt_map_color)
530
const gx_device_X_wrapper gs_x11cmyk2_device = {
531
std_device_dci_type_body(gx_device_X_wrapper, &x_cmyk_procs, "x11cmyk2",
532
&st_device_X_wrapper,
533
FAKE_RES * 85 / 10, FAKE_RES * 11, /* x and y extent (nominal) */
534
FAKE_RES, FAKE_RES, /* x and y density (nominal) */
536
X_WRAPPER_DATA(x_cmyk_alt_map_color)
538
const gx_device_X_wrapper gs_x11cmyk4_device = {
539
std_device_dci_type_body(gx_device_X_wrapper, &x_cmyk_procs, "x11cmyk4",
540
&st_device_X_wrapper,
541
FAKE_RES * 85 / 10, FAKE_RES * 11, /* x and y extent (nominal) */
542
FAKE_RES, FAKE_RES, /* x and y density (nominal) */
543
4, 16, 15, 15, 16, 16),
544
X_WRAPPER_DATA(x_cmyk_alt_map_color)
546
const gx_device_X_wrapper gs_x11cmyk8_device = {
547
std_device_dci_type_body(gx_device_X_wrapper, &x_cmyk_procs, "x11cmyk8",
548
&st_device_X_wrapper,
549
FAKE_RES * 85 / 10, FAKE_RES * 11, /* x and y extent (nominal) */
550
FAKE_RES, FAKE_RES, /* x and y density (nominal) */
551
4, 32, 255, 255, 256, 256),
552
X_WRAPPER_DATA(x_cmyk_alt_map_color)
555
/* Map a fake color to RGB. */
557
x_cmyk_alt_map_color(gx_device * dev, gx_color_index color,
558
gx_color_value rgb[3])
560
int shift = dev->color_info.depth >> 2;
561
int mask = (1 << shift) - 1;
562
/* The following division is guaranteed exact. */
563
gx_color_value scale = gx_max_color_value / mask;
564
int cw = ~color & mask;
565
int cb = cw - ((color >> shift) & mask);
566
int cg = cw - ((color >> (shift * 2)) & mask);
567
int cr = cw - ((color >> (shift * 3)) & mask);
569
rgb[0] = max(cr, 0) * scale;
570
rgb[1] = max(cg, 0) * scale;
571
rgb[2] = max(cb, 0) * scale;
575
/* Set color mapping procedures */
577
x_cmyk_set_procs(gx_device *dev)
579
if (dev->color_info.depth == 4) {
580
set_dev_proc(dev, map_cmyk_color, cmyk_1bit_map_cmyk_color);
582
set_dev_proc(dev, map_cmyk_color, x_cmyk_map_cmyk_color);
586
/* Device procedures */
589
x_cmyk_open(gx_device *dev)
591
int code = x_wrap_open(dev);
594
x_cmyk_set_procs(dev);
599
x_cmyk_put_params(gx_device * dev, gs_param_list * plist)
601
int code = x_wrap_put_params(dev, plist);
604
x_cmyk_set_procs(dev);
608
static gx_color_index
609
x_cmyk_map_cmyk_color(gx_device * dev, const gx_color_value cv[])
611
int shift = dev->color_info.depth >> 2;
612
gx_color_index pixel = cv[0] >> (gx_color_value_bits - shift);
613
gx_color_value c, m, y, k;
614
c = cv[0]; m = cv[1]; y = cv[2]; k = cv[3];
615
pixel = (pixel << shift) | (m >> (gx_color_value_bits - shift));
616
pixel = (pixel << shift) | (y >> (gx_color_value_bits - shift));
617
return (pixel << shift) | (k >> (gx_color_value_bits - shift));
620
/* ---------------- Black-and-white procedures ---------------- */
622
/* Extended device procedures */
623
static dev_proc_map_color_rgb(x_mono_alt_map_color);
625
/* The device descriptor */
626
static const gx_device_procs x_mono_procs = {
628
gx_forward_get_initial_matrix,
629
x_forward_sync_output,
630
x_forward_output_page,
632
gx_default_b_w_map_rgb_color,
633
x_wrap_map_color_rgb,
634
x_wrap_fill_rectangle,
635
gx_default_tile_rectangle,
637
gx_default_copy_color, /* this is fast for the 1-bit case */
638
gx_default_draw_line,
642
gx_default_map_cmyk_color,
643
gx_forward_get_xfont_procs,
644
gx_forward_get_xfont_device,
645
NULL, /* map_rgb_alpha_color */
646
gx_forward_get_page_device,
647
gx_forward_get_alpha_bits,
648
NULL /* copy_alpha */
651
/* The instance is public. */
652
const gx_device_X_wrapper gs_x11mono_device = {
653
std_device_dci_type_body(gx_device_X_wrapper, &x_mono_procs, "x11mono",
654
&st_device_X_wrapper,
655
FAKE_RES * 85 / 10, FAKE_RES * 11, /* x and y extent (nominal) */
656
FAKE_RES, FAKE_RES, /* x and y density (nominal) */
658
X_WRAPPER_DATA(x_mono_alt_map_color)
661
/* Map a fake color to RGB. */
663
x_mono_alt_map_color(gx_device * dev, gx_color_index color,
664
gx_color_value rgb[3])
666
rgb[0] = rgb[1] = rgb[2] = (color ? 0 : gx_max_color_value);
670
/* ---------------- 2- and 4-bit gray-scale procedures ---------------- */
672
/* Extended device procedures */
673
static dev_proc_map_color_rgb(x_gray_alt_map_color);
675
/* The device descriptor */
676
static const gx_device_procs x_gray_procs = {
678
gx_forward_get_initial_matrix,
679
x_forward_sync_output,
680
x_forward_output_page,
682
gx_default_gray_map_rgb_color,
683
x_wrap_map_color_rgb,
684
x_wrap_fill_rectangle,
685
gx_default_tile_rectangle,
688
gx_default_draw_line,
692
gx_default_map_cmyk_color,
693
gx_forward_get_xfont_procs,
694
gx_forward_get_xfont_device,
695
NULL, /* map_rgb_alpha_color */
696
gx_forward_get_page_device,
697
gx_forward_get_alpha_bits,
698
NULL /* copy_alpha */
701
/* The instances are public. */
702
const gx_device_X_wrapper gs_x11gray2_device = {
703
std_device_dci_type_body(gx_device_X_wrapper, &x_gray_procs, "x11gray2",
704
&st_device_X_wrapper,
705
FAKE_RES * 85 / 10, FAKE_RES * 11, /* x and y extent (nominal) */
706
FAKE_RES, FAKE_RES, /* x and y density (nominal) */
708
X_WRAPPER_DATA(x_gray_alt_map_color)
711
const gx_device_X_wrapper gs_x11gray4_device = {
712
std_device_dci_type_body(gx_device_X_wrapper, &x_gray_procs, "x11gray4",
713
&st_device_X_wrapper,
714
FAKE_RES * 85 / 10, FAKE_RES * 11, /* x and y extent (nominal) */
715
FAKE_RES, FAKE_RES, /* x and y density (nominal) */
717
X_WRAPPER_DATA(x_gray_alt_map_color)
720
/* Map a fake color to RGB. */
722
x_gray_alt_map_color(gx_device * dev, gx_color_index color,
723
gx_color_value rgb[3])
725
rgb[0] = rgb[1] = rgb[2] =
726
color * gx_max_color_value / dev->color_info.max_gray;
730
/* Device procedures */
732
/* We encode a complemented alpha value in the top 8 bits of the */
734
static gx_color_index
735
x_alpha_map_rgb_alpha_color(gx_device * dev,
736
gx_color_value r, gx_color_value g, gx_color_value b, gx_color_value alpha)
738
gx_color_index color;
739
gx_color_value cv[3];
740
byte abyte = alpha >> (gx_color_value_bits - 8);
741
cv[0] = r; cv[1] = g; cv[2] = b;
742
color = gx_forward_map_rgb_color(dev, cv);
743
return (abyte == 0 ? (gx_color_index)0xff << 24 :
744
((gx_color_index) (abyte ^ 0xff) << 24) + color);
747
/* ---------------- Permuted RGB16/32 procedures ---------------- */
749
/* Device procedures */
750
static dev_proc_map_rgb_color(x_rg16x_map_rgb_color);
751
static dev_proc_map_rgb_color(x_rg32x_map_rgb_color);
752
/* Extended device procedures */
753
static dev_proc_map_color_rgb(x_rg16x_alt_map_color);
754
static dev_proc_map_color_rgb(x_rg32x_alt_map_color);
756
/* The device descriptor */
757
#define RGBX_PROCS(map_rgb_proc)\
759
gx_forward_get_initial_matrix,\
760
x_forward_sync_output,\
761
x_forward_output_page,\
763
map_rgb_proc, /* differs */\
764
x_wrap_map_color_rgb,\
765
x_wrap_fill_rectangle,\
766
gx_default_tile_rectangle,\
768
x_forward_copy_color,\
769
gx_default_draw_line,\
773
gx_forward_map_cmyk_color,\
774
gx_forward_get_xfont_procs,\
775
gx_forward_get_xfont_device,\
776
x_alpha_map_rgb_alpha_color,\
777
gx_forward_get_page_device,\
778
gx_default_get_alpha_bits,\
779
gx_default_copy_alpha
781
static const gx_device_procs x_rg16x_procs = {
782
RGBX_PROCS(x_rg16x_map_rgb_color)
784
const gx_device_X_wrapper gs_x11rg16x_device = {
785
std_device_dci_type_body(gx_device_X_wrapper, &x_rg16x_procs, "x11rg16x",
786
&st_device_X_wrapper,
787
FAKE_RES * 85 / 10, FAKE_RES * 11, /* x and y extent (nominal) */
788
FAKE_RES, FAKE_RES, /* x and y density (nominal) */
789
3, 16, 31, 31, 32, 32),
790
X_WRAPPER_DATA(x_rg16x_alt_map_color)
793
static const gx_device_procs x_rg32x_procs = {
794
RGBX_PROCS(x_rg32x_map_rgb_color)
796
const gx_device_X_wrapper gs_x11rg32x_device = {
797
std_device_dci_type_body(gx_device_X_wrapper, &x_rg32x_procs, "x11rg32x",
798
&st_device_X_wrapper,
799
FAKE_RES * 85 / 10, FAKE_RES * 11, /* x and y extent (nominal) */
800
FAKE_RES, FAKE_RES, /* x and y density (nominal) */
801
3, 32, 1023, 1023, 1024, 1024),
802
X_WRAPPER_DATA(x_rg32x_alt_map_color)
805
/* Map RGB to a fake color. */
806
static gx_color_index
807
x_rg16x_map_rgb_color(gx_device * dev, const gx_color_value cv[])
809
/* Permute the colors to G5/B5/R6. */
810
gx_color_value r, g, b;
811
r = cv[0]; g = cv[1]; b = cv[2];
812
return (r >> (gx_color_value_bits - 6)) +
813
((g >> (gx_color_value_bits - 5)) << 11) +
814
((b >> (gx_color_value_bits - 5)) << 6);
816
static gx_color_index
817
x_rg32x_map_rgb_color(gx_device * dev, const gx_color_value cv[])
819
/* Permute the colors to G11/B10/R11. */
820
gx_color_value r, g, b;
821
r = cv[0]; g = cv[1]; b = cv[2];
822
return (r >> (gx_color_value_bits - 11)) +
823
((gx_color_index)(g >> (gx_color_value_bits - 11)) << 21) +
824
((gx_color_index)(b >> (gx_color_value_bits - 10)) << 11);
827
/* Map a fake color to RGB. */
829
x_rg16x_alt_map_color(gx_device * dev, gx_color_index color,
830
gx_color_value rgb[3])
832
rgb[0] = (color & 0x3f) * gx_max_color_value / 0x3f;
833
rgb[1] = ((color >> 11) & 0x1f) * gx_max_color_value / 0x1f;
834
rgb[2] = ((color >> 6) & 0x1f) * gx_max_color_value / 0x1f;
838
x_rg32x_alt_map_color(gx_device * dev, gx_color_index color,
839
gx_color_value rgb[3])
841
rgb[0] = (color & 0x7ff) * gx_max_color_value / 0x7ff;
842
rgb[1] = ((color >> 21) & 0x7ff) * gx_max_color_value / 0x7ff;
843
rgb[2] = ((color >> 11) & 0x3ff) * gx_max_color_value / 0x3ff;
847
#ifdef GS_DEVS_SHARED
848
extern void gs_lib_register_device(const gx_device *dev);
852
gs_lib_register_device(&gs_x11_device);
853
gs_lib_register_device(&gs_x11alpha_device);
854
gs_lib_register_device(&gs_x11cmyk_device);
855
gs_lib_register_device(&gs_x11cmyk2_device);
856
gs_lib_register_device(&gs_x11cmyk4_device);
857
gs_lib_register_device(&gs_x11cmyk8_device);
858
gs_lib_register_device(&gs_x11gray2_device);
859
gs_lib_register_device(&gs_x11gray4_device);
860
gs_lib_register_device(&gs_x11mono_device);