Esempio n. 1
0
static void
wts_print_j(const gx_wts_cell_params_j_t *wcpj)
{
    double uf, vf;
    double us, vs;

    dlprintf3("cell = %d x %d, shift = %d\n",
	      wcpj->base.width, wcpj->base.height, wcpj->shift);
    wts_print_j_jump(wcpj, "a", wcpj->pa, wcpj->xa, wcpj->ya);
    wts_print_j_jump(wcpj, "b", wcpj->pb, wcpj->xb, wcpj->yb);
    wts_print_j_jump(wcpj, "c", wcpj->pc, wcpj->xc, wcpj->yc);
    wts_print_j_jump(wcpj, "d", wcpj->pd, wcpj->xd, wcpj->yd);
    uf = wcpj->ufast_a;
    vf = wcpj->vfast_a;
    us = wcpj->uslow_a;
    vs = wcpj->vslow_a;
    wts_j_add_jump(wcpj, &uf, &vf, wcpj->pa, wcpj->xa, wcpj->ya);
    wts_j_add_jump(wcpj, &uf, &vf, wcpj->pb, wcpj->xb, wcpj->yb);
    wts_j_add_jump(wcpj, &us, &vs, wcpj->pc, wcpj->xc, wcpj->yc);
    wts_j_add_jump(wcpj, &us, &vs, wcpj->pd, wcpj->xd, wcpj->yd);
    dlprintf6("d: %f, %f; a: %f, %f; err: %g, %g\n",
	    wcpj->base.ufast, wcpj->base.vfast,
	    wcpj->ufast_a, wcpj->vfast_a,
	    wcpj->base.ufast - uf, wcpj->base.vfast - vf);
    dlprintf6("d: %f, %f; a: %f, %f; err: %g, %g\n",
	    wcpj->base.uslow, wcpj->base.vslow,
	    wcpj->uslow_a, wcpj->vslow_a,
	    wcpj->base.uslow - us, wcpj->base.vslow - vs);
}
Esempio n. 2
0
/* Record next halftone sample */
int
gs_screen_next(gs_screen_enum * penum, floatp value)
{
    if (penum->order.wse) {
        return gs_wts_screen_enum_next (penum->order.wse, value);
    } else {
        ht_sample_t sample;
        int width = penum->order.width;
        gx_ht_bit *bits = (gx_ht_bit *)penum->order.bit_data;

        if (value < -1.0 || value > 1.0)
            return_error(gs_error_rangecheck);
        sample = (ht_sample_t) ((value + 1) * max_ht_sample);
#ifdef DEBUG
        if (gs_debug_c('H')) {
            gs_point pt;

            gs_screen_currentpoint(penum, &pt);
            dlprintf6("[H]sample x=%d y=%d (%f,%f): %f -> %u\n",
                      penum->x, penum->y, pt.x, pt.y, value, sample);
        }
#endif
        bits[penum->y * width + penum->x].mask = sample;
        if (++(penum->x) >= width)
            penum->x = 0, ++(penum->y);
        return 0;
    }
}
Esempio n. 3
0
static void
wts_print_j_jump(const gx_wts_cell_params_j_t *wcpj, const char *name,
		 double pa, int xa, int ya)
{
    dlprintf6("jump %s: (%d, %d) %f, actual (%f, %f)\n",
	      name, xa, ya, pa,
	      wcpj->ufast_a * xa + wcpj->uslow_a * ya,
	      wcpj->vfast_a * xa + wcpj->vslow_a * ya);
}
Esempio n. 4
0
int
gx_begin_transparency_group(gs_imager_state * pis, gx_device * pdev,
                                const gs_pdf14trans_params_t * pparams)
{
    gs_transparency_group_params_t tgp = {0};
    gs_rect bbox;

    if (pparams->Background_components != 0 &&
        pparams->Background_components != pdev->color_info.num_components)
        return_error(gs_error_rangecheck);
    tgp.Isolated = pparams->Isolated;
    tgp.Knockout = pparams->Knockout;
    tgp.idle = pparams->idle;
    tgp.mask_id = pparams->mask_id;

    /* Needed so that we do proper blending */
    tgp.group_color = pparams->group_color;
    tgp.group_color_numcomps = pparams->group_color_numcomps;
    tgp.iccprofile = pparams->iccprofile;
    tgp.icc_hashcode = pparams->icc_hash;

    pis->opacity.alpha = pparams->opacity.alpha;
    pis->shape.alpha = pparams->shape.alpha;
    pis->blend_mode = pparams->blend_mode;
    bbox = pparams->bbox;
#ifdef DEBUG
    if (gs_debug_c('v')) {
        static const char *const cs_names[] = {
            GS_COLOR_SPACE_TYPE_NAMES
        };
        dlprintf6("[v](0x%lx)gx_begin_transparency_group [%g %g %g %g] Num_grp_clr_comp = %d\n",
                  (ulong)pis, bbox.p.x, bbox.p.y, bbox.q.x, bbox.q.y,
                        pparams->group_color_numcomps);
        if (tgp.ColorSpace)
            dprintf1("     CS = %s",
                cs_names[(int)gs_color_space_get_index(tgp.ColorSpace)]);
        else
            dputs("     (no CS)");
        dprintf2("  Isolated = %d  Knockout = %d\n",
                 tgp.Isolated, tgp.Knockout);
        if (tgp.iccprofile)
            dprintf("     Have ICC Profile for blending\n");
    }
#endif
    if (dev_proc(pdev, begin_transparency_group) != 0)
        return (*dev_proc(pdev, begin_transparency_group)) (pdev, &tgp,
                                                        &bbox, pis, NULL, NULL);
    else
        return 0;
}
Esempio n. 5
0
/* Convert HSB to RGB. */
static void
color_hsb_to_rgb(floatp hue, floatp saturation, floatp brightness, float rgb[3])
{
    if (saturation == 0) {
        rgb[0] = rgb[1] = rgb[2] = brightness;
    } else {			/* Convert hsb to rgb. */
        /* We rely on the fact that the product of two */
        /* fracs fits into an unsigned long. */
        floatp h6 = hue * 6;
        ulong V = float2frac(brightness);	/* force arithmetic to long */
        frac S = float2frac(saturation);
        int I = (int)h6;
        ulong F = float2frac(h6 - I);	/* ditto */

        /* M = V*(1-S), N = V*(1-S*F), K = V*(1-S*(1-F)) = M-N+V */
        frac M = V * (frac_1_long - S) / frac_1_long;
        frac N = V * (frac_1_long - S * F / frac_1_long) / frac_1_long;
        frac K = M - N + V;
        frac R, G, B;

        switch (I) {
            default:
                R = V;
                G = K;
                B = M;
                break;
            case 1:
                R = N;
                G = V;
                B = M;
                break;
            case 2:
                R = M;
                G = V;
                B = K;
                break;
            case 3:
                R = M;
                G = N;
                B = V;
                break;
            case 4:
                R = K;
                G = M;
                B = V;
                break;
            case 5:
                R = V;
                G = M;
                B = N;
                break;
        }
        rgb[0] = frac2float(R);
        rgb[1] = frac2float(G);
        rgb[2] = frac2float(B);
#ifdef DEBUG
        if (gs_debug_c('c')) {
            dlprintf7("[c]hsb(%g,%g,%g)->VSFI(%ld,%d,%ld,%d)->\n",
                      hue, saturation, brightness, V, S, F, I);
            dlprintf6("   RGB(%d,%d,%d)->rgb(%g,%g,%g)\n",
                      R, G, B, rgb[0], rgb[1], rgb[2]);
        }
#endif
    }
}
Esempio n. 6
0
static void
trace_matrix(register const gs_matrix * pmat)
{
    dlprintf6("\t[%6g %6g %6g %6g %6g %6g]\n",
              pmat->xx, pmat->xy, pmat->yx, pmat->yy, pmat->tx, pmat->ty);
}
Esempio n. 7
0
/* We should cache the coefficients with the ctm.... */
int
gx_matrix_to_fixed_coeff(const gs_matrix * pmat, register fixed_coeff * pfc,
                         int max_bits)
{
    gs_matrix ctm;
    int scale = -10000;
    int expt, shift;

    ctm = *pmat;
    pfc->skewed = 0;
    if (!is_fzero(ctm.xx)) {
        discard(frexp(ctm.xx, &scale));
    }
    if (!is_fzero(ctm.xy)) {
        discard(frexp(ctm.xy, &expt));
        if (expt > scale)
            scale = expt;
        pfc->skewed = 1;
    }
    if (!is_fzero(ctm.yx)) {
        discard(frexp(ctm.yx, &expt));
        if (expt > scale)
            scale = expt;
        pfc->skewed = 1;
    }
    if (!is_fzero(ctm.yy)) {
        discard(frexp(ctm.yy, &expt));
        if (expt > scale)
            scale = expt;
    }
    /*
     * There are two multiplications in fixed_coeff_mult: one involves a
     * factor that may have max_bits significant bits, the other may have
     * fixed_fraction_bits (_fixed_shift) bits.  Ensure that neither one
     * will overflow.
     */
    if (max_bits < fixed_fraction_bits)
        max_bits = fixed_fraction_bits;
    scale = sizeof(long) * 8 - 1 - max_bits - scale;

    shift = scale - _fixed_shift;
    if (shift > 0) {
        pfc->shift = shift;
        pfc->round = (fixed) 1 << (shift - 1);
    } else {
        pfc->shift = 0;
        pfc->round = 0;
        scale -= shift;
    }
#define SET_C(c)\
  if ( is_fzero(ctm.c) ) pfc->c = 0;\
  else pfc->c = (long)ldexp(ctm.c, scale)
    SET_C(xx);
    SET_C(xy);
    SET_C(yx);
    SET_C(yy);
#undef SET_C
#ifdef DEBUG
    if (gs_debug_c('x')) {
        dlprintf6("[x]ctm: [%6g %6g %6g %6g %6g %6g]\n",
                  ctm.xx, ctm.xy, ctm.yx, ctm.yy, ctm.tx, ctm.ty);
        dlprintf6("   scale=%d fc: [0x%lx 0x%lx 0x%lx 0x%lx] shift=%d\n",
                  scale, pfc->xx, pfc->xy, pfc->yx, pfc->yy,
                  pfc->shift);
    }
#endif
    pfc->max_bits = max_bits;
    return 0;
}
Esempio n. 8
0
/* Allocate various kinds of blocks. */
static byte *
gs_heap_alloc_bytes(gs_memory_t * mem, uint size, client_name_t cname)
{
    gs_malloc_memory_t *mmem = (gs_malloc_memory_t *) mem;
    byte *ptr = 0;

#ifdef DEBUG
    const char *msg;
    static const char *const ok_msg = "OK";

#  define set_msg(str) (msg = (str))
#else
#  define set_msg(str) DO_NOTHING
#endif

        /* Exclusive acces so our decisions and changes are 'atomic' */
    if (mmem->monitor)
        gx_monitor_enter(mmem->monitor);
    if (size > mmem->limit - sizeof(gs_malloc_block_t)) {
        /* Definitely too large to allocate; also avoids overflow. */
        set_msg("exceeded limit");
    } else {
        uint added = size + sizeof(gs_malloc_block_t);

        if (mmem->limit - added < mmem->used)
            set_msg("exceeded limit");
        else if ((ptr = (byte *) malloc(added)) == 0)
            set_msg("failed");
        else {
            gs_malloc_block_t *bp = (gs_malloc_block_t *) ptr;

            /*
             * We would like to check that malloc aligns blocks at least as
             * strictly as the compiler (as defined by ARCH_ALIGN_MEMORY_MOD).
             * However, Microsoft VC 6 does not satisfy this requirement.
             * See gsmemory.h for more explanation.
             */
            set_msg(ok_msg);
            if (mmem->allocated)
                mmem->allocated->prev = bp;
            bp->next = mmem->allocated;
            bp->prev = 0;
            bp->size = size;
            bp->type = &st_bytes;
            bp->cname = cname;
            mmem->allocated = bp;
            ptr = (byte *) (bp + 1);
            mmem->used += size + sizeof(gs_malloc_block_t);
            if (mmem->used > mmem->max_used)
                mmem->max_used = mmem->used;
        }
    }
    if (mmem->monitor)
        gx_monitor_leave(mmem->monitor);	/* Done with exclusive access */
    /* We don't want to 'fill' under mutex to keep the window smaller */
    if (ptr)
        gs_alloc_fill(ptr, gs_alloc_fill_alloc, size);
#ifdef DEBUG
    if (gs_debug_c('a') || msg != ok_msg)
        dlprintf6("[a+]gs_malloc(%s)(%u) = 0x%lx: %s, used=%ld, max=%ld\n",
                  client_name_string(cname), size, (ulong) ptr, msg, mmem->used, mmem->max_used);
#endif
    return ptr;
#undef set_msg
}
Esempio n. 9
0
int
gs_begin_transparency_group(gs_state *pgs,
                            const gs_transparency_group_params_t *ptgp,
                            const gs_rect *pbbox)
{
    gs_pdf14trans_params_t params = { 0 };
    const gs_color_space *blend_color_space;
    gs_imager_state * pis = (gs_imager_state *)pgs;
    cmm_profile_t *profile;

    if (check_for_nontrans_pattern(pgs,
                  (unsigned char *)"gs_begin_transparency_group")) {
        return(0);
    }
    /*
     * Put parameters into a compositor parameter and then call the
     * create_compositor.  This will pass the data to the PDF 1.4
     * transparency device.
     */
    params.pdf14_op = PDF14_BEGIN_TRANS_GROUP;
    params.Isolated = ptgp->Isolated;
    params.Knockout = ptgp->Knockout;
    params.image_with_SMask = ptgp->image_with_SMask;
    params.opacity = pgs->opacity;
    params.shape = pgs->shape;
    params.blend_mode = pgs->blend_mode;
    /* This function is called during the c-list writer side.
       Store some information so that we know what the color space is
       so that we can adjust according later during the clist reader.
       We currently will use the concrete space for any space other than a
       device space.  However, if the device is a sep device it will blend
       in DeviceN color space as required.  */
    blend_color_space = gs_currentcolorspace_inline(pgs);
    if (gs_color_space_get_index(blend_color_space) > gs_color_space_index_DeviceCMYK) {
        /* ICC and PS CIE based case.  Note that unidirectional PS CIE color
           spaces should not be allowed but end up occuring when processing
           PDF files with -dUseCIEColor.  We will end up using the appropriate
           ICC default color space in these cases. */
        blend_color_space = gs_currentcolorspace_inline(pgs);
    } else {
        blend_color_space = cs_concrete_space(blend_color_space, pis);
    }
    /* Note that if the /CS parameter was NOT present in the push
       of the transparency group, then we must actually inherent
       the previous group color space, or the color space of the
       target device (process color model).  Here we just want
       to set it as a unknown type for clist writing, as we will take care
       of using the parent group color space later during clist reading.
       */
    if (ptgp->ColorSpace == NULL) {
        params.group_color = UNKNOWN;
        params.group_color_numcomps = 0;
    } else {
        /* The /CS parameter was present.  Use what was set.  Currently
           all our Device spaces are actually ICC based.  The other options
           are if -dUseCIEColor is set, in which case it could be
           coming in as a PS CIE color space, which should not be allowed
           but should default to one of the default ICC color spaces.  Note
           that CalRGB and CalGray, which are valid bidirectional color spaces
           are converted to ICC profiles during installation. PS CIE building
           to ICC is delayed. */
        if ( gs_color_space_is_ICC(blend_color_space) ) {
            /* Blending space is ICC based.  If we are doing c-list rendering
               we will need to write this color space into the clist.
               */
            params.group_color = ICC;
            params.group_color_numcomps =
                blend_color_space->cmm_icc_profile_data->num_comps;
            /* Get the ICC profile */
            params.iccprofile = blend_color_space->cmm_icc_profile_data;
            params.icc_hash = blend_color_space->cmm_icc_profile_data->hashcode;
        } else {
            /* Color space was NOT ICC based.  PS CIE space and DeviceN are the only
               other option.  Use the ICC default based upon the component count. */
            switch (cs_num_components(blend_color_space)) {
                case 1:
                    profile =  pgs->icc_manager->default_gray;
                    break;
                case 3:
                    profile =  pgs->icc_manager->default_rgb;
                    break;
                case 4:
                    profile =  pgs->icc_manager->default_cmyk;
                break;
                default:
                    /* We can end up here if we are in a deviceN color space and
                       we have a sep output device */
                    profile = NULL;
                    params.group_color = DEVICEN;
                    params.group_color_numcomps = cs_num_components(blend_color_space);
                break;
            }
            if (profile != NULL) {
                params.group_color = ICC;
                params.group_color_numcomps = profile->num_comps;
                params.iccprofile = profile;
                params.icc_hash = profile->hashcode;
            }
        }
    }
#ifdef DEBUG
    if (gs_debug_c('v')) {
        static const char *const cs_names[] = {
            GS_COLOR_SPACE_TYPE_NAMES
        };
        dlprintf6("[v](0x%lx)begin_transparency_group [%g %g %g %g] Num_grp_clr_comp = %d\n",
                  (ulong)pgs, pbbox->p.x, pbbox->p.y, pbbox->q.x, pbbox->q.y,params.group_color_numcomps);
        if (ptgp->ColorSpace)
            dprintf1("     CS = %s",
                cs_names[(int)gs_color_space_get_index(ptgp->ColorSpace)]);
        else
            dputs("     (no CS)");

        dprintf2("  Isolated = %d  Knockout = %d\n",
                 ptgp->Isolated, ptgp->Knockout);
    }
#endif
    params.bbox = *pbbox;
    return gs_state_update_pdf14trans(pgs, &params);
}