diff options
Diffstat (limited to 'base/gxblend1.c')
-rw-r--r-- | base/gxblend1.c | 271 |
1 files changed, 8 insertions, 263 deletions
diff --git a/base/gxblend1.c b/base/gxblend1.c index f439c0ac..6d42a094 100644 --- a/base/gxblend1.c +++ b/base/gxblend1.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2019 Artifex Software, Inc. +/* Copyright (C) 2001-2020 Artifex Software, Inc. All Rights Reserved. This software is provided AS-IS with no warranty, either express or @@ -346,7 +346,7 @@ pdf14_preserve_backdrop(pdf14_buf *buf, pdf14_buf *tos, bool from_backdrop y0 > buf->rect.p.y || y1 < buf->rect.q.y) { /* FIXME: There is potential for more optimisation here, * but I don't know how often we hit this case. */ - memset(buf_plane, 0, n_planes * buf->planestride); + memset(buf_plane, 0, (size_t)n_planes * buf->planestride); } else if (n_planes > tos->n_chan) { /* The next planes are alpha_g, shape, tags. We need to clear * alpha_g and shape, but don't need to clear the tag plane @@ -355,7 +355,8 @@ pdf14_preserve_backdrop(pdf14_buf *buf, pdf14_buf *tos, bool from_backdrop if (!from_backdrop && n_planes > tag_plane_num) n_planes = tag_plane_num; if (n_planes > tos->n_chan) - memset(buf->data + tos->n_chan * buf->planestride, 0, (n_planes - tos->n_chan) * buf->planestride); + memset(buf->data + (size_t)tos->n_chan * buf->planestride, 0, + (size_t)(n_planes - tos->n_chan) * buf->planestride); } buf_plane += (y0 - buf->rect.p.y) * buf->rowstride + ((x0 - buf->rect.p.x)<<deep); @@ -867,14 +868,14 @@ gx_blend_image_buffer16(byte *buf_ptr_, int width, int height, int rowstride, buf_ptr[position + planestride * comp_num] = bebg; } } else if (a == 0xffff) { - /* Convert from native -> big endian */ - /* FIXME: Are compilers smart enough to spot that this is - * a no-op on big endian hosts? */ +#if ARCH_IS_BIG_ENDIAN +#else for (comp_num = 0; comp_num < num_comp; comp_num++) { comp = buf_ptr[position + planestride * comp_num]; ((byte *)&buf_ptr[position + planestride * comp_num])[0] = comp>>8; ((byte *)&buf_ptr[position + planestride * comp_num])[1] = comp; } +#endif } else { a ^= 0xffff; a += a>>15; /* a is now 0 to 0x10000 */ @@ -935,262 +936,6 @@ gx_blend_image_buffer8to16(const byte *buf_ptr_in, unsigned short *buf_ptr_out, } int -gx_put_blended_image_cmykspot(gx_device *target, byte *buf_ptr, int planestride_in, - int rowstride_in, int x0, int y0, int width, int height, - int num_comp, uint16_t bg, bool has_tags, gs_int_rect rect, - gs_separations * pseparations, bool deep) -{ - int code = 0; - int x, y, tmp, comp_num, output_comp_num; - gx_color_index color; - gx_color_value cv[GX_DEVICE_COLOR_MAX_COMPONENTS]; - gx_color_value comp; - int input_map[GX_DEVICE_COLOR_MAX_COMPONENTS]; - int output_map[GX_DEVICE_COLOR_MAX_COMPONENTS]; - int num_known_comp = 0; - int output_num_comp = target->color_info.num_components; - int num_sep = pseparations->num_separations++; - int num_rows_left; - int i; - gx_drawing_color pdcolor; - gs_fixed_rect rect_fixed; - int bits_per_comp = ((target->color_info.depth - has_tags*8) / - target->color_info.num_components); - bool expand = (!deep && bits_per_comp > 8); - int planestride = planestride_in; - int rowstride = rowstride_in; - byte *buf16_ptr = NULL; - - /* - * The process color model for the PDF 1.4 compositor device is CMYK plus - * spot colors. The target device may have only some of these colorants due - * to the SeparationOrder device parameter. Thus we need to determine the - * mapping between the PDF 1.4 compositor and the target device. Note: - * There should not be a spot colorant in the PDF 1.4 device that is not - * present in the target device. - */ - /* Check if target processes CMYK colorants. */ - for (comp_num = 0; comp_num < 4; comp_num++) { - const char * pcomp_name = (const char *)DeviceCMYKComponents[comp_num]; - - output_comp_num = dev_proc(target, get_color_comp_index) - (target, pcomp_name, strlen(pcomp_name), NO_COMP_NAME_TYPE); - if (output_comp_num >=0 && - output_comp_num < GX_DEVICE_COLOR_MAX_COMPONENTS) { - output_map[num_known_comp] = output_comp_num; - input_map[num_known_comp++] = comp_num; - } - } - /* Check if target processes our spot colorants. */ - for (comp_num = 0; comp_num < num_sep; comp_num++) { - output_comp_num = dev_proc(target, get_color_comp_index) - (target, (const char *)(pseparations->names[comp_num].data), - pseparations->names[comp_num].size, NO_COMP_NAME_TYPE); - if (output_comp_num >= 0 && - output_comp_num < GX_DEVICE_COLOR_MAX_COMPONENTS) { - output_map[num_known_comp] = output_comp_num; - input_map[num_known_comp++] = comp_num + 4; - } - } - - { - /* See if the target device can handle the data in its current - form with the alpha component */ - int alpha_offset = num_comp; - int tag_offset = has_tags ? num_comp + 1 : 0; - const byte *buf_ptrs[GS_CLIENT_COLOR_MAX_COMPONENTS]; - - for (i = 0; i < num_comp; i++) - buf_ptrs[i] = buf_ptr + i * planestride; - code = dev_proc(target, put_image) (target, target, buf_ptrs, num_comp, - rect.p.x, rect.p.y, width, height, - rowstride, - num_comp, tag_offset); - if (code == 0) { - /* Device could not handle the alpha data. Go ahead and - preblend now. Note that if we do this, and we end up in the - default below, we only need to repack in chunky not blend. Add - in conversion to 16 bits if the target device is planar and - a 16 bit device. */ -#if RAW_DUMP - /* Dump before and after the blend to make sure we are doing that ok */ - dump_raw_buffer(target->memory, height, width, num_comp + 1, planestride, rowstride, - "pre_final_blend", buf_ptr, deep); - global_index++; -#endif - if (expand) { - buf16_ptr = gs_alloc_bytes(target->memory, - planestride * num_comp * 2, "gx_put_blended_image_cmykspot"); - gx_blend_image_buffer8to16(buf_ptr, (unsigned short*)buf16_ptr, width, height, - rowstride, planestride, num_comp, bg>>8); - planestride = planestride_in * 2; - rowstride = rowstride_in * 2; - for (i = 0; i < num_comp; i++) - buf_ptrs[i] = buf16_ptr + i * planestride; - } else { - if (deep) { - gx_blend_image_buffer16(buf_ptr, width, height, rowstride, - planestride, num_comp, bg); - } else { - gx_blend_image_buffer(buf_ptr, width, height, rowstride, - planestride, num_comp, bg>>8); - } -#if RAW_DUMP - /* Dump before and after the blend to make sure we are doing that ok */ - dump_raw_buffer_be(target->memory, height, width, num_comp, planestride, rowstride, - "post_final_blend", buf_ptr, deep); - global_index++; - /* clist_band_count++; */ -#endif - } - /* Try again now */ - alpha_offset = 0; - code = dev_proc(target, put_image) (target, target, buf_ptrs, num_comp, - rect.p.x, rect.p.y, width, height, - rowstride, alpha_offset, tag_offset); - if (code > 0) { - /* We processed some or all of the rows. Continue until we are done */ - num_rows_left = height - code; - while (num_rows_left > 0) { - code = dev_proc(target, put_image) (target, target, buf_ptrs, num_comp, - rect.p.x, rect.p.y + code, width, - num_rows_left, rowstride, - alpha_offset, tag_offset); - if (code < 0) { - if (buf16_ptr != NULL) - gs_free_object(target->memory, buf16_ptr, "gx_put_blended_image_cmykspot"); - return code; - } - num_rows_left = num_rows_left - code; - } - } - if (buf16_ptr != NULL) - gs_free_object(target->memory, buf16_ptr, "gx_put_blended_image_cmykspot"); - return 0; - } - } - - if (buf16_ptr != NULL) - gs_free_object(target->memory, buf16_ptr, "gx_put_blended_image_cmykspot"); - planestride = planestride_in; - rowstride = rowstride_in; - - /* Clear all output colorants first */ - for (comp_num = 0; comp_num < output_num_comp; comp_num++) - cv[comp_num] = 0; - - /* Send pixel data to the target device. */ - if (deep) { - /* NOTE: buf_ptr points to big endian data */ - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - - /* composite CMYKA, etc. pixel with over solid background */ -#define GET16_BE2NATIVE(v) \ - ((((byte *)&(v))[0]<<8) | (((byte *)&(v))[1])) - uint16_t a = GET16_BE2NATIVE(buf_ptr[x + planestride * num_comp]); - - if (a == 0) { - for (comp_num = 0; comp_num < num_known_comp; comp_num++) { - cv[output_map[comp_num]] = bg; - } - } else if (a == 0xffff) { - for (comp_num = 0; comp_num < num_known_comp; comp_num++) { - comp = GET16_BE2NATIVE(buf_ptr[x + planestride * input_map[comp_num]]); - cv[output_map[comp_num]] = comp; - } - } else { - /* a ^= 0xff; */ /* No inversion here! Bug 689895 */ - for (comp_num = 0; comp_num < num_known_comp; comp_num++) { - comp = GET16_BE2NATIVE(buf_ptr[x + planestride * input_map[comp_num]]); - tmp = ((comp - bg) * a) + 0x8000; - comp += (tmp + (tmp >> 16))>>16; - cv[output_map[comp_num]] = comp; - } - } - - /* If we have spot colors we need to encode and fill as a high level - color if the device supports it which should always be the case - if we are in this procedure */ - if (dev_proc(target, dev_spec_op)(target, gxdso_supports_devn, NULL, 0)) { - for (i = 0; i < output_num_comp; i++) { - pdcolor.colors.devn.values[i] = cv[i]; - } - pdcolor.type = gx_dc_type_devn; - rect_fixed.p.x = int2fixed(x + x0); - rect_fixed.p.y = int2fixed(y + y0); - rect_fixed.q.x = int2fixed(x + x0 + 1); - rect_fixed.q.y = int2fixed(y + y0 + 1); - code = dev_proc(target, fill_rectangle_hl_color)(target, &rect_fixed, - NULL, &pdcolor, NULL); - } else { - /* encode as a color index */ - color = dev_proc(target, encode_color)(target, cv); - code = dev_proc(target, fill_rectangle)(target, x + x0, y + y0, 1, 1, color); - } - if (code < 0) - return code; - } - - buf_ptr += rowstride; - } - } else { - bg >>= 8; - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - - /* composite CMYKA, etc. pixel with over solid background */ - byte a = buf_ptr[x + planestride * num_comp]; - - if ((a + 1) & 0xfe) { - /* a ^= 0xff; */ /* No inversion here! Bug 689895 */ - for (comp_num = 0; comp_num < num_known_comp; comp_num++) { - comp = buf_ptr[x + planestride * input_map[comp_num]]; - tmp = ((comp - bg) * a) + 0x80; - comp += tmp + (tmp >> 8); - cv[output_map[comp_num]] = comp; - } - } else if (a == 0) { - for (comp_num = 0; comp_num < num_known_comp; comp_num++) { - cv[output_map[comp_num]] = bg; - } - } else { - for (comp_num = 0; comp_num < num_known_comp; comp_num++) { - comp = buf_ptr[x + planestride * input_map[comp_num]]; - cv[output_map[comp_num]] = (comp << 8) + comp; - } - } - - /* If we have spot colors we need to encode and fill as a high level - color if the device supports it which should always be the case - if we are in this procedure */ - if (dev_proc(target, dev_spec_op)(target, gxdso_supports_devn, NULL, 0)) { - for (i = 0; i < output_num_comp; i++) { - pdcolor.colors.devn.values[i] = cv[i]; - } - pdcolor.type = gx_dc_type_devn; - rect_fixed.p.x = int2fixed(x + x0); - rect_fixed.p.y = int2fixed(y + y0); - rect_fixed.q.x = int2fixed(x + x0 + 1); - rect_fixed.q.y = int2fixed(y + y0 + 1); - code = dev_proc(target, fill_rectangle_hl_color)(target, &rect_fixed, - NULL, &pdcolor, NULL); - } else { - /* encode as a color index */ - color = dev_proc(target, encode_color)(target, cv); - code = dev_proc(target, fill_rectangle)(target, x + x0, y + y0, 1, 1, color); - } - if (code < 0) - return code; - } - - buf_ptr += rowstride; - } - } - return code; -} - -int gx_put_blended_image_custom(gx_device *target, byte *buf_ptr_, int planestride, int rowstride, int x0, int y0, int width, int height, @@ -1275,4 +1020,4 @@ gx_put_blended_image_custom(gx_device *target, byte *buf_ptr_, } } return code; -} +}
\ No newline at end of file |