diff options
Diffstat (limited to 'contrib/lips4/gdevl4v.c')
-rw-r--r-- | contrib/lips4/gdevl4v.c | 230 |
1 files changed, 83 insertions, 147 deletions
diff --git a/contrib/lips4/gdevl4v.c b/contrib/lips4/gdevl4v.c index 47b3fd17..1cdc17c4 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 @@ -145,7 +145,8 @@ gs_public_st_suffix_add0_final(st_device_lips4v, gx_device_lips4v, std_device_part3_() #define lips4v_device_body\ - lips_device_full_body(gx_device_lips4v, 0, "lips4v",\ + lips_device_full_body(gx_device_lips4v,\ + lips4v_initialize_device_procs, "lips4v",\ &st_device_lips4v,\ DEFAULT_WIDTH_10THS * X_DPI / 10,\ DEFAULT_HEIGHT_10THS * Y_DPI / 10,\ @@ -156,48 +157,34 @@ gs_public_st_suffix_add0_final(st_device_lips4v, gx_device_lips4v, LIPS4_RIGHT_MARGIN_DEFAULT,\ LIPS4_TOP_MARGIN_DEFAULT) -#define lips4v_procs\ - { lips4v_open,\ - gx_upright_get_initial_matrix,\ - NULL, /* sync_output */\ - lips4v_output_page,\ - lips4v_close,\ - gx_default_gray_map_rgb_color,\ - gx_default_gray_map_color_rgb,\ - gdev_vector_fill_rectangle,\ - NULL, /* tile_rectangle */\ - lips4v_copy_mono,\ - lips4v_copy_color,\ - NULL, /* draw_line */\ - NULL, /* get_bits */\ - lips4v_get_params,\ - lips4v_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 */\ - NULL, /* copy_alpha */\ - NULL, /* get_band */\ - NULL, /* copy_rop */\ - gdev_vector_fill_path,\ - gdev_vector_stroke_path,\ - lips4v_fill_mask,\ - gdev_vector_fill_trapezoid,\ - gdev_vector_fill_parallelogram,\ - gdev_vector_fill_triangle,\ - NULL /****** WRONG ******/, /* draw_thin_line */\ - lips4v_begin_image,\ - NULL,\ - NULL,\ - NULL, /* strip_tile_rectangle */\ - NULL/******strip_copy_rop******/\ - } +static void +lips4v_initialize_device_procs(gx_device *dev) +{ + set_dev_proc(dev, open_device, lips4v_open); + set_dev_proc(dev, get_initial_matrix, gx_upright_get_initial_matrix); + set_dev_proc(dev, output_page, lips4v_output_page); + set_dev_proc(dev, close_device, lips4v_close); + set_dev_proc(dev, map_rgb_color, gx_default_gray_map_rgb_color); + set_dev_proc(dev, map_color_rgb, gx_default_gray_map_color_rgb); + set_dev_proc(dev, fill_rectangle, gdev_vector_fill_rectangle); + set_dev_proc(dev, copy_mono, lips4v_copy_mono); + set_dev_proc(dev, copy_color, lips4v_copy_color); + set_dev_proc(dev, get_params, lips4v_get_params); + set_dev_proc(dev, put_params, lips4v_put_params); + set_dev_proc(dev, get_page_device, gx_page_device_get_page_device); + set_dev_proc(dev, fill_path, gdev_vector_fill_path); + set_dev_proc(dev, stroke_path, gdev_vector_stroke_path); + set_dev_proc(dev, fill_mask, lips4v_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, lips4v_begin_typed_image); + set_dev_proc(dev, get_bits_rectangle, gx_blank_get_bits_rectangle); +} gx_device_lips4v far_data gs_lips4v_device = { lips4v_device_body, - lips4v_procs, + { 0 }, vector_initial_values, LIPS_CASSETFEED_DEFAULT, LIPS_USERNAME_DEFAULT, @@ -226,7 +213,6 @@ gx_device_lips4v far_data gs_lips4v_device = { }; /* Vector device implementation */ -#if GS_VERSION_MAJOR >= 8 static int lips4v_beginpage(gx_device_vector * vdev); static int lips4v_setfillcolor(gx_device_vector * vdev, const gs_gstate * pgs, const gx_drawing_color * pdc); @@ -258,43 +244,6 @@ lips4v_closepath(gx_device_vector * vdev, double x, double y, double x_start, double y_start, gx_path_type_t type); static int lips4v_endpath(gx_device_vector * vdev, gx_path_type_t type); -#else -static int lips4v_beginpage(P1(gx_device_vector * vdev)); -static int lips4v_setfillcolor(P2(gx_device_vector * vdev, - const gx_drawing_color * pdc)); -static int lips4v_setstrokecolor(P2(gx_device_vector * vdev, - const gx_drawing_color * pdc)); -static int lips4v_setdash(P4(gx_device_vector * vdev, const float *pattern, - uint count, double offset)); -static int lips4v_setflat(P2(gx_device_vector * vdev, double flatness)); -static int -lips4v_setlogop(P3 - - (gx_device_vector * vdev, gs_logical_operation_t lop, - gs_logical_operation_t diff)); -static int - -lips4v_beginpath(P2(gx_device_vector * vdev, gx_path_type_t type)); -static int -lips4v_moveto(P6 - (gx_device_vector * vdev, double x0, double y0, double x, - double y, gx_path_type_t type)); -static int -lips4v_lineto(P6 - (gx_device_vector * vdev, double x0, double y0, double x, - double y, gx_path_type_t type)); -static int -lips4v_curveto(P10 - (gx_device_vector * vdev, double x0, double y0, double x1, - double y1, double x2, double y2, double x3, double y3, - gx_path_type_t type)); -static int -lips4v_closepath(P6 - (gx_device_vector * vdev, double x, double y, double x_start, - double y_start, gx_path_type_t type)); - -static int lips4v_endpath(P2(gx_device_vector * vdev, gx_path_type_t type)); -#endif static int lips4v_setlinewidth(gx_device_vector * vdev, double width); static int lips4v_setlinecap(gx_device_vector * vdev, gs_line_cap cap); static int lips4v_setlinejoin(gx_device_vector * vdev, gs_line_join join); @@ -311,9 +260,7 @@ static const gx_device_vector_procs lips4v_vector_procs = { lips4v_setflat, lips4v_setlogop, /* Other state */ -#if GS_VERSION_MAJOR >= 8 lips4v_can_handle_hl_color, /* can_handle_hl_color (dummy) */ -#endif lips4v_setfillcolor, /* fill & stroke colors are the same */ lips4v_setstrokecolor, /* Paths */ @@ -1070,13 +1017,8 @@ lips4v_setmiterlimit(gx_device_vector * vdev, double limit) return 0; } -#if GS_VERSION_MAJOR >= 8 static int lips4v_setfillcolor(gx_device_vector * vdev, const gs_gstate * pgs, const gx_drawing_color * pdc) -#else -static int -lips4v_setfillcolor(gx_device_vector * vdev, const gx_drawing_color * pdc) -#endif { if (!gx_dc_is_pure(pdc)) @@ -1138,13 +1080,8 @@ lips4v_setfillcolor(gx_device_vector * vdev, const gx_drawing_color * pdc) return 0; } -#if GS_VERSION_MAJOR >= 8 static int lips4v_setstrokecolor(gx_device_vector * vdev, const gs_gstate * pgs, const gx_drawing_color * pdc) -#else -static int -lips4v_setstrokecolor(gx_device_vector * vdev, const gx_drawing_color * pdc) -#endif { if (!gx_dc_is_pure(pdc)) return_error(gs_error_rangecheck); @@ -1280,7 +1217,6 @@ lips4v_setlogop(gx_device_vector * vdev, gs_logical_operation_t lop, return 0; } -#if GS_VERSION_MAJOR >= 8 /*--- added for Ghostscritp 8.15 ---*/ static int lips4v_can_handle_hl_color(gx_device_vector * vdev, const gs_gstate * pgs1, @@ -1288,7 +1224,6 @@ lips4v_can_handle_hl_color(gx_device_vector * vdev, const gs_gstate * pgs1, { return false; /* High level color is not implemented yet. */ } -#endif static int lips4v_beginpath(gx_device_vector * vdev, gx_path_type_t type) @@ -1438,21 +1373,15 @@ lips4v_open(gx_device * dev) /****** WRONG ******/ vdev->vec_procs = &lips4v_vector_procs; -#if GS_VERSION_MAJOR >= 8 - code = gdev_vector_open_file_options(vdev, 512, + code = gdev_vector_open_file_options(vdev, 512, (VECTOR_OPEN_FILE_SEQUENTIAL|VECTOR_OPEN_FILE_BBOX)); -#else - code = gdev_vector_open_file_bbox(vdev, 512, true); -#endif if (code < 0) return code; -#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 + if (pdev->bbox_device != NULL) { + if (pdev->bbox_device->memory == NULL) + pdev->bbox_device->memory = gs_memory_stable(dev->memory); + } gdev_vector_init(vdev); pdev->first_page = true; @@ -1874,11 +1803,7 @@ lips4v_copy_mono(gx_device * dev, const byte * data, gx_drawing_color dcolor; color_set_pure(&dcolor, one); -#if GS_VERSION_MAJOR >= 8 lips4v_setfillcolor(vdev, NULL, &dcolor); -#else - lips4v_setfillcolor(vdev, &dcolor); -#endif if (lips4v_copy_text_char(dev, data, raster, id, x, y, w, h) >= 0) return 0; @@ -1978,13 +1903,8 @@ lips4v_copy_mono(gx_device * dev, const byte * data, } color_set_pure(&color, one); -#if GS_VERSION_MAJOR >= 8 code = gdev_vector_update_fill_color((gx_device_vector *) pdev, NULL, &color); -#else - code = gdev_vector_update_fill_color((gx_device_vector *) pdev, - &color); -#endif } if (code < 0) return 0; @@ -2061,11 +1981,7 @@ lips4v_copy_color(gx_device * dev, /* LIPS IV ではグレースケールも単色イメージ・カラー指定命令に 影響されるので黒色を指定しなければならない。 */ color_set_pure(&dcolor, vdev->black); -#if GS_VERSION_MAJOR >= 8 lips4v_setfillcolor(vdev, NULL, &dcolor); -#else - lips4v_setfillcolor(vdev, &dcolor); -#endif } else { if (pdev->TextMode) { sputc(s, LIPS_CSI); @@ -2131,11 +2047,7 @@ lips4v_fill_mask(gx_device * dev, if (w <= 0 || h <= 0) return 0; if (depth > 1 || -#if GS_VERSION_MAJOR >= 8 gdev_vector_update_fill_color(vdev, NULL, pdcolor) < 0 || -#else - gdev_vector_update_fill_color(vdev, pdcolor) < 0 || -#endif gdev_vector_update_clip_path(vdev, pcpath) < 0 || gdev_vector_update_log_op(vdev, lop) < 0) return gx_default_fill_mask(dev, data, data_x, raster, id, @@ -2179,6 +2091,18 @@ lips4v_fill_mask(gx_device * dev, byte *buf = gs_alloc_bytes(vdev->memory, num_bytes, "lips4v_fill_mask(buf)"); + /* This code seems suspect to me; we allocate a buffer + * rounding each line up to a multiple of 4, and then + * fill it without reference to this rounding. I suspect + * that each line should be padded, rather than all the + * data being crammed at the start, but I can't make that + * change in the absence of any way to test this. I will + * make do by adding the memset here so that any untouched + * bytes are at least consistently set to 0 to avoid + * indeterminisms (and valgrind errors). RJW */ + if (width_bytes * h < num_bytes) { + memset(buf + width_bytes * h, 0, num_bytes - width_bytes * h); + } for (i = 0; i < h; ++i) { memcpy(buf + i * width_bytes, data + (data_x >> 3) + i * raster, width_bytes); @@ -2202,32 +2126,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) @@ -2266,21 +2202,19 @@ 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; /* LIPS IV ではグレースケールも単色イメージ・カラー指定命令に 影響されるので黒色を明示的に指定しなければならない。 */ color_set_pure(&dcolor, vdev->black); -#if GS_VERSION_MAJOR >= 8 lips4v_setfillcolor(vdev, NULL, &dcolor); -#else - lips4v_setfillcolor(vdev, &dcolor); -#endif } if (pim->ImageMask || (pim->BitsPerComponent == 1 && num_components == 1)) { if (pim->Decode[0] > pim->Decode[1]) @@ -2305,7 +2239,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 の座標系に変換を行なう。 @@ -2386,7 +2322,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); |