Ejemplo n.º 1
0
/* Common code for token reading + execution. */
static int
tokenexec_continue(i_ctx_t *i_ctx_p, scanner_state * pstate, bool save)
{
    os_ptr op;
    int code;
    /* Note that gs_scan_token may change osp! */
    pop(1);
again:
    check_estack(1);
    code = gs_scan_token(i_ctx_p, (ref *) (esp + 1), pstate);
    op = osp;
    switch (code) {
        case 0:
            if (r_is_proc(esp + 1)) {   /* Treat procedure as a literal. */
                push(1);
                ref_assign(op, esp + 1);
                code = 0;
                break;
            }
            /* falls through */
        case scan_BOS:
            ++esp;
            code = o_push_estack;
            break;
        case scan_EOF:          /* no tokens */
            code = 0;
            break;
        case scan_Refill:       /* need more data */
            code = gs_scan_handle_refill(i_ctx_p, pstate, save,
                                      ztokenexec_continue);
            switch (code) {
                case 0: /* state is not copied to the heap */
                    goto again;
                case o_push_estack:
                    return code;
            }
            break;              /* error */
        case scan_Comment:
        case scan_DSC_Comment:
            return ztoken_handle_comment(i_ctx_p, pstate, esp + 1, code,
                                         save, true, ztokenexec_continue);
        default:                /* error */
            gs_scanner_error_object(i_ctx_p, pstate, &i_ctx_p->error_object);
            break;
    }
    if (!save) {                /* Deallocate the scanner state record. */
        gs_free_object(((scanner_state_dynamic *)pstate)->mem, pstate, "token_continue");
    }
    return code;
}
Ejemplo n.º 2
0
static int
alpha_buffer_init(gs_state * pgs, fixed extra_x, fixed extra_y, int alpha_bits, 
                  bool devn)
{
    gx_device *dev = gs_currentdevice_inline(pgs);
    int log2_alpha_bits = ilog2(alpha_bits);
    gs_fixed_rect bbox;
    gs_int_rect ibox;
    uint width, raster, band_space;
    uint height;
    gs_log2_scale_point log2_scale;
    gs_memory_t *mem;
    gx_device_memory *mdev;

    log2_scale.x = log2_scale.y = log2_alpha_bits;
    gx_path_bbox(pgs->path, &bbox);
    ibox.p.x = fixed2int(bbox.p.x - extra_x) - 1;
    ibox.p.y = fixed2int(bbox.p.y - extra_y) - 1;
    ibox.q.x = fixed2int_ceiling(bbox.q.x + extra_x) + 1;
    ibox.q.y = fixed2int_ceiling(bbox.q.y + extra_y) + 1;
    width = (ibox.q.x - ibox.p.x) << log2_scale.x;
    raster = bitmap_raster(width);
    band_space = raster << log2_scale.y;
    height = (abuf_nominal / band_space) << log2_scale.y;
    if (height == 0)
        height = 1 << log2_scale.y;
    mem = pgs->memory;
    mdev = gs_alloc_struct(mem, gx_device_memory, &st_device_memory,
                           "alpha_buffer_init");
    if (mdev == 0)
        return 0;		/* if no room, don't buffer */
    /* We may have to update the marking parameters if we have a pdf14 device
       as our target.  Need to do while dev is still active in pgs */
    if (dev_proc(dev, dev_spec_op)(dev, gxdso_is_pdf14_device, NULL, 0) > 0) {
        gs_update_trans_marking_params(pgs);
    }
    gs_make_mem_abuf_device(mdev, mem, dev, &log2_scale,
                            alpha_bits, ibox.p.x << log2_scale.x, devn);
    mdev->width = width;
    mdev->height = height;
    mdev->bitmap_memory = mem;
    if ((*dev_proc(mdev, open_device)) ((gx_device *) mdev) < 0) {
        /* No room for bits, punt. */
        gs_free_object(mem, mdev, "alpha_buffer_init");
        return 0;
    }
    gx_set_device_only(pgs, (gx_device *) mdev);
    scale_paths(pgs, log2_scale.x, log2_scale.y, true);
    return 1;
}
Ejemplo n.º 3
0
/* Delete a dictionary entry. */
static void
pl_dict_free(pl_dict_t * pdict, pl_dict_entry_t ** ppde, client_name_t cname)
{
    pl_dict_entry_t *pde = *ppde;
    gs_memory_t *mem = pdict->memory;

    *ppde = pde->next;
    if (!pde->link)             /* values are not freed for links */
        (*pdict->free_proc) (mem, pde->value, cname);
    if (pde->key.size > pl_dict_max_short_key)
        gs_free_string(mem, (byte *) pde->key.data, pde->key.size, cname);
    gs_free_object(mem, pde, cname);
    pdict->entry_count--;
}
Ejemplo n.º 4
0
/* Set the cache up for reading. The filesize is used for EOF */
CL_CACHE *
cl_cache_read_init(CL_CACHE *cache, int nslots, int64_t block_size, int64_t filesize)
{
    /* NB: if fail, and cache is still NULL, proceed without cache, reading will cope */
    if (cache == NULL || cache->filesize != 0)
        return cache;		/* once we've done the init, filesize will be set */

    if ((filesize+block_size)/block_size < nslots)
        nslots = (filesize + block_size)/block_size;	/* limit at blocks needed for entire file */
    cache->slots = (CL_CACHE_SLOT *)gs_alloc_bytes(cache->memory, nslots * sizeof(CL_CACHE_SLOT),
                                                       "CL_CACHE slots array");
    if (cache->slots == NULL) {
        gs_free_object(cache->memory, cache, "Free CL_CACHE for IFILE");
        cache = NULL;			/* cache not possible */
    } else {
        cache->slots[0].base = (byte *)gs_alloc_bytes(cache->memory, nslots * block_size,
                                                       "CL_CACHE_SLOT data");
        if (cache->slots[0].base == NULL) {
            gs_free_object(cache->memory, cache->slots, "Free CL_CACHE for IFILE");
            gs_free_object(cache->memory, cache, "Free CL_CACHE for IFILE");
            cache = NULL;			/* cache not possible */
        } else {
            /* success, initialize the slots */
            int i;

            for (i=0; i < nslots; i++) {
                cache->slots[i].blocknum = CL_CACHE_SLOT_EMPTY;
                cache->slots[i].base = cache->slots[0].base + (i * block_size);
            }
            cache->base = cache->slots[0].base;         /* save for the 'destroy' (slots array moves around) */
            cache->nslots = nslots;
            cache->block_size = block_size;
            cache->filesize = filesize;
        }
    }
    return cache;	/* May be NULL. If so, no cache used */
}
Ejemplo n.º 5
0
gs_color_index_cache_t *
gs_color_index_cache_create(gs_memory_t *memory, const gs_color_space *direct_space, gx_device *dev,
                            gs_imager_state *pis, bool need_frac, gx_device *trans_dev)
{
    int client_num_components = cs_num_components(direct_space);
    int device_num_components = trans_dev->color_info.num_components;
    gs_color_index_cache_elem_t *buf = ( gs_color_index_cache_elem_t *)gs_alloc_byte_array(memory, COLOR_INDEX_CACHE_SIZE,
                    sizeof(gs_color_index_cache_elem_t), "gs_color_index_cache_create");
    float *paint_values = (float *)gs_alloc_byte_array(memory, COLOR_INDEX_CACHE_SIZE * client_num_components,
                    sizeof(float), "gs_color_index_cache_create");
    frac31 *frac_values = (need_frac ? (frac31 *)gs_alloc_byte_array(memory, COLOR_INDEX_CACHE_SIZE * device_num_components,
                                            sizeof(frac31), "gs_color_index_cache_create") : NULL);
    gs_color_index_cache_t *pcic = gs_alloc_struct(memory, gs_color_index_cache_t, &st_color_index_cache, "gs_color_index_cache_create");

    if (buf == NULL || paint_values == NULL || (need_frac && frac_values == NULL) || pcic == NULL) {
        gs_free_object(memory, buf, "gs_color_index_cache_create");
        gs_free_object(memory, paint_values, "gs_color_index_cache_create");
        gs_free_object(memory, frac_values, "gs_color_index_cache_create");
        gs_free_object(memory, pcic, "gs_color_index_cache_create");
        return NULL;
    }
    memset(pcic, 0, sizeof(*pcic));
    memset(buf, 0, COLOR_INDEX_CACHE_SIZE * sizeof(gs_color_index_cache_elem_t));
    pcic->direct_space = direct_space;
    pcic->pis = pis;
    pcic->dev = dev;
    pcic->trans_dev = trans_dev;
    pcic->device_num_components = device_num_components;
    pcic->client_num_components = client_num_components;
    pcic->memory = memory;
    pcic->used = 1; /* Never use the 0th element. */
    pcic->buf = buf;
    pcic->recent_touch = MYNULL;
    pcic->paint_values = paint_values;
    pcic->frac_values = frac_values;
    return pcic;
}
Ejemplo n.º 6
0
/* Do per-instance interpreter allocation/init. No device is set yet */
static int   /* ret 0 ok, else -ve error code */
pxl_impl_allocate_interp_instance(
  pl_interp_instance_t   **instance,     /* RETURNS instance struct */
  pl_interp_t            *interp,        /* dummy interpreter */
  gs_memory_t            *mem            /* allocator to allocate instance from */
)
{
	/* Allocate everything up front */
	pxl_interp_instance_t *pxli  /****** SHOULD HAVE A STRUCT DESCRIPTOR ******/
	 = (pxl_interp_instance_t *)gs_alloc_bytes( mem,
	                                            sizeof(pxl_interp_instance_t),
	                                            "pxl_allocate_interp_instance(pxl_interp_instance_t)"
                                              );
	gs_state *pgs = gs_state_alloc(mem);
	px_parser_state_t *st = px_process_alloc(mem);	/* parser init, cheap */
	px_state_t *pxs = px_state_alloc(mem);	/* inits interp state, potentially expensive */
	/* If allocation error, deallocate & return */
	if (!pxli || !pgs || !st || !pxs) {
	  if (pxli)
	    gs_free_object(mem, pxli, "pxl_impl_allocate_interp_instance(pxl_interp_instance_t)");
	  if (pgs)
	    gs_state_free(pgs);
	  if (st)
	    px_process_release(st);
	  if (pxs)
	    px_state_release(pxs);
	  return gs_error_VMerror;
	}
        gsicc_init_iccmanager(pgs);

	/* Setup pointers to allocated mem within instance */
	pxli->memory = mem;
	pxli->pgs = pgs;
	pxli->pxs = pxs;
	pxli->st = st;

	/* zero-init pre/post page actions for now */
	pxli->pre_page_action = 0;
	pxli->post_page_action = 0;

	/* General init of pxl_state */
	px_state_init(pxs, pgs);	/*pgs only needed to set pxs as pgs' client */
	pxs->client_data = pxli;
	pxs->end_page = pxl_end_page_top;	/* after px_state_init */

	/* Return success */
	*instance = (pl_interp_instance_t *)pxli;
	return 0;
}
Ejemplo n.º 7
0
/* Provide zlib-compatible allocation and freeing functions. */
void *
s_zlib_alloc(void *zmem, uint items, uint size)
{
    zlib_dynamic_state_t *const zds = zmem;
    gs_memory_t *mem = zds->memory->stable_memory;
    zlib_block_t *block =
        gs_alloc_struct(mem, zlib_block_t, &st_zlib_block,
                        "s_zlib_alloc(block)");
    void *data =
        gs_alloc_byte_array_immovable(mem, items, size, "s_zlib_alloc(data)");

    if (block == 0 || data == 0) {
        gs_free_object(mem, data, "s_zlib_alloc(data)");
        gs_free_object(mem, block, "s_zlib_alloc(block)");
        return Z_NULL;
    }
    block->data = data;
    block->next = zds->blocks;
    block->prev = 0;
    if (zds->blocks)
        zds->blocks->prev = block;
    zds->blocks = block;
    return data;
}
Ejemplo n.º 8
0
void
s_zlib_free(void *zmem, void *data)
{
    zlib_dynamic_state_t *const zds = zmem;
    gs_memory_t *mem = zds->memory->stable_memory;
    zlib_block_t *block = zds->blocks;

    gs_free_object(mem, data, "s_zlib_free(data)");
    for (; ; block = block->next) {
        if (block == 0) {
            lprintf1("Freeing unrecorded data 0x%lx!\n", (ulong)data);
            return;
        }
        if (block->data == data)
            break;
    }
    if (block->next)
        block->next->prev = block->prev;
    if (block->prev)
        block->prev->next = block->next;
    else
        zds->blocks = block->next;
    gs_free_object(mem, block, "s_zlib_free(block)");
}
Ejemplo n.º 9
0
void gs_lib_ctx_fin(gs_memory_t *mem)
{
    gs_lib_ctx_t *ctx;
    gs_memory_t *ctx_mem;

    if (!mem || !mem->gs_lib_ctx)
        return;
    
    ctx = mem->gs_lib_ctx;
    ctx_mem = ctx->memory;

    gscms_destroy(ctx_mem);
    gs_free_object(ctx_mem, ctx->profiledir,
        "gs_lib_ctx_fin");
        
    gs_free_object(ctx_mem, ctx->default_device_list,
                "gs_lib_ctx_fin");

#ifndef GS_THREADSAFE
    mem_err_print = NULL;
#endif
    remove_ctx_pointers(ctx_mem);
    gs_free_object(ctx_mem, ctx, "gs_lib_ctx_init");
}
Ejemplo n.º 10
0
/*
 * Adjust the reference count on our client data,
 * freeing it if necessary.
 */
static void
client_adjust_cspace_count(const gs_color_space * pcs, int delta)
{
    demo_color_space_data_t * pdata =
	(demo_color_space_data_t *)(pcs->pclient_color_space_data);

    pdata->ref_count += delta;
    if (pdata->ref_count <= 0) {
	/* Free up the CIE to XYZ imager state if it was allocated */
	if (pdata->CIEtoXYZ_pis) {
	    gx_cie_to_xyz_free(pdata->CIEtoXYZ_pis);
	}
	gs_free_object(pdata->memory, pdata, "client_adjust_cspace_count(pdata)");
    }
}
Ejemplo n.º 11
0
/* Create a Type 0 wrapper for a CIDFont. */
int
gs_font_type0_from_cidfont(gs_font_type0 **ppfont0, gs_font *font, int wmode,
			   const gs_matrix *psmat, gs_memory_t *mem)
{
    gs_cmap_t *pcmap;
    int code = gs_cmap_create_identity(&pcmap, 2, wmode, mem);

    if (code < 0)
	return code;
    code = type0_from_cidfont_cmap(ppfont0, font, pcmap, wmode, psmat, mem);
    if (code < 0) {
	gs_free_object(mem, pcmap, "gs_font_type0_from_cidfont(CMap)");
	/****** FREE SUBSTRUCTURES -- HOW? ******/
    }
    return code;
}
Ejemplo n.º 12
0
static
void gs_lcms2_free(cmsContext id, void *ptr)
{
    gs_memory_t *mem = (gs_memory_t *)id;
    if (ptr != NULL) {
#if DEBUG_LCMS_MEM
        gs_warn1("lcms free at 0x%x",ptr);
#endif

#if defined(SHARE_LCMS) && SHARE_LCMS==1
        free(ptr);
#else
        gs_free_object(mem, ptr, "lcms");
#endif
    }
}
Ejemplo n.º 13
0
static void
px_gstate_client_free(void *old, gs_memory_t *mem)
{	px_gstate_t *pxgs = old;

	px_dict_release(&pxgs->temp_pattern_dict);
	if ( pxgs->halftone.thresholds.data )
            gs_free_string(mem, (byte *)pxgs->halftone.thresholds.data,
			 pxgs->halftone.thresholds.size,
			 "px_gstate_free(halftone.thresholds)");
	if ( pxgs->dither_matrix.data )
            gs_free_string(mem, (byte *)pxgs->dither_matrix.data,
			 pxgs->dither_matrix.size,
			 "px_gstate_free(dither_matrix)");
	px_gstate_rc_adjust(old, -1, mem);
	gs_free_object(mem, old, "px_gstate_free");
}
Ejemplo n.º 14
0
/* This routine is used for all formats. */
static int
bmp_cmyk_print_page(gx_device_printer * pdev, FILE * file)
{
    int plane_depth = pdev->color_info.depth / 4;
    uint raster = (pdev->width * plane_depth + 7) >> 3;
    /* 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 = 0;		/* return code */
    int plane;

    if (row == 0)		/* can't allocate row buffer */
	return_error(gs_error_VMerror);
    memset(row+raster, 0, bmp_raster - raster); /* clear the padding bytes */
    
    for (plane = 0; plane <= 3; ++plane) {
	gx_render_plane_t render_plane;

	/* Write the page header. */

    	code = write_bmp_separated_header(pdev, file);
	if (code < 0)
	    break;

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

	gx_render_plane_init(&render_plane, (gx_device *)pdev, plane);
	for (y = pdev->height - 1; y >= 0; y--) {
	    byte *actual_data;
	    uint actual_raster;

	    code = gdev_prn_get_lines(pdev, y, 1, row, bmp_raster,
				      &actual_data, &actual_raster,
				      &render_plane);
	    if (code < 0)
		goto done;
	    fwrite((const char *)actual_data, bmp_raster, 1, file);
	}
    }

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

    return code;
}
Ejemplo n.º 15
0
/* Special version, called with 8 bit grey input to be downsampled to 1bpp
 * output. */
int
tiff_downscale_and_print_page(gx_device_printer *dev, TIFF *tif, int factor,
                              int mfs, int aw, int bpc, int num_comps)
{
    int code = 0;
    byte *data = NULL;
    int size = gdev_mem_bytes_per_scan_line((gx_device *)dev);
    int max_size = max(size, TIFFScanlineSize(tif));
    int row;
    int width  = dev->width/factor;
    int height = dev->height/factor;
    gx_downscaler_t ds;

    code = TIFFCheckpointDirectory(tif);
    if (code < 0)
        return code;

    code = gx_downscaler_init(&ds, (gx_device *)dev, 8, bpc, num_comps,
                              factor, mfs, &fax_adjusted_width, aw);
    if (code < 0)
        return code;

    data = gs_alloc_bytes(dev->memory, max_size, "tiff_print_page(data)");
    if (data == NULL) {
        gx_downscaler_fin(&ds);
        return_error(gs_error_VMerror);
    }

    for (row = 0; row < height && code >= 0; row++) {
        code = gx_downscaler_copy_scan_lines(&ds, row, data, size);
        if (code < 0)
            break;

        code = TIFFWriteScanline(tif, data, row, 0);
        if (code < 0)
            break;
    }

    if (code >= 0)
        code = TIFFWriteDirectory(tif);

    gx_downscaler_fin(&ds);
    gs_free_object(dev->memory, data, "tiff_print_page(data)");

    return code;
}
Ejemplo n.º 16
0
/*
 * Allocate a color space and its parameter structure.
 * Return 0 if VMerror, otherwise the parameter structure.
 *
 * This is exported for the benefit of gsicc.c
 */
void *
gx_build_cie_space(gs_color_space ** ppcspace,
		const gs_color_space_type * pcstype,
		gs_memory_type_ptr_t stype, gs_memory_t * pmem)
{
    gs_color_space *pcspace = gs_cspace_alloc(pmem, pcstype);
    gs_cie_common_elements_t *pdata;

    if (pcspace == NULL)
	return NULL;
    rc_alloc_struct_1(pdata, gs_cie_common_elements_t, stype, pmem,
		      {
		      gs_free_object(pmem, pcspace, "gx_build_cie_space");
		      return 0;
		      }
		      ,
		      "gx_build_cie_space(data)");
Ejemplo n.º 17
0
/* a line to the start followed by a closepath. */
int
gx_path_pop_close_notes(gx_path * ppath, segment_notes notes)
{
    subpath *psub = ppath->current_subpath;
    segment *pseg;
    segment *prev;

    if (psub == 0 || (pseg = psub->last) == 0 ||
        pseg->type != s_line
        )
        return_error(gs_error_unknownerror);
    prev = pseg->prev;
    prev->next = 0;
    psub->last = prev;
    gs_free_object(ppath->memory, pseg, "gx_path_pop_close_subpath");
    return gx_path_close_subpath_notes(ppath, notes);
}
Ejemplo n.º 18
0
/* Build a ShadingType 1 (Function-based) shading. */
static int
build_shading_1(i_ctx_t *i_ctx_p, const ref * op, const gs_shading_params_t * pcommon,
                gs_shading_t ** ppsh, gs_memory_t *mem)
{
    gs_shading_Fb_params_t params;
    int code;
    static const float default_Domain[4] = {0, 1, 0, 1};
    ref *pmatrix;

    *(gs_shading_params_t *)&params = *pcommon;
    gs_make_identity(&params.Matrix);
    params.Function = 0;
    code = dict_floats_param_errorinfo(i_ctx_p, op, "Domain",
                                  4, params.Domain, default_Domain);
    if (code < 0)
        goto out;
    if (params.Domain[0] > params.Domain[1] || params.Domain[2] > params.Domain[3]) {
        gs_errorinfo_put_pair_from_dict(i_ctx_p, op, "Domain");
        code = gs_note_error(gs_error_rangecheck);
        goto out; /* CPSI 3017 and CET 12-14b reject un-normalised domain */
    }
    if (dict_find_string(op, "Matrix", &pmatrix) > 0 ) {
        code = read_matrix(imemory, pmatrix, &params.Matrix);
        if (code < 0) {
            gs_errorinfo_put_pair_from_dict(i_ctx_p, op, "Matrix");
            goto out;
        }
    }
    code = build_shading_function(i_ctx_p, op, &params.Function, 2, mem, params.Domain);
    if (code < 0)
        goto out;
    if (params.Function == 0) {  /* Function is required */
        code = gs_note_error(gs_error_undefined);
        gs_errorinfo_put_pair_from_dict(i_ctx_p, op, "Function");
        goto out;
    }
    code = check_indexed_vs_function(i_ctx_p, op, params.ColorSpace, params.Function);
    if (code < 0)
        goto out;
    code = gs_shading_Fb_init(ppsh, &params, mem);
 out:;
    if (code < 0 && params.Function)
        gs_free_object(mem, params.Function, "Function");
    return code;
}
Ejemplo n.º 19
0
/* Build a ShadingType 2 (Axial) shading. */
static int
build_shading_2(i_ctx_t *i_ctx_p, const ref * op, const gs_shading_params_t * pcommon,
                gs_shading_t ** ppsh, gs_memory_t *mem)
{
    gs_shading_A_params_t params;
    int code;

    *(gs_shading_params_t *)&params = *pcommon;
    if ((code = build_directional_shading(i_ctx_p, op, params.Coords, 4,
                                          params.Domain, &params.Function,
                                          params.Extend, mem)) < 0 ||
        (code = check_indexed_vs_function(i_ctx_p, op, params.ColorSpace, params.Function)) < 0 ||
        (code = gs_shading_A_init(ppsh, &params, mem)) < 0
        ) {
        gs_free_object(mem, params.Function, "Function");
    }
    return code;
}
Ejemplo n.º 20
0
static int
ref_param_read_string_array(gs_param_list * plist, gs_param_name pkey,
			    gs_param_string_array * pvalue)
{
    iparam_list *const iplist = (iparam_list *) plist;
    iparam_loc loc;
    ref aref;
    int code = ref_param_read_array(iplist, pkey, &loc);
    gs_param_string *psv;
    uint size;
    long i;

    if (code != 0)
	return code;
    size = r_size(loc.pvalue);
    psv = (gs_param_string *)
	gs_alloc_byte_array(plist->memory, size, sizeof(gs_param_string),
			    "ref_param_read_string_array");
    if (psv == 0)
	return_error(e_VMerror);
    aref = *loc.pvalue;
    if (r_has_type(&aref, t_array)) {
	for (i = 0; code >= 0 && i < size; i++) {
	    loc.pvalue = aref.value.refs + i;
	    code = ref_param_read_string_value(plist->memory, &loc, psv + i);
	}
    } else {
	ref elt;

	loc.pvalue = &elt;
	for (i = 0; code >= 0 && i < size; i++) {
	    array_get(plist->memory, &aref, i, &elt);
	    code = ref_param_read_string_value(plist->memory, &loc, psv + i);
	}
    }
    if (code < 0) {
	gs_free_object(plist->memory, psv, "ref_param_read_string_array");
	return (*loc.presult = code);
    }
    pvalue->data = psv;
    pvalue->size = size;
    pvalue->persistent = true;
    return 0;
}
Ejemplo n.º 21
0
static int
alpha_buffer_init(gs_state * pgs, fixed extra_x, fixed extra_y, int alpha_bits)
{
    gx_device *dev = gs_currentdevice_inline(pgs);
    int log2_alpha_bits = ilog2(alpha_bits);
    gs_fixed_rect bbox;
    gs_int_rect ibox;
    uint width, raster, band_space;
    uint height;
    gs_log2_scale_point log2_scale;
    gs_memory_t *mem;
    gx_device_memory *mdev;

    log2_scale.x = log2_scale.y = log2_alpha_bits;
    gx_path_bbox(pgs->path, &bbox);
    ibox.p.x = fixed2int(bbox.p.x - extra_x) - 1;
    ibox.p.y = fixed2int(bbox.p.y - extra_y) - 1;
    ibox.q.x = fixed2int_ceiling(bbox.q.x + extra_x) + 1;
    ibox.q.y = fixed2int_ceiling(bbox.q.y + extra_y) + 1;
    width = (ibox.q.x - ibox.p.x) << log2_scale.x;
    raster = bitmap_raster(width);
    band_space = raster << log2_scale.y;
    height = (abuf_nominal / band_space) << log2_scale.y;
    if (height == 0)
	height = 1 << log2_scale.y;
    mem = pgs->memory;
    mdev = gs_alloc_struct(mem, gx_device_memory, &st_device_memory,
			   "alpha_buffer_init");
    if (mdev == 0)
	return 0;		/* if no room, don't buffer */
    gs_make_mem_abuf_device(mdev, mem, dev, &log2_scale,
			    alpha_bits, ibox.p.x << log2_scale.x);
    mdev->width = width;
    mdev->height = height;
    mdev->bitmap_memory = mem;
    if ((*dev_proc(mdev, open_device)) ((gx_device *) mdev) < 0) {
	/* No room for bits, punt. */
	gs_free_object(mem, mdev, "alpha_buffer_init");
	return 0;
    }
    gx_set_device_only(pgs, (gx_device *) mdev);
    scale_paths(pgs, log2_scale.x, log2_scale.y, true);
    return 1;
}
Ejemplo n.º 22
0
/*
 * Open a stream using a filename that can include a PS style IODevice prefix
 * If iodev_default is the '%os' device, then the file will be on the host
 * file system transparently to the caller. The "%os%" prefix can be used
 * to explicilty access the host file system.
 */
stream *
sfopen(const char *path, const char *mode, gs_memory_t *memory)
{
    gs_parsed_file_name_t pfn;
    stream *s;
    iodev_proc_open_file((*open_file));
    gs_memory_t *mem = (memory == NULL) ? gs_lib_ctx_get_non_gc_memory_t() : memory;

    int code = gs_parse_file_name(&pfn, path, strlen(path));
    if (code < 0) {
#	define EMSG	"sfopen: gs_parse_file_name failed.\n"
	errwrite(EMSG, strlen(EMSG));
#	undef EMSG
	return NULL;
    }
    if (pfn.fname == NULL) {	/* just a device */
#	define EMSG	"sfopen: not allowed with %device only.\n"
	errwrite(EMSG, strlen(EMSG));
#	undef EMSG
	return NULL;
    }
    if (pfn.iodev == NULL)
	pfn.iodev = iodev_default;
    open_file = pfn.iodev->procs.open_file;
    if (open_file == 0)
	code = file_open_stream(pfn.fname, pfn.len, mode, 2048, &s,
				pfn.iodev, pfn.iodev->procs.fopen, mem);
    else
	code = open_file(pfn.iodev, pfn.fname, pfn.len, mode, &s, mem);
    if (code < 0)
	return NULL;
    s->position = 0;
    code = ssetfilename(s, (const byte *)path, strlen(path));
    if (code < 0) {
	/* Only error is e_VMerror */
	sclose(s);
	gs_free_object(s->memory, s, "sfopen: allocation error");
#	define EMSG	"sfopen: allocation error setting path name into stream.\n"
	errwrite(EMSG, strlen(EMSG));
#	undef EMSG
	return NULL;
    }
    return s;
}
Ejemplo n.º 23
0
GSDLLEXPORT int GSDLLAPI
gsapi_run_file(void *lib, const char *file_name,
        int user_errors, int *pexit_code)
{
#ifndef GS_NO_UTF8
    char *d, *temp;
    const char *c = file_name;
    char dummy[6];
    int rune, code, len;
#endif
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
    gs_main_instance *minst;
    if (lib == NULL)
        return gs_error_Fatal;
    minst = get_minst_from_memory(ctx->memory);

#ifdef GS_NO_UTF8
    return gs_main_run_file(minst, file_name, user_errors, pexit_code,
                            &(minst->error_object));
#else
    /* Convert the file_name to utf8 */
    if (minst->get_codepoint) {
        len = 1;
        while ((rune = minst->get_codepoint(NULL, &c)) >= 0)
            len += codepoint_to_utf8(dummy, rune);
        temp = (char *)gs_alloc_bytes_immovable(ctx->memory, len, "gsapi_run_file");
        if (temp == NULL)
            return 0;
        c = file_name;
        d = temp;
        while ((rune = minst->get_codepoint(NULL, &c)) >= 0)
           d += codepoint_to_utf8(d, rune);
        *d = 0;
    }
    else {
      temp = (char *)file_name;
    }
    code =  gs_main_run_file(minst, temp, user_errors, pexit_code,
                             &(minst->error_object));
    if (temp != file_name)
        gs_free_object(ctx->memory, temp, "gsapi_run_file");
    return code;
#endif
}
Ejemplo n.º 24
0
/* Print one page in 24-bit RLE direct color format. */
static int
miff24_print_page(gx_device_printer * pdev, FILE * file)
{
    int raster = gx_device_raster((gx_device *) pdev, true);
    byte *line = gs_alloc_bytes(pdev->memory, raster, "miff line buffer");
    int y;
    int code = 0;		/* return code */

    if (line == 0)		/* can't allocate line buffer */
        return_error(gs_error_VMerror);
    fputs("id=ImageMagick\n", file);
    fputs("class=DirectClass\n", file);
    fprintf(file, "columns=%d\n", pdev->width);
    fputs("compression=RunlengthEncoded\n", file);
    fprintf(file, "rows=%d\n", pdev->height);
    fputs(":\n", file);
    for (y = 0; y < pdev->height; ++y) {
        byte *row;
        byte *end;

        code = gdev_prn_get_bits(pdev, y, line, &row);
        if (code < 0)
            break;
        end = row + pdev->width * 3;
        while (row < end) {
            int count = 0;

            while (count < 255 && row < end - 3 &&
                   row[0] == row[3] && row[1] == row[4] &&
                   row[2] == row[5]
                )
                ++count, row += 3;
            putc(row[0], file);
            putc(row[1], file);
            putc(row[2], file);
            putc(count, file);
            row += 3;
        }
    }
    gs_free_object(pdev->memory, line, "miff line buffer");

    return code;
}
Ejemplo n.º 25
0
static int
test6(gs_state * pgs, gs_memory_t * mem)
{
    gs_color_space *pcs;
    gs_cie_abc *pabc;
    gs_cie_render *pcrd;
    static const gs_vector3 white_point =
    {1, 1, 1};
    static const gs_cie_render_proc3 encode_abc =
    {
        {render_abc, render_abc, render_abc}
    };
    int code;
    gs_color_space *rgb_cs;

    rgb_cs = gs_cspace_new_DeviceRGB(mem);

    gs_scale(pgs, 150.0, 150.0);
    gs_translate(pgs, 0.5, 0.5);
    gs_setcolorspace(pgs, rgb_cs);
    spectrum(pgs, 5);
    gs_translate(pgs, 1.2, 0.0);
    /* We must set the CRD before the color space. */
    code = gs_cie_render1_build(&pcrd, mem, "test6");
    if (code < 0)
        return code;
    gs_cie_render1_initialize(mem, pcrd, NULL, &white_point, NULL,
                              NULL, NULL, NULL,
                              NULL, NULL, NULL,
                              NULL, &encode_abc, NULL,
                              NULL);
    gs_setcolorrendering(pgs, pcrd);
    gs_cspace_build_CIEABC(&pcs, NULL, mem);
    /* There should be an API for initializing CIE color spaces too.... */
    pabc = pcs->params.abc;
    pabc->common.points.WhitePoint = white_point;
    gs_cie_abc_complete(pabc);
    /* End of initializing the color space. */
    gs_setcolorspace(pgs, pcs);
    spectrum(pgs, 5);
    gs_free_object(mem, rgb_cs, "test6 rgb_cs");
    return 0;
}
Ejemplo n.º 26
0
static int
bbox_close_device(gx_device * dev)
{
    gx_device_bbox *const bdev = (gx_device_bbox *) dev;
    gx_device *tdev = bdev->target;

    if (bdev->box_procs.init_box != box_procs_default.init_box) {
	/*
	 * This device was created as a wrapper for a compositor.
	 * Just free the devices.
	 */
	int code = (tdev && bdev->forward_open_close ? gs_closedevice(tdev) : 0);

	gs_free_object(dev->memory, dev, "bbox_close_device(composite)");
	return code;
    } else {
	return (tdev && bdev->forward_open_close ? gs_closedevice(tdev) : 0);
    }
}
Ejemplo n.º 27
0
/* Deallocate a interpreter instance */
static int   /* ret 0 ok, else -ve error code */
pxl_impl_deallocate_interp_instance(
  pl_interp_instance_t   *instance     /* instance to dealloc */
)
{
	pxl_interp_instance_t *pxli = (pxl_interp_instance_t *)instance;
	gs_memory_t *mem = pxli->memory;
	
	px_dict_release(&pxli->pxs->font_dict);
	px_dict_release(&pxli->pxs->builtin_font_dict);
	/* do total dnit of interp state */
	px_state_finit(pxli->pxs);
	/* free halftone cache */
	gs_state_free(pxli->pgs);
	px_process_release(pxli->st);
	px_state_release(pxli->pxs);
	gs_free_object(mem, pxli, "pxl_impl_deallocate_interp_instance(pxl_interp_instance_t)");
	return 0;
}
Ejemplo n.º 28
0
/*
 * Free the segments of a path when their reference count goes to zero.
 * We do this in reverse order so as to maximize LIFO allocator behavior.
 * We don't have to worry about cleaning up pointers, because we're about
 * to free the segments object.
 */
static void
rc_free_path_segments_local(gs_memory_t * mem, void *vpsegs,
                            client_name_t cname)
{
    gx_path_segments *psegs = (gx_path_segments *) vpsegs;
    segment *pseg;

    mem = gs_memory_stable(mem);
    if (psegs->contents.subpath_first == 0)
        return;			/* empty path */
    pseg = (segment *) psegs->contents.subpath_current->last;
    while (pseg) {
        segment *prev = pseg->prev;

        trace_segment("[P]release", pseg);
        gs_free_object(mem, pseg, cname);
        pseg = prev;
    }
}
Ejemplo n.º 29
0
/* <function_proc> <array> .scalefunction <function_proc> */
static int
zscalefunction(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    gs_function_t *pfn;
    gs_function_t *psfn;
    gs_range_t *ranges;
    int code;
    uint i;

    check_proc(op[-1]);
    pfn = ref_function(op - 1);
    if (pfn == 0 || !r_is_array(op))
        return_error(gs_error_typecheck);
    if (r_size(op) != 2 * pfn->params.n)
        return_error(gs_error_rangecheck);
    ranges = (gs_range_t *)
        gs_alloc_byte_array(imemory, pfn->params.n, sizeof(gs_range_t),
                            "zscalefunction");
    if (ranges == 0)
        return_error(gs_error_VMerror);
    for (i = 0; i < pfn->params.n; ++i) {
        ref rval[2];
        float val[2];

        if ((code = array_get(op, 2 * i, &rval[0])) < 0 ||
            (code = array_get(op, 2 * i + 1, &rval[1])) < 0 ||
            (code = float_params(rval + 1, 2, val)) < 0)
            return code;
        ranges[i].rmin = val[0];
        ranges[i].rmax = val[1];
    }
    code = gs_function_make_scaled(pfn, &psfn, ranges, imemory);
    gs_free_object(imemory, ranges, "zscalefunction");
    if (code < 0 ||
        (code = make_function_proc(i_ctx_p, op - 1, psfn)) < 0) {
        gs_function_free(psfn, true, imemory);
        return code;
    }
    pop(1);
    return 0;
}
Ejemplo n.º 30
0
static int
bbox_image_begin(const gs_imager_state * pis, const gs_matrix * pmat,
		 const gs_image_common_t * pic, const gs_int_rect * prect,
		 const gx_clip_path * pcpath, gs_memory_t * memory,
		 bbox_image_enum ** ppbe)
{
    int code;
    gs_matrix mat;
    bbox_image_enum *pbe;

    if (pmat == 0)
	pmat = &ctm_only(pis);
    if ((code = gs_matrix_invert(&pic->ImageMatrix, &mat)) < 0 ||
	(code = gs_matrix_multiply(&mat, pmat, &mat)) < 0
	)
	return code;
    pbe = gs_alloc_struct(memory, bbox_image_enum, &st_bbox_image_enum,
			  "bbox_image_begin");
    if (pbe == 0)
	return_error(gs_error_VMerror);
    pbe->memory = memory;
    pbe->matrix = mat;
    pbe->pcpath = pcpath;
    pbe->target_info = 0;	/* in case no target */
    pbe->params_are_const = false;	/* check the first time */
    if (prect) {
	pbe->x0 = prect->p.x, pbe->x1 = prect->q.x;
	pbe->y = prect->p.y, pbe->height = prect->q.y - prect->p.y;
    } else {
	gs_int_point size;
	int code = (*pic->type->source_size) (pis, pic, &size);

	if (code < 0) {
	    gs_free_object(memory, pbe, "bbox_image_begin");
	    return code;
	}
	pbe->x0 = 0, pbe->x1 = size.x;
	pbe->y = 0, pbe->height = size.y;
    }
    *ppbe = pbe;
    return 0;
}