Esempio n. 1
0
int
gs_pop_transparency_state(gs_state *pgs, bool force)
{
    gs_pdf14trans_params_t params = { 0 };
    gs_imager_state * pis = (gs_imager_state *)pgs;
    int code;

    if (check_for_nontrans_pattern(pgs,
                  (unsigned char *)"gs_pop_transparency_state")) {
        return(0);
    }
    /* Check if flag is set, which indicates that we have
       an active softmask for the graphic state.  We
       need to communicate to the compositor to pop
       the softmask */
    if ( pis->trans_flags.xstate_change || force) {
        if_debug0('v', "[v]gs_pop_transparency_state sending\n");
        params.pdf14_op = PDF14_POP_TRANS_STATE;
        code = gs_state_update_pdf14trans(pgs, &params);
        if ( code < 0 )
            return (code);
    } else {
        if_debug0('v', "[v]gs_pop_transparency_state NOT sending\n");
    }
    /* There is no reason to reset any of the flags since
       they will be reset by the graphic state restore */
    return(0);
}
Esempio n. 2
0
static int
svg_endpath(gx_device_vector *vdev, gx_path_type_t type)
{
    gx_device_svg *svg = (gx_device_svg *)vdev;

    /* hack single-page output */
    if (svg->page_count)
      return 0;

    /* skip non-drawing paths for now */
    if (!(type & gx_path_type_fill) && !(type & gx_path_type_stroke))
      return 0;

    if_debug0('_', "svg_endpath ");
    svg_print_path_type(svg, type);
    if_debug0('_', "\n");

    /* close the path data attribute */
    svg_write(svg, "'");

    /* override the inherited stroke attribute if we're not stroking */
    if (!(type & gx_path_type_stroke) && (svg->strokecolor != gx_no_color_index))
      svg_write(svg, " stroke='none'");

    /* override the inherited fill attribute if we're not filling */
    if (!(type & gx_path_type_fill) && (svg->fillcolor != gx_no_color_index))
      svg_write(svg, " fill='none'");

    svg_write(svg, "/>\n");

    return 0;
}
Esempio n. 3
0
/* Note that we treat this as "texture" for RasterOp. */
static int
tile_pattern_clist(const tile_fill_state_t * ptfs,
                  int x, int y, int w, int h)
{
    gx_color_tile *ptile = ptfs->pdevc->colors.pattern.p_tile;
    gx_device_clist *cdev = ptile->cdev;
    gx_device_clist_reader *crdev = (gx_device_clist_reader *)cdev;
    gx_device *dev = ptfs->orig_dev;
    int code;

    crdev->offset_map = NULL;
    crdev->page_info.io_procs->rewind(crdev->page_info.bfile, false, NULL);
    crdev->page_info.io_procs->rewind(crdev->page_info.cfile, false, NULL);
     /* Check for and get ICC profile table */
    if (crdev->icc_table == NULL)
        code = clist_read_icctable(crdev);
    /* Also allocate the icc cache for the clist reader */
    if ( crdev->icc_cache_cl == NULL )
        crdev->icc_cache_cl = gsicc_cache_new(crdev->memory);
    if_debug0('L', "Pattern clist playback begin\n");
    code = clist_playback_file_bands(playback_action_render,
                crdev, &crdev->page_info, dev, 0, 0, ptfs->xoff - x, ptfs->yoff - y);
    if_debug0('L', "Pattern clist playback end\n");
    return code;
}
Esempio n. 4
0
static int
svg_can_handle_hl_color(gx_device_vector *vdev, const gs_imager_state *pis,
                          const gx_drawing_color * pdc)
{
    if_debug0('_', "svg_can_handle_hl_color\n");
    return 0;
}
Esempio n. 5
0
static int
svg_curveto(gx_device_vector *vdev, floatp x0, floatp y0,
            floatp x1, floatp y1, floatp x2, floatp y2,
            floatp x3, floatp y3, gx_path_type_t type)
{
    gx_device_svg *svg = (gx_device_svg *)vdev;
    char line[SVG_LINESIZE];

    /* hack single-page output */
    if (svg->page_count)
      return 0;

    /* skip non-drawing paths for now */
    if (!(type & gx_path_type_fill) && !(type & gx_path_type_stroke))
      return 0;

    if_debug8('_', "svg_curveto(%lf,%lf, %lf,%lf, %lf,%lf, %lf,%lf) ",
        x0,y0, x1,y1, x2,y2, x3,y3);
    svg_print_path_type(svg, type);
    if_debug0('_', "\n");

    sprintf(line, " C%lf,%lf %lf,%lf %lf,%lf", x1,y1, x2,y2, x3,y3);
    svg_write(svg, line);

    return 0;
}
Esempio n. 6
0
/* Common code shared between remap and concretize */
static int
gx_ciea_to_icc(gs_color_space **ppcs_icc, gs_color_space *pcs, gs_memory_t *memory)
{
    int code = 0;
    gs_color_space *palt_cs = pcs->base_space;
    gx_cie_vector_cache *a_cache = &(pcs->params.a->caches.DecodeA);
    gx_cie_scalar_cache    *lmn_caches = &(pcs->params.a->common.caches.DecodeLMN[0]);

    if_debug0(gs_debug_flag_icc,"[icc] Creating ICC profile from CIEA object");  
    /* build the ICC color space object */
    code = gs_cspace_build_ICC(ppcs_icc, NULL, memory);
    /* record the cie alt space as the icc alternative color space */
    (*ppcs_icc)->base_space = palt_cs;
    rc_increment_cs(palt_cs);
    (*ppcs_icc)->cmm_icc_profile_data = gsicc_profile_new(NULL, memory, NULL, 0);
    code = gsicc_create_froma(pcs, &((*ppcs_icc)->cmm_icc_profile_data->buffer),
                    &((*ppcs_icc)->cmm_icc_profile_data->buffer_size), memory,
                    a_cache, lmn_caches);
    gsicc_init_profile_info((*ppcs_icc)->cmm_icc_profile_data);
    (*ppcs_icc)->cmm_icc_profile_data->default_match = CIE_A;
    /* Assign to the icc_equivalent member variable */
    pcs->icc_equivalent = *ppcs_icc;
    pcs->icc_equivalent->cmm_icc_profile_data->data_cs = gsGRAY;
    return(code);
}
Esempio n. 7
0
/* Common code shared between remap and concretize for defg */
static int
gx_ciedefg_to_icc(gs_color_space **ppcs_icc, gs_color_space *pcs, gs_memory_t *memory)
{
    int code = 0;
    gs_color_space *palt_cs = pcs->base_space;
    gx_cie_vector_cache *abc_caches = &(pcs->params.abc->caches.DecodeABC.caches[0]);
    gx_cie_scalar_cache    *lmn_caches = &(pcs->params.abc->common.caches.DecodeLMN[0]);
    gx_cie_scalar_cache *defg_caches = &(pcs->params.defg->caches_defg.DecodeDEFG[0]);

    if_debug0(gs_debug_flag_icc,"[icc] Creating ICC profile from defg object");  
    /* build the ICC color space object */
    code = gs_cspace_build_ICC(ppcs_icc, NULL, memory->stable_memory);
    /* record the cie alt space as the icc alternative color space */
    (*ppcs_icc)->base_space = palt_cs;
    rc_increment_cs(palt_cs);
    (*ppcs_icc)->cmm_icc_profile_data = gsicc_profile_new(NULL, memory, NULL, 0);
    code = gsicc_create_fromdefg(pcs, &((*ppcs_icc)->cmm_icc_profile_data->buffer),
                    &((*ppcs_icc)->cmm_icc_profile_data->buffer_size), memory,
                    abc_caches, lmn_caches, defg_caches);
    gsicc_init_profile_info((*ppcs_icc)->cmm_icc_profile_data);
    (*ppcs_icc)->cmm_icc_profile_data->default_match = CIE_DEFG;
    pcs->icc_equivalent = *ppcs_icc;
    pcs->icc_equivalent->cmm_icc_profile_data->data_cs = gsCMYK;
    return(0);
}
Esempio n. 8
0
/* Common code shared between remap and concretize for def */
static int
gx_ciedef_to_icc(gs_color_space **ppcs_icc, gs_color_space *pcs, gs_memory_t *memory)
{
    int code;
    gs_color_space *palt_cs = pcs->base_space;
    gx_cie_vector_cache *abc_caches = &(pcs->params.abc->caches.DecodeABC.caches[0]);
    gx_cie_scalar_cache    *lmn_caches = &(pcs->params.abc->common.caches.DecodeLMN[0]);
    gx_cie_scalar_cache *def_caches = &(pcs->params.def->caches_def.DecodeDEF[0]);

    if_debug0(gs_debug_flag_icc,"[icc] Creating ICC profile from def object");  
    /* build the ICC color space object */
    code = gs_cspace_build_ICC(ppcs_icc, NULL, memory->stable_memory);
    if (code < 0)
        return gs_rethrow(code, "Failed to build ICC color space");
    /* record the cie alt space as the icc alternative color space */
    (*ppcs_icc)->base_space = palt_cs;
    rc_increment_cs(palt_cs);
    (*ppcs_icc)->cmm_icc_profile_data = gsicc_profile_new(NULL, memory, NULL, 0);
    if ((*ppcs_icc)->cmm_icc_profile_data == NULL)
        gs_throw(gs_error_VMerror, "Failed to create ICC profile");
    code = gsicc_create_fromdef(pcs, &((*ppcs_icc)->cmm_icc_profile_data->buffer),
                    &((*ppcs_icc)->cmm_icc_profile_data->buffer_size), memory,
                    abc_caches, lmn_caches, def_caches);
    if (code < 0)
        return gs_rethrow(code, "Failed to build ICC profile from CIEDEF");
    code = gsicc_init_profile_info((*ppcs_icc)->cmm_icc_profile_data);
    if (code < 0)
        return gs_rethrow(code, "Failed to build ICC profile from CIEDEF");
    (*ppcs_icc)->cmm_icc_profile_data->default_match = CIE_DEF;
    /* Assign to the icc_equivalent member variable */
    pcs->icc_equivalent = *ppcs_icc;
    pcs->icc_equivalent->cmm_icc_profile_data->data_cs = gsUNDEFINED;
    return 0;
    }
Esempio n. 9
0
/* parse a globals stream packed into a gs_bytestring for us by the postscript
   layer and stuff the resulting context into a pointer for use in later decoding */
int
s_jbig2decode_make_global_data(byte *data, uint length, void **result)
{
    Jbig2Ctx *ctx = NULL;
    int code;

    /* the cvision encoder likes to include empty global streams */
    if (length == 0) {
        if_debug0('w', "[w] ignoring zero-length jbig2 global stream.\n");
        *result = NULL;
        return 0;
    }

    /* allocate a context with which to parse our global segments */
    ctx = jbig2_ctx_new(NULL, JBIG2_OPTIONS_EMBEDDED, NULL,
                            s_jbig2decode_error, NULL);
    if (ctx == NULL) return 0;

    /* parse the global bitstream */
    code = jbig2_data_in(ctx, data, length);

    if (code) {
        /* error parsing the global stream */
        *result = NULL;
        return code;
    }

    /* canonize and store our global state */
    *result = jbig2_make_global_ctx(ctx);

    return 0; /* todo: check for allocation failure */
}
Esempio n. 10
0
static int
svg_setdash(gx_device_vector *vdev, const float *pattern,
            uint count, floatp offset)
{
    if_debug0('_', "svg_setdash\n");
    return 0;
}
Esempio n. 11
0
int eprn_output_page(gx_device *dev, int num_copies, int flush)
{
  eprn_Eprn *eprn = &((eprn_Device *)dev)->eprn;
  int rc;

#ifdef EPRN_TRACE
  clock_t start_time = clock();
  if_debug0(EPRN_TRACE_CHAR, "! eprn_output_page()...\n");
#endif

  /* Initialize eprn_get_planes() data */
  eprn->next_y = 0;
  if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) {
    /* Fetch the first line and store it in 'next_scan_line'. */
    if (eprn_fetch_scan_line((eprn_Device *)dev, &eprn->next_scan_line) == 0)
      eprn->next_y++;
  }

  /* Ship out */
  rc = gdev_prn_output_page(dev, num_copies, flush);

  /*  CUPS page accounting message. The CUPS documentation is not perfectly
      clear on whether one should generate this message before printing a page
      or after printing has been successful. The rasterto* filters generate it
      before sending the page, but as the scheduler uses these messages for
      accounting, this seems unfair.
  */
  if (rc == 0 && eprn->CUPS_accounting)
    eprintf2("PAGE: %ld %d\n", dev->ShowpageCount, num_copies);
    /* The arguments are the number of the page, starting at 1, and the number
       of copies of that page. */

#ifndef EPRN_NO_PAGECOUNTFILE
  /* On success, record the number of pages printed */
  if (rc == 0 && eprn->pagecount_file != NULL) {
    assert(num_copies > 0);     /* because of signed/unsigned */
    if (pcf_inccount(eprn->pagecount_file, num_copies) != 0) {
      /* pcf_inccount() has issued an error message. */
      eprintf(
        "  No further attempts will be made to access the page count file.\n");
      gs_free(dev->memory->non_gc_memory, eprn->pagecount_file, strlen(eprn->pagecount_file) + 1,
        sizeof(char), "eprn_output_page");
      eprn->pagecount_file = NULL;
    }
  }
#endif  /* !EPRN_NO_PAGECOUNTFILE */

  /* If soft tumble has been demanded, ensure the get_initial_matrix procedure
     is consulted for the next page */
  if (eprn->soft_tumble) eprn_forget_defaultmatrix(dev->memory->non_gc_memory);

#ifdef EPRN_TRACE
  if_debug1(EPRN_TRACE_CHAR, "! eprn_output_page() terminates after %f s.\n",
    ((float)(clock() - start_time))/CLOCKS_PER_SEC);
#endif

  return rc;
}
Esempio n. 12
0
/*
 * Copy from tmp to dst, taking into account PixelOut vs. PixelIn sizes
 * We do the conversion from PixelIn to PixelOut here (if needed)
 * since if the Y is scaled down we will convert less often.
 * This is simpler because we can treat all columns identically
 * without regard to the number of samples per pixel.
 */
static void
idownscale_y(void /*PixelOut */ *dst, const void /* PixelIn */ *tmp,
             stream_ISpecialDownScale_state *const ss)
{
    int kn = ss->params.WidthOut * ss->params.spp_interp;
    int kc;
    float scale = (float) ss->params.MaxValueOut/255.0;

    if_debug0('W', "[W]idownscale_y: ");

    if (ss->sizeofPixelOut == 1) {
        if (ss->sizeofPixelIn == 1) {
            const byte *pp = (byte *)tmp;

            for ( kc = 0; kc < kn; ++kc, pp++ ) {
                if_debug1('W', " %d", *pp);
                ((byte *)dst)[kc] = *pp;
            }
        } else {	/* sizeofPixelIn == 2 */
            const bits16 *pp = (bits16 *)tmp;

            for ( kc = 0; kc < kn; ++kc, pp++ ) {
                if_debug1('W', " %d", *pp);
                ((byte *)dst)[kc] = frac2byte(*pp);
            }
        }
    } else {		/* sizeofPixelOut == 2 */
        if (ss->sizeofPixelIn == 1) {
            const byte *pp = (byte *)tmp;

            for ( kc = 0; kc < kn; ++kc, pp++ ) {
                if_debug1('W', " %d", *pp);
                ((bits16 *)dst)[kc] = (bits16)((*pp)*scale);
            }
        } else {	/* sizeofPixelIn == 2 */
            const bits16 *pp = (bits16 *)tmp;

            for ( kc = 0; kc < kn; ++kc, pp++ ) {
                if_debug1('W', " %d", *pp);
                ((bits16 *)dst)[kc] = *pp;
            }
        }
    }
    if_debug0('W', "n");
}
Esempio n. 13
0
int
gx_end_transparency_group(gs_imager_state * pis, gx_device * pdev)
{
    if_debug0('v', "[v]gx_end_transparency_group\n");
    if (dev_proc(pdev, end_transparency_group) != 0)
	return (*dev_proc(pdev, end_transparency_group)) (pdev, pis, NULL);
    else
	return 0;
}
Esempio n. 14
0
int
gs_end_transparency_group(gs_state *pgs)
{
    gs_pdf14trans_params_t params = { 0 };

    if_debug0('v', "[v]gs_end_transparency_group\n");
    params.pdf14_op = PDF14_END_TRANS_GROUP;  /* Other parameters not used */
    return gs_state_update_pdf14trans(pgs, &params);
}
Esempio n. 15
0
int
gx_push_transparency_state(gs_imager_state * pis, gx_device * pdev)
{
    if_debug0('v', "[v]gx_push_transparency_state\n");
    if (dev_proc(pdev, push_transparency_state) != 0)
        return (*dev_proc(pdev, push_transparency_state)) (pdev, pis);
    else
        return 0;
}
Esempio n. 16
0
int
gs_update_trans_marking_params(gs_state * pgs)
{
    gs_pdf14trans_params_t params = { 0 };

    if_debug0('v', "[v]gs_update_trans_marking_params\n");
    params.pdf14_op = PDF14_SET_BLEND_PARAMS;
    return gs_state_update_pdf14trans(pgs, &params);
}
Esempio n. 17
0
static int
svg_closepath(gx_device_vector *vdev, floatp x, floatp y,
              floatp x_start, floatp y_start, gx_path_type_t type)
{
    gx_device_svg *svg = (gx_device_svg *)vdev;

    /* hack single-page output */
    if (svg->page_count)
      return 0;

    /* skip non-drawing paths for now */
    if (!(type & gx_path_type_fill) && !(type & gx_path_type_stroke))
      return 0;

    if_debug0('_', "svg_closepath ");
    svg_print_path_type(svg, type);
    if_debug0('_', "\n");

    svg_write(svg, " z");

    return 0;
}
Esempio n. 18
0
static int
svg_dorect(gx_device_vector *vdev, fixed x0, fixed y0,
           fixed x1, fixed y1, gx_path_type_t type)
{
    gx_device_svg *svg = (gx_device_svg *)vdev;
    char line[300];

    /* hack single-page output */
    if (svg->page_count)
      return 0;

    if_debug0('_', "svg_dorect");
    svg_print_path_type(svg, type);
    if_debug0('_', "\n");

    svg_write_state(svg);

    if (type & gx_path_type_clip) {
        svg_write(svg, "<clipPath>\n");
    }

    sprintf(line, "<rect x='%lf' y='%lf' width='%lf' height='%lf'",
        fixed2float(x0), fixed2float(y0),
        fixed2float(x1 - x0), fixed2float(y1 - y0));
    svg_write(svg, line);
    /* override the inherited stroke attribute if we're not stroking */
    if (!(type & gx_path_type_stroke) && (svg->strokecolor != gx_no_color_index))
        svg_write(svg, " stroke='none'");
    /* override the inherited fill attribute if we're not filling */
    if (!(type & gx_path_type_fill) && (svg->fillcolor != gx_no_color_index))
        svg_write(svg, " fill='none'");
    svg_write(svg, "/>\n");

    if (type & gx_path_type_clip) {
        svg_write(svg, "</clipPath>\n");
    }

    return 0;
}
Esempio n. 19
0
int
gs_end_transparency_group(gs_state *pgs)
{
    gs_pdf14trans_params_t params = { 0 };

    if (pgs->is_gstate && check_for_nontrans_pattern(pgs,
                  (unsigned char *)"gs_end_transparency_group")) {
        return(0);
    }
    if_debug0('v', "[v]gs_end_transparency_group\n");
    params.pdf14_op = PDF14_END_TRANS_GROUP;  /* Other parameters not used */
    return gs_state_update_pdf14trans(pgs, &params);
}
Esempio n. 20
0
int
gs_push_transparency_state(gs_state *pgs)
{
    gs_pdf14trans_params_t params = { 0 };
    gs_imager_state * pis = (gs_imager_state *)pgs;
    int code;

    if (check_for_nontrans_pattern(pgs,
                  (unsigned char *)"gs_push_transparency_state")) {
        return(0);
    }
    /* Set the pending flag to true, which indicates
       that we need to watch for end transparency
       soft masks when we are at this graphic state
       level */
    /* pis->trans_flags.xstate_pending = true; */
    /* Actually I believe the above flag is not
       needed.  We really should be watching for
       the softmask even at the base level.  What
       we need to watch for are q operations after
       a soft mask end has occured. */
    /* Check if we have a change flag set to true.
       this indicates that a softmask is present.
       We will need to send a push state to save
       the current soft mask, so that we can
       restore it later */
    if (pis->trans_flags.xstate_change) {
        if_debug0('v', "[v]gs_push_transparency_state sending\n");
        params.pdf14_op = PDF14_PUSH_TRANS_STATE;
        code = gs_state_update_pdf14trans(pgs, &params);
        if (code < 0)
            return(code);
    } else {
        if_debug0('v', "[v]gs_push_transparency_state NOT sending\n");
    }
    return(0);
}
Esempio n. 21
0
/* Respond to a device parameter query from the client */
static int
svg_get_params(gx_device *dev, gs_param_list *plist)
{
    int code = 0;

    if_debug0('_', "svg_get_params\n");

    /* call our superclass to add its standard set */
    code = gdev_vector_get_params(dev, plist);
    if (code < 0)
      return gs_rethrow_code(code);

    /* svg specific parameters are added to plist here */

    return code;
}
Esempio n. 22
0
/* Read the device parameters passed to us by the client */
static int
svg_put_params(gx_device *dev, gs_param_list *plist)
{
    int code = 0;

    if_debug0('_', "svg_put_params\n");

    /* svg specific parameters are parsed here */

    /* call our superclass to get its parameters, like OutputFile */
    code = gdev_vector_put_params(dev, plist);
    if (code < 0)
      return gs_rethrow_code(code);

    return code;
}
Esempio n. 23
0
static int
svg_setfillcolor(gx_device_vector *vdev, const gs_imager_state *pis,
                 const gx_drawing_color *pdc)
{
    gx_device_svg *svg = (gx_device_svg*)vdev;
    gx_color_index fill = svg_get_color(svg, pdc);

    if_debug0('_', "svg_setfillcolor\n");

    if (svg->fillcolor != fill)
      return 0; /* not a new color */
    /* update our state with the new color */
    svg->fillcolor = fill;
    /* request a new group element */
    svg->dirty++;
    return 0;
}
Esempio n. 24
0
static int
svg_write_header(gx_device_svg *svg)
{
    /* we're called from beginpage, so we can't use
       svg_write() which calls gdev_vector_stream()
       which calls beginpage! */
    stream *s = svg->strm;
    uint used;
    char line[300];

    if_debug0('_', "svg_write_header\n");

    /* only write the header once */
    if (svg->header)
      return 1;

    /* write the initial boilerplate */
    sprintf(line, "%s\n", XML_DECL);
    /* svg_write(svg, line); */
    sputs(s, (byte *)line, strlen(line), &used);
    sprintf(line, "%s\n", SVG_DOCTYPE);
    /* svg_write(svg, line); */
    sputs(s, (byte *)line, strlen(line), &used);
    sprintf(line, "<svg xmlns='%s' version='%s'",
        SVG_XMLNS, SVG_VERSION);
    /* svg_write(svg, line); */
    sputs(s, (byte *)line, strlen(line), &used);
    sprintf(line, "\n\twidth='%dpt' height='%dpt'>\n",
        (int)svg->MediaSize[0], (int)svg->MediaSize[1]);
    sputs(s, (byte *)line, strlen(line), &used);

    /* Scale drawing so our coordinates are in pixels */
    sprintf(line, "<g transform='scale(%lf,%lf)'>\n",
        72.0 / svg->HWResolution[0],
        72.0 / svg->HWResolution[1]);
    /* svg_write(svg, line); */
    sputs(s, (byte *)line, strlen(line), &used);
    svg->mark++;

    /* mark that we've been called */
    svg->header = 1;

    return 0;
}
Esempio n. 25
0
int eprn_close_device(gx_device *device)
{
  eprn_Eprn *eprn = &((eprn_Device *)device)->eprn;

#ifdef EPRN_TRACE
  if_debug0(EPRN_TRACE_CHAR, "! eprn_close_device()...\n");
#endif

  if (eprn->scan_line.str != NULL) {
    gs_free(device->memory->non_gc_memory, eprn->scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet),
      "eprn_close_device");
    eprn->scan_line.str = NULL;
  }
  if (eprn->next_scan_line.str != NULL) {
    gs_free(device->memory->non_gc_memory, eprn->next_scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet),
      "eprn_close_device");
    eprn->next_scan_line.str = NULL;
  }

  return gdev_prn_close(device);
}
Esempio n. 26
0
/* The caller must supply a string to the first call of gs_type1_interpret. */
int
gs_type1_interp_init(register gs_type1_state * pcis, gs_imager_state * pis,
    gx_path * ppath, const gs_log2_scale_point * pscale, 
    const gs_log2_scale_point * psubpixels, bool no_grid_fitting,
		     int paint_type, gs_font_type1 * pfont)
{
    static const gs_log2_scale_point no_scale = {0, 0};
    const gs_log2_scale_point *plog2_scale =
	(FORCE_HINTS_TO_BIG_PIXELS && pscale != NULL ? pscale : &no_scale);
    const gs_log2_scale_point *plog2_subpixels =
	(FORCE_HINTS_TO_BIG_PIXELS ? (psubpixels != NULL ? psubpixels : plog2_scale) : &no_scale);

    if_debug0('1', "[1]gs_type1_interp_init\n");
    pcis->pfont = pfont;
    pcis->pis = pis;
    pcis->path = ppath;
    pcis->callback_data = pfont; /* default callback data */
    pcis->no_grid_fitting = no_grid_fitting;
    pcis->paint_type = paint_type;
    pcis->os_count = 0;
    pcis->ips_count = 1;
    pcis->ipstack[0].ip = 0;
    gs_glyph_data_from_null(&pcis->ipstack[0].cs_data);
    pcis->ignore_pops = 0;
    pcis->init_done = -1;
    pcis->sb_set = false;
    pcis->width_set = false;
    pcis->seac_flag = false;
    pcis->num_hints = 0;
    pcis->seac_accent = -1;
    pcis->log2_subpixels = *plog2_subpixels;
    pcis->origin_offset.x = pcis->origin_offset.y = 0;

    /* Set the sampling scale. */
    set_pixel_scale(&pcis->scale.x, plog2_scale->x);
    set_pixel_scale(&pcis->scale.y, plog2_scale->y);

    return 0;
}
Esempio n. 27
0
int
gs_end_transparency_mask(gs_state *pgs,
                         gs_transparency_channel_selector_t csel)
{
    gs_pdf14trans_params_t params = { 0 };
    gs_pdf14trans_params_t params_color = { 0 };
    gs_imager_state * pis = (gs_imager_state *)pgs;
    int code;

    if (check_for_nontrans_pattern(pgs,
                  (unsigned char *)"gs_end_transparency_mask")) {
        return(0);
    }
    /* If we have done a q then set a flag to watch for any Qs */
   /* if (pis->trans_flags.xstate_pending)
        pis->trans_flags.xstate_change = true; */
    /* This should not depend upon if we have encountered a q
       operation.  We could be setting a softmask, before
       there is any q operation.  Unlikely but it could happen.
       Then if we encouter a q operation (and this flag
       is true) we will need to
       push the mask graphic state (PDF14_PUSH_TRANS_STATE). */
    pis->trans_flags.xstate_change = true;
    if_debug1('v', "[v]xstate_changed set true, gstate level is %d\n", pgs->level);
    if_debug2('v', "[v](0x%lx)gs_end_transparency_mask(%d)\n", (ulong)pgs,
              (int)csel);
    params.pdf14_op = PDF14_END_TRANS_MASK;  /* Other parameters not used */
    params.csel = csel;
    /* If this is the outer end then return us to our normal defaults */
    if_debug0('v', "[v]popping soft mask color sending\n");
    params_color.pdf14_op = PDF14_POP_SMASK_COLOR;
    code = gs_state_update_pdf14trans(pgs, &params_color);
    if (code < 0)
        return(code);
    return gs_state_update_pdf14trans(pgs, &params);
}
Esempio n. 28
0
/* <source> <dict> /JPXDecode <file> */
static int
z_jpx_decode(i_ctx_t * i_ctx_p)
{
    os_ptr op = osp;
    ref *sop = NULL;
    ref *csname = NULL;
    stream_jpxd_state state;

    /* it's our responsibility to call set_defaults() */
    state.memory = imemory->non_gc_memory;
    if (s_jpxd_template.set_defaults)
      (*s_jpxd_template.set_defaults)((stream_state *)&state);
    state.jpx_memory = imemory->non_gc_memory;
    if (r_has_type(op, t_dictionary)) {
        check_dict_read(*op);
        if ( dict_find_string(op, "Alpha", &sop) > 0) {
            check_type(*sop, t_boolean);
            if (sop->value.boolval)
                state.alpha = true;
        }
        if ( dict_find_string(op, "ColorSpace", &sop) > 0) {
            /* parse the value */
            if (r_is_array(sop)) {
                /* assume it's the first array element */
                csname =  sop->value.refs;
            } else if (r_has_type(sop,t_name)) {
                /* use the name directly */
                csname = sop;
            } else {
                dprintf("warning: JPX ColorSpace value is an unhandled type!\n");
            }
            if (csname != NULL) {
                ref sref;
                /* get a reference to the name's string value */
                name_string_ref(imemory, csname, &sref);
                /* request raw index values if the colorspace is /Indexed */
                if (!ISTRCMP(&sref, "Indexed"))
                    state.colorspace = gs_jpx_cs_indexed;
                /* tell the filter what output we want for other spaces */
                else if (!ISTRCMP(&sref, "DeviceGray"))
                    state.colorspace = gs_jpx_cs_gray;
                else if (!ISTRCMP(&sref, "DeviceRGB"))
                    state.colorspace = gs_jpx_cs_rgb;
                else if (!ISTRCMP(&sref, "DeviceCMYK"))
                    state.colorspace = gs_jpx_cs_cmyk;
                else if (!ISTRCMP(&sref, "ICCBased")) {
                    /* The second array element should be the profile's
                       stream dict */
                    ref *csdict = sop->value.refs + 1;
                    ref *nref;
                    ref altname;
                    if (r_is_array(sop) && (r_size(sop) > 1) &&
                      r_has_type(csdict, t_dictionary)) {
                        check_dict_read(*csdict);
                        /* try to look up the alternate space */
                        if (dict_find_string(csdict, "Alternate", &nref) > 0) {
                          name_string_ref(imemory, csname, &altname);
                          if (!ISTRCMP(&altname, "DeviceGray"))
                            state.colorspace = gs_jpx_cs_gray;
                          else if (!ISTRCMP(&altname, "DeviceRGB"))
                            state.colorspace = gs_jpx_cs_rgb;
                          else if (!ISTRCMP(&altname, "DeviceCMYK"))
                            state.colorspace = gs_jpx_cs_cmyk;
                        }
                        /* else guess based on the number of components */
                        if (state.colorspace == gs_jpx_cs_unset &&
                                dict_find_string(csdict, "N", &nref) > 0) {
                          if_debug1('w', "[w] JPX image has an external %d"
                                   " channel colorspace\n", nref->value.intval);
                          switch (nref->value.intval) {
                            case 1: state.colorspace = gs_jpx_cs_gray;
                                break;
                            case 3: state.colorspace = gs_jpx_cs_rgb;
                                break;
                            case 4: state.colorspace = gs_jpx_cs_cmyk;
                                break;
                          }
                        }
                    }
                }
            } else {
                if_debug0('w', "[w] Couldn't read JPX ColorSpace key!\n");
            }
        }
    }

    /* we pass npop=0, since we've no arguments left to consume */
    /* we pass 0 instead of the usual rspace(sop) which will allocate storage
       for filter state from the same memory pool as the stream it's coding.
       this causes no trouble because we maintain no pointers */
    return filter_read(i_ctx_p, 0, &s_jpxd_template,
                       (stream_state *) & state, 0);
}
Esempio n. 29
0
/* Apply filter to downscale horizontally from src to tmp. */
static void
idownscale_x(void /* PixelIn */ * tmp, const void /* PixelIn */ *src, stream_ISpecialDownScale_state *const ss)
{
    int c, i;
    int Colors = ss->params.spp_interp;
    int WidthIn = ss->params.WidthIn;
    int prev_y;
    int cur_y;
    bool firstline;
    bool polarity_additive = ss->params.ColorPolarityAdditive;

    dda_previous_assign(ss->dda_y, prev_y);
    dda_next_assign(ss->dda_y, cur_y);
    firstline = prev_y != cur_y; /* at the start of a new group of lines */
    /* The following could be a macro, BUT macro's with control */
    /* are not good style and hard to debug */
    if (ss->sizeofPixelIn == 1) {
        for (c = 0; c < Colors; ++c) {
            byte *tp = (byte *)tmp + c;		/* destination */
            const byte *pp =  (const byte *)src + c;

            ss->dda_x = ss->dda_x_init;
            if_debug1('W', "[W]idownscale_x color %d:", c);

            for ( i = 0; i < WidthIn; tp += Colors) {
                int endx;
                dda_next_assign(ss->dda_x, endx);
                if (firstline)
                    *tp = *pp;
                else {
                    if ((polarity_additive && (*pp < *tp)) ||
                        (!polarity_additive && (*pp > *tp)) )
                        *tp = *pp;
                }
                i++; pp += Colors;
                while (i < endx) {
                   if (*pp < *tp)
                        *tp = *pp;
                   i++; pp += Colors;
                }
                if_debug1('W', " %d", *tp);
            }
            if_debug0('W', "\n");
        }
    } else {		/* sizeofPixelIn == 2 */
        for (c = 0; c < Colors; ++c) {
            bits16 *tp = (bits16 *)tmp + c;		/* destination */
            const bits16 *pp =  (const bits16 *)src + c;

            ss->dda_x = ss->dda_x_init;
            if_debug1('W', "[W]idownscale_x color %d:", c);

            for ( i = 0; i < WidthIn; tp += Colors) {
                int endx;
                dda_next_assign(ss->dda_x,endx);
                if (firstline)
                    *tp = *pp;
                else {
                    if ((polarity_additive && (*pp < *tp)) ||
                        (!polarity_additive && (*pp > *tp)) )
                        *tp = *pp;
                }
                i++; pp += Colors;
                while (i < endx) {
                   if (*pp < *tp)
                        *tp = *pp;
                   i++; pp += Colors;
                }
                if_debug1('W', " %d", *tp);
            }
            if_debug0('W', "\n");
        }
    }
}
Esempio n. 30
0
int eprn_open_device(gx_device *device)
{
  eprn_Eprn *eprn = &((eprn_Device *)device)->eprn;
  const char *epref = eprn->CUPS_messages? CUPS_ERRPREF: "";
  int rc;

#ifdef EPRN_TRACE
  if_debug0(EPRN_TRACE_CHAR, "! eprn_open_device()...\n");
#endif

  /* Checks on page size and determination of derived values */
  if (eprn_set_page_layout((eprn_Device *)device) != 0)
    return_error(gs_error_rangecheck);

  /* Check the rendering parameters */
  if (eprn_check_colour_info(eprn->cap->colour_info, &eprn->colour_model,
      &device->HWResolution[0], &device->HWResolution[1],
      &eprn->black_levels, &eprn->non_black_levels) != 0) {
    gs_param_string str;

    eprintf1("%s" ERRPREF "The requested combination of colour model (",
      epref);
    str.size = 0;
    if (eprn_get_string(eprn->colour_model, eprn_colour_model_list, &str) != 0)
      assert(0); /* Bug. No harm on NDEBUG because I've just set the size. */
    errwrite(device->memory, (const char *)str.data, str.size * sizeof(str.data[0]));
    eprintf7("),\n"
      "%s  resolution (%gx%g ppi) and intensity levels (%d, %d) is\n"
      "%s  not supported by the %s.\n",
      epref, device->HWResolution[0], device->HWResolution[1],
      eprn->black_levels, eprn->non_black_levels, epref, eprn->cap->name);
    return_error(gs_error_rangecheck);
  }

  /* Initialization for colour rendering */
  if (device->color_info.num_components == 4) {
    /* Native colour space is 'DeviceCMYK' */
    set_dev_proc(device, map_rgb_color, NULL);

    if (eprn->intensity_rendering == eprn_IR_FloydSteinberg)
      set_dev_proc(device, map_cmyk_color, &eprn_map_cmyk_color_max);
    else if (device->color_info.max_gray > 1 || device->color_info.max_color > 1)
      set_dev_proc(device, map_cmyk_color, &eprn_map_cmyk_color_flex);
    else
      set_dev_proc(device, map_cmyk_color, &eprn_map_cmyk_color);

    if (eprn->intensity_rendering == eprn_IR_FloydSteinberg)
      set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_max);
    else if (device->color_info.max_gray > 1 || device->color_info.max_color > 1)
      set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_flex);
    else
      set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K);

  }
  else {
    set_dev_proc(device, map_cmyk_color, NULL);

    if (eprn->colour_model == eprn_DeviceRGB) {
      if (eprn->intensity_rendering == eprn_IR_FloydSteinberg)
        set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_RGB_max);
      else if (device->color_info.max_color > 1)
        set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_RGB_flex);
      else
        set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_RGB);
    } else {
      if (eprn->intensity_rendering == eprn_IR_FloydSteinberg)
        set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_max);
      else if (device->color_info.max_gray > 1 || device->color_info.max_color > 1)
        set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_flex);
      else
        set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K);
    }
  }
  eprn->output_planes = eprn_bits_for_levels(eprn->black_levels) +
    3 * eprn_bits_for_levels(eprn->non_black_levels);

#if !defined(GS_REVISION) || GS_REVISION >= 600
  /*  According to my understanding, the following call should be superfluous
      (because the colour mapping functions may not be called while the device
      is closed) and I am also not aware of any situation where it does make a
      difference. It shouldn't do any harm, though, and I feel safer with it :-)
  */
  gx_device_decache_colors(device);
#endif

#ifndef EPRN_NO_PAGECOUNTFILE
  /* Read the page count value */
  if (eprn->pagecount_file != NULL) {
    unsigned long count;
    if (pcf_getcount(eprn->pagecount_file, &count) == 0)
      device->PageCount = count;
       /* unsigned to signed. The C standard permits
          an implementation to generate an overflow indication if the value is
          too large. I consider this to mean that the type of 'PageCount' is
          inappropriate :-). Note that eprn does not use 'PageCount' for
          updating the file. */
    else {
      /* pcf_getcount() has issued an error message. */
      eprintf(
        "  No further attempts will be made to access the page count file.\n");
      gs_free(device->memory->non_gc_memory, eprn->pagecount_file, strlen(eprn->pagecount_file) + 1,
        sizeof(char), "eprn_open_device");
      eprn->pagecount_file = NULL;
    }
  }
#endif  /* !EPRN_NO_PAGECOUNTFILE */

  /* Open the "prn" device part */
  if ((rc = gdev_prn_open(device)) != 0) return rc;

  /* Just in case a previous open call failed in a derived device (note that
     'octets_per_line' is still the same as then): */
  if (eprn->scan_line.str != NULL)
    gs_free(device->memory->non_gc_memory, eprn->scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet),
      "eprn_open_device");
  if (eprn->next_scan_line.str != NULL) {
    gs_free(device->memory->non_gc_memory, eprn->next_scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet),
      "eprn_open_device");
    eprn->next_scan_line.str = NULL;
  }

  /* Calls which might depend on prn having been initialized */
  eprn->octets_per_line = gdev_prn_raster((gx_device_printer *)device);
  eprn->scan_line.str = (eprn_Octet *) gs_malloc(device->memory->non_gc_memory, eprn->octets_per_line,
    sizeof(eprn_Octet), "eprn_open_device");
  if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) {
    eprn->next_scan_line.str = (eprn_Octet *) gs_malloc(device->memory->non_gc_memory, eprn->octets_per_line,
      sizeof(eprn_Octet), "eprn_open_device");
    if (eprn->next_scan_line.str == NULL && eprn->scan_line.str != NULL) {
      gs_free(device->memory->non_gc_memory, eprn->scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet),
        "eprn_open_device");
      eprn->scan_line.str = NULL;
    }
  }
  if (eprn->scan_line.str == NULL) {
    eprintf1("%s" ERRPREF
      "Memory allocation failure from gs_malloc() in eprn_open_device().\n",
      epref);
    return_error(gs_error_VMerror);
  }

  return rc;
}