Ejemplo n.º 1
0
/* Flush any buffered data. */
int
gx_image1_flush(gx_image_enum_common_t * info)
{
    gx_image_enum *penum = (gx_image_enum *)info;
    int width_spp = penum->rect.w * penum->spp;
    fixed adjust = penum->adjust;

    penum->cur.x = dda_current(penum->dda.row.x);
    penum->cur.y = dda_current(penum->dda.row.y);
    switch (penum->posture) {
        case image_portrait:
            {
                fixed yc = penum->cur.y;

                penum->yci = fixed2int_rounded(yc - adjust);
                penum->hci = fixed2int_rounded(yc + adjust) - penum->yci;
            }
            break;
        case image_landscape:
            {
                fixed xc = penum->cur.x;

                penum->xci = fixed2int_rounded(xc - adjust);
                penum->wci = fixed2int_rounded(xc + adjust) - penum->xci;
            }
            break;
        case image_skewed:	/* pacify compilers */
            ;
    }
    update_strip(penum);
    penum->prev = penum->cur;
    return (*penum->render)(penum, NULL, 0, width_spp, 0,
                            setup_image_device(penum));
}
Ejemplo n.º 2
0
/* Process the next piece of an image */
int
gx_default_image_data(gx_device *dev,
  void *info, const byte **planes, int data_x, uint raster, int height)
{	gx_image_enum *penum = info;
	int y = penum->y;
	int y_end = min(y + height, penum->rect.h);
	int width_spp = penum->rect.w * penum->spp;
	int nplanes = penum->num_planes;
	uint bcount =			/* bytes per data row */
	  (width_spp / penum->num_planes * penum->bps + 7) >> 3;
	fixed adjust = penum->adjust;
	gx_dda_fixed_point pixel0;
	ulong offset = 0;
	int ignore_data_x;
	int code;

	if ( height == 0 )
	  return 0;

	/* Set up the clipping and/or RasterOp device if needed. */

	if ( penum->clip_dev )
	   {	gx_device_clip *cdev = penum->clip_dev;
		cdev->target = dev;
		dev = (gx_device *)cdev;
	   }
	if ( penum->rop_dev )
	  {	gx_device_rop_texture *rtdev = penum->rop_dev;
		((gx_device_forward *)rtdev)->target = dev;
		dev = (gx_device *)rtdev;
	  }
	pixel0 = penum->dda.pixel0;

	/* Now render complete rows. */

	for ( ; penum->y < y_end; offset += raster, penum->y++ )
	   {	int px;
		/*
		 * Normally, we unpack the data into the buffer, but if
		 * there is only one plane and we don't need to expand the
		 * input samples, we may use the data directly.
		 */
	        int sourcex = data_x;
		const byte *buffer =
		  (*penum->unpack)(penum->buffer, &sourcex,
				   planes[0] + offset, data_x, bcount,
				   &penum->map[0].table, penum->spread);

		for ( px = 1; px < nplanes; ++px )
		  (*penum->unpack)(penum->buffer + (px << penum->log2_xbytes),
				   &ignore_data_x, planes[px] + offset,
				   data_x, bcount,
				   &penum->map[px].table, penum->spread);
#ifdef DEBUG
		if ( gs_debug_c('B') )
		  { int i, n = width_spp;
		    dputs("[B]row:");
		    for ( i = 0; i < n; i++ )
		      dprintf1(" %02x", buffer[i]);
		    dputs("\n");
		  }
#endif
		penum->cur.x = dda_current(penum->dda.row.x);
		dda_next(penum->dda.row.x);
		penum->cur.y = dda_current(penum->dda.row.y);
		dda_next(penum->dda.row.y);
		if ( !penum->interpolate )
		  switch ( penum->posture )
		    {
		    case image_portrait:
		      { /* Precompute integer y and height, */
			/* and check for clipping. */
			fixed yc = penum->cur.y,
			  yn = dda_current(penum->dda.row.y);

			if ( yn < yc )
			  { fixed temp = yn; yn = yc; yc = temp; }
			yc -= adjust;
			if ( yc >= penum->clip_outer.q.y ) goto mt;
			yn += adjust;
			if ( yn <= penum->clip_outer.p.y ) goto mt;
			penum->yci = fixed2int_pixround(yc);
			penum->hci = fixed2int_pixround(yn) - penum->yci;
			if ( penum->hci == 0 ) goto mt;
		      }	break;
		    case image_landscape:
		      { /* Check for no pixel centers in x. */
			fixed xc = penum->cur.x,
			  xn = dda_current(penum->dda.row.x);

			if ( xn < xc )
			  { fixed temp = xn; xn = xc; xc = temp; }
			xc -= adjust;
			if ( xc >= penum->clip_outer.q.x ) goto mt;
			xn += adjust;
			if ( xn <= penum->clip_outer.p.x ) goto mt;
			penum->xci = fixed2int_pixround(xc);
			penum->wci = fixed2int_pixround(xn) - penum->xci;
			if ( penum->wci == 0 ) goto mt;
		      }	break;
		    case image_skewed:
		      ;
		    }
		dda_translate(penum->dda.pixel0.x,
			      penum->cur.x - penum->prev.x);
		dda_translate(penum->dda.pixel0.y,
			      penum->cur.y - penum->prev.y);
		penum->prev = penum->cur;
		code = (*penum->render)(penum, buffer, sourcex, width_spp, 1,
					dev);
		if ( code < 0 )
		  goto err;
mt:		;
	   }
	if ( penum->y < penum->rect.h )
	  { code = 0;
	    goto out;
	  }
	/* End of data.  Render any left-over buffered data. */
	switch ( penum->posture )
	  {
	  case image_portrait:
	    {	fixed yc = dda_current(penum->dda.row.y);
		penum->yci = fixed2int_rounded(yc - adjust);
		penum->hci = fixed2int_rounded(yc + adjust) - penum->yci;
	    }	break;
	  case image_landscape:
	    {	fixed xc = dda_current(penum->dda.row.x);
		penum->xci = fixed2int_rounded(xc - adjust);
		penum->wci = fixed2int_rounded(xc + adjust) - penum->xci;
	    }	break;
	  case image_skewed:		/* pacify compilers */
	    ;
	  }
	dda_translate(penum->dda.pixel0.x, penum->cur.x - penum->prev.x);
	dda_translate(penum->dda.pixel0.y, penum->cur.y - penum->prev.y);
	code = (*penum->render)(penum, NULL, 0, width_spp, 0, dev);
	if ( code < 0 )
	  { penum->y--;
	    goto err;
	  }
	code = 1;
	goto out;
err:	/* Error or interrupt, restore original state. */
	while ( penum->y > y )
	  { dda_previous(penum->dda.row.x);
	    dda_previous(penum->dda.row.y);
	    --(penum->y);
	  }
	/* Note that caller must call end_image */
	/* for both error and normal termination. */
out:	return code;
}
Ejemplo n.º 3
0
irender_proc_t
gs_image_class_1_simple(gx_image_enum * penum)
{
    irender_proc_t rproc;
    fixed ox = dda_current(penum->dda.pixel0.x);
    fixed oy = dda_current(penum->dda.pixel0.y);

    if (penum->use_rop || penum->spp != 1 || penum->bps != 1)
        return 0;
    switch (penum->posture) {
        case image_portrait:
            {			/* Use fast portrait algorithm. */
                long dev_width =
                    fixed2long_pixround(ox + penum->x_extent.x) -
                    fixed2long_pixround(ox);

                if (dev_width != penum->rect.w) {
                    /*
                     * Add an extra align_bitmap_mod of padding so that
                     * we can align scaled rows with the device.
                     */
                    long line_size =
                        bitmap_raster(any_abs(dev_width)) + align_bitmap_mod;

                    if (penum->adjust != 0 || line_size > max_uint)
                        return 0;
                    /* Must buffer a scan line. */
                    penum->line_width = any_abs(dev_width);
                    penum->line_size = (uint) line_size;
                    penum->line = gs_alloc_bytes(penum->memory,
                                            penum->line_size, "image line");
                    if (penum->line == 0) {
                        gx_default_end_image(penum->dev,
                                             (gx_image_enum_common_t *)penum,
                                             false);
                        return 0;
                    }
                }
                if_debug2('b', "[b]render=simple, unpack=copy; rect.w=%d, dev_width=%ld\n",
                          penum->rect.w, dev_width);
                rproc = image_render_simple;
                break;
            }
        case image_landscape:
            {			/* Use fast landscape algorithm. */
                long dev_width =
                    fixed2long_pixround(oy + penum->x_extent.y) -
                    fixed2long_pixround(oy);
                long line_size =
                    (dev_width = any_abs(dev_width),
                     bitmap_raster(dev_width) * 8 +
                     ROUND_UP(dev_width, 8) * align_bitmap_mod);

                if ((dev_width != penum->rect.w && penum->adjust != 0) ||
                    line_size > max_uint
                    )
                    return 0;
                /* Must buffer a group of 8N scan lines. */
                penum->line_width = dev_width;
                penum->line_size = (uint) line_size;
                penum->line = gs_alloc_bytes(penum->memory,
                                             penum->line_size, "image line");
                if (penum->line == 0) {
                    gx_default_end_image(penum->dev,
                                         (gx_image_enum_common_t *) penum,
                                         false);
                    return 0;
                }
                penum->xi_next = penum->line_xy = fixed2int_var_rounded(ox);
                if_debug3('b', "[b]render=landscape, unpack=copy; rect.w=%d, dev_width=%ld, line_size=%ld\n",
                          penum->rect.w, dev_width, line_size);
                rproc = image_render_landscape;
                /* Precompute values needed for rasterizing. */
                penum->dxy =
                    float2fixed(penum->matrix.xy +
                                fixed2float(fixed_epsilon) / 2);
                break;
            }
        default:
            return 0;
    }
    /* Precompute values needed for rasterizing. */
    penum->dxx =
        float2fixed(penum->matrix.xx + fixed2float(fixed_epsilon) / 2);
    /*
     * We don't want to spread the samples, but we have to reset unpack_bps
     * to prevent the buffer pointer from being incremented by 8 bytes per
     * input byte.
     */
    penum->unpack = sample_unpack_copy;
    penum->unpack_bps = 8;
    if (penum->use_mask_color) {
        /*
         * Set the masked color as 'no_color' to make it transparent
         *  according to the mask color range and the decoding.
         */
        penum->masked = true;
        if (penum->mask_color.values[0] == 1) {
            /* if v0 == 1, 1 is transparent since v1 must be == 1 to be a valid range */
            set_nonclient_dev_color(penum->map[0].inverted ? penum->icolor0 : penum->icolor1,
                        gx_no_color_index);
        } else if (penum->mask_color.values[1] == 0) {
            /* if v1 == 0, 0 is transparent since v0 must be == 0 to be a valid range */
            set_nonclient_dev_color(penum->map[0].inverted ? penum->icolor1 : penum->icolor0,
                        gx_no_color_index);
        } else {
            /*
             * The only other possible in-range value is v0 = 0, v1 = 1.
             * The image is completely transparent!
             */
            rproc = image_render_skip;
        }
        penum->map[0].decoding = sd_none;
    }
    return rproc;
}
Ejemplo n.º 4
0
/* Process a buffer.  Note that this handles Encode and Decode identically. */
static int
s_ISpecialDownScale_process(stream_state * st, stream_cursor_read * pr,
                 stream_cursor_write * pw, bool last)
{
    stream_ISpecialDownScale_state *const ss = (stream_ISpecialDownScale_state *) st;
    uint cur_y = dda_current(ss->dda_y);

    /* Check whether we need to deliver any output. */

top:
    if (cur_y > ss->dst_y) {
        /* Deliver some or all of the current scaled row. */
        /* to generate a vertically scaled output row. */
        uint wleft = pw->limit - pw->ptr;

        if (ss->dst_y == ss->params.HeightOut)
            return EOFC;
        if (wleft == 0)
            return 1;
        if (ss->dst_offset == 0) {
            byte *row;

            if (wleft >= ss->dst_size) {	/* We can scale the row directly into the output. */
                row = pw->ptr + 1;
                pw->ptr += ss->dst_size;
            } else {		/* We'll have to buffer the row. */
                row = ss->dst;
            }
            /* Apply filter to zoom vertically from tmp to dst. */
            idownscale_y(row, ss->tmp, ss);
            /* Idiotic C coercion rules allow T* and void* to be */
            /* inter-assigned freely, but not compared! */
            if ((void *)row != ss->dst)		/* no buffering */
                goto adv;
        } {			/* We're delivering a buffered output row. */
            uint wcount = ss->dst_size - ss->dst_offset;
            uint ncopy = min(wleft, wcount);

            memcpy(pw->ptr + 1, (byte *) ss->dst + ss->dst_offset, ncopy);
            pw->ptr += ncopy;
            ss->dst_offset += ncopy;
            if (ncopy != wcount)
                return 1;
            ss->dst_offset = 0;
        }
        /* Advance to the next output row. */
adv:	++(ss->dst_y);
    }

    /* Read input data and scale horizontally into tmp. */

    {
        uint rleft = pr->limit - pr->ptr;
        uint rcount = ss->src_size - ss->src_offset;

        if (rleft == 0)
            return 0;		/* need more input */
        if (ss->src_y >= ss->params.HeightIn)
            return ERRC;
        if (rleft >= rcount) {	/* We're going to fill up a row. */
            const byte *row;

            if (ss->src_offset == 0) {	/* We have a complete row.  Read the data */
                /* directly from the input. */
                row = pr->ptr + 1;
            } else {		/* We're buffering a row in src. */
                row = ss->src;
                memcpy((byte *) ss->src + ss->src_offset, pr->ptr + 1,
                       rcount);
                ss->src_offset = 0;
            }
            /* Apply filter to zoom horizontally from src to tmp. */
            if_debug2('w', "[w]idownscale_x y = %d to tmp row %d\n",
                      ss->src_y, (ss->src_y % MAX_ISCALE_SUPPORT));
            idownscale_x(ss->tmp, row, ss);
            pr->ptr += rcount;
            ++(ss->src_y);
            dda_next_assign(ss->dda_y,cur_y);
            goto top;
        } else {		/* We don't have a complete row.  Copy data to src buffer. */
            memcpy((byte *) ss->src + ss->src_offset, pr->ptr + 1, rleft);
            ss->src_offset += rleft;
            pr->ptr += rleft;
            return 0;
        }
    }
}
Ejemplo n.º 5
0
/* Process the next piece of an ImageType 1 image. */
int
gx_image1_plane_data(gx_image_enum_common_t * info,
                     const gx_image_plane_t * planes, int height,
                     int *rows_used)
{
    gx_image_enum *penum = (gx_image_enum *) info;
    gx_device *dev;
    const int y = penum->y;
    int y_end = min(y + height, penum->rect.h);
    int width_spp = penum->rect.w * penum->spp;
    int num_planes = penum->num_planes;
    int num_components_per_plane = 1;

#define BCOUNT(plane)		/* bytes per data row */\
  (((penum->rect.w + (plane).data_x) * penum->spp * penum->bps / num_planes\
    + 7) >> 3)

    fixed adjust = penum->adjust;
    ulong offsets[GS_IMAGE_MAX_COMPONENTS];
    int ignore_data_x;
    bool bit_planar = penum->num_planes > penum->spp;
    int code;

    if (height == 0) {
        *rows_used = 0;
        return 0;
    }
    dev = setup_image_device(penum);

    /* Now render complete rows. */

    if (penum->used.y) {
        /*
         * Processing was interrupted by an error.  Skip over rows
         * already processed.
         */
        int px;

        for (px = 0; px < num_planes; ++px)
            offsets[px] = planes[px].raster * penum->used.y;
        penum->used.y = 0;
    } else
        memset(offsets, 0, num_planes * sizeof(offsets[0]));
    if (num_planes == 1 && penum->plane_depths[0] != penum->bps) {
        /* A single plane with multiple components. */
        num_components_per_plane = penum->plane_depths[0] / penum->bps;
    }
    for (; penum->y < y_end; penum->y++) {
        int px;
        const byte *buffer;
        int sourcex;
        int x_used = penum->used.x;

        if (bit_planar) {
            /* Repack the bit planes into byte-wide samples. */

            buffer = penum->buffer;
            sourcex = 0;
            for (px = 0; px < num_planes; px += penum->bps)
                repack_bit_planes(planes, offsets, penum->bps, penum->buffer,
                                  penum->rect.w, &penum->map[px].table,
                                  penum->spread);
            for (px = 0; px < num_planes; ++px)
                offsets[px] += planes[px].raster;
        } else {
            /*
             * Normally, we unpack the data into the buffer, but if
             * there is only one plane and we don't need to expand the
             * input samples, we may use the data directly.
             */
            sourcex = planes[0].data_x;
            buffer =
                (*penum->unpack)(penum->buffer, &sourcex,
                                 planes[0].data + offsets[0],
                                 planes[0].data_x, BCOUNT(planes[0]),
                                 &penum->map[0], penum->spread, num_components_per_plane);

            offsets[0] += planes[0].raster;
            for (px = 1; px < num_planes; ++px) {
                (*penum->unpack)(penum->buffer + (px << penum->log2_xbytes),
                                 &ignore_data_x,
                                 planes[px].data + offsets[px],
                                 planes[px].data_x, BCOUNT(planes[px]),
                                 &penum->map[px], penum->spread, 1);
                offsets[px] += planes[px].raster;
            }
        }
#ifdef DEBUG
        if (gs_debug_c('b'))
            dprintf1("[b]image1 y=%d\n", y);
        if (gs_debug_c('B')) {
            int i, n = width_spp;

            if (penum->bps > 8)
                n *= 2;
            else if (penum->bps == 1 && penum->unpack_bps == 8)
                n = (n + 7) / 8;
            dlputs("[B]row:");
            for (i = 0; i < n; i++)
                dprintf1(" %02x", buffer[i]);
            dputs("\n");
        }
#endif
        penum->cur.x = dda_current(penum->dda.row.x);
        dda_next(penum->dda.row.x);
        penum->cur.y = dda_current(penum->dda.row.y);
        dda_next(penum->dda.row.y);
        if (!penum->interpolate)
            switch (penum->posture) {
                case image_portrait:
                    {		/* Precompute integer y and height, */
                        /* and check for clipping. */
                        fixed yc = penum->cur.y,
                            yn = dda_current(penum->dda.row.y);

                        if (yn < yc) {
                            fixed temp = yn;

                            yn = yc;
                            yc = temp;
                        }
                        yc -= adjust;
                        if (yc >= penum->clip_outer.q.y)
                            goto mt;
                        yn += adjust;
                        if (yn <= penum->clip_outer.p.y)
                            goto mt;
                        penum->yci = fixed2int_pixround_perfect(yc);
                        penum->hci = fixed2int_pixround_perfect(yn) - penum->yci;
                        if (penum->hci == 0)
                            goto mt;
                        if_debug2('b', "[b]yci=%d, hci=%d\n",
                                  penum->yci, penum->hci);
                    }
                    break;
                case image_landscape:
                    {		/* Check for no pixel centers in x. */
                        fixed xc = penum->cur.x,
                            xn = dda_current(penum->dda.row.x);

                        if (xn < xc) {
                            fixed temp = xn;

                            xn = xc;
                            xc = temp;
                        }
                        xc -= adjust;
                        if (xc >= penum->clip_outer.q.x)
                            goto mt;
                        xn += adjust;
                        if (xn <= penum->clip_outer.p.x)
                            goto mt;
                        penum->xci = fixed2int_pixround_perfect(xc);
                        penum->wci = fixed2int_pixround_perfect(xn) - penum->xci;
                        if (penum->wci == 0)
                            goto mt;
                        if_debug2('b', "[b]xci=%d, wci=%d\n",
                                  penum->xci, penum->wci);
                    }
                    break;
                case image_skewed:
                    ;
            }
        update_strip(penum);
        if (x_used) {
            /*
             * Processing was interrupted by an error.  Skip over pixels
             * already processed.
             */
            dda_advance(penum->dda.pixel0.x, x_used);
            dda_advance(penum->dda.pixel0.y, x_used);
            penum->used.x = 0;
        }
        if_debug2('b', "[b]pixel0 x=%g, y=%g\n",
                  fixed2float(dda_current(penum->dda.pixel0.x)),
                  fixed2float(dda_current(penum->dda.pixel0.y)));
        code = (*penum->render)(penum, buffer, sourcex + x_used,
                                width_spp - x_used * penum->spp, 1, dev);
        if (code < 0) {
            /* Error or interrupt, restore original state. */
            penum->used.x += x_used;
            if (!penum->used.y) {
                dda_previous(penum->dda.row.x);
                dda_previous(penum->dda.row.y);
                dda_translate(penum->dda.strip.x,
                              penum->prev.x - penum->cur.x);
                dda_translate(penum->dda.strip.y,
                              penum->prev.y - penum->cur.y);
            }
            goto out;
        }
        penum->prev = penum->cur;
      mt:;
    }
    if (penum->y < penum->rect.h) {
        code = 0;
    } else {
        /* End of input data.  Render any left-over buffered data. */
        code = gx_image1_flush(info);
        if (code >= 0)
            code = 1;
    }
out:
    /* Note that caller must call end_image */
    /* for both error and normal termination. */
    *rows_used = penum->y - y;
    return code;
}
Ejemplo n.º 6
0
int
gxht_thresh_image_init(gx_image_enum *penum)
{
    int code = 0;
    fixed ox, oy;
    int temp;
    int dev_width, max_height;
    int spp_out;
    int k;
    gx_ht_order *d_order;

    if (gx_device_must_halftone(penum->dev)) {
        if (penum->pis != NULL && penum->pis->dev_ht != NULL) {
            for (k = 0; k < penum->pis->dev_ht->num_comp; k++) {
                d_order = &(penum->pis->dev_ht->components[k].corder);
                code = gx_ht_construct_threshold(d_order, penum->dev, 
                                                 penum->pis, k);
                if (code < 0 ) {
                    return gs_rethrow(code, "threshold creation failed");
                }
            }
        } else {
            return -1;
        }
    }
    spp_out = penum->dev->color_info.num_components;
    /* If the image is landscaped then we want to maintain a buffer
       that is sufficiently large so that we can hold a byte
       of halftoned data along the column.  This way we avoid doing
       multiple writes into the same position over and over.
       The size of the buffer we need depends upon the bitdepth of
       the output device, the number of device coloranants and the
       number of  colorants in the source space.  Note we will
       need to eventually  consider  multi-level halftone case
       here too.  For now, to make use of the SSE2 stuff, we would
       like to have 16 bytes of data to process at a time.  So we
       will collect the columns of data in a buffer that is 16 wide.
       We will also keep track of the widths of each column.  When
       the total width count reaches 16, we will create our
       threshold array and apply it.  We may have one column that is
       buffered between calls in this case.  Also if a call is made
       with h=0 we will flush the buffer as we are at the end of the
       data.  */
    if (penum->posture == image_landscape) {
        int col_length = 
            fixed2int_var_rounded(any_abs(penum->x_extent.y)) * spp_out;
        ox = dda_current(penum->dda.pixel0.x);
        oy = dda_current(penum->dda.pixel0.y);
        temp = (int) ceil((float) col_length/16.0);
        penum->line_size = temp * 16;  /* The stride */
        /* Now we need at most 16 of these */
        penum->line = gs_alloc_bytes(penum->memory,
                                     16 * penum->line_size + 16,
                                     "gxht_thresh");
        /* Same with this */
        penum->thresh_buffer = gs_alloc_bytes(penum->memory,
                                   penum->line_size * 16  + 16,
                                   "gxht_thresh");
        /* That maps into 2 bytes of Halftone data */
        penum->ht_buffer = gs_alloc_bytes(penum->memory,
                                       penum->line_size * 2,
                                       "gxht_thresh");
        penum->ht_stride = penum->line_size;
        if (penum->line == NULL || penum->thresh_buffer == NULL
                    || penum->ht_buffer == NULL)
            return -1;
        penum->ht_landscape.count = 0;
        penum->ht_landscape.num_contones = 0;
        if (penum->y_extent.x < 0) {
            /* Going right to left */
            penum->ht_landscape.curr_pos = 15;
            penum->ht_landscape.index = -1;
        } else {
            /* Going left to right */
            penum->ht_landscape.curr_pos = 0;
            penum->ht_landscape.index = 1;
        }
        if (penum->x_extent.y < 0) {
            penum->ht_landscape.flipy = true;
            penum->ht_landscape.y_pos =
                fixed2int_pixround_perfect(dda_current(penum->dda.pixel0.y) + penum->x_extent.y);
        } else {
            penum->ht_landscape.flipy = false;
            penum->ht_landscape.y_pos =
                fixed2int_pixround_perfect(dda_current(penum->dda.pixel0.y));
        }
        memset(&(penum->ht_landscape.widths[0]), 0, sizeof(int)*16);
        penum->ht_landscape.offset_set = false;
        penum->ht_offset_bits = 0; /* Will get set in call to render */
        if (code >= 0) {
#if defined(DEBUG) || defined(PACIFY_VALGRIND)
            memset(penum->line, 0, 16 * penum->line_size + 16);
            memset(penum->ht_buffer, 0, penum->line_size * 2);
            memset(penum->thresh_buffer, 0, 16 * penum->line_size + 16);
#endif
        }
    } else {
        /* In the portrait case we allocate a single line buffer
           in device width, a threshold buffer of the same size
           and possibly wider and the buffer for the halftoned
           bits. We have to do a bit of work to enable 16 byte
           boundary after an offset to ensure that we can make use
           of  the SSE2 operations for thresholding.  We do the
           allocations now to avoid doing them with every line */
        /* Initialize the ht_landscape stuff to zero */
        memset(&(penum->ht_landscape), 0, sizeof(ht_landscape_info_t));
        ox = dda_current(penum->dda.pixel0.x);
        oy = dda_current(penum->dda.pixel0.y);
        dev_width =
           (int) fabs((long) fixed2long_pixround(ox + penum->x_extent.x) -
                    fixed2long_pixround(ox));
        /* Get the bit position so that we can do a copy_mono for
           the left remainder and then 16 bit aligned copies for the
           rest.  The right remainder will be OK as it will land in
           the MSBit positions. Note the #define chunk bits16 in
           gdevm1.c.  Allow also for a 15 sample over run.
        */
        penum->ht_offset_bits = (-fixed2int_var_pixround(ox)) & 15;
        if (penum->ht_offset_bits > 0) {
            penum->ht_stride = ((7 + (dev_width + 4)) / 8) +
                                ARCH_SIZEOF_LONG;
        } else {
            penum->ht_stride = ((7 + (dev_width + 2)) / 8) +
                            ARCH_SIZEOF_LONG;
        }
        /* We want to figure out the maximum height that we may
           have in taking a single source row and going to device
           space */
        max_height = (int) ceil(fixed2float(any_abs(penum->dst_height)) /
                                            (float) penum->Height);
        penum->ht_buffer = gs_alloc_bytes(penum->memory,
                                          penum->ht_stride * max_height * spp_out,
                                          "gxht_thresh");
        /* We want to have 128 bit alignement for our contone and
           threshold strips so that we can use SSE operations
           in the threshold operation.  Add in a minor buffer and offset
           to ensure this.  If gs_alloc_bytes provides at least 16
           bit alignment so we may need to move 14 bytes.  However, the
           HT process is split in two operations.  One that involves
           the HT of a left remainder and the rest which ensures that
           we pack in the HT data in the bits with no skew for a fast
           copy into the gdevm1 device (16 bit copies).  So, we
           need to account for those pixels which occur first and which
           are NOT aligned for the contone buffer.  After we offset
           by this remainder portion we should be 128 bit aligned.
           Also allow a 15 sample over run during the execution.  */
        temp = (int) ceil((float) ((dev_width + 15.0) + 15.0)/16.0);
        penum->line_size = temp * 16;  /* The stride */
        penum->line = gs_alloc_bytes(penum->memory, penum->line_size * spp_out, 
                                     "gxht_thresh");
        penum->thresh_buffer = gs_alloc_bytes(penum->memory, 
                                              penum->line_size * max_height * spp_out,
                                              "gxht_thresh");
        if (penum->line == NULL || penum->thresh_buffer == NULL || 
            penum->ht_buffer == NULL) {
            return -1;
        } else {
#if defined(DEBUG) || defined(PACIFY_VALGRIND)
            memset(penum->line, 0, penum->line_size * spp_out);
            memset(penum->ht_buffer, 0,
                   penum->ht_stride * max_height * spp_out);
            memset(penum->thresh_buffer, 0,
                   penum->line_size * max_height * spp_out);
#endif
        }
    }
    /* Precompute values needed for rasterizing. */
    penum->dxx = float2fixed(penum->matrix.xx + fixed2float(fixed_epsilon) / 2);
    return code;
}