From e44dd287289e34ef75f50316a0acb04d9094cf16 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Wed, 21 Apr 2021 19:59:58 +0100 Subject: Move devices away from begin_image to begin_typed_image. --- contrib/eplaser/gdevescv.c | 60 +++++++++++++++++++++++++------------- contrib/lips4/gdevl4v.c | 64 +++++++++++++++++++++++++---------------- contrib/opvp/gdevopvp.c | 72 ++++++++++++++++++++++------------------------ 3 files changed, 114 insertions(+), 82 deletions(-) (limited to 'contrib') diff --git a/contrib/eplaser/gdevescv.c b/contrib/eplaser/gdevescv.c index 5dd90f95a..9410fddc4 100644 --- a/contrib/eplaser/gdevescv.c +++ b/contrib/eplaser/gdevescv.c @@ -66,7 +66,7 @@ static dev_proc_copy_color(escv_copy_color); static dev_proc_put_params(escv_put_params); static dev_proc_get_params(escv_get_params); static dev_proc_fill_mask(escv_fill_mask); -static dev_proc_begin_image(escv_begin_image); +static dev_proc_begin_typed_image(escv_begin_typed_image); gs_public_st_suffix_add0_final(st_device_escv, gx_device_escv, "gx_device_escv", device_escv_enum_ptrs, device_escv_reloc_ptrs, @@ -144,7 +144,7 @@ esc_initialize(gx_device *dev) 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_image, escv_begin_image); + set_dev_proc(dev, begin_typed_image, escv_begin_typed_image); return 0; } @@ -2361,23 +2361,25 @@ static const gx_image_enum_procs_t escv_image_enum_procs = /* Start processing an image. */ static int -escv_begin_image(gx_device * dev, - const gs_gstate * pgs, const gs_image_t * pim, - gs_image_format_t format, const gs_int_rect * prect, - const gx_drawing_color * pdcolor, const gx_clip_path * pcpath, - gs_memory_t * mem, gx_image_enum_common_t **pinfo) +escv_begin_typed_image(gx_device *dev, + const gs_gstate *pgs, + 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, + gs_memory_t *mem, + gx_image_enum_common_t **pinfo) { + const gs_image_t *pim = (const gs_image_t *)pic; gx_device_vector *const vdev = (gx_device_vector *) dev; gx_device_escv *const pdev = (gx_device_escv *) dev; - stream *s = gdev_vector_stream((gx_device_vector *) pdev); - gdev_vector_image_enum_t *pie = - gs_alloc_struct(mem, gdev_vector_image_enum_t, &st_vector_image_enum, "escv_begin_image"); - const gs_color_space *pcs = pim->ColorSpace; + stream *s; + gdev_vector_image_enum_t *pie; + const gs_color_space *pcs; gs_color_space_index index; int num_components = 1; - bool can_do = prect == 0 && - (pim->format == gs_image_format_chunky || - pim->format == gs_image_format_component_planar); + bool can_do; gs_matrix imat; int code; @@ -2385,10 +2387,24 @@ escv_begin_image(gx_device * dev, char obuf[128]; - if (pie == 0) return_error(gs_error_VMerror); + s = gdev_vector_stream((gx_device_vector *) pdev); + pie = gs_alloc_struct(mem, gdev_vector_image_enum_t, + &st_vector_image_enum, "escv_begin_typed_image"); + if (pie == NULL) return_error(gs_error_VMerror); pie->memory = mem; - code = gdev_vector_begin_image(vdev, pgs, pim, format, prect, - pdcolor, pcpath, mem, &escv_image_enum_procs, pie); + + /* This code can only cope with type1 images. Anything else, we need + * to send to the default. */ + if (pic->type->index != 1) + goto fallback; + + can_do = prect == NULL && + (pim->format == gs_image_format_chunky || + pim->format == gs_image_format_component_planar); + pcs = pim->ColorSpace; + code = gdev_vector_begin_image(vdev, pgs, pim, pim->format, prect, + pdcolor, pcpath, mem, + &escv_image_enum_procs, pie); if (code < 0) return code; *pinfo = (gx_image_enum_common_t *) pie; @@ -2418,8 +2434,10 @@ escv_begin_image(gx_device * dev, } } if (!can_do) { - return gx_default_begin_image(dev, pgs, pim, format, prect, - pdcolor, pcpath, mem, &pie->default_info); +fallback: + return gx_default_begin_typed_image(dev, pgs, pmat, pic, prect, + pdcolor, pcpath, mem, + &pie->default_info); } if (pim->ImageMask || (pim->BitsPerComponent == 1 && num_components == 1)) { @@ -2440,7 +2458,9 @@ escv_begin_image(gx_device * dev, if (code < 0) return code; - gs_matrix_multiply(&imat, &ctm_only(pgs), &imat); + if (pmat == NULL) + pmat = &ctm_only(pgs); + gs_matrix_multiply(&imat, pmat, &imat); ty = imat.ty; bx = imat.xx * pim->Width + imat.yx * pim->Height + imat.tx; diff --git a/contrib/lips4/gdevl4v.c b/contrib/lips4/gdevl4v.c index b2ce2d6c0..32613fe60 100644 --- a/contrib/lips4/gdevl4v.c +++ b/contrib/lips4/gdevl4v.c @@ -97,7 +97,7 @@ static dev_proc_copy_color(lips4v_copy_color); static dev_proc_put_params(lips4v_put_params); static dev_proc_get_params(lips4v_get_params); static dev_proc_fill_mask(lips4v_fill_mask); -static dev_proc_begin_image(lips4v_begin_image); +static dev_proc_begin_typed_image(lips4v_begin_typed_image); #define X_DPI 600 #define Y_DPI 600 @@ -177,7 +177,7 @@ lips4v_initialize(gx_device *dev) 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_image, lips4v_begin_image); + set_dev_proc(dev, begin_typed_image, lips4v_begin_typed_image); return 0; } @@ -2114,32 +2114,44 @@ static const gx_image_enum_procs_t lips4v_image_enum_procs = { /* Start processing an image. */ static int -lips4v_begin_image(gx_device * dev, - const gs_gstate * pgs, const gs_image_t * pim, - gs_image_format_t format, const gs_int_rect * prect, - const gx_drawing_color * pdcolor, - const gx_clip_path * pcpath, gs_memory_t * mem, - gx_image_enum_common_t ** pinfo) +lips4v_begin_typed_image(gx_device *dev, + const gs_gstate *pgs, + 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, + gs_memory_t *mem, + gx_image_enum_common_t **pinfo) { gx_device_vector *const vdev = (gx_device_vector *) dev; gx_device_lips4v *const pdev = (gx_device_lips4v *) dev; - gdev_vector_image_enum_t *pie = - gs_alloc_struct(mem, gdev_vector_image_enum_t, - &st_vector_image_enum, "lips4v_begin_image"); - const gs_color_space *pcs = pim->ColorSpace; + const gs_image_t *pim = (const gs_image_t *)pic; + gdev_vector_image_enum_t *pie; + const gs_color_space *pcs; gs_color_space_index index = 0; int num_components = 1; - bool can_do = prect == 0 && - (pim->format == gs_image_format_chunky || - - pim->format == gs_image_format_component_planar); - + bool can_do; int code; + pie = gs_alloc_struct(mem, gdev_vector_image_enum_t, + &st_vector_image_enum, "lips4v_begin_typed_image"); if (pie == 0) return_error(gs_error_VMerror); pie->memory = mem; - code = gdev_vector_begin_image(vdev, pgs, pim, format, prect, + + /* We can only cope with type 1 images here.*/ + if (pic->type->index != 1) { + *pinfo = (gx_image_enum_common_t *) pie; + goto fallback; + } + + pcs = pim->ColorSpace; + can_do = prect == NULL && + (pim->format == gs_image_format_chunky || + pim->format == gs_image_format_component_planar); + + code = gdev_vector_begin_image(vdev, pgs, pim, pim->format, prect, pdcolor, pcpath, mem, &lips4v_image_enum_procs, pie); if (code < 0) @@ -2178,10 +2190,12 @@ lips4v_begin_image(gx_device * dev, } } } - if (!can_do) - return gx_default_begin_image(dev, pgs, pim, format, prect, - pdcolor, pcpath, mem, - &pie->default_info); + if (!can_do) { +fallback: + return gx_default_begin_typed_image(dev, pgs, pmat, pic, prect, + pdcolor, pcpath, mem, + &pie->default_info); + } else if (index == gs_color_space_index_DeviceGray) { gx_drawing_color dcolor; @@ -2213,7 +2227,9 @@ lips4v_begin_image(gx_device * dev, if (code < 0) return code; - gs_matrix_multiply(&imat, &ctm_only(pgs), &imat); + if (pmat == NULL) + pmat = &ctm_only(pgs); + gs_matrix_multiply(&imat, pmat, &imat); /* [xx xy yx yy tx ty] LIPS の座標系に変換を行なう。 @@ -2294,7 +2310,7 @@ lips4v_begin_image(gx_device * dev, if (index == gs_color_space_index_DeviceGray) lputs(s, "0"); else { - if (format == gs_image_format_chunky) /* RGBRGBRGB... */ + if (pim->format == gs_image_format_chunky) /* RGBRGBRGB... */ sputc(s, 0x3a); else /* RRR...GGG...BBB... */ sputc(s, 0x3b); diff --git a/contrib/opvp/gdevopvp.c b/contrib/opvp/gdevopvp.c index 439bdd704..6d9793478 100644 --- a/contrib/opvp/gdevopvp.c +++ b/contrib/opvp/gdevopvp.c @@ -268,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); @@ -321,7 +321,7 @@ opvp_initialize(gx_device *dev) 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_image, opvp_begin_image); + 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 @@ -3558,11 +3558,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, @@ -3570,7 +3570,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; @@ -3582,16 +3583,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, @@ -3600,8 +3598,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); @@ -3619,14 +3617,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 @@ -3648,26 +3642,25 @@ opvp_begin_image( } 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; } } } @@ -3680,7 +3673,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)) { @@ -3913,8 +3908,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; } } @@ -3925,8 +3919,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); } /* -- cgit v1.2.1