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: gdevm8.c 8250 2007-09-25 13:31:24Z giles $ */
14
/* 8-bit-per-pixel "memory" (stored bitmap) device */
18
#include "gxdevmem.h" /* semi-public definitions */
19
#include "gdevmem.h" /* private definitions */
21
#define mem_gray8_strip_copy_rop mem_gray8_rgb24_strip_copy_rop
23
/* ================ Standard (byte-oriented) device ================ */
29
declare_mem_procs(mem_mapped8_copy_mono, mem_mapped8_copy_color, mem_mapped8_fill_rectangle);
31
/* The device descriptor. */
32
const gx_device_memory mem_mapped8_device =
33
mem_device("image8", 8, 0,
34
mem_mapped_map_rgb_color, mem_mapped_map_color_rgb,
35
mem_mapped8_copy_mono, mem_mapped8_copy_color, mem_mapped8_fill_rectangle,
36
mem_gray8_strip_copy_rop);
38
/* Convert x coordinate to byte offset in scan line. */
40
#define x_to_byte(x) (x)
42
/* Fill a rectangle with a color. */
44
mem_mapped8_fill_rectangle(gx_device * dev,
45
int x, int y, int w, int h, gx_color_index color)
47
gx_device_memory * const mdev = (gx_device_memory *)dev;
49
fit_fill(dev, x, y, w, h);
50
bytes_fill_rectangle(scan_line_base(mdev, y) + x, mdev->raster,
55
/* Copy a monochrome bitmap. */
56
/* We split up this procedure because of limitations in the bcc32 compiler. */
57
static void mapped8_copy01(chunk *, const byte *, int, int, uint,
58
int, int, byte, byte);
59
static void mapped8_copyN1(chunk *, const byte *, int, int, uint,
61
static void mapped8_copy0N(chunk *, const byte *, int, int, uint,
64
mem_mapped8_copy_mono(gx_device * dev,
65
const byte * base, int sourcex, int sraster, gx_bitmap_id id,
66
int x, int y, int w, int h, gx_color_index zero, gx_color_index one)
68
gx_device_memory * const mdev = (gx_device_memory *)dev;
72
declare_scan_ptr(dest);
73
fit_copy(dev, base, sourcex, sraster, id, x, y, w, h);
75
line = base + (sourcex >> 3);
76
first_bit = 0x80 >> (sourcex & 7);
77
#define is_color(c) ((int)(c) != (int)gx_no_color_index)
80
mapped8_copy01(dest, line, first_bit, sraster, draster,
81
w, h, (byte) zero, (byte) one);
83
mapped8_copyN1(dest, line, first_bit, sraster, draster,
85
} else if (is_color(zero))
86
mapped8_copy0N(dest, line, first_bit, sraster, draster,
91
/* Macros for copy loops */
94
{ register byte *pptr = dest;\
95
const byte *sptr = line;\
96
register int sbyte = *sptr;\
97
register uint bit = first_bit;\
102
if ( (bit >>= 1) == 0 )\
103
bit = 0x80, sbyte = *++sptr;\
106
while ( --count > 0 );\
108
inc_ptr(dest, draster);\
110
/* Halftone coloring */
112
mapped8_copy01(chunk * dest, const byte * line, int first_bit,
113
int sraster, uint draster, int w, int h, byte b0, byte b1)
116
* pptr = (sbyte & bit ? b1 : b0);
121
mapped8_copyN1(chunk * dest, const byte * line, int first_bit,
122
int sraster, uint draster, int w, int h, byte b1)
129
/* Reverse stenciling */
131
mapped8_copy0N(chunk * dest, const byte * line, int first_bit,
132
int sraster, uint draster, int w, int h, byte b0)
142
/* Copy a color bitmap. */
144
mem_mapped8_copy_color(gx_device * dev,
145
const byte * base, int sourcex, int sraster, gx_bitmap_id id,
146
int x, int y, int w, int h)
148
gx_device_memory * const mdev = (gx_device_memory *)dev;
150
fit_copy(dev, base, sourcex, sraster, id, x, y, w, h);
151
mem_copy_byte_rect(mdev, base, sourcex, sraster, x, y, w, h);
155
/* ================ "Word"-oriented device ================ */
157
/* Note that on a big-endian machine, this is the same as the */
158
/* standard byte-oriented-device. */
160
#if !arch_is_big_endian
163
declare_mem_procs(mem8_word_copy_mono, mem8_word_copy_color, mem8_word_fill_rectangle);
165
/* Here is the device descriptor. */
166
const gx_device_memory mem_mapped8_word_device =
167
mem_full_device("image8w", 8, 0, mem_open,
168
mem_mapped_map_rgb_color, mem_mapped_map_color_rgb,
169
mem8_word_copy_mono, mem8_word_copy_color, mem8_word_fill_rectangle,
170
gx_default_map_cmyk_color, gx_default_strip_tile_rectangle,
171
gx_no_strip_copy_rop, mem_word_get_bits_rectangle);
173
/* Fill a rectangle with a color. */
175
mem8_word_fill_rectangle(gx_device * dev, int x, int y, int w, int h,
176
gx_color_index color)
178
gx_device_memory * const mdev = (gx_device_memory *)dev;
182
fit_fill(dev, x, y, w, h);
183
base = scan_line_base(mdev, y);
184
raster = mdev->raster;
185
mem_swap_byte_rect(base, raster, x << 3, w << 3, h, true);
186
bytes_fill_rectangle(base + x, raster, (byte) color, w, h);
187
mem_swap_byte_rect(base, raster, x << 3, w << 3, h, true);
193
mem8_word_copy_mono(gx_device * dev,
194
const byte * base, int sourcex, int sraster, gx_bitmap_id id,
195
int x, int y, int w, int h, gx_color_index zero, gx_color_index one)
197
gx_device_memory * const mdev = (gx_device_memory *)dev;
202
fit_copy(dev, base, sourcex, sraster, id, x, y, w, h);
203
row = scan_line_base(mdev, y);
204
raster = mdev->raster;
205
store = (zero != gx_no_color_index && one != gx_no_color_index);
206
mem_swap_byte_rect(row, raster, x << 3, w << 3, h, store);
207
mem_mapped8_copy_mono(dev, base, sourcex, sraster, id,
208
x, y, w, h, zero, one);
209
mem_swap_byte_rect(row, raster, x << 3, w << 3, h, false);
213
/* Copy a color bitmap. */
215
mem8_word_copy_color(gx_device * dev,
216
const byte * base, int sourcex, int sraster, gx_bitmap_id id,
217
int x, int y, int w, int h)
219
gx_device_memory * const mdev = (gx_device_memory *)dev;
223
fit_copy(dev, base, sourcex, sraster, id, x, y, w, h);
224
row = scan_line_base(mdev, y);
225
raster = mdev->raster;
226
mem_swap_byte_rect(row, raster, x << 3, w << 3, h, true);
227
mem_copy_byte_rect(mdev, base, sourcex, sraster, x, y, w, h);
228
mem_swap_byte_rect(row, raster, x << 3, w << 3, h, false);
232
#endif /* !arch_is_big_endian */