11
11
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
14
/* $Id: gxclip.c 8022 2007-06-05 22:23:38Z giles $ */
14
/* $Id: gxclip.c 8250 2007-09-25 13:31:24Z giles $ */
15
15
/* Implementation of (path-based) clipping */
17
17
#include "gxdevice.h"
27
27
/* Device for clipping with a region. */
28
28
/* We forward non-drawing operations, but we must be sure to intercept */
29
29
/* all drawing operations. */
30
private dev_proc_open_device(clip_open);
31
private dev_proc_fill_rectangle(clip_fill_rectangle);
32
private dev_proc_copy_mono(clip_copy_mono);
33
private dev_proc_copy_color(clip_copy_color);
34
private dev_proc_copy_alpha(clip_copy_alpha);
35
private dev_proc_fill_mask(clip_fill_mask);
36
private dev_proc_strip_tile_rectangle(clip_strip_tile_rectangle);
37
private dev_proc_strip_copy_rop(clip_strip_copy_rop);
38
private dev_proc_get_clipping_box(clip_get_clipping_box);
39
private dev_proc_get_bits_rectangle(clip_get_bits_rectangle);
30
static dev_proc_open_device(clip_open);
31
static dev_proc_fill_rectangle(clip_fill_rectangle);
32
static dev_proc_copy_mono(clip_copy_mono);
33
static dev_proc_copy_color(clip_copy_color);
34
static dev_proc_copy_alpha(clip_copy_alpha);
35
static dev_proc_fill_mask(clip_fill_mask);
36
static dev_proc_strip_tile_rectangle(clip_strip_tile_rectangle);
37
static dev_proc_strip_copy_rop(clip_strip_copy_rop);
38
static dev_proc_get_clipping_box(clip_get_clipping_box);
39
static dev_proc_get_bits_rectangle(clip_get_bits_rectangle);
41
41
/* The device descriptor. */
42
private const gx_device_clip gs_clip_device =
42
static const gx_device_clip gs_clip_device =
43
43
{std_device_std_body(gx_device_clip, 0, "clipper",
109
109
/* Make a clipping device. */
111
gx_make_clip_translate_device(gx_device_clip * dev, const gx_clip_list * list,
112
int tx, int ty, gs_memory_t *mem)
111
gx_make_clip_device_on_stack(gx_device_clip * dev, const gx_clip_path *pcpath, gx_device *target)
114
gx_device_init((gx_device *)dev, (const gx_device *)&gs_clip_device,
117
dev->translation.x = tx;
118
dev->translation.y = ty;
113
gx_device_init((gx_device *)dev, (const gx_device *)&gs_clip_device, NULL, true);
114
dev->list = *gx_cpath_list(pcpath);
115
dev->translation.x = 0;
116
dev->translation.y = 0;
117
dev->HWResolution[0] = target->HWResolution[0];
118
dev->HWResolution[1] = target->HWResolution[1];
119
dev->target = target;
120
(*dev_proc(dev, open_device)) ((gx_device *)dev);
121
gx_make_clip_path_device(gx_device_clip * dev, const gx_clip_path * pcpath)
123
gx_make_clip_device_in_heap(gx_device_clip * dev, const gx_clip_path *pcpath, gx_device *target,
123
gx_make_clip_device(dev, gx_cpath_list(pcpath));
126
gx_device_init((gx_device *)dev, (const gx_device *)&gs_clip_device, mem, true);
127
dev->list = *gx_cpath_list(pcpath);
128
dev->translation.x = 0;
129
dev->translation.y = 0;
130
dev->HWResolution[0] = target->HWResolution[0];
131
dev->HWResolution[1] = target->HWResolution[1];
132
gx_device_set_target((gx_device_forward *)dev, target);
133
gx_device_retain((gx_device *)dev, true); /* will free explicitly */
134
(*dev_proc(dev, open_device)) ((gx_device *)dev);
126
136
/* Define debugging statistics for the clipping loops. */
128
138
struct stats_clip_s {
130
140
loops, out, in_y, in, in1, down, up, x, no_x;
133
private const uint clip_interval = 10000;
143
static const uint clip_interval = 10000;
135
145
# define INCR(v) (++(stats_clip.v))
136
146
# define INCR_THEN(v, e) (INCR(v), (e))
143
153
* Enumerate the rectangles of the x,w,y,h argument that fall within
144
154
* the clipping region.
147
157
clip_enumerate_rest(gx_device_clip * rdev,
148
158
int x, int y, int xe, int ye,
149
159
int (*process)(clip_callback_data_t * pccd,
255
265
clip_enumerate(gx_device_clip * rdev, int x, int y, int w, int h,
256
266
int (*process)(clip_callback_data_t * pccd,
257
267
int xc, int yc, int xec, int yec),
304
314
return (*dev_proc(pccd->tdev, fill_rectangle))
305
315
(pccd->tdev, xc, yc, xec - xc, yec - yc, pccd->color[0]);
308
318
clip_fill_rectangle(gx_device * dev, int x, int y, int w, int h,
309
319
gx_color_index color)
360
370
pccd->sourcex + xc - pccd->x, pccd->raster, gx_no_bitmap_id,
361
371
xc, yc, xec - xc, yec - yc, pccd->color[0], pccd->color[1]);
364
374
clip_copy_mono(gx_device * dev,
365
375
const byte * data, int sourcex, int raster, gx_bitmap_id id,
366
376
int x, int y, int w, int h,
403
413
pccd->sourcex + xc - pccd->x, pccd->raster, gx_no_bitmap_id,
404
414
xc, yc, xec - xc, yec - yc);
407
417
clip_copy_color(gx_device * dev,
408
418
const byte * data, int sourcex, int raster, gx_bitmap_id id,
409
419
int x, int y, int w, int h)
424
434
pccd->sourcex + xc - pccd->x, pccd->raster, gx_no_bitmap_id,
425
435
xc, yc, xec - xc, yec - yc, pccd->color[0], pccd->depth);
428
438
clip_copy_alpha(gx_device * dev,
429
439
const byte * data, int sourcex, int raster, gx_bitmap_id id,
430
440
int x, int y, int w, int h,
448
458
xc, yc, xec - xc, yec - yc, pccd->pdcolor, pccd->depth,
449
459
pccd->lop, NULL);
452
462
clip_fill_mask(gx_device * dev,
453
463
const byte * data, int sourcex, int raster, gx_bitmap_id id,
454
464
int x, int y, int w, int h,
475
485
(pccd->tdev, pccd->tiles, xc, yc, xec - xc, yec - yc,
476
486
pccd->color[0], pccd->color[1], pccd->phase.x, pccd->phase.y);
479
489
clip_strip_tile_rectangle(gx_device * dev, const gx_strip_bitmap * tiles,
480
490
int x, int y, int w, int h,
481
491
gx_color_index color0, gx_color_index color1, int phase_x, int phase_y)
500
510
xc, yc, xec - xc, yec - yc, pccd->phase.x, pccd->phase.y,
504
514
clip_strip_copy_rop(gx_device * dev,
505
515
const byte * sdata, int sourcex, uint raster, gx_bitmap_id id,
506
516
const gx_color_index * scolors,
568
578
/* Get bits back from the device. */
570
580
clip_get_bits_rectangle(gx_device * dev, const gs_int_rect * prect,
571
581
gs_get_bits_params_t * params, gs_int_rect ** unread)