diff options
author | Robin Watts <robin.watts@artifex.com> | 2016-01-29 19:06:22 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-02-05 15:47:25 +0000 |
commit | afbffabc7bf3593d3de5a210899e364371807c66 (patch) | |
tree | 90dd645f6ddc14d95509c8d5373ca59bdc73789e /base/claptrap.c | |
parent | 049ba9c4de3514452e4bd3b6601c20e1d22188fd (diff) | |
download | ghostpdl-afbffabc7bf3593d3de5a210899e364371807c66.tar.gz |
Simple optimisations to ClapTrap.
Diffstat (limited to 'base/claptrap.c')
-rw-r--r-- | base/claptrap.c | 103 |
1 files changed, 50 insertions, 53 deletions
diff --git a/base/claptrap.c b/base/claptrap.c index 3aced9e6e..a74042839 100644 --- a/base/claptrap.c +++ b/base/claptrap.c @@ -32,7 +32,8 @@ inline static void process_at_pixel(ClapTrap * restrict ct, int last_comp, int prev_comp, int comp, - int line_offset) + int line_offset, + unsigned char *process) { /* We look at the pixel values on comp. * We look at the process values passed into us from prev_comp, and pass out @@ -48,18 +49,14 @@ inline static void process_at_pixel(ClapTrap * restrict ct, int span = ct->span; int lines_in_buf = ct->lines_in_buf; unsigned char *linebuf = ct->linebuf; - unsigned char *process = ct->process; int y = ct->y; /* Some offsets we will use repeatedly */ int o = x * num_comps; int oc = o + comp; /* p != 0 if we need to be processed because a previous component shadows us. * If we're the first component then no one can shadow us. */ - int p = (first_comp ? 0 : - process[line_offset + o + prev_comp]); - /* Process flag for next component inherits from this one */ - int np = p; - int cx, cy, sx, sy, ex, ey, lo; + int p = (first_comp ? 0 : *process); + int sx, sy, ex, ey, lo, v; unsigned char *pc; unsigned char *ppc; @@ -85,31 +82,28 @@ inline static void process_at_pixel(ClapTrap * restrict ct, * here if we are not the first component (!first_comp) and * if (p != 0) then we need to search for the maximum local value * of this component. */ + v = linebuf[line_offset + oc]; if (!last_comp || (!first_comp && p)) { - int min_v, max_v, v; + int min_v, max_v; lo = sy % lines_in_buf; if (!first_comp) - max_v = 0; + max_v = v; if (!last_comp) - min_v = 255; + min_v = v; pc = &linebuf[lo * span + sx * num_comps + comp]; - for (cy = sy; cy <= ey; cy++) + ex -= sx; + for (sy = ey-sy; sy >= 0; sy--) { ppc = pc; - for (cx = sx; cx <= ex; cx++) + for (sx = ex; sx >= 0; sx--) { int cv = *ppc; ppc += num_comps; - if (cx == x && cy == y) - { - v = cv; - continue; - } if (!first_comp && cv > max_v) max_v = cv; - if (!last_comp && cv < min_v) + else if (!last_comp && cv < min_v) min_v = cv; } pc += span; @@ -121,33 +115,28 @@ inline static void process_at_pixel(ClapTrap * restrict ct, } /* If we're not the last component, and we meet the criteria * the next component needs processing. */ - if (!last_comp && shadow_here(v, min_v, comp)) + if (!last_comp) { - if (v > np) + /* Process flag for next component inherits from this one */ + int np = p; + if (v > np && shadow_here(v, min_v, comp)) np = v; - } - - /* Update the next components process flag if required */ - if (!last_comp) - process[line_offset + oc] = np; + *process = np; #ifdef SAVE_PROCESS_BUFFER - if (!last_comp) - { - buffer[oc] = ct->process[line_offset + oc]; + buffer[oc] = np; return; +#endif } -#else + if (!first_comp && p > v && trap_here(v, max_v, comp)) { if (max_v < p) p = max_v; - buffer[oc] = p; - return; + v = p; } -#endif } - buffer[oc] = linebuf[line_offset + oc]; + buffer[oc] = v; } int ClapTrap_GetLine(ClapTrap * restrict ct, @@ -161,6 +150,7 @@ int ClapTrap_GetLine(ClapTrap * restrict ct, int comp; int x; int line_offset; + unsigned char *process; /* Read in as many lines as we need */ max_y = ct->y + ct->max_y_offset; @@ -172,7 +162,6 @@ int ClapTrap_GetLine(ClapTrap * restrict ct, int code = ct->get_line(ct->get_line_arg, &ct->linebuf[bufpos]); if (code < 0) return code; - memset(&ct->process[bufpos], 0, ct->span); ct->lines_read++; } @@ -184,101 +173,109 @@ int ClapTrap_GetLine(ClapTrap * restrict ct, r_margin = 0; l_margin = 0; } - line_offset = (ct->y % ct->lines_in_buf) * ct->span; + x = (ct->y % ct->lines_in_buf); + process = &ct->process[x * ct->width]; + line_offset = x * ct->span; if (ct->y < ct->max_y_offset || ct->y >= ct->height - ct->max_y_offset) { + unsigned char *p = process; /* Some of our search area is off the end of the bitmap. We must be careful. */ comp = ct->comp_order[0]; for (x = 0; x < l_margin; x++) { - process_at_pixel(ct, buffer, x, 1, 1, 1, 0, -1, comp, line_offset); + process_at_pixel(ct, buffer, x, 1, 1, 1, 0, -1, comp, line_offset, p++); } for (; x < r_margin; x++) { - process_at_pixel(ct, buffer, x, 0, 1, 1, 0, -1, comp, line_offset); + process_at_pixel(ct, buffer, x, 0, 1, 1, 0, -1, comp, line_offset, p++); } for (; x < ct->width; x++) { - process_at_pixel(ct, buffer, x, 1, 1, 1, 0, -1, comp, line_offset); + process_at_pixel(ct, buffer, x, 1, 1, 1, 0, -1, comp, line_offset, p++); } for (comp_idx = 1; comp_idx < ct->num_comps-1; comp_idx++) { + p = process; prev_comp = comp; comp = ct->comp_order[comp_idx]; for (x = 0; x < l_margin; x++) { - process_at_pixel(ct, buffer, x, 1, 1, 0, 0, prev_comp, comp, line_offset); + process_at_pixel(ct, buffer, x, 1, 1, 0, 0, prev_comp, comp, line_offset, p++); } for (; x < r_margin; x++) { - process_at_pixel(ct, buffer, x, 0, 1, 0, 0, prev_comp, comp, line_offset); + process_at_pixel(ct, buffer, x, 0, 1, 0, 0, prev_comp, comp, line_offset, p++); } for (; x < ct->width; x++) { - process_at_pixel(ct, buffer, x, 1, 1, 0, 0, prev_comp, comp, line_offset); + process_at_pixel(ct, buffer, x, 1, 1, 0, 0, prev_comp, comp, line_offset, p++); } } + p = process; prev_comp = comp; comp = ct->comp_order[comp_idx]; for (x = 0; x < l_margin; x++) { - process_at_pixel(ct, buffer, x, 1, 1, 0, 1, prev_comp, comp, line_offset); + process_at_pixel(ct, buffer, x, 1, 1, 0, 1, prev_comp, comp, line_offset, p++); } for (; x < r_margin; x++) { - process_at_pixel(ct, buffer, x, 0, 1, 0, 1, prev_comp, comp, line_offset); + process_at_pixel(ct, buffer, x, 0, 1, 0, 1, prev_comp, comp, line_offset, p++); } for (; x < ct->width; x++) { - process_at_pixel(ct, buffer, x, 1, 1, 0, 1, prev_comp, comp, line_offset); + process_at_pixel(ct, buffer, x, 1, 1, 0, 1, prev_comp, comp, line_offset, p++); } } else { + unsigned char *p = process; /* Our search area never clips on y at least. */ comp = ct->comp_order[0]; for (x = 0; x < l_margin; x++) { - process_at_pixel(ct, buffer, x, 1, 0, 1, 0, -1, comp, line_offset); + process_at_pixel(ct, buffer, x, 1, 0, 1, 0, -1, comp, line_offset, p++); } for (; x < r_margin; x++) { - process_at_pixel(ct, buffer, x, 0, 0, 1, 0, -1, comp, line_offset); + process_at_pixel(ct, buffer, x, 0, 0, 1, 0, -1, comp, line_offset, p++); } for (; x < ct->width; x++) { - process_at_pixel(ct, buffer, x, 1, 0, 1, 0, -1, comp, line_offset); + process_at_pixel(ct, buffer, x, 1, 0, 1, 0, -1, comp, line_offset, p++); } for (comp_idx = 1; comp_idx < ct->num_comps-1; comp_idx++) { + p = process; prev_comp = comp; comp = ct->comp_order[comp_idx]; for (x = 0; x < l_margin; x++) { - process_at_pixel(ct, buffer, x, 1, 0, 0, 0, prev_comp, comp, line_offset); + process_at_pixel(ct, buffer, x, 1, 0, 0, 0, prev_comp, comp, line_offset, p++); } for (; x < r_margin; x++) { - process_at_pixel(ct, buffer, x, 0, 0, 0, 0, prev_comp, comp, line_offset); + process_at_pixel(ct, buffer, x, 0, 0, 0, 0, prev_comp, comp, line_offset, p++); } for (; x < ct->width; x++) { - process_at_pixel(ct, buffer, x, 1, 0, 0, 0, prev_comp, comp, line_offset); + process_at_pixel(ct, buffer, x, 1, 0, 0, 0, prev_comp, comp, line_offset, p++); } } + p = process; prev_comp = comp; comp = ct->comp_order[comp_idx]; for (x = 0; x < l_margin; x++) { - process_at_pixel(ct, buffer, x, 1, 0, 0, 1, prev_comp, comp, line_offset); + process_at_pixel(ct, buffer, x, 1, 0, 0, 1, prev_comp, comp, line_offset, p++); } for (; x < r_margin; x++) { - process_at_pixel(ct, buffer, x, 0, 0, 0, 1, prev_comp, comp, line_offset); + process_at_pixel(ct, buffer, x, 0, 0, 0, 1, prev_comp, comp, line_offset, p++); } for (; x < ct->width; x++) { - process_at_pixel(ct, buffer, x, 1, 0, 0, 1, prev_comp, comp, line_offset); + process_at_pixel(ct, buffer, x, 1, 0, 0, 1, prev_comp, comp, line_offset, p++); } } ct->y++; |