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.
13
/* $Id: gdevm16.c 8250 2007-09-25 13:31:24Z giles $ */
14
/* 16-bit-per-pixel "memory" (stored bitmap) device */
18
#include "gxdevmem.h" /* semi-public definitions */
19
#include "gdevmem.h" /* private definitions */
24
/* The 16 bits are divided 5 for red, 6 for green, and 5 for blue. */
25
/* Note that the bits must always be kept in big-endian order. */
28
declare_mem_map_procs(mem_true16_map_rgb_color, mem_true16_map_color_rgb);
29
declare_mem_procs(mem_true16_copy_mono, mem_true16_copy_color, mem_true16_fill_rectangle);
31
/* The device descriptor. */
32
const gx_device_memory mem_true16_device =
33
mem_device("image16", 16, 0,
34
mem_true16_map_rgb_color, mem_true16_map_color_rgb,
35
mem_true16_copy_mono, mem_true16_copy_color,
36
mem_true16_fill_rectangle, mem_default_strip_copy_rop);
38
/* Map a r-g-b color to a color index. */
40
mem_true16_map_rgb_color(gx_device * dev, const gx_color_value cv[])
42
return ((cv[0] >> (gx_color_value_bits - 5)) << 11) +
43
((cv[1] >> (gx_color_value_bits - 6)) << 5) +
44
(cv[2] >> (gx_color_value_bits - 5));
47
/* Map a color index to a r-g-b color. */
49
mem_true16_map_color_rgb(gx_device * dev, gx_color_index color,
50
gx_color_value prgb[3])
52
ushort value = color >> 11;
54
prgb[0] = ((value << 11) + (value << 6) + (value << 1) + (value >> 4))
55
>> (16 - gx_color_value_bits);
56
value = (color >> 5) & 0x3f;
57
prgb[1] = ((value << 10) + (value << 4) + (value >> 2))
58
>> (16 - gx_color_value_bits);
60
prgb[2] = ((value << 11) + (value << 6) + (value << 1) + (value >> 4))
61
>> (16 - gx_color_value_bits);
65
/* Convert x coordinate to byte offset in scan line. */
67
#define x_to_byte(x) ((x) << 1)
69
/* Fill a rectangle with a color. */
71
mem_true16_fill_rectangle(gx_device * dev,
72
int x, int y, int w, int h, gx_color_index color)
74
gx_device_memory * const mdev = (gx_device_memory *)dev;
75
#if arch_is_big_endian
76
const ushort color16 = (ushort)color;
78
const ushort color16 = (ushort)((color << 8) | (color >> 8));
80
declare_scan_ptr(dest);
82
fit_fill(dev, x, y, w, h);
86
*(ushort *)dest = color16;
87
inc_ptr(dest, draster);
89
} else if ((color16 >> 8) == (color16 & 0xff)) {
90
bytes_fill_rectangle(scan_line_base(mdev, y) + (x << 1), draster,
91
(byte)color, w << 1, h);
94
ushort *pptr = (ushort *) dest;
97
for (; cnt >= 4; pptr += 4, cnt -= 4)
98
pptr[3] = pptr[2] = pptr[1] = pptr[0] = color16;
100
case 3: pptr[2] = color16;
101
case 2: pptr[1] = color16;
102
case 1: pptr[0] = color16;
105
inc_ptr(dest, draster);
111
/* Copy a monochrome bitmap. */
113
mem_true16_copy_mono(gx_device * dev,
114
const byte * base, int sourcex, int sraster,
115
gx_bitmap_id id, int x, int y, int w, int h,
116
gx_color_index zero, gx_color_index one)
118
gx_device_memory * const mdev = (gx_device_memory *)dev;
119
#if arch_is_big_endian
120
const ushort zero16 = (ushort)zero;
121
const ushort one16 = (ushort)one;
123
ushort zero16 = ((uint) (byte) zero << 8) + ((ushort) zero >> 8);
124
ushort one16 = ((uint) (byte) one << 8) + ((ushort) one >> 8);
129
declare_scan_ptr(dest);
130
fit_copy(dev, base, sourcex, sraster, id, x, y, w, h);
132
line = base + (sourcex >> 3);
133
first_bit = 0x80 >> (sourcex & 7);
135
register ushort *pptr = (ushort *) dest;
136
const byte *sptr = line;
137
register int sbyte = *sptr++;
138
register int bit = first_bit;
143
if (one != gx_no_color_index)
146
if (zero != gx_no_color_index)
149
if ((bit >>= 1) == 0)
150
bit = 0x80, sbyte = *sptr++;
155
inc_ptr(dest, draster);
160
/* Copy a color bitmap. */
162
mem_true16_copy_color(gx_device * dev,
163
const byte * base, int sourcex, int sraster, gx_bitmap_id id,
164
int x, int y, int w, int h)
166
gx_device_memory * const mdev = (gx_device_memory *)dev;
168
fit_copy(dev, base, sourcex, sraster, id, x, y, w, h);
169
mem_copy_byte_rect(mdev, base, sourcex, sraster, x, y, w, h);