diff options
Diffstat (limited to 'gs/base/gxclipm.c')
-rw-r--r-- | gs/base/gxclipm.c | 276 |
1 files changed, 138 insertions, 138 deletions
diff --git a/gs/base/gxclipm.c b/gs/base/gxclipm.c index 4c64d6845..4b5b633d5 100644 --- a/gs/base/gxclipm.c +++ b/gs/base/gxclipm.c @@ -1,6 +1,6 @@ /* Copyright (C) 2001-2006 Artifex Software, Inc. All Rights Reserved. - + This software is provided AS-IS with no warranty, either express or implied. @@ -32,7 +32,7 @@ static dev_proc_get_clipping_box(mask_clip_get_clipping_box); /* The device descriptor. */ const gx_device_mask_clip gs_mask_clip_device = {std_device_std_body_open(gx_device_mask_clip, 0, "mask clipper", - 0, 0, 1, 1), + 0, 0, 1, 1), {gx_default_open_device, gx_forward_get_initial_matrix, gx_default_sync_output, @@ -105,7 +105,7 @@ const gx_device_mask_clip gs_mask_clip_device = /* Fill a rectangle by painting through the mask. */ static int mask_clip_fill_rectangle(gx_device * dev, int x, int y, int w, int h, - gx_color_index color) + gx_color_index color) { gx_device_mask_clip *cdev = (gx_device_mask_clip *) dev; gx_device *tdev = cdev->target; @@ -115,18 +115,18 @@ mask_clip_fill_rectangle(gx_device * dev, int x, int y, int w, int h, int mx1 = mx0 + w, my1 = my0 + h; if (mx0 < 0) - mx0 = 0; + mx0 = 0; if (my0 < 0) - my0 = 0; + my0 = 0; if (mx1 > cdev->tiles.size.x) - mx1 = cdev->tiles.size.x; + mx1 = cdev->tiles.size.x; if (my1 > cdev->tiles.size.y) - my1 = cdev->tiles.size.y; + my1 = cdev->tiles.size.y; return (*dev_proc(tdev, copy_mono)) - (tdev, cdev->tiles.data + my0 * cdev->tiles.raster, mx0, - cdev->tiles.raster, cdev->tiles.id, - mx0 - cdev->phase.x, my0 - cdev->phase.y, - mx1 - mx0, my1 - my0, gx_no_color_index, color); + (tdev, cdev->tiles.data + my0 * cdev->tiles.raster, mx0, + cdev->tiles.raster, cdev->tiles.id, + mx0 - cdev->phase.x, my0 - cdev->phase.y, + mx1 - mx0, my1 - my0, gx_no_color_index, color); } /* @@ -137,29 +137,29 @@ mask_clip_fill_rectangle(gx_device * dev, int x, int y, int w, int h, * References cdev, data, sourcex, raster, x, y, w, h. */ #define DECLARE_MASK_COPY\ - const byte *sdata;\ - int sx, mx0, my0, mx1, my1 + const byte *sdata;\ + int sx, mx0, my0, mx1, my1 #define FIT_MASK_COPY(data, sourcex, raster, vx, vy, vw, vh)\ - BEGIN\ - sdata = data, sx = sourcex;\ - mx0 = vx + cdev->phase.x, my0 = vy + cdev->phase.y;\ - mx1 = mx0 + vw, my1 = my0 + vh;\ - if ( mx0 < 0 )\ - sx -= mx0, mx0 = 0;\ - if ( my0 < 0 )\ - sdata -= my0 * raster, my0 = 0;\ - if ( mx1 > cdev->tiles.size.x )\ - mx1 = cdev->tiles.size.x;\ - if ( my1 > cdev->tiles.size.y )\ - my1 = cdev->tiles.size.y;\ - END + BEGIN\ + sdata = data, sx = sourcex;\ + mx0 = vx + cdev->phase.x, my0 = vy + cdev->phase.y;\ + mx1 = mx0 + vw, my1 = my0 + vh;\ + if ( mx0 < 0 )\ + sx -= mx0, mx0 = 0;\ + if ( my0 < 0 )\ + sdata -= my0 * raster, my0 = 0;\ + if ( mx1 > cdev->tiles.size.x )\ + mx1 = cdev->tiles.size.x;\ + if ( my1 > cdev->tiles.size.y )\ + my1 = cdev->tiles.size.y;\ + END /* Copy a monochrome bitmap by playing Boolean games. */ static int mask_clip_copy_mono(gx_device * dev, - const byte * data, int sourcex, int raster, gx_bitmap_id id, - int x, int y, int w, int h, - gx_color_index color0, gx_color_index color1) + const byte * data, int sourcex, int raster, gx_bitmap_id id, + int x, int y, int w, int h, + gx_color_index color0, gx_color_index color1) { gx_device_mask_clip *cdev = (gx_device_mask_clip *) dev; gx_device *tdev = cdev->target; @@ -172,35 +172,35 @@ mask_clip_copy_mono(gx_device * dev, setup_mask_copy_mono(cdev, color, mcolor0, mcolor1); FIT_MASK_COPY(data, sourcex, raster, x, y, w, h); for (cy = my0; cy < my1; cy += ny) { - int ty = cy - cdev->phase.y; - int cx, nx; + int ty = cy - cdev->phase.y; + int cx, nx; - ny = my1 - cy; - if (ny > cdev->mdev.height) - ny = cdev->mdev.height; - for (cx = mx0; cx < mx1; cx += nx) { - int tx = cx - cdev->phase.x; + ny = my1 - cy; + if (ny > cdev->mdev.height) + ny = cdev->mdev.height; + for (cx = mx0; cx < mx1; cx += nx) { + int tx = cx - cdev->phase.x; - nx = mx1 - cx; /* also should be min */ - /* Copy a tile slice to the memory device buffer. */ - memcpy(cdev->buffer.bytes, - cdev->tiles.data + cy * cdev->tiles.raster, - cdev->tiles.raster * ny); - /* Intersect the tile with the source data. */ - /* mcolor0 and mcolor1 invert the data if needed. */ - /* This call can't fail. */ - (*dev_proc(&cdev->mdev, copy_mono)) ((gx_device *) & cdev->mdev, - sdata + (ty - y) * raster, sx + tx - x, - raster, gx_no_bitmap_id, - cx, 0, nx, ny, mcolor0, mcolor1); - /* Now copy the color through the double mask. */ - code = (*dev_proc(tdev, copy_mono)) (cdev->target, - cdev->buffer.bytes, cx, cdev->tiles.raster, - gx_no_bitmap_id, - tx, ty, nx, ny, gx_no_color_index, color); - if (code < 0) - return code; - } + nx = mx1 - cx; /* also should be min */ + /* Copy a tile slice to the memory device buffer. */ + memcpy(cdev->buffer.bytes, + cdev->tiles.data + cy * cdev->tiles.raster, + cdev->tiles.raster * ny); + /* Intersect the tile with the source data. */ + /* mcolor0 and mcolor1 invert the data if needed. */ + /* This call can't fail. */ + (*dev_proc(&cdev->mdev, copy_mono)) ((gx_device *) & cdev->mdev, + sdata + (ty - y) * raster, sx + tx - x, + raster, gx_no_bitmap_id, + cx, 0, nx, ny, mcolor0, mcolor1); + /* Now copy the color through the double mask. */ + code = (*dev_proc(tdev, copy_mono)) (cdev->target, + cdev->buffer.bytes, cx, cdev->tiles.raster, + gx_no_bitmap_id, + tx, ty, nx, ny, gx_no_color_index, color); + if (code < 0) + return code; + } } return 0; } @@ -212,8 +212,8 @@ mask_clip_copy_mono(gx_device * dev, */ static int clip_runs_enumerate(gx_device_mask_clip * cdev, - int (*process) (clip_callback_data_t * pccd, int xc, int yc, int xec, int yec), - clip_callback_data_t * pccd) + int (*process) (clip_callback_data_t * pccd, int xc, int yc, int xec, int yec), + clip_callback_data_t * pccd) { DECLARE_MASK_COPY; int cy; @@ -222,82 +222,82 @@ clip_runs_enumerate(gx_device_mask_clip * cdev, int code; FIT_MASK_COPY(pccd->data, pccd->sourcex, pccd->raster, - pccd->x, pccd->y, pccd->w, pccd->h); + pccd->x, pccd->y, pccd->w, pccd->h); tile_row = cdev->tiles.data + my0 * cdev->tiles.raster + (mx0 >> 3); prev.p.x = 0; /* arbitrary */ prev.q.x = prev.p.x - 1; /* an impossible rectangle */ prev.p.y = prev.q.y = -1; /* arbitrary */ for (cy = my0; cy < my1; cy++) { - int cx = mx0; - const byte *tp = tile_row; + int cx = mx0; + const byte *tp = tile_row; - if_debug1('B', "[B]clip runs y=%d:", cy - cdev->phase.y); - while (cx < mx1) { - int len; - int tx1, tx, ty; + if_debug1('B', "[B]clip runs y=%d:", cy - cdev->phase.y); + while (cx < mx1) { + int len; + int tx1, tx, ty; - /* Skip a run of 0s. */ - len = byte_bit_run_length[cx & 7][*tp ^ 0xff]; - if (len < 8) { - cx += len; - if (cx >= mx1) - break; - } else { - cx += len - 8; - tp++; - while (cx < mx1 && *tp == 0) - cx += 8, tp++; - if (cx >= mx1) - break; - cx += byte_bit_run_length_0[*tp ^ 0xff]; - if (cx >= mx1) - break; - } - tx1 = cx - cdev->phase.x; - /* Scan a run of 1s. */ - len = byte_bit_run_length[cx & 7][*tp]; - if (len < 8) { - cx += len; - if (cx > mx1) - cx = mx1; - } else { - cx += len - 8; - tp++; - while (cx < mx1 && *tp == 0xff) - cx += 8, tp++; - if (cx > mx1) - cx = mx1; - else { - cx += byte_bit_run_length_0[*tp]; - if (cx > mx1) - cx = mx1; - } - } - tx = cx - cdev->phase.x; - if_debug2('B', " %d-%d,", tx1, tx); - ty = cy - cdev->phase.y; - /* Detect vertical rectangles. */ - if (prev.p.x == tx1 && prev.q.x == tx && prev.q.y == ty) - prev.q.y = ty + 1; - else { - if (prev.q.y > prev.p.y) { - code = (*process)(pccd, prev.p.x, prev.p.y, prev.q.x, prev.q.y); - if (code < 0) - return code; - } - prev.p.x = tx1; - prev.p.y = ty; - prev.q.x = tx; - prev.q.y = ty + 1; - } - } - if_debug0('B', "\n"); - tile_row += cdev->tiles.raster; + /* Skip a run of 0s. */ + len = byte_bit_run_length[cx & 7][*tp ^ 0xff]; + if (len < 8) { + cx += len; + if (cx >= mx1) + break; + } else { + cx += len - 8; + tp++; + while (cx < mx1 && *tp == 0) + cx += 8, tp++; + if (cx >= mx1) + break; + cx += byte_bit_run_length_0[*tp ^ 0xff]; + if (cx >= mx1) + break; + } + tx1 = cx - cdev->phase.x; + /* Scan a run of 1s. */ + len = byte_bit_run_length[cx & 7][*tp]; + if (len < 8) { + cx += len; + if (cx > mx1) + cx = mx1; + } else { + cx += len - 8; + tp++; + while (cx < mx1 && *tp == 0xff) + cx += 8, tp++; + if (cx > mx1) + cx = mx1; + else { + cx += byte_bit_run_length_0[*tp]; + if (cx > mx1) + cx = mx1; + } + } + tx = cx - cdev->phase.x; + if_debug2('B', " %d-%d,", tx1, tx); + ty = cy - cdev->phase.y; + /* Detect vertical rectangles. */ + if (prev.p.x == tx1 && prev.q.x == tx && prev.q.y == ty) + prev.q.y = ty + 1; + else { + if (prev.q.y > prev.p.y) { + code = (*process)(pccd, prev.p.x, prev.p.y, prev.q.x, prev.q.y); + if (code < 0) + return code; + } + prev.p.x = tx1; + prev.p.y = ty; + prev.q.x = tx; + prev.q.y = ty + 1; + } + } + if_debug0('B', "\n"); + tile_row += cdev->tiles.raster; } if (prev.q.y > prev.p.y) { - code = (*process)(pccd, prev.p.x, prev.p.y, prev.q.x, prev.q.y); - if (code < 0) - return code; + code = (*process)(pccd, prev.p.x, prev.p.y, prev.q.x, prev.q.y); + if (code < 0) + return code; } return 0; } @@ -305,8 +305,8 @@ clip_runs_enumerate(gx_device_mask_clip * cdev, /* Copy a color rectangle */ static int mask_clip_copy_color(gx_device * dev, - const byte * data, int sourcex, int raster, gx_bitmap_id id, - int x, int y, int w, int h) + const byte * data, int sourcex, int raster, gx_bitmap_id id, + int x, int y, int w, int h) { gx_device_mask_clip *cdev = (gx_device_mask_clip *) dev; clip_callback_data_t ccdata; @@ -320,8 +320,8 @@ mask_clip_copy_color(gx_device * dev, /* Copy a rectangle with alpha */ static int mask_clip_copy_alpha(gx_device * dev, - const byte * data, int sourcex, int raster, gx_bitmap_id id, - int x, int y, int w, int h, gx_color_index color, int depth) + const byte * data, int sourcex, int raster, gx_bitmap_id id, + int x, int y, int w, int h, gx_color_index color, int depth) { gx_device_mask_clip *cdev = (gx_device_mask_clip *) dev; clip_callback_data_t ccdata; @@ -335,9 +335,9 @@ mask_clip_copy_alpha(gx_device * dev, static int mask_clip_strip_tile_rectangle(gx_device * dev, const gx_strip_bitmap * tiles, - int x, int y, int w, int h, - gx_color_index color0, gx_color_index color1, - int phase_x, int phase_y) + int x, int y, int w, int h, + gx_color_index color0, gx_color_index color1, + int phase_x, int phase_y) { gx_device_mask_clip *cdev = (gx_device_mask_clip *) dev; clip_callback_data_t ccdata; @@ -352,11 +352,11 @@ mask_clip_strip_tile_rectangle(gx_device * dev, const gx_strip_bitmap * tiles, static int mask_clip_strip_copy_rop(gx_device * dev, - const byte * data, int sourcex, uint raster, gx_bitmap_id id, - const gx_color_index * scolors, - const gx_strip_bitmap * textures, const gx_color_index * tcolors, - int x, int y, int w, int h, - int phase_x, int phase_y, gs_logical_operation_t lop) + const byte * data, int sourcex, uint raster, gx_bitmap_id id, + const gx_color_index * scolors, + const gx_strip_bitmap * textures, const gx_color_index * tcolors, + int x, int y, int w, int h, + int phase_x, int phase_y, gs_logical_operation_t lop) { gx_device_mask_clip *cdev = (gx_device_mask_clip *) dev; clip_callback_data_t ccdata; @@ -365,7 +365,7 @@ mask_clip_strip_copy_rop(gx_device * dev, ccdata.x = x, ccdata.y = y, ccdata.w = w, ccdata.h = h; ccdata.data = data, ccdata.sourcex = sourcex, ccdata.raster = raster; ccdata.scolors = scolors, ccdata.textures = textures, - ccdata.tcolors = tcolors; + ccdata.tcolors = tcolors; ccdata.phase.x = phase_x, ccdata.phase.y = phase_y, ccdata.lop = lop; return clip_runs_enumerate(cdev, clip_call_strip_copy_rop, &ccdata); } |