Example #1
0
/* Send the page to the printer.  Compress each scan line.  NB - the
 * render mode as well as color parameters - bpp etc. are all
 * hardwired.
 */
static int
cljc_print_page(gx_device_printer * pdev, FILE * prn_stream)
{
    gs_memory_t *mem = pdev->memory;
    uint raster = gx_device_raster((gx_device *)pdev, false);
    int i;
    int worst_case_comp_size = raster + (raster / 8) + 1;
    byte *data = 0;
    byte *cdata = 0;
    byte *prow = 0;
    int code = 0;

    /* allocate memory for the raw data and compressed data.  */
    if (((data = gs_alloc_bytes(mem, raster, "cljc_print_page(data)")) == 0) ||
        ((cdata = gs_alloc_bytes(mem, worst_case_comp_size, "cljc_print_page(cdata)")) == 0) ||
        ((prow = gs_alloc_bytes(mem, worst_case_comp_size, "cljc_print_page(prow)")) == 0)) {
        code = gs_note_error(gs_error_VMerror);
        goto out;
    }
    /* send a reset and the the paper definition */
    fprintf(prn_stream, "\033E\033&u300D\033&l%dA",
            gdev_pcl_paper_size((gx_device *) pdev));
    /* turn off source and pattern transparency */
    fprintf(prn_stream, "\033*v1N\033*v1O");
    /* set color render mode and the requested resolution */
    fprintf(prn_stream, "\033*t4J\033*t%dR", (int)(pdev->HWResolution[0]));
    /* set up the color model - NB currently hardwired to direct by
       pixel which requires 8 bits per component.  See PCL color
       technical reference manual for other possible encodings. */
    fprintf(prn_stream, "\033*v6W%c%c%c%c%c%c", 0, 3, 0, 8, 8, 8);
    /* set up raster width and height, compression mode 3 */
    fprintf(prn_stream, "\033&l0e-180u36Z\033*p0x0Y\033*r1A\033*b3M");
    /* initialize the seed row */
    memset(prow, 0, worst_case_comp_size);
    /* process each scanline */
    for (i = 0; i < pdev->height; i++) {
        int compressed_size;

        code = gdev_prn_copy_scan_lines(pdev, i, (byte *) data, raster);
        if (code < 0)
            break;
        compressed_size = gdev_pcl_mode3compress(raster, data, prow, cdata);
        fprintf(prn_stream, "\033*b%dW", compressed_size);
        fwrite(cdata, sizeof(byte), compressed_size, prn_stream);
    }
    /* PCL will take care of blank lines at the end */
    fputs("\033*rC\f", prn_stream);
out:
    gs_free_object(mem, prow, "cljc_print_page(prow)");
    gs_free_object(mem, cdata, "cljc_print_page(cdata)");
    gs_free_object(mem, data, "cljc_print_page(data)");
    return code;
}
Example #2
0
/* If fname==0, set up stream, and buffer. */
int
file_prepare_stream(const char *fname, uint len, const char *file_access, 
		 uint buffer_size, stream ** ps, char fmode[4], gs_memory_t *mem)
{
    byte *buffer;
    register stream *s;

    /* Open the file, always in binary mode. */
    strcpy(fmode, file_access);
    strcat(fmode, gp_fmode_binary_suffix);
    if (buffer_size == 0)
	buffer_size = file_default_buffer_size;
    if (len >= buffer_size)    /* we copy the file name into the buffer */
	return_error(gs_error_limitcheck);
    /* Allocate the stream first, since it persists */
    /* even after the file has been closed. */
    s = file_alloc_stream(mem, "file_prepare_stream");
    if (s == 0)
	return_error(gs_error_VMerror);
    /* Allocate the buffer. */
    buffer = gs_alloc_bytes(mem, buffer_size, "file_prepare_stream(buffer)");
    if (buffer == 0)
	return_error(gs_error_VMerror);
    if (fname != 0) {
	memcpy(buffer, fname, len);
	buffer[len] = 0;	/* terminate string */
    } else
	buffer[0] = 0;	/* safety */
    s->cbuf = buffer;
    s->bsize = s->cbsize = buffer_size;
    *ps = s;
    return 0;
}
Example #3
0
static int
stderr_open(gx_io_device * iodev, const char *access, stream ** ps,
	    gs_memory_t * mem)
{
    i_ctx_t *i_ctx_p = (i_ctx_t *)iodev->state;	/* see above */
    stream *s;

    if (!streq1(access, 'w'))
	return_error(e_invalidfileaccess);
    if (file_is_invalid(s, &ref_stderr)) {
	gs_memory_t *mem = imemory_system;
	byte *buf;

	s = file_alloc_stream(mem, "stderr_open(stream)");
	buf = gs_alloc_bytes(mem, STDERR_BUF_SIZE, "stderr_open(buffer)");
	if (s == 0 || buf == 0)
	    return_error(e_VMerror);
	swrite_file(s, gs_stderr, buf, STDERR_BUF_SIZE);
	s->save_close = s->procs.flush;
	s->procs.close = file_close_file;
	make_file(&ref_stderr, a_write | avm_system, s->write_id, s);
	*ps = s;
	return 1;
    }
    *ps = s;
    return 0;
}
Example #4
0
/* This routine is used for all non-separated formats. */
static int
bmp_print_page(gx_device_printer * pdev, FILE * file)
{
    uint raster = gdev_prn_raster(pdev);
    /* BMP scan lines are padded to 32 bits. */
    uint bmp_raster = raster + (-(int)raster & 3);
    byte *row = gs_alloc_bytes(pdev->memory, bmp_raster, "bmp file buffer");
    int y;
    int code;		/* return code */

    if (row == 0)		/* can't allocate row buffer */
	return_error(gs_error_VMerror);
    memset(row+raster, 0, bmp_raster - raster); /* clear the padding bytes */

    /* Write the file header. */

    code = write_bmp_header(pdev, file);
    if (code < 0)
	goto done;

    /* Write the contents of the image. */
    /* BMP files want the image in bottom-to-top order! */

    for (y = pdev->height - 1; y >= 0; y--) {
	gdev_prn_copy_scan_lines(pdev, y, row, raster);
	fwrite((const char *)row, bmp_raster, 1, file);
    }

done:
    gs_free_object(pdev->memory, row, "bmp file buffer");

    return code;
}
Example #5
0
/* Return 0 if we used the default implementation, 1 if not. */
int
gdev_vector_end_image(gx_device_vector * vdev,
         gdev_vector_image_enum_t * pie, bool draw_last, gx_color_index pad)
{
    int code;

    if (pie->default_info) {
        code = gx_default_end_image((gx_device *) vdev, pie->default_info,
                                    draw_last);
        if (code >= 0)
            code = 0;
    } else {			/* Fill out to the full image height. */
        if (pie->y < pie->height && pad != gx_no_color_index) {
            uint bytes_per_row = (pie->bits_per_row + 7) >> 3;
            byte *row = gs_alloc_bytes(pie->memory, bytes_per_row,
                                       "gdev_vector_end_image(fill)");

            if (row == 0)
                return_error(gs_error_VMerror);
/****** FILL VALUE IS WRONG ******/
            memset(row, (byte) pad, bytes_per_row);
            for (; pie->y < pie->height; pie->y++)
                gx_image_data((gx_image_enum_common_t *) pie,
                              (const byte **)&row, 0,
                              bytes_per_row, 1);
            gs_free_object(pie->memory, row,
                           "gdev_vector_end_image(fill)");
        }
        code = 1;
    }
Example #6
0
/* Allocate & Init a monitor */
gx_monitor_t *			/* returns a new monitor, 0 if error */
gx_monitor_alloc(
                    gs_memory_t * memory	/* memory allocator to use */
)
{
    gx_monitor_t *mon;

    /* sizeof decl'd mon struct, minus monitor placeholder's size, + actual monitor size */
    unsigned monSizeof
    = sizeof(*mon) - sizeof(mon->native) + gp_monitor_sizeof();

    if (gp_monitor_open(0) == 0)	/* see if gp_monitors are movable */
        /* movable */
        mon = (gx_monitor_t *) gs_alloc_bytes(memory, monSizeof,
                                              "gx_monitor (create)");
    else
        /* unmovable */
        mon = (gx_monitor_t *) gs_alloc_bytes_immovable(memory, monSizeof,
                                                     "gx_monitor (create)");
    if (mon == 0)
        return 0;

    /* Make monitor remember which allocator was used to allocate it */
    mon->memory = memory;

    if (gp_monitor_open(&mon->native) < 0) {
        gs_free_object(memory, mon, "gx_monitor (alloc)");
        return 0;
    }
    return mon;
}
Example #7
0
/* Allocate & initialize a semaphore */
gx_semaphore_t *		/* returns a new semaphore, 0 if error */
gx_semaphore_alloc(
                      gs_memory_t * memory	/* memory allocator to use */
)
{
    gx_semaphore_t *sema;

    /* sizeof decl'd sema struct, minus semaphore placeholder's size, + actual semaphore size */
    unsigned semaSizeof
    = sizeof(*sema) - sizeof(sema->native) + gp_semaphore_sizeof();

    if (gp_semaphore_open(0) == 0)	/* see if gp_semaphores are movable */
        /* movable */
        sema = (gx_semaphore_t *) gs_alloc_bytes(memory, semaSizeof,
                                                 "gx_semaphore (create)");
    else
        /* unmovable */
        sema = (gx_semaphore_t *) gs_alloc_bytes_immovable(memory, semaSizeof,
                                                   "gx_semaphore (create)");
    if (sema == 0)
        return 0;

    /* Make sema remember which allocator was used to allocate it */
    sema->memory = memory;

    if (gp_semaphore_open(&sema->native) < 0) {
        gs_free_object(memory, sema, "gx_semaphore (alloc)");
        return 0;
    }
    return sema;
}
Example #8
0
/* Get the nth colorant name in the clrt tag */
char*
gscms_get_clrtname(gcmmhprofile_t profile, int colorcount, gs_memory_t *memory)
{
    cmsNAMEDCOLORLIST *lcms_names;
    char name[256];
    char *buf;
    int length;

    lcms_names = (cmsNAMEDCOLORLIST *)cmsReadTag(profile,
                 cmsSigColorantTableTag);
    if (colorcount >= cmsNamedColorCount(lcms_names)) return(NULL);
    if (cmsNamedColorInfo(lcms_names,
                          colorcount,
                          name,
                          NULL,
                          NULL,
                          NULL,
                          NULL) == 0)
        return NULL;
    length = strlen(name);
    buf = (char*) gs_alloc_bytes(memory, length + 1, "gscms_get_clrtname");
    if (buf)
        strcpy(buf, name);
    return buf;
}
Example #9
0
int gs_jpeg_mem_init (gs_memory_t *mem, j_common_ptr cinfo)
{
    int code = 0;
#if SHARE_JPEG == 0
    jpeg_cust_mem_data custm, *custmptr;

    memset(&custm, 0x00, sizeof(custm));

    if (!jpeg_cust_mem_init(&custm, (void *) mem, gs_j_mem_init, gs_j_mem_term, NULL,
                            gs_j_mem_alloc, gs_j_mem_free,
                            gs_j_mem_alloc, gs_j_mem_free, NULL)) {
        code = gs_note_error(gs_error_VMerror);
    }
    if (code == 0) {
        custmptr = (jpeg_cust_mem_data *)gs_alloc_bytes(mem->non_gc_memory, sizeof(custm) + sizeof(void *), "JPEG custom memory descriptor");
        if (!custmptr) {
            code = gs_note_error(gs_error_VMerror);
        }
        else {
            memcpy(custmptr, &custm, sizeof(custm));
            cinfo->client_data = custmptr;
        }
    }
#endif /* SHAREJPEG == 0 */
    return code;
}
Example #10
0
static void *
jpeg_alloc(j_common_ptr cinfo, size_t size, const char *info)
{
    gs_memory_t *mem = cinfo2jcd(cinfo)->cmem;

    return(gs_alloc_bytes(mem, size, info));
}
Example #11
0
static int
stdin_open(gx_io_device * iodev, const char *access, stream ** ps,
	   gs_memory_t * mem)
{
    i_ctx_t *i_ctx_p = (i_ctx_t *)iodev->state;	/* see above */
    stream *s;

    if (!streq1(access, 'r'))
	return_error(e_invalidfileaccess);
    if (file_is_invalid(s, &ref_stdin)) {
	/****** stdin SHOULD NOT LINE-BUFFER ******/
	gs_memory_t *mem = imemory_system;
	byte *buf;

	s = file_alloc_stream(mem, "stdin_open(stream)");
	/* We want stdin to read only one character at a time, */
	/* but it must have a substantial buffer, in case it is used */
	/* by a stream that requires more than one input byte */
	/* to make progress. */
	buf = gs_alloc_bytes(mem, STDIN_BUF_SIZE, "stdin_open(buffer)");
	if (s == 0 || buf == 0)
	    return_error(e_VMerror);
	sread_file(s, gs_stdin, buf, STDIN_BUF_SIZE);
	s->procs.process = s_stdin_read_process;
	s->save_close = s_std_null;
	s->procs.close = file_close_file;
	make_file(&ref_stdin, a_readonly | avm_system, s->read_id, s);
	*ps = s;
	return 1;
    }
    *ps = s;
    return 0;
}
Example #12
0
/* Sets/Gets the string containing the list of default devices we should try */
int
gs_lib_ctx_set_default_device_list(const gs_memory_t *mem, const char* dev_list_str,
                        int list_str_len)
{
    char *result;
    gs_lib_ctx_t *p_ctx = mem->gs_lib_ctx;
    gs_memory_t *ctx_mem = p_ctx->memory;
    int code = 0;
    
    result = (char *)gs_alloc_bytes(ctx_mem, list_str_len + 1,
             "gs_lib_ctx_set_default_device_list");

    if (result) {
      gs_free_object(ctx_mem, p_ctx->default_device_list,
                "gs_lib_ctx_set_default_device_list");

      memcpy(result, dev_list_str, list_str_len);
      result[list_str_len] = '\0';
      p_ctx->default_device_list = result;
    }
    else {
        code = gs_note_error(gs_error_VMerror);
    }
    return code;
}
Example #13
0
/*  This sets the directory to prepend to the ICC profile names specified for
    defaultgray, defaultrgb, defaultcmyk, proofing, linking, named color and device */
void
gs_lib_ctx_set_icc_directory(const gs_memory_t *mem_gc, const char* pname,
                        int dir_namelen)
{
    char *result;
    gs_lib_ctx_t *p_ctx = mem_gc->gs_lib_ctx;

    /* If it is already set and the incoming is the default then don't set
       as we are coming from a VMreclaim which is trying to reset the user
       parameter */
    if (p_ctx->profiledir != NULL && strcmp(pname,DEFAULT_DIR_ICC) == 0) {
        return;
    }
    if (p_ctx->profiledir_len > 0) {
        if (strncmp(pname, p_ctx->profiledir, p_ctx->profiledir_len) == 0) {
            return;
        }
        gs_free_object(mem_gc->non_gc_memory, p_ctx->profiledir,
                       "gsicc_set_icc_directory");
    }
    /* User param string.  Must allocate in non-gc memory */
    result = (char*) gs_alloc_bytes(mem_gc->non_gc_memory, dir_namelen+1,
                                     "gsicc_set_icc_directory");
    if (result != NULL) {
        strcpy(result, pname);
        p_ctx->profiledir = result;
        p_ctx->profiledir_len = dir_namelen;
    }
}
Example #14
0
/* Define allocator procedures for the CGM library. */
static void *
cgm_gs_alloc(void *private_data, uint size)
{
    gx_device_cgm *cdev = private_data;

    return gs_alloc_bytes(cdev->memory, size, "cgm_gs_alloc");
}
Example #15
0
/* Add a command to the DL table - pen up or pen down coordinates.
   Resizing the table as appropriate. */
static int
hpgl_add_dl_char_data(hpgl_state_t * pgls, hpgl_dl_cdata_t * pcdata,
                      short cc_data)
{
    /* characters stored as short */
    int csz = sizeof(short);

    if (pcdata->index == -1) {
        /* first element - allocate a small array which will be resized as needed */
        pcdata->data =
            (short *)gs_alloc_bytes(pgls->memory, 2 * csz, "DL data");
        if (pcdata->data == 0)
            return e_Memory;
    } else if (gs_object_size(pgls->memory, pcdata->data) ==
               (pcdata->index + 1) * csz) {
        /* new character doesn't fit - double the size of the array */
        short *new_cdata =
            (short *)gs_resize_object(pgls->memory, pcdata->data,
                                      (pcdata->index + 1) * csz * 2,
                                      "DL data resize");

        if (new_cdata == 0) {
            return e_Memory;
        }
        pcdata->data = new_cdata;
    }
    pcdata->data[++pcdata->index] = cc_data;
    return 0;
}
Example #16
0
gslt_font_t *
gslt_new_font(gs_memory_t *mem, gs_font_dir *fontdir, char *buf, int buflen, int subfontid)
{
    gslt_font_t *xf;
    int t;

    xf = (void*) gs_alloc_bytes(mem, sizeof(gslt_font_t), "gslt_font struct");
    if (!xf)
    {
        gs_throw(-1, "out of memory");
        return NULL;
    }

    xf->data = (byte*)buf;
    xf->length = buflen;
    xf->font = NULL;

    xf->subfontid = subfontid;
    xf->cmaptable = 0;
    xf->cmapsubcount = 0;
    xf->cmapsubtable = 0;
    xf->usepua = 0;

    xf->cffdata = 0;
    xf->cffend = 0;
    xf->gsubrs = 0;
    xf->subrs = 0;
    xf->charstrings = 0;

    if (memcmp(xf->data, "OTTO", 4) == 0)
	t = gslt_init_postscript_font(mem, fontdir, xf);
    else if (memcmp(xf->data, "\0\1\0\0", 4) == 0)
	t = gslt_init_truetype_font(mem, fontdir, xf);
    else if (memcmp(xf->data, "true", 4) == 0)
	t = gslt_init_truetype_font(mem, fontdir, xf);
    else if (memcmp(xf->data, "ttcf", 4) == 0)
	t = gslt_init_truetype_font(mem, fontdir, xf);
    else
    {
        gslt_free_font(mem, xf);
	gs_throw(-1, "not an opentype font");
	return NULL;
    }

    if (t < 0)
    {
        gslt_free_font(mem, xf);
        gs_rethrow(-1, "cannot init font");
        return NULL;
    }

    t = gslt_load_sfnt_cmap(xf);
    if (t < 0)
    {
        errprintf("warning: no cmap table found in font\n");
    }

    return xf;
}
Example #17
0
void* _cmsMalloc(unsigned int size)
{
#if defined(SHARE_LCMS) && SHARE_LCMS==1
    return malloc(size);
#else
    return gs_alloc_bytes(gs_lib_ctx_get_non_gc_memory_t(), size, "lcms");
#endif
}
Example #18
0
void* _cmsMalloc(unsigned int size)
{
    void *ptr;

    ptr = gs_alloc_bytes(gs_lib_ctx_get_non_gc_memory_t(), size, "lcms");
    gs_warn2("lcms malloc (%d) at 0x%x",size,ptr);
    return ptr;
}
Example #19
0
file_enum *
gp_enumerate_files_init (const char *pat, uint patlen, gs_memory_t *memory)

{	file_enum *pfen =
                (file_enum *)gs_alloc_bytes(memory, sizeof(file_enum), "gp_enumerate_files");
        char *pattern;
        if ( pfen == 0 ) return 0;
        pattern =
                (char *)gs_alloc_bytes(memory, patlen + 1, "gp_enumerate_files(pattern)");
        if ( pattern == 0 ) return 0;
        memcpy(pattern, pat, patlen);
        pattern[patlen] = 0;
        pfen->pattern = pattern;
        pfen->memory = memory;
        pfen->first_time = 1;
        return pfen;
}
Example #20
0
int
pdf_replace_names(gx_device_pdf * pdev, const gs_param_string * from,
		  gs_param_string * to)
{
    const byte *start = from->data;
    const byte *end = start + from->size;
    const byte *scan;
    uint size = 0;
    cos_object_t *pco;
    bool any = false;
    byte *sto;
    char ref[1 + 10 + 5 + 1];	/* max obj number is 10 digits */

    /* Do a first pass to compute the length of the result. */
    for (scan = start; scan < end;) {
	const byte *sname;
	const byte *next =
	    pdfmark_next_object(scan, end, &sname, &pco, pdev);

	size += sname - scan;
	if (pco) {
	    sprintf(ref, " %ld 0 R ", pco->id);
	    size += strlen(ref);
	}
	scan = next;
	any |= next != sname;
    }
    to->persistent = true;	/* ??? */
    if (!any) {
	to->data = start;
	to->size = size;
	return 0;
    }
    sto = gs_alloc_bytes(pdev->pdf_memory, size, "pdf_replace_names");
    if (sto == 0)
	return_error(gs_error_VMerror);
    to->data = sto;
    to->size = size;
    /* Do a second pass to do the actual substitutions. */
    for (scan = start; scan < end;) {
	const byte *sname;
	const byte *next =
	    pdfmark_next_object(scan, end, &sname, &pco, pdev);
	uint copy = sname - scan;
	int rlen;

	memcpy(sto, scan, copy);
	sto += copy;
	if (pco) {
	    sprintf(ref, " %ld 0 R ", pco->id);
	    rlen = strlen(ref);
	    memcpy(sto, ref, rlen);
	    sto += rlen;
	}
	scan = next;
    }
    return 0;
}
Example #21
0
/* DL [Character Code, Coords] */
int
hpgl_DL(hpgl_args_t * pargs, hpgl_state_t * pgls)
{
    int code;
    hpgl_dl_cdata_t *cdata;

    /* first call */
    if (pargs->phase == 0) {
        int32 cc;

        /* double byte characters are not yet supported */
        if (pgls->g.label.double_byte)
            return e_Unimplemented;
        /* parse the character code, no arguments clears all defined
           characters */
        if (!hpgl_arg_c_int(pgls->memory, pargs, &cc)) {
            hpgl_clear_dl_chars(pgls);
            return 0;
        }

        if (cc < 0 || cc > 255)
            return e_Range;

        cdata =
            (hpgl_dl_cdata_t *) gs_alloc_bytes(pgls->memory,
                                               sizeof(hpgl_dl_cdata_t),
                                               "DL header");
        if (cdata == 0)
            return e_Memory;
        cdata->index = -1;
        cdata->data = NULL;
        id_set_value(pgls->g.current_dl_char_id, (ushort) cc);
        pl_dict_put(&pgls->g.dl_531_fontdict,
                    id_key(pgls->g.current_dl_char_id), 2, cdata);
        hpgl_args_init(pargs);
        pargs->phase = 1;
    }

    if (!pl_dict_find
        (&pgls->g.dl_531_fontdict, id_key(pgls->g.current_dl_char_id), 2,
         (void **)&cdata))
        /* this should be a failed assertion */
        return -1;
    do {
        int c;

        if (!hpgl_arg_c_int(pgls->memory, pargs, &c))
            break;
        code = hpgl_add_dl_char_data(pgls, cdata, c);
        if (code < 0) {
            pl_dict_undef(&pgls->g.dl_531_fontdict,
                          id_key(pgls->g.current_dl_char_id), 2);
            return code;
        }
        hpgl_args_init(pargs);
    } while (1);
    return 0;
}
Example #22
0
/* The file device procedures */
static int
mswin_printer_init(gx_io_device * iodev, gs_memory_t * mem)
{
    /* state -> structure containing thread handle */
    iodev->state = gs_alloc_bytes(mem, sizeof(tid_t), "mswin_printer_init");
    if (iodev->state == NULL)
        return_error(gs_error_VMerror);
    ((tid_t *)iodev->state)->tid = -1;
    return 0;
}
Example #23
0
/* RJW: Does too. The opendevice call at the end calls clist_open */
static int
do_page_save(gx_device_printer * pdev, gx_saved_page * page, clist_file_ptr *save_files)
{
    gx_device_clist *cdev = (gx_device_clist *) pdev;
    gx_device_clist_writer * const pcldev = (gx_device_clist_writer *)pdev;
    int code;
    gs_c_param_list paramlist;

    /* Save the device information. */
    strncpy(page->dname, pdev->dname, sizeof(page->dname));
    page->color_info = pdev->color_info;
    page->io_procs = cdev->common.page_info.io_procs;
    /* Save the page information. */
    strncpy(page->cfname, pcldev->page_info.cfname, sizeof(page->cfname));
    strncpy(page->bfname, pcldev->page_info.bfname, sizeof(page->bfname));
    page->bfile_end_pos = pcldev->page_info.bfile_end_pos;
    if (save_files != NULL) {
      save_files[0] =  pcldev->page_info.cfile;
      save_files[1] =  pcldev->page_info.bfile;
      pcldev->page_info.cfile = NULL;
      pcldev->page_info.bfile = NULL;
    }
    pcldev->page_info.cfname[0] = 0;
    pcldev->page_info.bfname[0] = 0;
    page->tile_cache_size = pcldev->page_info.tile_cache_size;
    page->band_params = pcldev->page_info.band_params;
    /* Now serialize and save the rest of the information from the device params */
    /* we count on this to correctly set the color_info, devn_params and icc_struct */
    page->mem = pdev->memory->non_gc_memory;
    gs_c_param_list_write(&paramlist, pdev->memory);
    if ((code = gs_getdeviceparams((gx_device *)pdev, (gs_param_list *)&paramlist)) < 0) {
        goto params_out;
    }
    /* fetch bytes needed for param list */
    gs_c_param_list_read(&paramlist);
    if ((code = gs_param_list_serialize((gs_param_list *)&paramlist, NULL, 0)) < 0) {
        goto params_out;
    }
    page->paramlist_len = code;
    if ((page->paramlist = gs_alloc_bytes(page->mem,
                                           page->paramlist_len,
                                           "saved_page paramlist")) == NULL) {
        goto params_out;
    }
    code = gs_param_list_serialize((gs_param_list *)&paramlist, page->paramlist,
                                   page->paramlist_len);
params_out:
    gs_c_param_list_release(&paramlist);
    if (code < 0)
        return code;			/* all device param errors collect here */

    /* Save other information. */
    /* Now re-open the clist device so that we get new files for the next page */
    return (*gs_clist_device_procs.open_device) ((gx_device *) pdev);
}
Example #24
0
/*
 * Add a new saved page to the end of an in memory list. Refer to the
 * documentation for gx_saved_pages_list. This allocates the saved_
 * page as well as the saved_pages_list_element and relies on the
 * gdev_prn_save_page to use non_gc_memory since this list is never
 * in GC memory.
 */
int
gx_saved_pages_list_add(gx_device_printer * pdev)
{
    gx_saved_pages_list *list = pdev->saved_pages_list;
    gx_saved_pages_list_element *new_list_element;
    gx_saved_page *newpage;
    int code;

    if ((newpage =
         (gx_saved_page *)gs_alloc_bytes(list->mem,
                                         sizeof(gx_saved_page),
                                         "gx_saved_pages_list_add")) == NULL)
        return_error (gs_error_VMerror);

    if ((new_list_element =
         (gx_saved_pages_list_element *)gs_alloc_bytes(list->mem,
                                                      sizeof(gx_saved_pages_list_element),
                                                      "gx_saved_pages_list_add")) == NULL) {
        gs_free_object(list->mem, newpage, "gx_saved_pages_list_add");
        return_error (gs_error_VMerror);
    }

    if ((code = gdev_prn_save_page(pdev, newpage)) < 0) {
        gs_free_object(list->mem, new_list_element, "gx_saved_pages_list_add");
        gs_free_object(list->mem, newpage, "gx_saved_pages_list_add");
        return code;
    }
    new_list_element->sequence_number = ++list->count;
    new_list_element->page = newpage;
    new_list_element->next = NULL;
    if (list->tail == NULL) {
        /* list was empty, start it */
        new_list_element->prev = NULL;
        list->head = list->tail = new_list_element;
    } else {
        /* place as new tail */
        new_list_element->prev = list->tail;
        list->tail->next = new_list_element;
        list->tail = new_list_element;
    }
    return 0;			/* success */
}
Example #25
0
ClapTrap *ClapTrap_Init(gs_memory_t     *mem,
                        int              width,
                        int              height,
                        int              num_comps,
                        const int       *comp_order,
                        int              max_x_offset,
                        int              max_y_offset,
                        ClapTrap_LineFn *get_line,
                        void            *get_line_arg)
{
    ClapTrap *ct;

    ct = (ClapTrap *)gs_alloc_bytes(mem, sizeof(*ct), "ClapTrap");
    if (ct == NULL)
        return NULL;

    ct->width        = width;
    ct->height       = height;
    ct->num_comps    = num_comps;
    ct->comp_order   = comp_order;
    ct->max_x_offset = max_x_offset;
    ct->max_y_offset = max_y_offset;
    ct->get_line     = get_line;
    ct->get_line_arg = get_line_arg;
    ct->lines_in_buf = max_y_offset * 2 + 1;
    ct->lines_read   = 0;
    ct->y            = 0;
    ct->span         = width * num_comps;

    ct->linebuf      = gs_alloc_bytes(mem, ct->span * ct->lines_in_buf, "ClapTrap linebuf");
    ct->process      = gs_alloc_bytes(mem, ct->width * ct->lines_in_buf, "ClapTrap process");
    if (ct->linebuf == NULL || ct->process == NULL)
    {
        gs_free_object(mem, ct->linebuf, "ClapTrap linebuf");
        gs_free_object(mem, ct->process, "ClapTrap process");
        gs_free_object(mem, ct, "ClapTrap");
        return NULL;
    }

    return ct;
}
Example #26
0
/* Copy an argument string to the heap. */
char *
arg_copy(const char *str, gs_memory_t * mem)
{
    char *sstr = (char *)gs_alloc_bytes(mem, strlen(str) + 1, "arg_copy");

    if (sstr == 0) {
        lprintf("Out of memory!\n");
        return NULL;
    }
    strcpy(sstr, str);
    return sstr;
}
Example #27
0
/* The file device procedures */
static int
os2_printer_init(gx_io_device * iodev, gs_memory_t * mem)
{
    /* state -> structure containing thread handle */
    iodev->state = gs_alloc_bytes(mem, sizeof(os2_printer_t),
                                  "os2_printer_init");
    if (iodev->state == NULL)
        return_error(gs_error_VMerror);
    memset(iodev->state, 0, sizeof(os2_printer_t));
    iodev->state->memory = mem;
    return 0;
}
Example #28
0
void* _cmsMalloc(unsigned int size)
{
    void *ptr;

#if defined(SHARE_LCMS) && SHARE_LCMS==1
    ptr = malloc(size);
#else
    ptr = gs_alloc_bytes(gs_lib_ctx_get_non_gc_memory_t(), size, "lcms");
#endif
    gs_warn2("lcms malloc (%d) at 0x%x",size,ptr);
    return ptr;
}
Example #29
0
/* Initialize CCITTFaxDecode filter */
static int
s_CFD_init(stream_state * st)
{
    stream_CFD_state *const ss = (stream_CFD_state *) st;
    int raster = ss->raster =
        ROUND_UP((ss->Columns + 7) >> 3, ss->DecodedByteAlign);
    byte white = (ss->BlackIs1 ? 0 : 0xff);

    s_hcd_init_inline(ss);
    /* Because skip_white_pixels can look as many as 4 bytes ahead, */
    /* we need to allow 4 extra bytes at the end of the row buffers. */
    ss->lbuf = gs_alloc_bytes(st->memory, raster + CFD_BUFFER_SLOP, "CFD lbuf");
    ss->lprev = 0;
    if (ss->lbuf == 0)
        return ERRC;		/****** WRONG ******/
    memset(ss->lbuf, white, raster);
    memset(ss->lbuf + raster, 0xaa, CFD_BUFFER_SLOP);  /* for Valgrind */
    if (ss->K != 0) {
        ss->lprev = gs_alloc_bytes(st->memory, raster + CFD_BUFFER_SLOP, "CFD lprev");
        if (ss->lprev == 0)
            return ERRC;	/****** WRONG ******/
        /* Clear the initial reference line for 2-D encoding. */
        memset(ss->lprev, white, raster);
        /* Ensure that the scan of the reference line will stop. */
        memset(ss->lprev + raster, 0xaa, CFD_BUFFER_SLOP);
    }
    ss->k_left = min(ss->K, 0);
    ss->run_color = 0;
    ss->damaged_rows = 0;
    ss->skipping_damage = false;
    ss->cbit = 0;
    ss->uncomp_run = 0;
    ss->rows_left = (ss->Rows <= 0 || ss->EndOfBlock ? -1 : ss->Rows);
    ss->row = 0;
    ss->rpos = ss->wpos = -1;
    ss->eol_count = 0;
    ss->invert = white;
    ss->min_left = 1;
    return 0;
}
Example #30
0
/* Allocate a parser state. */
px_parser_state_t *
px_process_alloc(gs_memory_t * memory)
{
    px_parser_state_t *st = (px_parser_state_t *) gs_alloc_bytes(memory,
                                                                 sizeof
                                                                 (px_parser_state_t),
                                                                 "px_process_alloc");

    if (st == 0)
        return 0;
    st->memory = memory;
    px_process_init(st, true);
    return st;
}