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: gxdevmem.h 8528 2008-02-17 22:32:15Z leonardo $ */
15
/* Structure and procedures for memory devices */
16
/* Requires gxdevice.h */
18
#ifndef gxdevmem_INCLUDED
19
# define gxdevmem_INCLUDED
24
* A 'memory' device is essentially a stored bitmap.
25
* There are several different kinds: 1-bit black and white,
26
* 2-, 4-, and 8-bit mapped color, 16- and 24-bit RGB color,
27
* and 32-bit CMYK color. (16-bit uses 5/6/5 bits per color.)
28
* All use the same structure, since it's so awkward to get the effect of
31
* Memory devices come in two flavors: standard, which always stores bytes
32
* big-endian, and word-oriented, which stores bytes in the machine order
33
* within 32-bit "words". The source data for copy_mono and
34
* copy_color must be in big-endian order, and since memory devices
35
* also are guaranteed to allocate the bitmap consecutively,
36
* the bitmap of a standard memory device can serve directly as input
37
* to copy_mono or copy_color operations. This is not true of word-oriented
38
* memory devices, which are provided only in response to a request by
39
* a customer with their own image processing library that uses this format.
41
* In addition to the device structure itself, memory devices require two
42
* other pieces of storage: the bitmap, and a table of pointers to the scan
43
* lines of the bitmap. Clients have several options for allocating these:
45
* 1) Set bitmap_memory to an allocator before opening the device.
46
* With this option, opening the device allocates the bitmap and the
47
* line pointer table (contiguously), and closing the device frees
50
* 2) Set line_pointer_memory to an allocator, base to the base address
51
* of the bitmap, and raster to the length of each scan line (distance
52
* from one scan line to the next) before opening the device. With
53
* this option, opening the device allocates the line table, but not
54
* the bitmap; closing the device frees the table.
56
* 3) Set line_pointer_memory but not base or raster. Opening /
57
* closing the device will allocate / free the line pointer table, but
58
* the client must set the pointers with a subsequent call of
59
* gdev_mem_set_line_ptrs.
61
* 4) Set neither _memory field. In this case, it's up to the client
62
* to call gdev_mem_set_line_ptrs and to manage storage for the
63
* line pointers and the bitmap.
65
* In cases (2) through (4), it is the client's responsibility to set
66
* foreign_bits (and foreign_line_pointers, if the line pointers are not
67
* contiguous with the bits) to tell the GC whether to trace the pointers.
68
* By default, anything allocated by bitmap_memory or line_pointer_memory is
69
* assumed GC'able (i.e., case (1) assumes that the bits + line pointers are
70
* GC'able, and cases (2) and (3) assume that the line pointers are GC'able,
71
* but not the bits), but the client can change the foreign_* flag(s) after
72
* opening the device if this is not the case.
74
#ifndef gx_device_memory_DEFINED
75
# define gx_device_memory_DEFINED
76
typedef struct gx_device_memory_s gx_device_memory;
79
struct gx_device_memory_s {
80
gx_device_forward_common; /* (see gxdevice.h) */
82
* The following may be set by the client before or just after
83
* opening the device. See above.
85
uint raster; /* bytes per scan line */
87
#define scan_line_base(dev,y) ((dev)->line_ptrs[y])
88
gs_memory_t *bitmap_memory; /* allocator for bits + line pointers */
89
bool foreign_bits; /* if true, bits are not in GC-able space */
90
gs_memory_t *line_pointer_memory; /* allocate for line pointers */
91
bool foreign_line_pointers; /* if true, line_ptrs are not in GC-able space */
93
* The following are only used for planar devices. num_planes == 0
94
* means this is a chunky device. Note that for planar devices, we
95
* require color_info.depth = the sum of the individual plane depths.
98
gx_render_plane_t planes[GX_DEVICE_COLOR_MAX_COMPONENTS];
100
* End of client-initializable fields.
102
gs_matrix initial_matrix; /* the initial transformation */
103
byte **line_ptrs; /* scan line pointers */
104
/* Following is used for mapped color, */
105
/* including 1-bit devices (to specify polarity). */
106
gs_const_string palette; /* RGB triples */
107
/* Following is only used for 24-bit color. */
109
gx_color_index rgb; /* cache key */
110
bits32 rgbr, gbrg, brgb; /* cache value */
112
/* Following is only used for 40-bit color. */
114
gx_color_index abcde; /* cache key */
115
bits32 abcd, bcde, cdea, deab, eabc; /* cache value */
117
/* Following is only used for 48-bit color. */
119
gx_color_index abcdef; /* cache key */
120
bits32 abcd, cdef, efab; /* cache value */
122
/* Following is only used for 56-bit color. */
124
gx_color_index abcdefg; /* cache key */
125
bits32 abcd, bcde, cdef, defg, efga, fgab, gabc; /* cache value */
127
/* Following is only used for 64-bit color. */
129
gx_color_index abcdefgh; /* cache key */
130
bits32 abcd, efgh; /* cache value */
132
/* Following are only used for alpha buffers. */
133
/* The client initializes those marked with $; */
134
/* they don't change after initialization. */
135
gs_log2_scale_point log2_scale; /* $ oversampling scale factors */
136
int log2_alpha_bits; /* $ log2 of # of alpha bits being produced */
137
int mapped_x; /* $ X value mapped to buffer X=0 */
138
int mapped_y; /* lowest Y value mapped to buffer */
139
int mapped_height; /* # of Y values mapped to buffer */
140
int mapped_start; /* local Y value corresponding to mapped_y */
141
gx_color_index save_color; /* last (only) color displayed */
142
/* Following are used only for planar devices. */
143
int plane_depth; /* if non-zero, depth of all planes */
144
int band_y; /* Debug purpose only. */
147
extern_st(st_device_memory);
148
#define public_st_device_memory() /* in gdevmem.c */\
149
gs_public_st_composite_use_final(st_device_memory, gx_device_memory,\
150
"gx_device_memory", device_memory_enum_ptrs, device_memory_reloc_ptrs,\
152
#define st_device_memory_max_ptrs (st_device_forward_max_ptrs + 2)
153
#define mem_device_init_private\
155
(byte *)0, /* base */\
156
0, /* bitmap_memory */\
157
true, /* foreign_bits (default) */\
158
0, /* line_pointer_memory */\
159
true, /* foreign_line_pointers (default) */\
160
0, /* num_planes (default) */\
161
{ { 0 } }, /* planes (only used for planar) */\
162
{ identity_matrix_body }, /* initial matrix (filled in) */\
163
(byte **)0, /* line_ptrs (filled in by mem_open) */\
164
{ (byte *)0, 0 }, /* palette (filled in for color) */\
165
{ gx_no_color_index }, /* color24 */\
166
{ gx_no_color_index }, /* color40 */\
167
{ gx_no_color_index }, /* color48 */\
168
{ gx_no_color_index }, /* color56 */\
169
{ gx_no_color_index }, /* color64 */\
170
{ 0, 0 }, 0, /* scale, log2_alpha_bits */\
171
0, 0, 0, 0, /* mapped_* */\
172
gx_no_color_index /* save_color */
175
* Memory devices may have special setup requirements. In particular, it
176
* may not be obvious how much space to allocate for the bitmap. Here is
177
* the routine that computes this from the width and height. Note that this
178
* size includes both the bitmap and the line pointers.
181
int gdev_mem_bits_size(const gx_device_memory *mdev, int width,
182
int height, ulong *size);
183
/* line pointers only */
184
ulong gdev_mem_line_ptrs_size(const gx_device_memory *mdev, int width,
186
/* bits + line pointers */
187
int gdev_mem_data_size(const gx_device_memory *mdev, int width,
188
int height, ulong *size);
190
#define gdev_mem_bitmap_size(mdev, size)\
191
gdev_mem_data_size(mdev, (mdev)->width, (mdev)->height, size)
194
* Do the inverse computation: given the device width and a buffer size,
195
* compute the maximum height.
197
int gdev_mem_max_height(const gx_device_memory * dev, int width, ulong size,
198
bool page_uses_transparency);
201
* Compute the standard raster (data bytes per line) similarly.
203
#define gdev_mem_raster(mdev)\
204
gx_device_raster((const gx_device *)(mdev), true)
206
/* Determine the appropriate memory device for a given */
207
/* number of bits per pixel (0 if none suitable). */
208
const gx_device_memory *gdev_mem_device_for_bits(int);
210
/* Determine the word-oriented memory device for a given depth. */
211
const gx_device_memory *gdev_mem_word_device_for_bits(int);
213
/* Make a memory device. */
214
/* mem is 0 if the device is temporary and local, */
215
/* or the allocator that was used to allocate it if it is a real object. */
216
/* page_device is 1 if the device should be a page device, */
217
/* 0 if it should propagate this property from its target, or */
218
/* -1 if it should not be a page device. */
219
void gs_make_mem_mono_device(gx_device_memory * mdev, gs_memory_t * mem,
221
void gs_make_mem_device(gx_device_memory * mdev,
222
const gx_device_memory * mdproto,
223
gs_memory_t * mem, int page_device,
225
void gs_make_mem_abuf_device(gx_device_memory * adev, gs_memory_t * mem,
227
const gs_log2_scale_point * pscale,
228
int alpha_bits, int mapped_x);
229
void gs_make_mem_alpha_device(gx_device_memory * adev, gs_memory_t * mem,
230
gx_device * target, int alpha_bits);
233
* Open a memory device, only setting line pointers to a subset of its
234
* scan lines. Banding devices use this (see gxclread.c).
236
int gdev_mem_open_scan_lines(gx_device_memory *mdev, int setup_height);
239
* Initialize the line pointers of a memory device. base and/or line_ptrs
240
* may be NULL, in which case the value already stored in the device is
241
* used; if base is NULL, raster is also ignored and the existing value is
242
* used. Note that this takes raster and setup_height arguments.
243
* If the base is not NULL and the device is planar, all planes must have
244
* the same depth, since otherwise a single raster value is not sufficient.
246
* Note that setup_height may be less than height. In this case, for
247
* planar devices, only setup_height * num_planes line pointers are set,
248
* in the expectation that the device's height will be reset to
251
int gdev_mem_set_line_ptrs(gx_device_memory *mdev,
252
byte *base, int raster, byte **line_ptrs,
255
/* Define whether a monobit memory device is inverted (black=1). */
256
void gdev_mem_mono_set_inverted(gx_device_memory * mdev, bool black_is_1);
258
/* Test whether a device is a memory device. */
259
bool gs_device_is_memory(const gx_device *);
261
/* Test whether a device is an alpha-buffering device. */
262
bool gs_device_is_abuf(const gx_device *);
264
#endif /* gxdevmem_INCLUDED */