Example #1
0
/* Define the default implementation of ImageType 3 processing. */
static IMAGE3_MAKE_MID_PROC(make_mid_default); /* check prototype */
static int
make_mid_default(gx_device **pmidev, gx_device *dev, int width, int height,
                 gs_memory_t *mem)
{
    gx_device_memory *midev =
        gs_alloc_struct(mem, gx_device_memory, &st_device_memory,
                        "make_mid_default");
    int code;

    if (midev == 0)
        return_error(gs_error_VMerror);
    gs_make_mem_mono_device(midev, mem, NULL);
    midev->bitmap_memory = mem;
    midev->width = width;
    midev->height = height;
    check_device_separable((gx_device *)midev);
    gx_device_fill_in_procs((gx_device *)midev);
    code = dev_proc(midev, open_device)((gx_device *)midev);
    if (code < 0) {
        gs_free_object(mem, midev, "make_mid_default");
        return code;
    }
    midev->is_open = true;
    dev_proc(midev, fill_rectangle)
        ((gx_device *)midev, 0, 0, width, height, (gx_color_index)0);
    *pmidev = (gx_device *)midev;
    return 0;
}
Example #2
0
/* Initialize a RasterOp source device. */
void
gx_make_rop_texture_device(gx_device_rop_texture * dev, gx_device * target,
	     gs_logical_operation_t log_op, const gx_device_color * texture)
{
    gx_device_init((gx_device *) dev,
		   (const gx_device *)&gs_rop_texture_device,
		   NULL, true);
    gx_device_set_target((gx_device_forward *)dev, target);
    /* Drawing operations are defaulted, non-drawing are forwarded. */
    check_device_separable((gx_device *) dev);
    gx_device_fill_in_procs((gx_device *) dev);
    gx_device_copy_params((gx_device *)dev, target);
    dev->log_op = log_op;
    dev->texture = *texture;
}
Example #3
0
/*
 * Create an imdi memory device for page or band buffering,
 * possibly preceded by a plane extraction device.
 */
int
wtsimdi_create_buf_device(gx_device **pbdev, gx_device *target,
    const gx_render_plane_t *render_plane, gs_memory_t *mem, bool for_band)
{
    int plane_index = (render_plane ? render_plane->index : -1);
    int depth;
    const gx_device_memory *mdproto;
    gx_device_memory *mdev;

    if (plane_index >= 0)
        depth = render_plane->depth;
    else
        depth = target->color_info.depth;
    mdproto = gdev_mem_device_for_bits(depth);
    if (mdproto == 0)
        return_error(gs_error_rangecheck);
    if (mem) {
        mdev = gs_alloc_struct(mem, gx_device_memory, &st_device_memory,
                               "create_buf_device");
        if (mdev == 0)
            return_error(gs_error_VMerror);
    } else {
        mdev = (gx_device_memory *)*pbdev;
    }
    if (target == (gx_device *)mdev) {
        /* The following is a special hack for setting up printer devices. */
        assign_dev_procs(mdev, mdproto);
        check_device_separable((gx_device *)mdev);
        gx_device_fill_in_procs((gx_device *)mdev);
    } else
        gs_make_mem_device(mdev, mdproto, mem, (for_band ? 1 : 0),
                           (target == (gx_device *)mdev ? NULL : target));
    mdev->width = target->width;
    /*
     * The matrix in the memory device is irrelevant,
     * because all we do with the device is call the device-level
     * output procedures, but we may as well set it to
     * something halfway reasonable.
     */
    gs_deviceinitialmatrix(target, &mdev->initial_matrix);
    /****** QUESTIONABLE, BUT BETTER THAN OMITTING ******/
    mdev->color_info = target->color_info;
    *pbdev = (gx_device *)mdev;
    return 0;
}
Example #4
0
int
main(int argc, const char *argv[])
{
    char achar = '0';
    gs_memory_t *mem;

    gs_state *pgs;
    const gx_device *const *list;
    gx_device *dev;
    gx_device_bbox *bbdev;
    int code;

    gp_init();
    mem = gs_malloc_init();
    gs_lib_init1(mem);
    if (argc < 2 || (achar = argv[1][0]) < '1' ||
        achar > '0' + countof(tests) - 1
        ) {
        lprintf1("Usage: gslib 1..%c\n", '0' + (char)countof(tests) - 1);
        gs_abort(mem);
    }
    gs_debug['@'] = 1;
    gs_debug['?'] = 1;
/*gs_debug['B'] = 1; *//****** PATCH ******/
/*gs_debug['L'] = 1; *//****** PATCH ******/
    /*
     * gs_iodev_init must be called after the rest of the inits, for
     * obscure reasons that really should be documented!
     */
    gs_iodev_init(mem);
/****** WRONG ******/
    gs_lib_device_list(&list, NULL);
    gs_copydevice(&dev, list[0], mem);
    check_device_separable(dev);
    gx_device_fill_in_procs(dev);
    bbdev =
        gs_alloc_struct_immovable(mem, gx_device_bbox, &st_device_bbox,
                                  "bbox");
    gx_device_bbox_init(bbdev, dev, mem);

    code = dev_proc(dev, get_profile)(dev, &bbdev->icc_struct);
    rc_increment(bbdev->icc_struct);

    /* Print out the device name just to test the gsparam.c API. */
    {
        gs_c_param_list list;
        gs_param_string nstr;

        gs_c_param_list_write(&list, mem);
        code = gs_getdeviceparams(dev, (gs_param_list *) & list);
        if (code < 0) {
            lprintf1("getdeviceparams failed! code = %d\n", code);
            gs_abort(mem);
        }
        gs_c_param_list_read(&list);
        code = param_read_string((gs_param_list *) & list, "Name", &nstr);
        if (code < 0) {
            lprintf1("reading Name failed! code = %d\n", code);
            gs_abort(mem);
        }
        dputs("Device name = ");
        debug_print_string(nstr.data, nstr.size);
        dputs("\n");
        gs_c_param_list_release(&list);
    }
    /*
     * If this is a device that takes an OutputFile, set the OutputFile
     * to "-" in the copy.
     */
    {
        gs_c_param_list list;
        gs_param_string nstr;

        gs_c_param_list_write(&list, mem);
        param_string_from_string(nstr, "-");
        code = param_write_string((gs_param_list *)&list, "OutputFile", &nstr);
        if (code < 0) {
            lprintf1("writing OutputFile failed! code = %d\n", code);
            gs_abort(mem);
        }
        gs_c_param_list_read(&list);
        code = gs_putdeviceparams(dev, (gs_param_list *)&list);
        gs_c_param_list_release(&list);
        if (code < 0 && code != gs_error_undefined) {
            lprintf1("putdeviceparams failed! code = %d\n", code);
            gs_abort(mem);
        }
    }
    dev = (gx_device *) bbdev;
    pgs = gs_state_alloc(mem);
    gs_setdevice_no_erase(pgs, dev);	/* can't erase yet */
    {
        gs_point dpi;
        gs_screen_halftone ht;

        gs_dtransform(pgs, 72.0, 72.0, &dpi);
        ht.frequency = min(fabs(dpi.x), fabs(dpi.y)) / 16.001;
        ht.angle = 0;
        ht.spot_function = odsf;
        gs_setscreen(pgs, &ht);
    }
    /* gsave and grestore (among other places) assume that */
    /* there are at least 2 gstates on the graphics stack. */
    /* Ensure that now. */
    gs_gsave(pgs);
    gs_erasepage(pgs);

    code = (*tests[achar - '1']) (pgs, mem);
    gs_output_page(pgs, 1, 1);
    {
        gs_rect bbox;

        gx_device_bbox_bbox(bbdev, &bbox);
        dprintf4("Bounding box: [%g %g %g %g]\n",
                 bbox.p.x, bbox.p.y, bbox.q.x, bbox.q.y);
    }
    if (code)
        dprintf1("**** Test returned code = %d.\n", code);
    dputs("Done.  Press <enter> to exit.");
    fgetc(mem->gs_lib_ctx->fstdin);
    gs_lib_finit(0, 0, mem);
    return 0;
#undef mem
}
Example #5
0
/* Write the page. */
static int
pcx2up_print_page(gx_device_printer * pdev, FILE * file)
{
    gx_device_2up *pdev2 = (gx_device_2up *) pdev;
    const gx_device_printer *prdev_template =
    (const gx_device_printer *)&gs_pcx2up_device;

    if (!pdev2->have_odd_page) {	/* This is the odd page, just save it. */
        pdev2->have_odd_page = true;
        return gdev_prn_save_page(pdev, &pdev2->odd_page, 1);
    } else {			/* This is the even page, do 2-up output. */
        gx_saved_page even_page;
        gx_placed_page pages[2];
        int x_offset = (int)(pdev->HWResolution[0] * 0.5);
        int code = gdev_prn_save_page(pdev, &even_page, 1);
        int prdev_size = prdev_template->params_size;
        gx_device_printer *prdev;

#define rdev ((gx_device *)prdev)

        if (code < 0)
            return code;
        /* Create the placed page list. */
        pages[0].page = &pdev2->odd_page;
        pages[0].offset.x = x_offset;
        pages[0].offset.y = 0 /*y_offset */ ;
        pages[1].page = &even_page;
        pages[1].offset.x = pdev->width + x_offset * 3;
        pages[1].offset.y = 0 /*y_offset */ ;
        /* Create and open a device for rendering. */
        prdev = (gx_device_printer *)
            gs_alloc_bytes(pdev->memory, prdev_size,
                           "pcx2up_print_page(device)");
        if (prdev == 0)
            return_error(gs_error_VMerror);
        memcpy(prdev, prdev_template, prdev_size);
        check_device_separable((gx_device *)rdev);
        gx_device_fill_in_procs(rdev);
        set_dev_proc(prdev, open_device,
                     dev_proc(&gs_pcx256_device, open_device));
        prdev->printer_procs.print_page =
            gs_pcx256_device.printer_procs.print_page;
        prdev->space_params.band =
            pages[0].page->info.band_params;	/* either one will do */
        prdev->space_params.MaxBitmap = 0;
        prdev->space_params.BufferSpace =
            prdev->space_params.band.BandBufferSpace;
        prdev->width = prdev->space_params.band.BandWidth;
        prdev->OpenOutputFile = false;
        code = (*dev_proc(rdev, open_device)) (rdev);
        if (code < 0)
            return code;
        rdev->is_open = true;
        prdev->file = pdev->file;
        /* Render the pages. */
        code = gdev_prn_render_pages(prdev, pages, 2);
        /* Clean up. */
        if (pdev->file != 0)
            prdev->file = 0;	/* don't close it */
        gs_closedevice(rdev);
        pdev2->have_odd_page = false;
        return code;
#undef rdev
    }
}