summaryrefslogtreecommitdiff
path: root/base/gxblend1.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2017-10-03 19:50:33 +0100
committerRobin Watts <robin.watts@artifex.com>2017-10-05 19:43:57 +0100
commit29e07d407e997a596f682cffa2069e5cea9e3fb4 (patch)
tree16dba046876feffc4672ffd1be1b6463f981093c /base/gxblend1.c
parent65c442f7b2c1a91816f9026553004d66dde147ec (diff)
downloadghostpdl-29e07d407e997a596f682cffa2069e5cea9e3fb4.tar.gz
Use inlining on pdf14_compose_group functions.
We move pdf14_compose_group into gxblend.c to enable us to make the constituent functions static inlines.
Diffstat (limited to 'base/gxblend1.c')
-rw-r--r--base/gxblend1.c422
1 files changed, 0 insertions, 422 deletions
diff --git a/base/gxblend1.c b/base/gxblend1.c
index 73e6706cc..01171b104 100644
--- a/base/gxblend1.c
+++ b/base/gxblend1.c
@@ -307,428 +307,6 @@ pdf14_preserve_backdrop(pdf14_buf *buf, pdf14_buf *tos, bool knockout_buff)
#endif
}
-typedef void (*compose_group_fn)(byte *tos_ptr, bool tos_isolated, int tos_planestride, int tos_rowstride, byte alpha, byte shape, gs_blend_mode_t blend_mode, bool tos_has_shape,
- int tos_shape_offset, int tos_alpha_g_offset, int tos_tag_offset, bool tos_has_tag,
- byte *nos_ptr, bool nos_isolated, int nos_planestride, int nos_rowstride, byte *nos_alpha_g_ptr, bool nos_knockout,
- int nos_shape_offset, int nos_tag_offset,
- byte *mask_row_ptr, int has_mask, pdf14_buf *maskbuf, byte mask_bg_alpha, byte *mask_tr_fn,
- byte *backdrop_ptr,
- bool has_matte, int n_chan, bool additive, int num_spots, bool overprint, gx_color_index drawn_comps, int x0, int y0, int x1, int y1,
- const pdf14_nonseparable_blending_procs_t *pblend_procs, pdf14_device *pdev);
-
-static inline void
-template_compose_group(byte *tos_ptr, bool tos_isolated, int tos_planestride, int tos_rowstride, byte alpha, byte shape, gs_blend_mode_t blend_mode, bool tos_has_shape,
- int tos_shape_offset, int tos_alpha_g_offset, int tos_tag_offset, bool tos_has_tag,
- byte *nos_ptr, bool nos_isolated, int nos_planestride, int nos_rowstride, byte *nos_alpha_g_ptr, bool nos_knockout,
- int nos_shape_offset, int nos_tag_offset,
- byte *mask_row_ptr, int has_mask, pdf14_buf *maskbuf, byte mask_bg_alpha, byte *mask_tr_fn,
- byte *backdrop_ptr,
- bool has_matte, int n_chan, bool additive, int num_spots, bool overprint, gx_color_index drawn_comps, int x0, int y0, int x1, int y1,
- const pdf14_nonseparable_blending_procs_t *pblend_procs, pdf14_device *pdev)
-{
- byte *mask_curr_ptr = NULL;
- int width = x1 - x0;
- int x, y;
- int i;
- byte tos_pixel[PDF14_MAX_PLANES];
- byte nos_pixel[PDF14_MAX_PLANES];
- byte back_drop[PDF14_MAX_PLANES];
- gx_color_index comps;
- bool in_mask_rect_y = false;
- bool in_mask_rect = false;
- byte pix_alpha;
- byte matte_alpha = 0xff;
- int first_spot = n_chan - num_spots;
- int first_blend_spot = n_chan;
- bool has_mask2 = has_mask;
-
- if (!nos_knockout && num_spots > 0 && !blend_valid_for_spot(blend_mode)) {
- first_blend_spot = first_spot;
- }
- if (!nos_isolated && backdrop_ptr != NULL)
- has_mask2 = false;
-
- for (y = y1 - y0; y > 0; --y) {
- mask_curr_ptr = mask_row_ptr;
- if (has_mask && y1 - y >= maskbuf->rect.p.y && y1 - y < maskbuf->rect.q.y) {
- in_mask_rect_y = true;
- } else {
- in_mask_rect_y = false;
- }
- for (x = 0; x < width; x++) {
- if (in_mask_rect_y && has_mask && x0 + x >= maskbuf->rect.p.x &&
- x0 + x < maskbuf->rect.q.x) {
- in_mask_rect = true;
- } else {
- in_mask_rect = false;
- }
- pix_alpha = alpha;
- /* If we have a soft mask, then we have some special handling of the
- group alpha value */
- if (maskbuf != NULL) {
- if (!in_mask_rect) {
- /* Special case where we have a soft mask but are outside
- the range of the soft mask and must use the background
- alpha value */
- pix_alpha = mask_bg_alpha;
- matte_alpha = 0xff;
- } else {
- if (has_matte)
- matte_alpha = mask_tr_fn[*mask_curr_ptr];
- }
- }
-
- /* Matte present, need to undo premultiplied alpha prior to blend */
- if (has_matte && matte_alpha != 0 && matte_alpha < 0xff) {
- for (i = 0; i < n_chan; i++) {
- /* undo */
- int val = (tos_ptr[i * tos_planestride] - maskbuf->matte[i] < 0 ?
- 0 : tos_ptr[i * tos_planestride] - maskbuf->matte[i]);
- int temp = ((((val * 0xff) << 8) / matte_alpha) >> 8) + maskbuf->matte[i];
-
- /* clip */
- if (temp > 0xff)
- tos_pixel[i] = 0xff;
- else
- tos_pixel[i] = temp;
-
- if (!additive) {
- /* Pure subtractive */
- tos_pixel[i] = 255 - tos_pixel[i];
- nos_pixel[i] = 255 - nos_ptr[i * nos_planestride];
- } else {
- /* additive or hybrid */
- if (i >= first_spot)
- nos_pixel[i] = 255 - nos_ptr[i * nos_planestride];
- else
- nos_pixel[i] = nos_ptr[i * nos_planestride];
- }
- }
- } else {
- /* No matte present */
- if (!additive) {
- /* Pure subtractive */
- for (i = 0; i < n_chan; ++i) {
- tos_pixel[i] = 255 - tos_ptr[i * tos_planestride];
- nos_pixel[i] = 255 - nos_ptr[i * nos_planestride];
- }
- } else {
- /* Additive or hybrid */
- for (i = 0; i < first_spot; ++i) {
- tos_pixel[i] = tos_ptr[i * tos_planestride];
- nos_pixel[i] = nos_ptr[i * nos_planestride];
- }
- for (; i < n_chan; i++) {
- tos_pixel[i] = 255 - tos_ptr[i * tos_planestride];
- nos_pixel[i] = 255 - nos_ptr[i * nos_planestride];
- }
- }
- }
- /* alpha */
- tos_pixel[n_chan] = tos_ptr[n_chan * tos_planestride];
- nos_pixel[n_chan] = nos_ptr[n_chan * nos_planestride];
-
- if (mask_curr_ptr != NULL) {
- if (in_mask_rect) {
- byte mask = mask_tr_fn[*mask_curr_ptr++];
- int tmp = pix_alpha * mask + 0x80;
- pix_alpha = (tmp + (tmp >> 8)) >> 8;
- } else {
- mask_curr_ptr++;
- }
- }
-
- if (nos_knockout) {
- /* We need to be knocking out what ever is on the nos, but may
- need to combine with it's backdrop */
- byte tos_shape = 255;
-
- if (tos_has_shape)
- tos_shape = tos_ptr[tos_shape_offset];
-
- if (nos_isolated || backdrop_ptr == NULL) {
- /* We do not need to compose with the backdrop */
- back_drop[n_chan] = 0;
- /* FIXME: The blend here can be simplified */
- } else {
- /* Per the PDF spec, since the tos is not isolated and we are
- going onto a knock out group, we do the composition with
- the nos initial backdrop. */
- if (additive) {
- /* additive or hybrid */
- for (i = 0; i < first_spot; ++i) {
- back_drop[i] = backdrop_ptr[i * nos_planestride];
- }
- for (; i < n_chan; i++) {
- back_drop[i] = 255 - backdrop_ptr[i * nos_planestride];
- }
- } else {
- /* pure subtractive */
- for (i = 0; i < n_chan; ++i) {
- back_drop[i] = 255 - backdrop_ptr[i * nos_planestride];
- }
- }
- /* alpha */
- back_drop[n_chan] = backdrop_ptr[n_chan * nos_planestride];
- }
- art_pdf_composite_knockout_group_8(back_drop, tos_shape,
- nos_pixel, nos_alpha_g_ptr,
- tos_pixel, n_chan, pix_alpha,
- blend_mode, pblend_procs,
- pdev, has_mask2);
- } else if (tos_isolated ?
- art_pdf_composite_group_8(nos_pixel, nos_alpha_g_ptr,
- tos_pixel, n_chan, pix_alpha,
- blend_mode, first_blend_spot,
- pblend_procs, pdev) :
- art_pdf_recomposite_group_8(nos_pixel, nos_alpha_g_ptr,
- tos_pixel, tos_ptr[tos_alpha_g_offset], n_chan,
- pix_alpha, blend_mode, first_blend_spot,
- pblend_procs, pdev)) {
- art_pdf_composite_pixel_alpha_8(nos_pixel, tos_pixel, n_chan,
- blend_mode, first_blend_spot,
- pblend_procs, pdev);
- }
- if (nos_shape_offset) {
- nos_ptr[nos_shape_offset] =
- art_pdf_union_mul_8 (nos_ptr[nos_shape_offset],
- tos_ptr[tos_shape_offset],
- shape);
- }
- /* Complement the results for subtractive color spaces. Again,
- * if we are in an additive blending color space, we are not
- * going to be fooling with overprint of spot colors */
- if (additive) {
- /* additive or hybrid */
- for (i = 0; i < first_spot; ++i) {
- nos_ptr[i * nos_planestride] = nos_pixel[i];
- }
- for (; i < n_chan; i++) {
- nos_ptr[i * nos_planestride] = 255 - nos_pixel[i];
- }
- } else {
- /* Pure subtractive */
- /* If we were running in the compatible overprint blend mode
- * and popping the group, we don't need to fool with the
- * drawn components as that should have already have been
- * handled during the blending within our special non-isolated
- * group. So in other words, if the blend mode is normal
- * (or compatible) and we are doing overprint, the overprint
- * has NOT been handled by compatible overprint mode and we
- * need to take care of it now */
- if (overprint) {
- for (i = 0, comps = drawn_comps; comps != 0; ++i, comps >>= 1) {
- if ((comps & 0x1) != 0) {
- nos_ptr[i * nos_planestride] = 255 - nos_pixel[i];
- }
- }
- } else {
- for (i = 0; i < n_chan; ++i)
- nos_ptr[i * nos_planestride] = 255 - nos_pixel[i];
- }
- }
- /* tags */
- if (nos_tag_offset && tos_has_tag) {
- nos_ptr[nos_tag_offset] |= tos_ptr[tos_tag_offset];
- }
- /* alpha */
- nos_ptr[n_chan * nos_planestride] = nos_pixel[n_chan];
-
- if (nos_alpha_g_ptr != NULL)
- ++nos_alpha_g_ptr;
- if (backdrop_ptr != NULL)
- ++backdrop_ptr;
- ++tos_ptr;
- ++nos_ptr;
- }
- tos_ptr += tos_rowstride - width;
- nos_ptr += nos_rowstride - width;
- if (nos_alpha_g_ptr != NULL)
- nos_alpha_g_ptr += nos_rowstride - width;
- if (mask_row_ptr != NULL)
- mask_row_ptr += maskbuf->rowstride;
- if (backdrop_ptr != NULL)
- backdrop_ptr += nos_rowstride - width;
- }
-}
-
-static void
-compose_group_knockout(byte *tos_ptr, bool tos_isolated, int tos_planestride, int tos_rowstride, byte alpha, byte shape, gs_blend_mode_t blend_mode, bool tos_has_shape,
- int tos_shape_offset, int tos_alpha_g_offset, int tos_tag_offset, bool tos_has_tag,
- byte *nos_ptr, bool nos_isolated, int nos_planestride, int nos_rowstride, byte *nos_alpha_g_ptr, bool nos_knockout,
- int nos_shape_offset, int nos_tag_offset,
- byte *mask_row_ptr, int has_mask, pdf14_buf *maskbuf, byte mask_bg_alpha, byte *mask_tr_fn,
- byte *backdrop_ptr,
- bool has_matte, int n_chan, bool additive, int num_spots, bool overprint, gx_color_index drawn_comps, int x0, int y0, int x1, int y1,
- const pdf14_nonseparable_blending_procs_t *pblend_procs, pdf14_device *pdev)
-{
- template_compose_group(tos_ptr, tos_isolated, tos_planestride, tos_rowstride, alpha, shape, blend_mode, tos_has_shape,
- tos_shape_offset, tos_alpha_g_offset, tos_tag_offset, tos_has_tag,
- nos_ptr, nos_isolated, nos_planestride, nos_rowstride, nos_alpha_g_ptr, /* nos_knockout = */1,
- nos_shape_offset, nos_tag_offset, mask_row_ptr, has_mask, maskbuf, mask_bg_alpha, mask_tr_fn,
- backdrop_ptr, has_matte, n_chan, additive, num_spots, overprint, drawn_comps, x0, y0, x1, y1, pblend_procs, pdev);
-}
-
-static void
-compose_group_isolated_nonknockout(byte *tos_ptr, bool tos_isolated, int tos_planestride, int tos_rowstride, byte alpha, byte shape, gs_blend_mode_t blend_mode, bool tos_has_shape,
- int tos_shape_offset, int tos_alpha_g_offset, int tos_tag_offset, bool tos_has_tag,
- byte *nos_ptr, bool nos_isolated, int nos_planestride, int nos_rowstride, byte *nos_alpha_g_ptr, bool nos_knockout,
- int nos_shape_offset, int nos_tag_offset,
- byte *mask_row_ptr, int has_mask, pdf14_buf *maskbuf, byte mask_bg_alpha, byte *mask_tr_fn,
- byte *backdrop_ptr,
- bool has_matte, int n_chan, bool additive, int num_spots, bool overprint, gx_color_index drawn_comps, int x0, int y0, int x1, int y1,
- const pdf14_nonseparable_blending_procs_t *pblend_procs, pdf14_device *pdev)
-{
- template_compose_group(tos_ptr, /* tos_isolated = */1, tos_planestride, tos_rowstride, alpha, shape, blend_mode, tos_has_shape,
- tos_shape_offset, tos_alpha_g_offset, tos_tag_offset, tos_has_tag,
- nos_ptr, nos_isolated, nos_planestride, nos_rowstride, nos_alpha_g_ptr, /* nos_knockout = */0,
- nos_shape_offset, nos_tag_offset, mask_row_ptr, has_mask, maskbuf, mask_bg_alpha, mask_tr_fn,
- backdrop_ptr, has_matte, n_chan, additive, num_spots, overprint, drawn_comps, x0, y0, x1, y1, pblend_procs, pdev);
-}
-
-static void
-compose_group_nonisolated_nonknockout(byte *tos_ptr, bool tos_isolated, int tos_planestride, int tos_rowstride, byte alpha, byte shape, gs_blend_mode_t blend_mode, bool tos_has_shape,
- int tos_shape_offset, int tos_alpha_g_offset, int tos_tag_offset, bool tos_has_tag,
- byte *nos_ptr, bool nos_isolated, int nos_planestride, int nos_rowstride, byte *nos_alpha_g_ptr, bool nos_knockout,
- int nos_shape_offset, int nos_tag_offset,
- byte *mask_row_ptr, int has_mask, pdf14_buf *maskbuf, byte mask_bg_alpha, byte *mask_tr_fn,
- byte *backdrop_ptr,
- bool has_matte, int n_chan, bool additive, int num_spots, bool overprint, gx_color_index drawn_comps, int x0, int y0, int x1, int y1,
- const pdf14_nonseparable_blending_procs_t *pblend_procs, pdf14_device *pdev)
-{
- template_compose_group(tos_ptr, /* tos_isolated = */0, tos_planestride, tos_rowstride, alpha, shape, blend_mode, tos_has_shape,
- tos_shape_offset, tos_alpha_g_offset, tos_tag_offset, tos_has_tag,
- nos_ptr, nos_isolated, nos_planestride, nos_rowstride, nos_alpha_g_ptr, /* nos_knockout = */0,
- nos_shape_offset, nos_tag_offset, mask_row_ptr, has_mask, maskbuf, mask_bg_alpha, mask_tr_fn,
- backdrop_ptr, has_matte, n_chan, additive, num_spots, overprint, drawn_comps, x0, y0, x1, y1, pblend_procs, pdev);
-}
-
-void
-pdf14_compose_group(pdf14_buf *tos, pdf14_buf *nos, pdf14_buf *maskbuf,
- int x0, int x1, int y0, int y1, int n_chan, bool additive,
- const pdf14_nonseparable_blending_procs_t * pblend_procs,
- bool overprint, gx_color_index drawn_comps, gs_memory_t *memory,
- gx_device *dev)
-{
- int num_spots = tos->num_spots;
- byte alpha = tos->alpha;
- byte shape = tos->shape;
- gs_blend_mode_t blend_mode = tos->blend_mode;
- byte *tos_ptr = tos->data + x0 - tos->rect.p.x +
- (y0 - tos->rect.p.y) * tos->rowstride;
- byte *nos_ptr = nos->data + x0 - nos->rect.p.x +
- (y0 - nos->rect.p.y) * nos->rowstride;
- byte *mask_row_ptr = NULL;
- int tos_planestride = tos->planestride;
- int nos_planestride = nos->planestride;
- byte mask_bg_alpha = 0; /* Quiet compiler. */
- bool tos_isolated = tos->isolated;
- bool nos_isolated = nos->isolated;
- bool nos_knockout = nos->knockout;
- byte *nos_alpha_g_ptr;
- int tos_shape_offset = n_chan * tos_planestride;
- int tos_alpha_g_offset = tos_shape_offset + (tos->has_shape ? tos_planestride : 0);
- bool tos_has_tag = tos->has_tags;
- int tos_tag_offset = tos_planestride * (tos->n_planes - 1);
- int nos_shape_offset = n_chan * nos_planestride;
- int nos_alpha_g_offset = nos_shape_offset + (nos->has_shape ? nos_planestride : 0);
- int nos_tag_offset = nos_planestride * (nos->n_planes - 1);
- byte *mask_tr_fn = NULL; /* Quiet compiler. */
- bool has_mask = false;
- byte *backdrop_ptr = NULL;
- pdf14_device *pdev = (pdf14_device *)dev;
- bool has_matte = false;
-#if RAW_DUMP
- byte *composed_ptr = NULL;
-#endif
- compose_group_fn fn;
-
- if ((tos->n_chan == 0) || (nos->n_chan == 0))
- return;
- rect_merge(nos->dirty, tos->dirty);
- if (nos->has_tags)
- if_debug7m('v', memory,
- "pdf14_pop_transparency_group y0 = %d, y1 = %d, w = %d, alpha = %d, shape = %d, tag = %d, bm = %d\n",
- y0, y1, x1 - x0, alpha, shape, dev->graphics_type_tag & ~GS_DEVICE_ENCODES_TAGS, blend_mode);
- else
- if_debug6m('v', memory,
- "pdf14_pop_transparency_group y0 = %d, y1 = %d, w = %d, alpha = %d, shape = %d, bm = %d\n",
- y0, y1, x1 - x0, alpha, shape, blend_mode);
- if (!nos->has_shape)
- nos_shape_offset = 0;
- if (!nos->has_tags)
- nos_tag_offset = 0;
- if (nos->has_alpha_g) {
- nos_alpha_g_ptr = nos_ptr + nos_alpha_g_offset;
- } else
- nos_alpha_g_ptr = NULL;
- if (nos->backdrop != NULL) {
- backdrop_ptr = nos->backdrop + x0 - nos->rect.p.x +
- (y0 - nos->rect.p.y) * nos->rowstride;
- }
- if (blend_mode != BLEND_MODE_Compatible && blend_mode != BLEND_MODE_Normal)
- overprint = false;
-
- if (maskbuf != NULL) {
- int tmp;
-
- mask_tr_fn = maskbuf->transfer_fn;
- /* Make sure we are in the mask buffer */
- if (maskbuf->data != NULL) {
- mask_row_ptr = maskbuf->data + x0 - maskbuf->rect.p.x +
- (y0 - maskbuf->rect.p.y) * maskbuf->rowstride;
- has_mask = true;
- }
- /* We may have a case, where we are outside the maskbuf rect. */
- /* We would have avoided creating the maskbuf->data */
- /* In that case, we should use the background alpha value */
- /* See discussion on the BC entry in the PDF spec. */
- mask_bg_alpha = maskbuf->alpha;
- /* Adjust alpha by the mask background alpha. This is only used
- if we are outside the soft mask rect during the filling operation */
- mask_bg_alpha = mask_tr_fn[mask_bg_alpha];
- tmp = alpha * mask_bg_alpha + 0x80;
- mask_bg_alpha = (tmp + (tmp >> 8)) >> 8;
- if (maskbuf->matte != NULL)
- has_matte = true;
- }
- n_chan--; /* Now the true number of colorants (i.e. not including alpha)*/
-#if RAW_DUMP
- composed_ptr = nos_ptr;
- dump_raw_buffer(y1-y0, width, tos->n_planes, tos_planestride, tos->rowstride,
- "bImageTOS",tos_ptr);
- dump_raw_buffer(y1-y0, width, nos->n_planes, nos_planestride, nos->rowstride,
- "cImageNOS",nos_ptr);
- if (maskbuf !=NULL && maskbuf->data != NULL) {
- dump_raw_buffer(maskbuf->rect.q.y - maskbuf->rect.p.y,
- maskbuf->rect.q.x - maskbuf->rect.p.x, maskbuf->n_planes,
- maskbuf->planestride, maskbuf->rowstride, "dMask",
- maskbuf->data);
- }
-#endif
-
- if (nos_knockout)
- fn = &compose_group_knockout;
- else if (tos_isolated)
- fn = &compose_group_isolated_nonknockout;
- else
- fn = &compose_group_nonisolated_nonknockout;
-
- fn(tos_ptr, tos_isolated, tos_planestride, tos->rowstride, alpha, shape, blend_mode, tos->has_shape,
- tos_shape_offset, tos_alpha_g_offset, tos_tag_offset, tos_has_tag,
- nos_ptr, nos_isolated, nos_planestride, nos->rowstride, nos_alpha_g_ptr, nos_knockout,
- nos_shape_offset, nos_tag_offset,
- mask_row_ptr, has_mask, maskbuf, mask_bg_alpha, mask_tr_fn,
- backdrop_ptr,
- has_matte, n_chan, additive, num_spots, overprint, drawn_comps, x0, y0, x1, y1,
- pblend_procs, pdev);
-
-#if RAW_DUMP
- dump_raw_buffer(y1-y0, width, nos->n_planes, nos_planestride, nos->rowstride,
- "eComposed", composed_ptr);
- global_index++;
-#endif
-}
/*
* Encode a list of colorant values into a gx_color_index_value.