diff options
Diffstat (limited to 'contrib/opvp/gdevopvp.c')
-rw-r--r-- | contrib/opvp/gdevopvp.c | 266 |
1 files changed, 85 insertions, 181 deletions
diff --git a/contrib/opvp/gdevopvp.c b/contrib/opvp/gdevopvp.c index 70475add..844b46cd 100644 --- a/contrib/opvp/gdevopvp.c +++ b/contrib/opvp/gdevopvp.c @@ -170,12 +170,7 @@ static int oprp_open(gx_device *); static void opvp_get_initial_matrix(gx_device *, gs_matrix *); static int opvp_output_page(gx_device *, int, int); static int opvp_close(gx_device *); -#if GS_VERSION_MAJOR >= 8 static gx_color_index opvp_map_rgb_color(gx_device *, const gx_color_value *); /* modified for gs 8.15 */ -#else -static gx_color_index opvp_map_rgb_color(gx_device *, gx_color_value, - gx_color_value, gx_color_value); -#endif static int opvp_map_color_rgb(gx_device *, gx_color_index, gx_color_value *); static int opvp_copy_mono(gx_device *, const byte *, int, int, gx_bitmap_id, int, int, int, int, @@ -221,14 +216,9 @@ static int opvp_setdash(gx_device_vector *, const float *, uint, double); static int opvp_setflat(gx_device_vector *, double); static int opvp_setlogop(gx_device_vector *, gs_logical_operation_t, gs_logical_operation_t); -#if GS_VERSION_MAJOR >= 8 static int opvp_can_handle_hl_color(gx_device_vector *, const gs_gstate *, const gx_drawing_color *); static int opvp_setfillcolor(gx_device_vector *, const gs_gstate *, const gx_drawing_color *); static int opvp_setstrokecolor(gx_device_vector *, const gs_gstate *,const gx_drawing_color *); -#else -static int opvp_setfillcolor(gx_device_vector *, const gx_drawing_color *); -static int opvp_setstrokecolor(gx_device_vector *, const gx_drawing_color *); -#endif static int opvp_vector_dopath(gx_device_vector *, const gx_path *, gx_path_type_t, const gs_matrix *); static int opvp_vector_dorect(gx_device_vector *, fixed, fixed, fixed, fixed, @@ -278,7 +268,7 @@ static dev_proc_get_params(oprp_get_params); static dev_proc_put_params(opvp_put_params); static dev_proc_put_params(oprp_put_params); static dev_proc_fill_rectangle(opvp_fill_rectangle); -static dev_proc_begin_image(opvp_begin_image); +static dev_proc_begin_typed_image(opvp_begin_typed_image); static image_enum_proc_plane_data(opvp_image_plane_data); static image_enum_proc_end_image(opvp_image_end_image); @@ -306,57 +296,35 @@ gs_public_st_suffix_add0_final( NULL /* *docInfo */ /* device procs */ -#define opvp_procs \ -{\ - opvp_open,\ - opvp_get_initial_matrix,\ - NULL, /* sync_output */\ - opvp_output_page,\ - opvp_close,\ - opvp_map_rgb_color,\ - opvp_map_color_rgb,\ - opvp_fill_rectangle, /*gdev_vector_fill_rectangle,*/\ - NULL, /* tile_rectangle OBSOLETE */\ - opvp_copy_mono,\ - opvp_copy_color,\ - NULL, /* draw_line OBSOLETE */\ - NULL, /* get_bits */\ - opvp_get_params,\ - opvp_put_params,\ - NULL, /* map_cmyk_color */\ - NULL, /* get_xfont_procs */\ - NULL, /* get_xfont_device */\ - NULL, /* map_rgb_alpha_color */\ - gx_page_device_get_page_device,\ - NULL, /* get_alpha_bits OBSOLETE */\ - NULL, /* copy_alpha */\ - NULL, /* get_band */\ - NULL, /* copy_rop */\ - opvp_fill_path,\ - opvp_stroke_path,\ - opvp_fill_mask,\ - gdev_vector_fill_trapezoid,\ - gdev_vector_fill_parallelogram,\ - gdev_vector_fill_triangle,\ - NULL, /* draw_thin_line */\ - opvp_begin_image,\ - NULL, /* image_data */\ - NULL, /* end_image */\ - NULL, /* strip_tile_rectangle */\ - NULL, /* strip_copy_rop */\ - NULL, /* get_clipping_box */\ - NULL, /* begin_typed_image */\ - NULL, /* get_bits_rectangle */\ - NULL, /* map_color_rgb_alpha */\ - NULL, /* create_compositor */\ - NULL, /* get_hardware_params */\ - NULL, /* text_begin */\ - NULL, /* finish_copydevice */\ - NULL, /* begin_transparency_group */\ - NULL, /* end_transparency_group */\ - NULL, /* begin_transparency_mask */\ - NULL, /* end_transparency_mask */\ - NULL /* discard_transparency_layer */\ +static void +opvp_initialize_device_procs(gx_device *dev) +{ + gdev_prn_initialize_device_procs(dev); + + set_dev_proc(dev, open_device, opvp_open); + set_dev_proc(dev, get_initial_matrix, opvp_get_initial_matrix); + set_dev_proc(dev, output_page, opvp_output_page); + set_dev_proc(dev, close_device, opvp_close); + set_dev_proc(dev, map_rgb_color, opvp_map_rgb_color); + set_dev_proc(dev, map_color_rgb, opvp_map_color_rgb); + set_dev_proc(dev, fill_rectangle, opvp_fill_rectangle); + set_dev_proc(dev, copy_mono, opvp_copy_mono); + set_dev_proc(dev, copy_color, opvp_copy_color); + set_dev_proc(dev, get_params, opvp_get_params); + set_dev_proc(dev, put_params, opvp_put_params); + set_dev_proc(dev, fill_path, opvp_fill_path); + set_dev_proc(dev, stroke_path, opvp_stroke_path); + set_dev_proc(dev, fill_mask, opvp_fill_mask); + set_dev_proc(dev, fill_trapezoid, gdev_vector_fill_trapezoid); + set_dev_proc(dev, fill_parallelogram, gdev_vector_fill_parallelogram); + set_dev_proc(dev, fill_triangle, gdev_vector_fill_triangle); + set_dev_proc(dev, begin_typed_image, opvp_begin_typed_image); + + /* The static init used in previous versions of the code leave + * encode_color and decode_color set to NULL (which are then rewritten + * by the system to the default. For compatibility we do the same. */ + set_dev_proc(dev, encode_color, NULL); + set_dev_proc(dev, decode_color, NULL); } /* vector procs */ @@ -373,9 +341,7 @@ static gx_device_vector_procs opvp_vector_procs = opvp_setflat, opvp_setlogop, /* Other state */ -#if GS_VERSION_MAJOR >= 8 opvp_can_handle_hl_color, /* added for gs 8.15 */ -#endif opvp_setfillcolor, opvp_setstrokecolor, /* Paths */ @@ -393,7 +359,7 @@ const gx_device_opvp gs_opvp_device = { std_device_dci_type_body( gx_device_opvp, - 0, + opvp_initialize_device_procs, "opvp", &st_device_opvp, DEFAULT_WIDTH_10THS_A4 * X_DPI / 10, @@ -406,27 +372,35 @@ const gx_device_opvp gs_opvp_device = 255, 256, 256 - ), - opvp_procs + ) }; /* for inkjet */ -static gx_device_procs prn_oprp_procs = - prn_color_params_procs( - oprp_open, - opvp_output_page, - opvp_close, - opvp_map_rgb_color, - opvp_map_color_rgb, - oprp_get_params, - oprp_put_params - ); +static void +oprp_initialize_device_procs(gx_device *dev) +{ + gdev_prn_initialize_device_procs(dev); + + set_dev_proc(dev, open_device, oprp_open); + set_dev_proc(dev, output_page, opvp_output_page); + set_dev_proc(dev, close_device, opvp_close); + set_dev_proc(dev, map_rgb_color, opvp_map_rgb_color); + set_dev_proc(dev, map_color_rgb, opvp_map_color_rgb); + set_dev_proc(dev, get_params, oprp_get_params); + set_dev_proc(dev, put_params, oprp_put_params); + + /* The static init used in previous versions of the code leave + * encode_color and decode_color set to NULL (which are then rewritten + * by the system to the default. For compatibility we do the same. */ + set_dev_proc(dev, encode_color, NULL); + set_dev_proc(dev, decode_color, NULL); +} const gx_device_oprp gs_oprp_device = { prn_device_std_margins_body( gx_device_oprp, - prn_oprp_procs, + oprp_initialize_device_procs, "oprp", DEFAULT_WIDTH_10THS_A4, DEFAULT_HEIGHT_10THS_A4, @@ -1931,11 +1905,9 @@ prepare_open(gx_device *dev) dev->color_info.dither_grays = 256; dev->color_info.dither_colors = 256; } -#if GS_VERSION_MAJOR >= 8 dev->procs.get_color_mapping_procs = NULL; dev->procs.get_color_comp_index = NULL; gx_device_fill_in_procs(dev); -#endif } /* call Closerinter as dummy */ @@ -2050,13 +2022,11 @@ opvp_open(gx_device *dev) } rdev = (gx_device_oprp *)(dev); pdev = (gx_device_opvp *)(dev); -#if GS_VERSION_MAJOR >= 8 if (pdev->bbox_device != NULL) { if (pdev->bbox_device->memory == NULL) { pdev->bbox_device->memory = gs_memory_stable(dev->memory); } } -#endif outputFD = fileno(gp_get_file(pdev->file)); } else { /* open printer device */ @@ -2479,17 +2449,9 @@ opvp_close(gx_device *dev) /* * map rgb color */ -#if GS_VERSION_MAJOR >= 8 static gx_color_index opvp_map_rgb_color(gx_device *dev, const gx_color_value *prgb /* modified for gs 8.15 */) -#else -static gx_color_index -opvp_map_rgb_color(gx_device *dev, - gx_color_value r, - gx_color_value g, - gx_color_value b) -#endif { opvp_cspace_t cs; uint c, m, y, k; @@ -2499,12 +2461,10 @@ opvp_map_rgb_color(gx_device *dev, opvp_result_t r; #endif -#if GS_VERSION_MAJOR >= 8 gx_color_value r, g, b; /* added for gs 8.15 */ r = prgb[0]; g = prgb[1]; b = prgb[2]; -#endif #if ENABLE_SIMPLE_MODE cs = colorSpace; @@ -2565,31 +2525,19 @@ opvp_map_rgb_color(gx_device *dev, ; break; case OPVP_CSPACE_DEVICEGRAY: -#if GS_VERSION_MAJOR >= 8 { gx_color_value rgb[3]; rgb[0] = rgb[1] = rgb[2] = r; return gx_default_gray_map_rgb_color(dev, rgb); } -#else - return gx_default_gray_map_rgb_color(dev, r, g, b); -#endif break; case OPVP_CSPACE_BW : -#if GS_VERSION_MAJOR >= 8 return gx_default_b_w_map_rgb_color(dev, prgb); -#else - return gx_default_b_w_map_rgb_color(dev, r, g, b); -#endif break; case OPVP_CSPACE_STANDARDRGB: case OPVP_CSPACE_DEVICEKRGB: default: -#if GS_VERSION_MAJOR >= 8 return gx_default_rgb_map_rgb_color(dev, prgb); -#else - return gx_default_rgb_map_rgb_color(dev, r, g, b); -#endif break; } } @@ -3584,11 +3532,7 @@ opvp_fill_mask( { if (vector) { int code; -#if GS_VERSION_MAJOR >= 8 /* for gs 8.15 */ code = gdev_vector_update_fill_color((gx_device_vector *)dev, NULL, pdcolor); -#else - code = gdev_vector_update_fill_color((gx_device_vector *)dev, pdcolor); -#endif if (code < 0) return code; code = gdev_vector_update_clip_path((gx_device_vector *)dev, pcpath); if (code < 0) return code; @@ -3604,11 +3548,11 @@ opvp_fill_mask( * begin image */ static int -opvp_begin_image( +opvp_begin_typed_image( gx_device *dev, const gs_gstate *pgs, - const gs_image_t *pim, - gs_image_format_t format, + const gs_matrix *pmat, + const gs_image_common_t *pic, const gs_int_rect *prect, const gx_drawing_color *pdcolor, const gx_clip_path *pcpath, @@ -3616,7 +3560,8 @@ opvp_begin_image( gx_image_enum_common_t **pinfo) { gx_device_vector *vdev =(gx_device_vector *)dev; - gdev_vector_image_enum_t *vinfo; + const gs_image_t *pim = (const gs_image_t *)pic; + gdev_vector_image_enum_t *vinfo = NULL; gs_matrix mtx; opvp_ctm_t ctm; bool draw_image = false; @@ -3628,16 +3573,13 @@ opvp_begin_image( bool can_reverse = false; int p; float mag[2] = {1, 1}; - const gs_color_space *pcs = pim->ColorSpace; + const gs_color_space *pcs; /* check if paths are too complex */ - if (!checkCPath(pcpath)) { - return gx_default_begin_image( - dev, pgs, pim, format, - prect, pdcolor, pcpath, - mem, pinfo); - } + if (pic->type->index != 1 || !checkCPath(pcpath)) + goto fallback; + pcs = pim->ColorSpace; color_index = 0; vinfo = gs_alloc_struct(mem, gdev_vector_image_enum_t, @@ -3646,8 +3588,8 @@ opvp_begin_image( if (vinfo) { memcpy(imageDecode,pim->Decode,sizeof(pim->Decode)); - vinfo->memory =mem; - code = gdev_vector_begin_image(vdev, pgs, pim, format, prect, + vinfo->memory = mem; + code = gdev_vector_begin_image(vdev, pgs, pim, pim->format, prect, pdcolor, pcpath, mem, &opvp_image_enum_procs, vinfo); @@ -3665,14 +3607,10 @@ opvp_begin_image( if (color_index == gs_color_space_index_Indexed) { base_color_index = gs_color_space_indexed_base_space(pcs)->type->index; - if (((pcs->params.indexed.hival + 1) > 256) - || (bits_per_pixel != 8 && bits_per_pixel != 1)) { - return gx_default_begin_image( - dev, pgs, pim, format, - prect, pdcolor, pcpath, - mem, pinfo); - } else if (base_color_index - == gs_color_space_index_DeviceCMYK) { + if (((pcs->params.indexed.hival + 1) > 256) || + (bits_per_pixel != 8 && bits_per_pixel != 1)) + goto fallback; + if (base_color_index == gs_color_space_index_DeviceCMYK) { /* for CMYK indexed color */ int count; const unsigned char *p @@ -3687,37 +3625,32 @@ opvp_begin_image( byte2frac((*(p + 1 + (count * 4)))), byte2frac((*(p + 2 + (count * 4)))), byte2frac((*(p + 3 + (count * 4)))), -#if GS_VERSION_MAJOR >= 9 pgs, rgb, mem); -#else - pgs, rgb); -#endif *(palette + 0 + (count * 3)) = frac2byte(rgb[0]); *(palette + 1 + (count * 3)) = frac2byte(rgb[1]); *(palette + 2 + (count * 3)) = frac2byte(rgb[2]); } bits_per_pixel = 24; - } else if (base_color_index - == gs_color_space_index_DeviceRGB || - base_color_index == gs_color_space_index_CIEABC) { + } else if (base_color_index == + gs_color_space_index_DeviceRGB || + base_color_index == + gs_color_space_index_CIEABC) { /* for RGB or CalRGB indexed color */ memcpy(palette, pcs->params.indexed.lookup.table.data,\ pcs->params.indexed.lookup.table.size); bits_per_pixel = 24; - } else if (base_color_index - == gs_color_space_index_DeviceGray || - base_color_index == gs_color_space_index_CIEA) { + } else if (base_color_index == + gs_color_space_index_DeviceGray || + base_color_index == + gs_color_space_index_CIEA) { /* for Gray or CalGray indexed color */ memcpy(palette, pcs->params.indexed.lookup.table.data,\ pcs->params.indexed.lookup.table.size); bits_per_pixel = 8; } else { /* except CMYK and RGB */ - return gx_default_begin_image( - dev, pgs, pim, format, - prect, pdcolor, pcpath, - mem, pinfo); + goto fallback; } } } @@ -3730,7 +3663,9 @@ opvp_begin_image( /* adjust matrix */ reverse_image = false; ecode = gs_matrix_invert(&pim->ImageMatrix, &mtx); - gs_matrix_multiply(&mtx, &ctm_only(pgs), &mtx); + if (pmat == NULL) + pmat = &ctm_only(pgs); + gs_matrix_multiply(&mtx, pmat, &mtx); switch (FastImageMode) { case FastImageNoCTM: if ((mtx.xy==0)&&(mtx.yx==0)&& (mtx.yy>=0)) { @@ -3963,8 +3898,7 @@ fallthrough: if(apiEntry->opvpResetCTM) { apiEntry->opvpResetCTM(printerContext); /* reset CTM */ } - return gx_default_begin_image(dev, pgs, pim, format, - prect, pdcolor, pcpath, mem, pinfo); + goto fallback; } } @@ -3975,8 +3909,10 @@ fallthrough: return ecode; } - return gx_default_begin_image(dev, pgs, pim, format, prect, - pdcolor, pcpath, mem, pinfo); +fallback: + gs_free_object(mem, vinfo, "opvp_end_image"); + return gx_default_begin_typed_image(dev, pgs, pmat, pic, prect, + pdcolor, pcpath, mem, pinfo); } /* @@ -4344,7 +4280,6 @@ opvp_image_plane_data( } } } -#if GS_VERSION_MAJOR >= 8 if (vinfo->bits_per_pixel == 24) { /* 24bit RGB color */ for (i = 0; i < height; i++) { ptr = buf + raster_length * i; @@ -4362,25 +4297,6 @@ opvp_image_plane_data( } } } -#else - if (vinfo->bits_per_pixel == 24) { /* 24bit RGB color */ - for (i = 0; i < height; i++) { - ptr = buf + raster_length * i; - for (j = 0; j < vinfo->width; j++) { - ptr[j*3+0] = frac2byte(gx_map_color_frac(pgs, byte2frac(ptr[j*3+0]), effective_transfer.colored.red)); - ptr[j*3+1] = frac2byte(gx_map_color_frac(pgs, byte2frac(ptr[j*3+1]), effective_transfer.colored.green)); - ptr[j*3+2] = frac2byte(gx_map_color_frac(pgs, byte2frac(ptr[j*3+2]), effective_transfer.colored.blue)); - } - } - } else if (vinfo->bits_per_pixel == 8) { /* 8bit Gray image */ - for (i = 0; i < height; i++) { - ptr = buf + raster_length * i; - for (j = 0; j < vinfo->width; j++) { - ptr[j] = frac2byte(gx_map_color_frac(pgs, byte2frac(ptr[j]), effective_transfer.colored.gray)); - } - } - } -#endif /* call TansferDrawImage */ if (apiEntry->opvpTransferDrawImage) { @@ -4721,29 +4637,22 @@ opvp_setlogop( return 0; } -#if GS_VERSION_MAJOR >= 8 -/*--- added for Ghostscritp 8.15 ---*/ +/*--- added for Ghostscript 8.15 ---*/ static int opvp_can_handle_hl_color(gx_device_vector * vdev, const gs_gstate * pgs1, const gx_drawing_color * pdc) { return false; /* High level color is not implemented yet. */ } -#endif /* * set fill color */ -#if GS_VERSION_MAJOR >= 8 static int opvp_setfillcolor( gx_device_vector *vdev, const gs_gstate *pgs, /* added for gs 8.15 */ const gx_drawing_color *pdc) -#else -static int -opvp_setfillcolor(gx_device_vector *vdev, const gx_drawing_color *pdc) -#endif { gx_device_opvp *pdev = (gx_device_opvp *)vdev; opvp_result_t r = -1; @@ -4775,16 +4684,11 @@ opvp_setfillcolor(gx_device_vector *vdev, const gx_drawing_color *pdc) /* * set stroke color */ -#if GS_VERSION_MAJOR >= 8 static int opvp_setstrokecolor( gx_device_vector *vdev, const gs_gstate *pgs, /* added for gs 8.15 */ const gx_drawing_color *pdc) -#else -static int -opvp_setstrokecolor(gx_device_vector *vdev, const gx_drawing_color *pdc) -#endif { gx_device_opvp *pdev = (gx_device_opvp *)vdev; opvp_result_t r = -1; |