Esempio n. 1
0
static int
bbox_begin_typed_image(gx_device * dev,
		       const gs_imager_state * pis, 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 * memory, gx_image_enum_common_t ** pinfo)
{
    bbox_image_enum *pbe;
    int code =
	bbox_image_begin(pis, pmat, pic, prect, pcpath, memory, &pbe);

    if (code < 0)
	return code;
    /*
     * If there is no target, we still have to call default_begin_image
     * to get the correct num_planes and plane_depths.
     */
    {
	gx_device_bbox *const bdev = (gx_device_bbox *) dev;
	gx_device *tdev = bdev->target;
	dev_proc_begin_typed_image((*begin_typed_image));
	byte wanted[GS_IMAGE_MAX_COMPONENTS];

	if (tdev == 0) {
	    tdev = dev;
	    begin_typed_image = gx_default_begin_typed_image;
	} else {
	    begin_typed_image = dev_proc(tdev, begin_typed_image);
	}
	code = (*begin_typed_image)
	    (tdev, pis, pmat, pic, prect, pdcolor, pcpath, memory,
	     &pbe->target_info);
	if (code) {
	    bbox_image_end_image((gx_image_enum_common_t *)pbe, false);
	    return code;
	}
	/*
	 * We fill in num_planes and plane_depths later.  format is
	 * irrelevant.  NOTE: we assume that if begin_typed_image returned
	 * 0, the image is a data image.
	 */
	code = gx_image_enum_common_init((gx_image_enum_common_t *) pbe,
					 (const gs_data_image_t *)pic,
					 &bbox_image_enum_procs, dev,
					 0, gs_image_format_chunky);
	if (code < 0)
	    return code;
	bbox_image_copy_target_info(pbe);
	pbe->params_are_const =
	    gx_image_planes_wanted(pbe->target_info, wanted);
    }
    *pinfo = (gx_image_enum_common_t *) pbe;
    return 0;
}
Esempio n. 2
0
/* Initialize for enumerating an image. */
int
gdev_vector_begin_image(gx_device_vector * vdev,
                        const gs_imager_state * pis, 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, const gx_image_enum_procs_t * pprocs,
                        gdev_vector_image_enum_t * pie)
{
    const gs_color_space *pcs = pim->ColorSpace;
    int num_components;
    int bits_per_pixel;
    int code;

    if (pim->ImageMask)
        bits_per_pixel = num_components = 1;
    else
        num_components = gs_color_space_num_components(pcs),
            bits_per_pixel = pim->BitsPerComponent;
    code = gx_image_enum_common_init((gx_image_enum_common_t *) pie,
                                     (const gs_data_image_t *)pim,
                                     pprocs, (gx_device *) vdev,
                                     num_components, format);
    if (code < 0)
        return code;
    pie->bits_per_pixel = bits_per_pixel * num_components /
        pie->num_planes;
    pie->default_info = 0;
    pie->bbox_info = 0;
    if ((code = gdev_vector_update_log_op(vdev, pis->log_op)) < 0 ||
        (code = gdev_vector_update_clip_path(vdev, pcpath)) < 0 ||
        ((pim->ImageMask ||
          (pim->CombineWithColor && rop3_uses_T(pis->log_op))) &&
         (code = gdev_vector_update_fill_color(vdev, pis, pdcolor)) < 0) ||
        (vdev->bbox_device &&
         (code = (*dev_proc(vdev->bbox_device, begin_image))
          ((gx_device *) vdev->bbox_device, pis, pim, format, prect,
           pdcolor, pcpath, mem, &pie->bbox_info)) < 0)
        )
        return code;
    pie->memory = mem;
    if (prect)
        pie->width = prect->q.x - prect->p.x,
            pie->height = prect->q.y - prect->p.y;
    else
        pie->width = pim->Width, pie->height = pim->Height;
    pie->bits_per_row = pie->width * pie->bits_per_pixel;
    pie->y = 0;
    return 0;
}
Esempio n. 3
0
int
gx_begin_image3_generic(gx_device * dev,
                        const gs_imager_state *pis, 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,
                        image3_make_mid_proc_t make_mid,
                        image3_make_mcde_proc_t make_mcde,
                        gx_image_enum_common_t **pinfo)
{
    const gs_image3_t *pim = (const gs_image3_t *)pic;
    gx_image3_enum_t *penum;
    gs_int_rect mask_rect, data_rect;
    gx_device *mdev = 0;
    gx_device *pcdev = 0;
    gs_image_t i_pixel, i_mask;
    gs_matrix mi_pixel, mi_mask, mat;
    gs_rect mrect;
    gs_int_point origin;
    int code;

    /* Validate the parameters. */
    if (pim->Height <= 0 || pim->MaskDict.Height <= 0)
        return_error(gs_error_rangecheck);
    switch (pim->InterleaveType) {
        default:
            return_error(gs_error_rangecheck);
        case interleave_chunky:
            if (pim->MaskDict.Width != pim->Width ||
                pim->MaskDict.Height != pim->Height ||
                pim->MaskDict.BitsPerComponent != pim->BitsPerComponent ||
                pim->format != gs_image_format_chunky
                )
                return_error(gs_error_rangecheck);
            break;
        case interleave_scan_lines:
            if (pim->MaskDict.Height % pim->Height != 0 &&
                pim->Height % pim->MaskDict.Height != 0
                )
                return_error(gs_error_rangecheck);
            /* falls through */
        case interleave_separate_source:
            if (pim->MaskDict.BitsPerComponent != 1)
                return_error(gs_error_rangecheck);
    }
    if (!check_image3_extent(pim->ImageMatrix.xx,
                             pim->MaskDict.ImageMatrix.xx) ||
        !check_image3_extent(pim->ImageMatrix.xy,
                             pim->MaskDict.ImageMatrix.xy) ||
        !check_image3_extent(pim->ImageMatrix.yx,
                             pim->MaskDict.ImageMatrix.yx) ||
        !check_image3_extent(pim->ImageMatrix.yy,
                             pim->MaskDict.ImageMatrix.yy)
        )
        return_error(gs_error_rangecheck);
    if ((code = gs_matrix_invert(&pim->ImageMatrix, &mi_pixel)) < 0 ||
        (code = gs_matrix_invert(&pim->MaskDict.ImageMatrix, &mi_mask)) < 0
        )
        return code;
    if (fabs(mi_pixel.tx - mi_mask.tx) >= 0.5 ||
        fabs(mi_pixel.ty - mi_mask.ty) >= 0.5
        )
        return_error(gs_error_rangecheck);
#ifdef DEBUG
    {
        /* Although the PLRM says that the Mask and Image *must* be the same size,  */
        /* Adobe CPSI (and other RIPS) ignore this and process anyway. Note that we */
        /* are not compatible if the Mask Height than the Data (pixel) Height. CPSI */
        /* de-interleaves the mask from the data image and stops at the Mask Height */
        /* Problem detected with Genoa 468-03 (part of file 468-01.ps)              */
        /*****           fixme: When Data Image Height > Mask Height            *****/
        gs_point ep, em;

        if ((code = gs_point_transform(pim->Width, pim->Height, &mi_pixel,
                                       &ep)) < 0 ||
            (code = gs_point_transform(pim->MaskDict.Width,
                                       pim->MaskDict.Height, &mi_mask,
                                       &em)) < 0
            )
            return code;
        if (fabs(ep.x - em.x) >= 0.5 || fabs(ep.y - em.y) >= 0.5)
            code = gs_error_rangecheck;	/* leave the check in for debug breakpoint */
    }
#endif /* DEBUG */
    penum = gs_alloc_struct(mem, gx_image3_enum_t, &st_image3_enum,
                            "gx_begin_image3");
    if (penum == 0)
        return_error(gs_error_VMerror);
    penum->num_components =
        gs_color_space_num_components(pim->ColorSpace);
    gx_image_enum_common_init((gx_image_enum_common_t *) penum,
                              (const gs_data_image_t *)pim,
                              &image3_enum_procs, dev,
                              1 + penum->num_components,
                              pim->format);
    /* Initialize pointers now in case we bail out. */
    penum->mask_data = 0;
    penum->pixel_data = 0;
    if (prect) {
        long lmw = pim->MaskDict.Width, lmh = pim->MaskDict.Height;

        data_rect = *prect;
        mask_rect.p.x = (int)(data_rect.p.x * lmw / pim->Width);
        mask_rect.p.y = (int)(data_rect.p.y * lmh / pim->Height);
        mask_rect.q.x = (int)((data_rect.q.x + pim->Width - 1) * lmw /
                              pim->Width);
        mask_rect.q.y = (int)((data_rect.q.y + pim->Height - 1) * lmh /
                              pim->Height);
    } else {
        mask_rect.p.x = mask_rect.p.y = 0;
        mask_rect.q.x = pim->MaskDict.Width;
        mask_rect.q.y = pim->MaskDict.Height;
        data_rect.p.x = data_rect.p.y = 0;
        data_rect.q.x = pim->Width;
        data_rect.q.y = pim->Height;
    }
    penum->mask_width = mask_rect.q.x - mask_rect.p.x;
    penum->mask_height = mask_rect.q.y - mask_rect.p.y;
    penum->mask_full_height = pim->MaskDict.Height;
    penum->mask_y = 0;
    penum->mask_skip = 0;
    penum->pixel_width = data_rect.q.x - data_rect.p.x;
    penum->pixel_height = data_rect.q.y - data_rect.p.y;
    penum->pixel_full_height = pim->Height;
    penum->pixel_y = 0;
    penum->mask_info = 0;
    penum->pixel_info = 0;
    if (pim->InterleaveType == interleave_chunky) {
        /* Allocate row buffers for the mask and pixel data. */
        penum->pixel_data =
            gs_alloc_bytes(mem,
                           (penum->pixel_width * pim->BitsPerComponent *
                            penum->num_components + 7) >> 3,
                           "gx_begin_image3(pixel_data)");
        penum->mask_data =
            gs_alloc_bytes(mem, (penum->mask_width + 7) >> 3,
                           "gx_begin_image3(mask_data)");
        if (penum->pixel_data == 0 || penum->mask_data == 0) {
            code = gs_note_error(gs_error_VMerror);
            goto out1;
        }
    }