Beispiel #1
0
/* This routine is used for all non-separated formats. */
static int
bmp_print_page(gx_device_printer * pdev, FILE * file)
{
    uint raster = gdev_prn_raster(pdev);
    /* BMP scan lines are padded to 32 bits. */
    uint bmp_raster = raster + (-(int)raster & 3);
    byte *row = gs_alloc_bytes(pdev->memory, bmp_raster, "bmp file buffer");
    int y;
    int code;		/* return code */

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

    /* Write the file header. */

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

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

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

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

    return code;
}
/* MD5000 monochrome mode print. */
static int
md50_print_page(gx_device_printer *pdev, FILE *prn_stream,
	      const char *init_str, int init_size)
{
  int lnum;
  int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
  byte *data = (byte *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), 8, line_size, "md50_print_page(data)" );
  int skipping = 0;
  int nbyte;
  int nskip;
  int n;

    /* Load Paper & Select Inc Cartridge */
  fwrite(init_str, sizeof(char), init_size, prn_stream);
  fflush(prn_stream);

  for ( lnum = 0; lnum <= pdev->height; lnum++ ) {
    byte *end_data = data + line_size;
    byte *start_data = data;
    memset(data, 0, LINE_SIZE);
    n = gdev_prn_copy_scan_lines(pdev, lnum,
			     (byte *)data, line_size);

    /* Remove trailing 0s. */
    while ( end_data > data && end_data[-1] == 0 )
      end_data--;
    /* Count pre print skip octets */
    while ( start_data < end_data && *start_data == 0 )
      start_data++;
    nbyte = end_data - start_data;
    nskip = start_data - data;

    if(nbyte == 0)
      {
	skipping++;
	continue;
      }
    else
      {
	if(skipping)
	  {
	    fprintf(prn_stream, "%c%c%c%c%c%c", 0x1b, 0x2a, 0x62,
		    skipping & 0xff, (skipping & 0xff00) / 0x100, 0x59);
	    skipping = 0;
	  }
	fprintf(prn_stream, "%c%c%c%c%c%c%c%c", 0x1b, 0x2a, 0x62,
		nbyte & 0xff, (nbyte & 0xff00) / 0x100, 0x54,
		nskip & 0xff, (nskip & 0xff00) / 0x100);
	fwrite(start_data, sizeof(char), nbyte, prn_stream);
      }
  }

  /* Eject Page */
  fwrite(end_md, sizeof(char), sizeof(end_md), prn_stream);
  fflush(prn_stream);
  
  return 0;
}
static void
BoundImage(gx_device_printer *pDev, struct bounding *pBox)
{
	int	x, y, flag;
	int	LineSize = gdev_mem_bytes_per_scan_line((gx_device *)pDev);
	int	Xsize, Ysize, Pt, Pb, Pl, Pr;
	int	Xres = (int)pDev->x_pixels_per_inch,
		Yres = (int)pDev->y_pixels_per_inch,
		height = pDev->height;
	byte	*Buf;
	enum	Paper	paper;

        /* ----==== Check parameters ====---- */
	paper = height*10/Yres < 82 ? postcard :\
		height*10/Yres < 98 ? a5 :\
		height*10/Yres < 109 ? b5 :\
		height*10/Yres < 116 ? letter : a4;
	Xsize = Xres * mm_to_inch(PaperInfo[paper].w-100) / 160;
	Ysize = Yres * mm_to_inch(PaperInfo[paper].h-100) / 10;
	/* ----==== Allocate momory ====---- */
	if (LineSize < Xsize*2+1) {
		LineSize = Xsize*2+1;
	}
	Buf = (byte *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), 1, LineSize, "LineBuffer");
	/* ----==== bounding image ====---- */
	Pt = Pb = Pl = Pr = -1;
	for(y=0 ; y<height && y<Ysize ; y++){
		flag = 0;
		gdev_prn_copy_scan_lines(pDev, y, Buf, LineSize);
		for (x=0 ; x<min(LineSize/2, Xsize) ; x++) {
			if (*(Buf+x*2) || *(Buf+x*2+1)) {
				if (Pl == -1 || Pl > x) {
				        Pl = x;
			        }
				if (Pr < x) {
				        Pr = x;
				}
				flag = 1;
			}
		}
		if (flag) {
			if (Pt == -1) {
			        Pt = y;
			}
			Pb = y;
		}
	}
	pBox->paper = paper;
	pBox->Top = Pt;
	pBox->Bottom = Pb;
	pBox->Left = Pl;
	pBox->Right = Pr;
	gs_free(gs_lib_ctx_get_non_gc_memory_t(), Buf, 1, LineSize, "LineBuffer");
}
Beispiel #4
0
/* Send the page to the printer.  Compress each scan line.  NB - the
 * render mode as well as color parameters - bpp etc. are all
 * hardwired.
 */
static int
cljc_print_page(gx_device_printer * pdev, FILE * prn_stream)
{
    gs_memory_t *mem = pdev->memory;
    uint raster = gx_device_raster((gx_device *)pdev, false);
    int i;
    int worst_case_comp_size = raster + (raster / 8) + 1;
    byte *data = 0;
    byte *cdata = 0;
    byte *prow = 0;
    int code = 0;

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

        code = gdev_prn_copy_scan_lines(pdev, i, (byte *) data, raster);
        if (code < 0)
            break;
        compressed_size = gdev_pcl_mode3compress(raster, data, prow, cdata);
        fprintf(prn_stream, "\033*b%dW", compressed_size);
        fwrite(cdata, sizeof(byte), compressed_size, prn_stream);
    }
    /* PCL will take care of blank lines at the end */
    fputs("\033*rC\f", prn_stream);
out:
    gs_free_object(mem, prow, "cljc_print_page(prow)");
    gs_free_object(mem, cdata, "cljc_print_page(cdata)");
    gs_free_object(mem, data, "cljc_print_page(data)");
    return code;
}
Beispiel #5
0
/* one scan line at a time */
static int
os2prn_print_page(gx_device_printer * pdev, FILE * file)
{
    int raster = gdev_prn_raster(pdev);

    /* BMP scan lines are padded to 32 bits. */
    ulong bmp_raster = (raster + 3) & (~3);
    ulong bmp_raster_multi;
    int height = pdev->height;
    int depth = pdev->color_info.depth;
    byte *row;
    int y;
    int code = 0;		/* return code */
    POINTL apts[4];
    APIRET rc;
    POINTL aptsb[4];
    HBITMAP hbmp, hbmr;
    int i, lines;
    int ystart, yend;
    int yslice;

    struct bmi_s {
	BITMAPINFOHEADER2 h;
	RGB2 pal[256];
    } bmi;

    yslice = 65535 / bmp_raster;
    bmp_raster_multi = bmp_raster * yslice;
    row = (byte *) gs_malloc(pdev->memory, bmp_raster_multi, 1, "bmp file buffer");
    if (row == 0)		/* can't allocate row buffer */
	return_error(gs_error_VMerror);

    if (opdev->newframe)
	DevEscape(opdev->hdc, DEVESC_NEWFRAME, 0L, NULL, NULL, NULL);
    opdev->newframe = 1;

    /* Write the info header. */

    memset(&bmi.h, 0, sizeof(bmi.h));
    bmi.h.cbFix = sizeof(bmi.h);
    bmi.h.cx = pdev->width;	/* opdev->mdev.width; */
    /* bmi.h.cy = height; */
    bmi.h.cy = yslice;		/* size for memory PS */
    bmi.h.cPlanes = 1;
    bmi.h.cBitCount = pdev->color_info.depth;

    /* Write the palette. */

    if (depth <= 8) {
	int i;
	gx_color_value rgb[3];
	PRGB2 pq;

	bmi.h.cclrUsed = 1 << depth;
	bmi.h.cclrImportant = 1 << depth;
	for (i = 0; i != 1 << depth; i++) {
	    (*dev_proc(pdev, map_color_rgb)) ((gx_device *) pdev,
					      (gx_color_index) i, rgb);
	    pq = &bmi.pal[i];
	    pq->bRed = gx_color_value_to_byte(rgb[0]);
	    pq->bGreen = gx_color_value_to_byte(rgb[1]);
	    pq->bBlue = gx_color_value_to_byte(rgb[2]);
	    pq->fcOptions = 0;
	}
    } else {
	bmi.h.cclrUsed = 0;
	bmi.h.cclrImportant = 0;
    }

    /* for GpiDrawBits */
    /* target is inclusive */
    apts[0].x = 0;
    apts[0].y = 0;		/* filled in later */
    apts[1].x = pdev->width - 1;
    apts[1].y = 0;		/* filled in later */
    /* source is not inclusive of top & right borders */
    apts[2].x = 0;
    apts[2].y = 0;
    apts[3].x = pdev->width;
    apts[3].y = 0;		/* filled in later */

    /* for GpiBitBlt */
    /* target is not inclusive */
    aptsb[0].x = opdev->clipbox[0];
    aptsb[0].y = 0;		/* filled in later */
    aptsb[1].x = opdev->clipbox[2];
    aptsb[1].y = 0;		/* filled in later */
    /* source is not inclusive */
    aptsb[2].x = opdev->clipbox[0];
    aptsb[2].y = 0;
    aptsb[3].x = opdev->clipbox[2];
    aptsb[3].y = 0;		/* filled in later */

    /* write the bits */
    ystart = opdev->clipbox[3];
    yend = opdev->clipbox[1];
    y = ystart;
    while (y > yend) {
	/* create a bitmap for the memory DC */
	hbmp = GpiCreateBitmap(opdev->hpsMem, &bmi.h, 0L, NULL, NULL);
	if (hbmp == GPI_ERROR)
	    goto bmp_done;
	hbmr = GpiSetBitmap(opdev->hpsMem, hbmp);

	/* copy slice to memory bitmap */
	if (y > yend + yslice)
	    lines = yslice;
	else
	    lines = y - yend;
	y -= lines;
	for (i = lines - 1; i >= 0; i--)
	    gdev_prn_copy_scan_lines(pdev, ystart - 1 - (y + i), row + (bmp_raster * i), raster);
	apts[0].y = 0;		/* target */
	apts[1].y = lines;
	apts[3].y = lines - 1;	/* source */
	/* copy DIB bitmap to memory bitmap */
	rc = GpiDrawBits(opdev->hpsMem, row, (BITMAPINFO2 *) & bmi, 4, apts,
			 (depth != 1) ? ROP_SRCCOPY : ROP_NOTSRCCOPY, 0);

	/* copy slice to printer */
	aptsb[0].y = y;
	aptsb[1].y = y + lines;
	aptsb[3].y = lines;
	rc = GpiBitBlt(opdev->hps, opdev->hpsMem, 4, aptsb, ROP_SRCCOPY, BBO_IGNORE);

	/* delete bitmap */
	if (hbmr != HBM_ERROR)
	    GpiSetBitmap(opdev->hpsMem, (ULONG) 0);
	hbmr = HBM_ERROR;
	if (hbmp != GPI_ERROR)
	    GpiDeleteBitmap(hbmp);
	hbmp = GPI_ERROR;
    }

  bmp_done:
    if (row)
	gs_free(pdev->memory, (char *)row, bmp_raster_multi, 1, "bmp file buffer");

    return code;
}
Beispiel #6
0
/* Send the page to the printer. */
#define DD 0x40				/* double density flag */
static int
eps_print_page(gx_device_printer *pdev, FILE *prn_stream, int y_9pin_high,
  const char *init_string, int init_length, const char *end_string,
  int archaic, int tab_hiccup)
{	
	static const char graphics_modes_9[5] =
	{	
	-1, 0 /*60*/, 1	/*120*/, 7 /*180*/, DD+3 /*240*/
	};

	static const char graphics_modes_24[7] =
	{	
    	-1, 32 /*60*/, 33 /*120*/, 39 /*180*/,
	DD+35 /*240*/, -1, DD+40 /*360*/
	};

	int y_24pin = (y_9pin_high ? 0 : pdev->y_pixels_per_inch > 72);
	int in_y_mult = ((y_24pin | y_9pin_high) ? 3 : 1);
	int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
	/* Note that in_size is a multiple of 8. */
	int in_size = line_size * (8 * in_y_mult);
	byte *buf1 = (byte *)gs_malloc(pdev->memory, in_size, 1, "eps_print_page(buf1)");
	byte *buf2 = (byte *)gs_malloc(pdev->memory, in_size, 1, "eps_print_page(buf2)");
	byte *in = buf1;
	byte *out = buf2;
	int out_y_mult = (y_24pin ? 3 : 1);
	int x_dpi = (int)pdev->x_pixels_per_inch;
	char start_graphics =
		(y_24pin ? graphics_modes_24 : graphics_modes_9)[x_dpi / 60];
	int first_pass = (start_graphics & DD ? 1 : 0);
	int last_pass = first_pass * (y_9pin_high == 2 ? 1 : 2); 
	int y_passes = (y_9pin_high ? 3 : 1);
	int dots_per_space = x_dpi / 10;	/* pica space = 1/10" */
	int bytes_per_space = dots_per_space * out_y_mult;
	int tab_min_pixels = x_dpi * MIN_TAB_10THS / 10;
	int skip = 0, lnum = 0, pass, ypass;

	/* Check allocations */
	if ( buf1 == 0 || buf2 == 0 )
	{	if ( buf1 ) 
		  gs_free(pdev->memory, (char *)buf1, in_size, 1, "eps_print_page(buf1)");
		if ( buf2 ) 
		  gs_free(pdev->memory, (char *)buf2, in_size, 1, "eps_print_page(buf2)");
		return_error(gs_error_VMerror);
	}

	/* Initialize the printer and reset the margins. */
	fwrite(init_string, 1, init_length, prn_stream);
	if ( init_string[init_length - 1] == 'Q' )
		fputc((int)(pdev->width / pdev->x_pixels_per_inch * 10) + 2,
		      prn_stream);

	/* Calculate the minimum tab distance. */
	if ( tab_min_pixels < max(MIN_TAB_PIXELS, 3) )
		tab_min_pixels = max(MIN_TAB_PIXELS, 3);
	tab_min_pixels -= tab_min_pixels % 3;	/* simplify life */

	/* Print lines of graphics */
	while ( lnum < pdev->height )
	{	
		byte *in_data;
		byte *inp;
		byte *in_end;
		byte *out_end;
		byte *out_blk;
		register byte *outp;
		int lcnt;

		/* Copy 1 scan line and test for all zero. */
		gdev_prn_get_bits(pdev, lnum, in, &in_data);
		if ( in_data[0] == 0 &&
		     !memcmp((char *)in_data, (char *)in_data + 1, line_size - 1)
		   )
	    	{	
			lnum++;
			skip += 3 / in_y_mult;
			continue;
		}

		/* Vertical tab to the appropriate position. */
		while ( skip > 255 )
		{	
			fputs("\033J\377", prn_stream);
			skip -= 255;
		}
		if ( skip )
		{
			fprintf(prn_stream, "\033J%c", skip);
		}

		/* Copy the the scan lines. */
	    	lcnt = gdev_prn_copy_scan_lines(pdev, lnum, in, in_size);
		if ( lcnt < 8 * in_y_mult )
		{	/* Pad with lines of zeros. */
			memset(in + lcnt * line_size, 0,
			       in_size - lcnt * line_size);
		}

		if ( y_9pin_high == 2 ) 
		{	/* Force printing of every dot in one pass */
			/* by reducing vertical resolution */
		        /* (ORing with the next line of data). */
		        /* This is necessary because some Epson compatibles */
			/* can't print neighboring dots. */
			int i;
			for ( i = 0; i < line_size * in_y_mult; ++i )
				in_data[i] |= in_data[i + line_size];
		}

		if ( y_9pin_high )
		{	/* Shuffle the scan lines */
			byte *p;
			int i;
			static const char index[] =
			{  0,  8, 16,  1,  9, 17,  
			   2, 10, 18,  3, 11, 19,
			   4, 12, 20,  5, 13, 21,
			   6, 14, 22,  7, 15, 23
			};

			for ( i = 0; i < 24; i++ )
			{
				memcpy(out+(index[i]*line_size),
				       in+(i*line_size), line_size);
			}
			p = in;
			in = out;
			out = p;
		}

	for ( ypass = 0; ypass < y_passes; ypass++ )
	{
	    for ( pass = first_pass; pass <= last_pass; pass++ )
	    {
		/* We have to 'transpose' blocks of 8 pixels x 8 lines, */
		/* because that's how the printer wants the data. */
		/* If we are in a 24-pin mode, we have to transpose */
		/* groups of 3 lines at a time. */

		if ( pass == first_pass )
		{
		    out_end = out;
		    inp = in;
		    in_end = inp + line_size;
    
		    if ( y_24pin )
    	            { 
    			for ( ; inp < in_end; inp++, out_end += 24 )
    			{ 
    	    	            gdev_prn_transpose_8x8(inp, line_size, out_end, 3);
    	                    gdev_prn_transpose_8x8(inp + line_size * 8, 
					           line_size, out_end + 1, 3);
    	                    gdev_prn_transpose_8x8(inp + line_size * 16, 
					           line_size, out_end + 2, 3);
			}
			/* Remove trailing 0s. */
			while ( out_end > out && out_end[-1] == 0 &&
    	   			out_end[-2] == 0 && out_end[-3] == 0)
			{
		             out_end -= 3;
			}
    	            }
		    else
    	            { 
    			for ( ; inp < in_end; inp++, out_end += 8 )
    			{ 
    		            gdev_prn_transpose_8x8(inp + (ypass * 8*line_size), 
					           line_size, out_end, 1);
		    	}
			/* Remove trailing 0s. */
			while ( out_end > out && out_end[-1] == 0 )
	        	{
		       	    out_end--;
			}
    	    	    }
		}

		for ( out_blk = outp = out; outp < out_end; )
    		{ 
    	 	    /* Skip a run of leading 0s.  At least */
    	            /* tab_min_pixels are needed to make tabbing */
    		    /* worth it.  We do everything by 3's to */
    		    /* avoid having to make different cases */
    		    /* for 9- and 24-pin. */
		   if ( !archaic &&
			*outp == 0 && out_end - outp >= tab_min_pixels &&
			(outp[1] | outp[2]) == 0 &&
			!memcmp((char *)outp, (char *)outp + 3,
				tab_min_pixels - 3)
		      )
    	    	    {
    			byte *zp = outp;
			int tpos;
			byte *newp;
           
			outp += tab_min_pixels;
    			while ( outp + 3 <= out_end && 
    		     		*outp == 0 &&
    				outp[1] == 0 && outp[2] == 0 )
    			{
			    outp += 3;
    			}
			tpos = (outp - out) / bytes_per_space;
			newp = out + tpos * bytes_per_space;
			if ( newp > zp + 10 )
    			{ 
    			    /* Output preceding bit data.*/
    		   	    if ( zp > out_blk )	
    			    {
    				/* only false at beginning of line */
			     	eps_output_run(out_blk, (int)(zp - out_blk),
    				    	       out_y_mult, start_graphics, 
					       prn_stream,
					       (y_9pin_high == 2 ?
					        (1 + ypass) & 1 : pass));
			    }
			    /* Tab over to the appropriate position. */
			    if ( tab_hiccup )
			      fputs("\010 ", prn_stream); /* bksp, space */
			    /* The following statement is broken up */
			    /* to work around a bug in emx/gcc. */
			    fprintf(prn_stream, "\033D%c", tpos);
			    fputc(0, prn_stream);
			    fputc('\t', prn_stream);
			    out_blk = outp = newp;
			}
		    }
		    else
		    {
    			outp += out_y_mult;
		    }
    		}
		if ( outp > out_blk )
		{
		    eps_output_run(out_blk, (int)(outp - out_blk),
			           out_y_mult, start_graphics,
				   prn_stream,
				   (y_9pin_high == 2 ? (1 + ypass) & 1 : pass));
		}

		fputc('\r', prn_stream);
	    }
	    if ( ypass < y_passes - 1 )
		fputs("\033J\001", prn_stream);
	}
	skip = 24 - y_passes + 1;		/* no skip on last Y pass */
	lnum += 8 * in_y_mult;
	}

	/* Eject the page and reinitialize the printer */
	fputs(end_string, prn_stream);
	fflush(prn_stream);

	gs_free(pdev->memory, (char *)buf2, in_size, 1, "eps_print_page(buf2)");
	gs_free(pdev->memory, (char *)buf1, in_size, 1, "eps_print_page(buf1)");
	return 0;
}
/* all? MD series monochrome mode print with data compression. */
static int
md1xm_print_page(gx_device_printer *pdev, FILE *prn_stream)
{
  int lnum;
  int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
  byte *data = (byte *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), 8, line_size, "md1xm_print_page(data)");
  byte *out_start = (byte *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), 8, line_size, "md1xm_print_page(data)");
  int skipping = 0;
  int nbyte;

  /* Load Paper & Select Inc Cartridge */
  fwrite(&init_md13[0], sizeof(char), sizeof(init_md13), prn_stream);
  fflush(prn_stream);

  for ( lnum = 0; lnum <= pdev->height; lnum++ ) {
    byte *end_data = data + line_size;
    byte *data_p = data;
    byte *out_data = out_start;
    byte *p, *q;
    int count;

    gdev_prn_copy_scan_lines(pdev, lnum, data, line_size);
    /* Remove trailing 0s. */
    while ( end_data > data && end_data[-1] == 0 ) 
      end_data--; 

     nbyte = end_data - data_p;

    if(nbyte == 0)
      {
	skipping++;
	continue;
      }
    else
      {
	if(skipping)
	  {
	    fprintf(prn_stream, "%c%c%c%c%c%c", 0x1b, 0x2a, 0x62,
		    skipping & 0xff, (skipping & 0xff00) / 0x100, 0x59);
	    skipping = 0;
	  }

	/* Following codes are borrowed from gdevescp.c */

	for ( p = data_p, q = data_p + 1; q < end_data; ){

	  if( *p != *q ) {

	    p += 2;
	    q += 2;

	  } else {
	    /*
	    ** Check behind us, just in case:
	    */

	    if( p > data_p && *p == *(p-1) )
	      p--;

	    /*
	    ** walk forward, looking for matches:
	    */

	    for( q++ ; *q == *p && q < end_data ; q++ ) {
	      if( (q-p) >= 128 ) {
		if( p > data_p ) {
		  count = p - data_p;
		  while( count > 128 ) {
   		    *out_data++ = '\177';
		    memcpy(out_data, data_p, 128);	/* data */
		    data_p += 128;
		    out_data += 128;
		    count -= 128;
		  }
		  *out_data++ = (char) (count - 1); /* count */
		  memcpy(out_data, data_p, count);	/* data */
		  out_data += count;
		}
 		*out_data++ = '\201';	/* Repeat 128 times */ 
		*out_data++ = *p;
		p += 128;
		data_p = p;
	      }
	    }

	    if( (q - p) > 2 ) {	/* output this sequence */
	      if( p > data_p ) {
		count = p - data_p;
		while( count > 128 ) {
  		  *out_data++ = '\177'; 
		  memcpy(out_data, data_p, 128);	/* data */
		  data_p += 128;
		  out_data += 128;
		  count -= 128;
		}
		*out_data++ = (char) (count - 1);	/* byte count */
		memcpy(out_data, data_p, count);	/* data */
		out_data += count;
	      }
	      count = q - p;
	      *out_data++ = (char) (256 - count + 1);
	      *out_data++ = *p;
	      p += count;
	      data_p = p;
	    } else	/* add to non-repeating data list */
	      p = q;
	    if( q < end_data )
	      q++;
	  }
	}
	/*
	** copy remaining part of line:
	*/
	
	if( data_p < end_data ) {

	  count = end_data - data_p;

	  /*
	  ** If we've had a long run of varying data followed by a
	  ** sequence of repeated data and then hit the end of line,
	  ** it's possible to get data counts > 128.
	  */

	  while( count > 128 ) {
  	    *out_data++ = '\177';  
	    memcpy(out_data, data_p, 128);	/* data */
	    data_p += 128;
	    out_data += 128;
	    count -= 128;
	  }

	  *out_data++ = (char) (count - 1);	/* byte count */
	  memcpy(out_data, data_p, count);	/* data */
	  out_data += count;
	}

	nbyte = out_data - out_start;

        fprintf(prn_stream, "%c%c%c%c%c%c", 0x1b, 0x2a, 0x62,
		nbyte & 0xff, (nbyte & 0xff00) / 0x100, 0x57);
	fwrite(out_start, sizeof(char), nbyte, prn_stream);
      }
  }
  
  /* Eject Page */
  fwrite(end_md, sizeof(char), sizeof(end_md), prn_stream);
  fflush(prn_stream);
  
  return 0;
}
/* Send the page to the printer. */
static int
m8510_print_page(gx_device_printer *pdev, FILE *prn_stream)
{
	int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
	byte *in1 = (byte *) gs_malloc(pdev->memory, 8, line_size, "m8510_print_page(in1)");
	byte *in2 = (byte *) gs_malloc(pdev->memory, 8, line_size, "m8510_print_page(in2)");
	byte *out = (byte *) gs_malloc(pdev->memory, 8, line_size, "m8510_print_page(out)");
	int lnum = 0;
	int code = 0;
	byte *inp, *in_end, *outp;
	int i;

	if (in1 == 0 || in2 == 0 || out == 0) {
		code = gs_note_error(gs_error_VMerror);
		goto out;
	}

	/*
	 * Initialize the printer.
	 * NLQ mode, proportional print (160x144 dpi).
	 * and 16/144" linefeeds.
	 */
	fwrite("\033m2\033P\033T16", 1, 9, prn_stream);

	/* Transfer pixels to printer */
	while ( lnum < pdev->height ) {
		/* get a raster */
		for (i = 7; i >= 0; i--) {
			gdev_prn_copy_scan_lines(pdev, lnum, &in1[i*line_size], line_size);
			lnum++;
			gdev_prn_copy_scan_lines(pdev, lnum, &in2[i*line_size], line_size);
			lnum++;
		}

		/* Transpose the 1st pass of data. */
		in_end = in1 + line_size;
		for (inp = in1, outp = out; inp < in_end; inp++, outp += 8)
			gdev_prn_transpose_8x8(inp, line_size, outp, 1);

		/* send the 1st line */
		m8510_output_run(pdev, out, 0, prn_stream);

		/* Transpose the 2nd pass of data. */
		in_end = in2 + line_size;
		for (inp = in2, outp = out; inp < in_end; inp++, outp += 8)
			gdev_prn_transpose_8x8(inp, line_size, outp, 1);

		/* send the 2nd line */
		m8510_output_run(pdev, out, 1, prn_stream);
	}

	/* reset the printer. */
	fwrite("\033c1", 1, 3, prn_stream);
	fflush(prn_stream);

out:;
	if (out) gs_free(pdev->memory, (char *) out, 8, line_size, "m8510_print_page(out)");
	if (in2) gs_free(pdev->memory, (char *) in2, 8, line_size, "m8510_print_page(in2)");
	if (in1) gs_free(pdev->memory, (char *) in1, 8, line_size, "m8510_print_page(in1)");

	return code;
}
Beispiel #9
0
/* Send the page to the printer.  For now, just send the whole image. */
static int
ljet5_print_page(gx_device_printer * pdev, FILE * prn_stream)
{
    gs_memory_t *mem = pdev->memory;
    uint line_size = gdev_mem_bytes_per_scan_line((gx_device *) pdev);
    uint line_size_words = (line_size + W - 1) / W;
    uint out_size = line_size + (line_size / 127) + 1;
    word *line = (word *)gs_alloc_byte_array(mem, line_size_words, W, "ljet5(line)");
    byte *out = gs_alloc_bytes(mem, out_size, "ljet5(out)");
    int code = 0;
    int lnum;
    stream fs;
    stream *const s = &fs;
    byte buf[200];		/* arbitrary */

    if (line == 0 || out == 0) {
	code = gs_note_error(gs_error_VMerror);
	goto done;
    }
    s_init(s, mem);
    swrite_file(s, prn_stream, buf, sizeof(buf));

    /* Write the page header. */
    {
	static const byte page_header[] = {
	    pxtBeginPage,
	    DUSP(0, 0), DA(pxaPoint),
	    pxtSetCursor
	};
	static const byte mono_header[] = {
	    DUB(eGray), DA(pxaColorSpace),
	    DUB(e8Bit), DA(pxaPaletteDepth),
	    pxt_ubyte_array, pxt_ubyte, 2, 0xff, 0x00, DA(pxaPaletteData),
	    pxtSetColorSpace
	};
	static const byte gray_header[] = {
	    DUB(eGray), DA(pxaColorSpace),
	    pxtSetColorSpace
	};

	px_write_page_header(s, (gx_device *)pdev);
	px_write_select_media(s, (gx_device *)pdev, NULL, NULL, 0, false, false);
	PX_PUT_LIT(s, page_header);
	if (pdev->color_info.depth == 1)
	    PX_PUT_LIT(s, mono_header);
	else
	    PX_PUT_LIT(s, gray_header);
    }

    /* Write the image header. */
    {
	static const byte mono_image_header[] = {
	    DA(pxaDestinationSize),
	    DUB(eIndexedPixel), DA(pxaColorMapping),
	    DUB(e1Bit), DA(pxaColorDepth),
	    pxtBeginImage
	};
	static const byte gray_image_header[] = {
	    DA(pxaDestinationSize),
	    DUB(eDirectPixel), DA(pxaColorMapping),
	    DUB(e8Bit), DA(pxaColorDepth),
	    pxtBeginImage
	};

	px_put_us(s, pdev->width);
	px_put_a(s, pxaSourceWidth);
	px_put_us(s, pdev->height);
	px_put_a(s, pxaSourceHeight);
	px_put_usp(s, pdev->width, pdev->height);
	if (pdev->color_info.depth == 1)
	    PX_PUT_LIT(s, mono_image_header);
	else
	    PX_PUT_LIT(s, gray_image_header);
    }

    /* Write the image data, compressing each line. */
    for (lnum = 0; lnum < pdev->height; ++lnum) {
	int ncompr;
	static const byte line_header[] = {
	    DA(pxaStartLine),
	    DUS(1), DA(pxaBlockHeight),
	    DUB(eRLECompression), DA(pxaCompressMode),
	    pxtReadImage
	};

	code = gdev_prn_copy_scan_lines(pdev, lnum, (byte *) line, line_size);
	if (code < 0)
	    goto fin;
	px_put_us(s, lnum);
	PX_PUT_LIT(s, line_header);
	ncompr = gdev_pcl_mode2compress_padded(line, line + line_size_words,
					       out, true);
	px_put_data_length(s, ncompr);
	px_put_bytes(s, out, ncompr);
    }

    /* Finish up. */
  fin:
    spputc(s, pxtEndImage);
    spputc(s, pxtEndPage);
    sflush(s);
  done:
    gs_free_object(mem, out, "ljet5(out)");
    gs_free_object(mem, line, "ljet5(line)");
    return code;
}
Beispiel #10
0
/* Send the page to the printer. */
static int
sj48_print_page(gx_device_printer *pdev, FILE *prn_stream)
{	int line_size = gx_device_raster((gx_device *)pdev, 0);
        int xres = pdev->x_pixels_per_inch;
        int yres = pdev->y_pixels_per_inch;
        int mode = (yres == 180 ?
                        (xres == 180 ? 39 : 40) :
                        (xres == 180 ? 71 : 72));
        int bytes_per_column = (yres == 180) ? 3 : 6;
        int bits_per_column = bytes_per_column * 8;
        int skip_unit = bytes_per_column * (xres == 180 ? 1 : 2); /* Skips in step of 1/180" */
        byte *in = (byte *)gs_malloc(pdev->memory, 8, line_size, "sj48_print_page(in)");
        byte *out = (byte *)gs_malloc(pdev->memory, bits_per_column, line_size, "sj48_print_page(out)");
        int lnum = 0;
        int skip = 0;
        int skips;
        int code = 0;
        int last_row = dev_print_scan_lines(pdev);
        int limit = last_row - bits_per_column;

        if ( in == 0 || out == 0 )
        {	code = gs_error_VMerror;
                gs_note_error(code);
                goto fin;
        }

        /* Abort if the requested resolution is unsupported. */
        if ((xres !=180 && xres != 360) || (yres !=180 && yres != 360))
        {	code = gs_error_rangecheck;
                gs_note_error(code);
                goto fin;
        }

        /* Initialize the printer. */
        fwrite("\033@\000\000", 1, 4, prn_stream);  /* <Printer reset>, <0>, <0>. */

        /* Transfer pixels to printer.  The last row we can print is defined
           by "last_row".  Only the bottom of the print head can print at the
           bottom margin, and so we align the final printing pass.  The print
           head is kept from moving below "limit", which is exactly one pass
           above the bottom margin.  Once it reaches this limit, we make our
           final printing pass of a full "bits_per_column" rows. */
        while ( lnum < last_row )
           {
                byte *in_data;
                byte *in_end = in + line_size;
                byte *out_beg = out;
                byte *out_end = out + bytes_per_column * pdev->width;
                byte *outl = out;
                int bnum;

                /* Copy 1 scan line and test for all zero. */
                code = gdev_prn_get_bits(pdev, lnum, in, &in_data);
                if ( code < 0 ) goto xit;
                /* The mem... or str... functions should be faster than */
                /* the following code, but all systems seem to implement */
                /* them so badly that this code is faster. */
                   {	register const long *zip = (const long *)in_data;
                        register int zcnt = line_size;
                        register const byte *zipb;
                        for ( ; zcnt >= 4 * sizeof(long); zip += 4, zcnt -= 4 * sizeof(long) )
                           {	if ( zip[0] | zip[1] | zip[2] | zip[3] )
                                        goto notz;
                           }
                        zipb = (const byte *)zip;
                        while ( --zcnt >= 0 )
                           {
                                if ( *zipb++ )
                                        goto notz;
                           }
                        /* Line is all zero, skip */
                        lnum++;
                        skip++;
                        continue;
notz:			;
                   }

                /* Vertical tab to the appropriate position.  Note here that
                   we make sure we don't move below limit. */
                if ( lnum > limit )
                    {	skip -= (limit - lnum);
                        lnum = limit;
                    }

                /* The SJ48 can only skip in steps of 1/180" */
                if (yres == 180) {
                  skips = skip;
                } else {
                  if (skip & 1) {
                    skip--; /* Makes skip even. */
                    lnum--;
                  }
                  skips = skip/2;
                }

                while ( skips > 255 )
                   {	fputs("\033J\377", prn_stream);
                        skips -= 255;
                   }
                if ( skips )
                        fprintf(prn_stream, "\033J%c", skips);

                /* If we've printed as far as "limit", then reset "limit"
                   to "last_row" for the final printing pass. */
                if ( lnum == limit )
                        limit = last_row;
                skip = 0;

                /* Transpose in blocks of 8 scan lines. */
                for ( bnum = 0; bnum < bits_per_column; bnum += 8 )
                   {	int lcnt = min(8, limit - lnum);
                        byte *inp = in;
                        byte *outp = outl;
                        lcnt = gdev_prn_copy_scan_lines(pdev,
                                lnum, in, lcnt * line_size);
                        if ( lcnt < 0 )
                           {	code = lcnt;
                                goto xit;
                           }
                        if ( lcnt < 8 )
                                memset(in + lcnt * line_size, 0,
                                       (8 - lcnt) * line_size);
                        for ( ; inp < in_end; inp++, outp += bits_per_column )
                           {	gdev_prn_transpose_8x8(inp, line_size,
                                        outp, bytes_per_column);
                           }
                        outl++;
                        lnum += lcnt;
                        skip += lcnt;
                   }

                /* Send the bits to the printer.  We alternate horizontal
                   skips with the data.  The horizontal skips are in units
                   of 1/180 inches, so we look at the data in groups of
                   1 or 2 columns depending on resolution (controlled
                   by skip_unit).  */
                outl = out;
                do
                   {	int count;
                        int n;
                        byte *out_ptr;

                        /* First look for blank groups of columns. */
                        while(outl < out_end)
                           {	n = count = min(out_end - outl, skip_unit);
                                out_ptr = outl;
                                while ( --count >= 0 )
                                   {	if ( *out_ptr++ )
                                                break;
                                   }
                                if ( count >= 0 )
                                        break;
                                else
                                        outl = out_ptr;
                           }
                        if (outl >= out_end)
                                break;
                        if (outl > out_beg)
                           {	count = (outl - out_beg) / skip_unit;
                                fprintf(prn_stream, "\033\\%c%c",
                                        count & 0xff, count >> 8);
                           }

                        /* Next look for non-blank groups of columns. */
                        out_beg = outl;
                        outl += n;
                        while(outl < out_end)
                           {	n = count = min(out_end - outl, skip_unit);
                                out_ptr = outl;
                                while ( --count >= 0 )
                                   {	if ( *out_ptr++ )
                                                break;
                                   }
                                if ( count < 0 )
                                        break;
                                else
                                        outl += n;
                           }
                        count = outl - out_beg;
                        {
                          /* What to transmit is the number of columns in the row.
                             Compare this with the <Esc>|*-command wich expects the
                             total number of bytes in the graphic row! */
                          int count1 = count/bytes_per_column;
                          fprintf(prn_stream, "\033*%c%c%c",
                                  mode, count1 & 0xff, count1 >> 8);
                        }
                        fwrite(out_beg, 1, count, prn_stream);
                        out_beg = outl;
                        outl += n;
                   }
                while ( out_beg < out_end );

                fputc('\r', prn_stream);
                skip = bits_per_column;  /* <CR> only moves to the beginning of the row. */
           }
Beispiel #11
0
/* Send the page to the printer.  */
static int
can_print_page(gx_device_printer *pdev, FILE *prn_stream,
  const char *init, int init_size, const char *end, int end_size)
{	
	char data[LINE_SIZE*2];
	char *out_data;
	int last_line_nro = 0;

	fwrite(init, init_size, 1, prn_stream);		/* initialize */

	/* Send each scan line in turn */
	{	
	    int lnum;
	    int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
	    byte rmask = (byte)(0xff << (-pdev->width & 7));

	    for ( lnum = 0; lnum < pdev->height; lnum++ ) {
    		char *end_data = data + LINE_SIZE;
		gdev_prn_copy_scan_lines(pdev, lnum,
					 (byte *)data, line_size);
	   	/* Mask off 1-bits beyond the line width. */
		end_data[-1] &= rmask;
		/* Remove trailing 0s. */
		while ( end_data > data && end_data[-1] == 0 )
			end_data--;
		if ( end_data != data ) {
		    int num_cols = 0;
		    int out_count;
		    int zero_count;
		    out_data = data;

		    /* move down */
		    fprintf(prn_stream, "%c[%de", 
			    ESC, lnum-last_line_nro );
		    last_line_nro = lnum;

		    while (out_data < end_data) {
			/* Remove leading 0s*/
			while(out_data < end_data && *out_data == 0) {	
		            num_cols += 8;
                            out_data++;
                        }

			out_count = end_data - out_data;
			zero_count = 0;
			
			/* if there is a lot data, find if there is sequence of zeros */
			if (out_count>22) {

				out_count = 1;

				while(out_data+out_count+zero_count < end_data) {
					if (out_data[zero_count+out_count] != 0) {
						out_count += 1+zero_count;
						zero_count = 0;
					}
					else {
						zero_count++;
						if (zero_count>20)
							break;
					}
				}

			}
	
			if (out_count==0)
				break;

			/* move down and across*/
			fprintf(prn_stream, "%c[%d`", 
				ESC, num_cols );
			/* transfer raster graphic command */
			fprintf(prn_stream, "%c[%d;%d;300;.r",
				ESC, out_count, out_count);

			/* send the row */
			fwrite(out_data, sizeof(char),
                               out_count, prn_stream);

			out_data += out_count+zero_count;
               	        num_cols += 8*(out_count+zero_count);
		    }
		}
	    }
	}

	/* eject page */
	fprintf(prn_stream, "%c=", ESC);

	/* terminate */
	if (end != NULL)
	    fwrite(end, end_size, 1, prn_stream);

	return 0;
}
Beispiel #12
0
/* Send the page to the printer. */
static int
bj10v_print_page(gx_device_printer *pdev, FILE *prn_stream)
{	int line_size = gdev_prn_raster((gx_device *)pdev);
	int xres = pdev->x_pixels_per_inch;
	int yres = pdev->y_pixels_per_inch;
	char *mode = (yres == 180 ?
		      (xres == 180 ? "\052\047" : "\052\050") :
		      "|*");
	int bits_per_column = 24 * (yres / 180);
	int bytes_per_column = bits_per_column / 8;
	int x_skip_unit = bytes_per_column * (xres / 180);
	int y_skip_unit = (yres / 180);
	byte *in = (byte *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), 8, line_size, "bj10v_print_page(in)");
	byte *out = (byte *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), bits_per_column, line_size, "bj10v_print_page(out)");
	int lnum = 0;
	int y_skip = 0;
	int code = 0;
	int blank_lines = 0;
	int bytes_per_data = ((xres == 360) && (yres == 360)) ? 1 : 3;

	if ( in == 0 || out == 0 )
		return -1;

	/* Initialize the printer. */
	prn_puts(pdev, "\033@");
	/* Transfer pixels to printer */
	while ( lnum < pdev->height )
	   {	byte *out_beg;
		byte *out_end;
		byte *outl, *outp;
		byte *zp;
		int count, bnum;

		/* Copy 1 scan line and test for all zero. */
		code = gdev_prn_get_bits(pdev, lnum + blank_lines, in, NULL);
		if ( code < 0 ) goto xit;
		/* The mem... or str... functions should be faster than */
		/* the following code, but all systems seem to implement */
		/* them so badly that this code is faster. */
		{	register long *zip = (long *)in;
			register int zcnt = line_size;
			static const long zeroes[4] = { 0, 0, 0, 0 };
			for ( ; zcnt >= 4 * sizeof(long); zip += 4, zcnt -= 4 * sizeof(long) )
			    {	if ( zip[0] | zip[1] | zip[2] | zip[3] )
				    goto notz;
			    }
			if ( !memcmp(in, (const char *)zeroes, zcnt) )
			    {	/* Line is all zero, skip */
				if (++blank_lines >= y_skip_unit) {
				    lnum += y_skip_unit;
				    y_skip++;
				    blank_lines = 0;
				}
				continue;
			    }
		}
notz:
		blank_lines = 0;
		out_end = out + bytes_per_column * pdev->width;
		/* Vertical tab to the appropriate position. */
		while ( y_skip > 255 )
		   {	prn_puts(pdev, "\033J\377");
			y_skip -= 255;
		   }
		if ( y_skip ) {
			prn_puts(pdev, "\033J");
			prn_putc(pdev, y_skip);
		}

		/* Transpose in blocks of 8 scan lines. */
		for ( bnum = 0, outl = out; bnum < bits_per_column; bnum += 8, lnum += 8 )
		   {	int lcnt = gdev_prn_copy_scan_lines(pdev,
				lnum, in, 8 * line_size);
			byte *inp = in;
			if ( lcnt < 0 )
			   {	code = lcnt;
				goto xit;
			   }
			if ( lcnt < 8 )
				memset(in + lcnt * line_size, 0,
				       (8 - lcnt) * line_size);
			for (outp = outl ; inp < in + line_size; inp++, outp += bits_per_column )
			   {	memflip8x8(inp, line_size,
					outp, bytes_per_column);
			   }
			outl++;
		   }

		/* Remove trailing 0s. */
		/* Note that non zero byte always exists. */
		outl = out_end;
		while ( *--outl == 0 )
		    ;
		count = ((out_end - (outl + 1)) / bytes_per_column) * bytes_per_column;
		out_end -= count;
		*out_end = 1;		/* sentinel */

		for ( out_beg = outp = out; outp < out_end; )
		    { /* Skip a run of leading 0s. */
			/* At least 10 bytes are needed to make tabbing worth it. */
			byte *zp = outp;
			int x_skip;
			while ( *outp == 0 )
				outp++;
			x_skip = ((outp - zp) / x_skip_unit) * x_skip_unit;
			outp = zp + x_skip;
			if (x_skip >= 10) {
			    /* Output preceding bit data. */
			    int bytes = zp - out_beg;
			    if (bytes > 0)
					/* Only false at beginning of line. */
					bj10v_output_run(out_beg, bytes / bytes_per_data, bytes,
									 mode, pdev);
			    /* Tab over to the appropriate position. */
			    {	int skip = x_skip / x_skip_unit;
					prn_puts(pdev, "\033\\");
					prn_putc(pdev, skip & 0xff);
					prn_putc(pdev, skip >> 8);
			    }
			    out_beg = outp;
			} else
			    outp += x_skip_unit;
		    }
Beispiel #13
0
/* Send the page to the printer. */
static int
dmp_print_page(gx_device_printer *pdev, FILE *prn_stream)
{	
	int dev_type;

	int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
	/* Note that in_size is a multiple of 8. */
	int in_size = line_size * 8;
  
	byte *buf1 = (byte *)gs_malloc(pdev->memory, in_size, 1, "dmp_print_page(buf1)");
	byte *buf2 = (byte *)gs_malloc(pdev->memory, in_size, 1, "dmp_print_page(buf2)");
	byte *prn = (byte *)gs_malloc(pdev->memory, 3*in_size, 1, "dmp_print_page(prn)");
  
	byte *in = buf1;
	byte *out = buf2;
	int lnum = 0;

	/* Check allocations */
	if ( buf1 == 0 || buf2 == 0 || prn == 0 )
	{
		if ( buf1 ) 
			gs_free(pdev->memory, (char *)buf1, in_size, 1,
			"dmp_print_page(buf1)");
		if ( buf2 ) 
			gs_free(pdev->memory, (char *)buf2, in_size, 1,
			"dmp_print_page(buf2)");
		if ( prn ) 
			gs_free(pdev->memory, (char *)prn, in_size, 1,
			"dmp_print_page(prn)");
		return_error(gs_error_VMerror);
	}

	if ( pdev->y_pixels_per_inch == 216 )
		dev_type = IWLQ;
	else if ( pdev->y_pixels_per_inch == 144 )
		dev_type = IWHI;
	else if ( pdev->x_pixels_per_inch == 160 )
		dev_type = IWLO;
	else
		dev_type = DMP;

	/* Initialize the printer and reset the margins. */

	fputs("\r\n\033>\033T16", prn_stream);

	switch(dev_type)
	{
	case IWLQ:
		fputs("\033P\033a3", prn_stream);
		break;
	case IWHI:
	case IWLO:
		fputs("\033P", prn_stream);
		break;
	case DMP: 
	default:
		fputs("\033q", prn_stream);
		break;
	}

	/* Print lines of graphics */
	while ( lnum < pdev->height )
	{	
		byte *inp;
		byte *in_end;
		byte *out_end;
		int lcnt,ltmp;
		int count, passes;
		byte *prn_blk, *prn_end, *prn_tmp;

/* The apple DMP printer seems to be odd in that the bit order on
 * each line is reverse what might be expected.  Meaning, an
 * underscore would be done as a series of 0x80, while on overscore
 * would be done as a series of 0x01.  So we get each
 * scan line in reverse order.
 */

		switch (dev_type)
		{
		case IWLQ: passes = 3; break;
		case IWHI: passes = 2; break;
		case IWLO:
		case DMP:
		default: passes = 1; break;
		}

		for (count = 0; count < passes; count++)
		{
			for (lcnt=0; lcnt<8; lcnt++)
			{
				switch(dev_type)
				{
				case IWLQ: ltmp = lcnt + 8*count; break;
				case IWHI: ltmp = 2*lcnt + count; break;
				case IWLO:
				case DMP:
				default: ltmp = lcnt; break;
				}

				if ((lnum+ltmp)>pdev->height) 
					memset(in+lcnt*line_size,0,line_size);
				else
					gdev_prn_copy_scan_lines(pdev,
					lnum+ltmp, in + line_size*(7 - lcnt),
					line_size);
			}

			out_end = out;
			inp = in;
			in_end = inp + line_size;
			for ( ; inp < in_end; inp++, out_end += 8 )
			{
				gdev_prn_transpose_8x8(inp, line_size,
				out_end, 1);
			}

			out_end = out;

			switch (dev_type)
			{
			case IWLQ: prn_end = prn + count; break;
			case IWHI: prn_end = prn + in_size*count; break;
			case IWLO:
			case DMP:
			default: prn_end = prn; break;
			}

			while ( (int)(out_end-out) < in_size)
			{
				*prn_end = *(out_end++);
				if ((dev_type) == IWLQ) prn_end += 3;
				else prn_end++;
			}
		}
      
		switch (dev_type)
		{
		case IWLQ:
			prn_blk = prn;
			prn_end = prn_blk + in_size * 3;
			while (prn_end > prn && prn_end[-1] == 0 &&
				prn_end[-2] == 0 && prn_end[-3] == 0)
			{
				prn_end -= 3;
			}
			while (prn_blk < prn_end && prn_blk[0] == 0 &&
				prn_blk[1] == 0 && prn_blk[2] == 0)
			{
				prn_blk += 3;
			}
			if (prn_end != prn_blk)
			{
				if ((prn_blk - prn) > 7)
					fprintf(prn_stream,"\033U%04d%c%c%c",
						(int)((prn_blk - prn)/3),
						0, 0, 0);
				else
					prn_blk = prn;
				fprintf(prn_stream,"\033C%04d",
					(int)((prn_end - prn_blk)/3));
				fwrite(prn_blk, 1, (int)(prn_end - prn_blk),
					prn_stream);
		        }
			break;
		case IWHI:
			for (count = 0; count < 2; count++)
			{
				prn_blk = prn_tmp = prn + in_size*count;
				prn_end = prn_blk + in_size;
				while (prn_end > prn_blk && prn_end[-1] == 0)
					prn_end--;
				while (prn_blk < prn_end && prn_blk[0] == 0)
					prn_blk++;
				if (prn_end != prn_blk)
				{
					if ((prn_blk - prn_tmp) > 7)
						fprintf(prn_stream,
							"\033V%04d%c",
							(int)(prn_blk-prn_tmp),
							 0);
					else
						prn_blk = prn_tmp;
					fprintf(prn_stream,"\033G%04d",
						(int)(prn_end - prn_blk));
					fwrite(prn_blk, 1,
						(int)(prn_end - prn_blk),
						prn_stream);
				}
				if (!count) fputs("\033T01\r\n",prn_stream);
			}
			fputs("\033T15",prn_stream);
			break;
		case IWLO:
		case DMP:
		default:
			prn_blk = prn;
			prn_end = prn_blk + in_size;
			while (prn_end > prn_blk && prn_end[-1] == 0)
				prn_end--;
			while (prn_blk < prn_end && prn_blk[0] == 0)
				prn_blk++;
			if (prn_end != prn_blk)
			{
				if ((prn_blk - prn) > 7)
					fprintf(prn_stream,"\033V%04d%c",
						(int)(prn_blk - prn), 0);
				else
					prn_blk = prn;
				fprintf(prn_stream,"\033G%04d",
					(int)(prn_end - prn_blk));
				fwrite(prn_blk, 1, (int)(prn_end - prn_blk),
					prn_stream);
			}
			break;
		}

		fputs("\r\n",prn_stream);

		switch (dev_type)
		{
			case IWLQ: lnum += 24 ; break;
			case IWHI: lnum += 16 ; break;
			case IWLO:
			case DMP:
			default: lnum += 8 ; break;
		}
	}

	/* ImageWriter will skip a whole page if too close to end */
	/* so skip back more than an inch */
	if ( !(dev_type == DMP) )
		fputs("\033T99\n\n\033r\n\n\n\n\033f", prn_stream);
  
	/* Formfeed and Reset printer */
	fputs("\033T16\f\033<\033B\033E", prn_stream);
	fflush(prn_stream);

	gs_free(pdev->memory, (char *)prn, in_size, 1, "dmp_print_page(prn)");
	gs_free(pdev->memory, (char *)buf2, in_size, 1, "dmp_print_page(buf2)");
	gs_free(pdev->memory, (char *)buf1, in_size, 1, "dmp_print_page(buf1)");
	return 0;
}
Beispiel #14
0
/* Send the page to the printer. */
static int
cfax_stream_print_page_width(gx_device_printer * pdev, FILE * prn_stream,
                             const stream_template * temp, stream_state * ss,
                             int width)
{
    gs_memory_t *mem = pdev->memory;
    int code = 0;
    stream_cursor_read r;
    stream_cursor_write w;
    int in_size = gdev_prn_raster((gx_device *) pdev);
    /*
     * Because of the width adjustment for fax systems, width may
     * be different from (either greater than or less than) pdev->width.
     * Allocate a large enough buffer to account for this.
     */
    int col_size = (width * pdev->color_info.depth + 7) >> 3;
    int max_size = max(in_size, col_size);
    int lnum, nbytes, i;
    byte *in;
    byte *out;
    /* If the file is 'nul', don't even do the writes. */
    bool nul = !strcmp(pdev->fname, "nul");

    /* Initialize the common part of the encoder state. */
    ss->templat = temp;
    ss->memory = mem;

    /* Allocate the buffers. */
    in = gs_alloc_bytes(mem, temp->min_in_size + max_size + 1,
        "cfax_stream_print_page(in)");

#define OUT_SIZE 1000
    out = gs_alloc_bytes(mem, OUT_SIZE, "cfax_stream_print_page(out)");
    if (in == 0 || out == 0) {
        code = gs_note_error(gs_error_VMerror);
        goto done;
    }

    /* Process the image */
    for (lnum = 0; lnum < pdev->height; lnum++) {
        /* Initialize read and write pointer each time, because they're getting modified */
        r.ptr = in - 1;
        r.limit = in + col_size;
        w.ptr = out - 1;
        w.limit = w.ptr + OUT_SIZE;
        /* Decoder must encode line for line, so init it for each line */
        code = (*temp->init) (ss);
        if (code < 0)
            return_error(gs_error_limitcheck);
        /* Now, get the bits and encode them */
        gdev_prn_copy_scan_lines(pdev, lnum, in, in_size);
        if (col_size > in_size) {
            memset(in + in_size , 0, col_size - in_size);
        }
        code = (*temp->process) (ss, &r, &w, 1 /* always last line */);
        nbytes = w.ptr - out + 1;
        if (!nul) {
            if (nbytes > 0) {
                if (nbytes < 217) {
                    cfax_byte(nbytes, prn_stream);
                    for (i = 0; i < nbytes; i++)
                          cfax_byte(out[i], prn_stream);
                } else {
                    cfax_byte(0, prn_stream);
                    cfax_word(nbytes, prn_stream);
                    for (i = 0; i < nbytes; i++)
                          cfax_byte(out[i], prn_stream);
                }
            } else {
                cfax_byte(218, prn_stream);
            }
        }
        if (temp->release != 0)
            (*temp->release) (ss);
    }
#undef OUT_SIZE

  done:
    gs_free_object(mem, out, "cfax_stream_print_page(out)");
    gs_free_object(mem, in, "cfax_stream_print_page(in)");
    return code;
}
Beispiel #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 code = 0;
    byte *data = NULL;
    byte *mfs_data = NULL;
    int *errors = NULL;
    int size = gdev_mem_bytes_per_scan_line((gx_device *)dev);
    int max_size;
    int row;
    int n;
    int width = dev->width/factor;
    int awidth = width;
    int padWhite;

    if (aw > 0)
        awidth = fax_adjusted_width(awidth);
    padWhite = awidth - width;
    if (padWhite < 0)
        padWhite = 0;

    max_size = max(size + padWhite*factor, TIFFScanlineSize(tif)) + factor-1;

    data = gs_alloc_bytes(dev->memory,
                          max_size * factor,
                          "tiff_print_page(data)");
    if (data == NULL)
        return_error(gs_error_VMerror);

    errors = (int *)gs_alloc_bytes(dev->memory,
                                   (awidth+3) * sizeof(int),
                                   "tiff_print_page(errors)");
    if (errors == NULL)
    {
        code = gs_note_error(gs_error_VMerror);
        goto cleanup;
    }
    if (mfs > 1) {
        mfs_data = (byte *)gs_alloc_bytes(dev->memory,
                                          (awidth+1),
                                          "tiff_print_page(mfs)");
        if (mfs_data == NULL)
        {
            code = gs_note_error(gs_error_VMerror);
            goto cleanup;
        }
    }

    code = TIFFCheckpointDirectory(tif);

    memset(data, 0xFF, max_size * factor);
    memset(errors, 0, (awidth+3) * sizeof(int));
    if (mfs_data)
        memset(mfs_data, 0, awidth+1);
    n = 0;
    for (row = 0; row < dev->height && code >= 0; row++) {
        code = gdev_prn_copy_scan_lines(dev, row, data + max_size*n, size);
        if (code < 0)
            break;
        n++;
        if (n == factor)
        {
            /* Do the downsample */
            n = 0;
            code = down_and_out(tif, data, max_size, factor, row/factor, awidth,
                                errors, mfs_data, padWhite);
        }
    }
#if DISABLED_AS_WE_DONT_ROUND_UP_ANY_MORE
    if (n != 0 && code >= 0)
    {
        row--;
        while (n != factor)
        {
            memset(data + max_size * n, 0xFF, max_size);
            n++;
            row++;
        }
        code = down_and_out(tif, data, max_size, factor, row/factor, awidth,
                            errors, mfs_data, padWhite);
    }
#endif

    if (code >= 0)
        code = TIFFWriteDirectory(tif);
cleanup:
    gs_free_object(dev->memory, mfs_data, "tiff_print_page(mfs)");
    gs_free_object(dev->memory, errors, "tiff_print_page(errors)");
    gs_free_object(dev->memory, data, "tiff_print_page(data)");

    return code;
}
Beispiel #16
0
static long
CompressImage(gx_device_printer *pDev, struct bounding *pBox, FILE *fp, const char *format)
{
	int	x, y, i, count = 255;
	int	Xres = (int)pDev->x_pixels_per_inch;
	int	LineSize = gdev_mem_bytes_per_scan_line((gx_device *)pDev);
	byte	*Buf, oBuf[128], c_prev, c_cur, c_tmp;
	long	DataSize = 0;

	/* ----==== Printer initialize ====---- */
	/* ----==== start TEXT mode ====---- */
	fprintf(fp, "\x1b%%@");
	/* ----==== job start ====---- */
	fprintf(fp, "\x1bP35;%d;1J;GhostScript\x1b\\", Xres);
	/* ----==== soft reset ====---- */
	fprintf(fp, "\x1b<");
	/* ----==== select size as dot ====---- */
	fprintf(fp, "\x1b[7 I");
	/* ----==== ??? ====---- */
	fprintf(fp, "\x1b[;1;'v");
	/* ----==== set paper size ====---- */
	fprintf(fp, "\x1b[%d;;p", PaperInfo[pBox->paper].id);
	/* ----==== select sheet feeder ====---- */
	fprintf(fp, "\x1b[1q");
	/* ----==== disable automatic FF ====---- */
	fprintf(fp, "\x1b[?2h");
	/* ----==== set number of copies ====---- */
	fprintf(fp, "\x1b[%dv", 1);
	/* ----==== move CAP location ====---- */
	fprintf(fp, "\x1b[%d;%df", pBox->Top, pBox->Left*16);
	/* ----==== draw raster image ====---- */
	fprintf(fp, format, pBox->Right-pBox->Left+1,
		Xres, pBox->Bottom-pBox->Top+1);

	/* ----==== Allocate momory ====---- */
	Buf = (byte *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), 1, LineSize, "LineBuffer");
	/* ----==== transfer raster image ====---- */
	for (y=pBox->Top ; y<=pBox->Bottom ; y++) {
		gdev_prn_copy_scan_lines(pDev, y, Buf, LineSize);
		for (x=pBox->Left*2 ; x<=pBox->Right*2+1 ; x++) {
		/* ----==== check pointer & Reverse bit order ====---- */
			c_cur = 0;
			if (x<LineSize) {
				c_tmp = *(Buf+x);
				for (i=0 ; i<8 ; i++) {
					c_cur = (c_cur << 1) | (c_tmp & 1);
					c_tmp = c_tmp >> 1;
				}
			}
			/* ----==== Compress data ====---- */
			if (count < 0) {
				if (c_prev == c_cur && count > -127) {
					count--;
					continue;
				} else {
					fprintf(fp, "%c%c", count, c_prev);
					DataSize += 2;
				}
			} else if (count == 0) {
				if (c_prev == c_cur) {
					count--;
				} else {
					count++;
					c_prev = *(oBuf+count) = c_cur;
				}
			continue;
			} else if (count < 127) {
				if (c_prev == c_cur) {
					fprintf(fp, "%c", count-1);
					fwrite(oBuf, 1, count, fp);
					DataSize += (count+1);
					count = -1;
				} else {
					count++;
					c_prev = *(oBuf+count) = c_cur;
				}
			continue;
			} else if (count == 127) {
				fprintf(fp, "%c", count);
				fwrite(oBuf, 1, count+1, fp);
				DataSize += (count+2);
			}
			c_prev = *oBuf = c_cur;
			count = 0;
		}
	}
Beispiel #17
0
/* Send the page to the printer. */
static int
cp50_print_page(gx_device_printer *pdev, FILE *prn_stream)
{
    int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
    byte *out = (byte *)gs_malloc(pdev->memory, line_size, 1, "cp50_print_page(out)");
    byte *r_plane = (byte *)gs_malloc(pdev->memory, X_PIXEL*Y_PIXEL, 1, "cp50_print_page(r_plane)");
    byte *g_plane = (byte *)gs_malloc(pdev->memory, X_PIXEL*Y_PIXEL, 1, "cp50_print_page(g_plane)");
    byte *b_plane = (byte *)gs_malloc(pdev->memory, X_PIXEL*Y_PIXEL, 1, "cp50_print_page(b_plane)");
    byte *t_plane = (byte *)gs_malloc(pdev->memory, X_PIXEL*Y_PIXEL, 1, "cp50_print_page(t_plane)");
    int lnum = FIRST_LINE;
    int last = LAST_LINE;
    int lines = X_PIXEL;
    byte hi_lines, lo_lines;
    byte num_copies;
    int i,j;


    /*fprintf(prn_stream, "%d,%d,%d,", pdev->width, pdev->height, line_size);*/

    /* Check allocations */
    if ( out == 0 || r_plane == 0 || g_plane == 0 || b_plane == 0 ||
            t_plane == 0)
    {   if ( out )
            gs_free(pdev->memory, (char *)out, line_size, 1,
                    "cp50_print_page(out)");
        if (r_plane)
            gs_free(pdev->memory, (char *)r_plane, X_PIXEL*Y_PIXEL, 1,
                    "cp50_print_page(r_plane)");
        if (g_plane)
            gs_free(pdev->memory, (char *)g_plane, X_PIXEL*Y_PIXEL, 1,
                    "cp50_print_page(g_plane)");
        if (b_plane)
            gs_free(pdev->memory, (char *)b_plane, X_PIXEL*Y_PIXEL, 1,
                    "cp50_print_page(b_plane)");
        if (t_plane)
            gs_free(pdev->memory, (char *)t_plane, X_PIXEL*Y_PIXEL, 1,
                    "cp50_print_page(t_plane)");
        return -1;
    }

    /* set each plane as white */
    memset(r_plane, -1, X_PIXEL*Y_PIXEL);
    memset(g_plane, -1, X_PIXEL*Y_PIXEL);
    memset(b_plane, -1, X_PIXEL*Y_PIXEL);
    memset(t_plane, -1, X_PIXEL*Y_PIXEL);

    /* Initialize the printer */ /* see programmer manual for CP50 */
    fprintf(prn_stream,"\033\101");
    fprintf(prn_stream,"\033\106\010\001");
    fprintf(prn_stream,"\033\106\010\003");

    /* set number of copies */
    fprintf(prn_stream,"\033\116");
    num_copies = copies & 0xFF;
    fwrite(&num_copies, sizeof(char), 1, prn_stream);

    /* download image */
    hi_lines = lines >> 8;
    lo_lines = lines & 0xFF;

    fprintf(prn_stream,"\033\123\062");
    fwrite(&hi_lines, sizeof(char), 1, prn_stream);
    fwrite(&lo_lines, sizeof(char), 1, prn_stream);
    fprintf(prn_stream,"\001"); /* dummy */

    /* Print lines of graphics */
    while ( lnum <= last )
    {
        int i, col;
        gdev_prn_copy_scan_lines(pdev, lnum, (byte *)out, line_size);
        /*fwrite(out, sizeof(char), line_size, prn_stream);*/
        for(i=0; i<X_PIXEL; i++)
        {
            col = (lnum-FIRST_LINE) * X_PIXEL + i;
            r_plane[col] = out[i*3+FIRST_COLUMN];
            g_plane[col] = out[i*3+1+FIRST_COLUMN];
            b_plane[col] = out[i*3+2+FIRST_COLUMN];
        }
        lnum ++;
    }

    /* rotate each plane and download it */
    for(i=0; i<X_PIXEL; i++)
        for(j=Y_PIXEL-1; j>=0; j--)
            t_plane[(Y_PIXEL-1-j)+i*Y_PIXEL] = r_plane[i+j*X_PIXEL];
    fwrite(t_plane, sizeof(char), X_PIXEL*Y_PIXEL, prn_stream);

    for(i=0; i<X_PIXEL; i++)
        for(j=Y_PIXEL-1; j>=0; j--)
            t_plane[(Y_PIXEL-1-j)+i*Y_PIXEL] = g_plane[i+j*X_PIXEL];
    fwrite(t_plane, sizeof(char), X_PIXEL*Y_PIXEL, prn_stream);

    for(i=0; i<X_PIXEL; i++)
        for(j=Y_PIXEL-1; j>=0; j--)
            t_plane[(Y_PIXEL-1-j)+i*Y_PIXEL] = b_plane[i+j*X_PIXEL];
    fwrite(t_plane, sizeof(char), X_PIXEL*Y_PIXEL, prn_stream);


    gs_free(pdev->memory, (char *)out, line_size, 1, "cp50_print_page(out)");
    gs_free(pdev->memory, (char *)r_plane, X_PIXEL*Y_PIXEL, 1, "cp50_print_page(r_plane)");
    gs_free(pdev->memory, (char *)g_plane, X_PIXEL*Y_PIXEL, 1, "cp50_print_page(g_plane)");
    gs_free(pdev->memory, (char *)b_plane, X_PIXEL*Y_PIXEL, 1, "cp50_print_page(b_plane)");
    gs_free(pdev->memory, (char *)t_plane, X_PIXEL*Y_PIXEL, 1, "cp50_print_page(t_plane)");

    return 0;
}
Beispiel #18
0
/* Send the page to the printer. */
static int
coslw_print_page(gx_device_printer * pdev, FILE * prn_stream)
{
    int line_size = gdev_mem_bytes_per_scan_line((gx_device *) pdev);
    int line_size_words = (line_size + W - 1) / W;
    uint storage_size_words = line_size_words * 8;	/* data, out_row, out_row_alt, prev_row */
    word *storage = (ulong *) gs_malloc(pdev->memory, storage_size_words, W,
                                        "coslw_print_page");

    word *data_words;
#define data ((byte *)data_words)

    byte *out_data;
    int num_rows = dev_print_scan_lines(pdev);
    int bytes_per_line = 0;
    int out_count;
    int code = 0;

    if (storage == 0)		/* can't allocate working area */
        return_error(gs_error_VMerror);
    data_words = storage;

    /* Clear temp storage */
    memset(data, 0, storage_size_words * W);

    /* Initialize printer. */
    if (pdev->PageCount == 0) {
    }

    /* Put out per-page initialization. */

    /* End raster graphics, position cursor at top. */

    /* Send each scan line in turn */
    {
        int lnum;
        int num_blank_lines = 0;
        word rmask = ~(word) 0 << (-pdev->width & (W * 8 - 1));

        /* Transfer raster graphics. */
        for (lnum = 0; lnum < num_rows; lnum++) {
            register word *end_data =
            data_words + line_size_words;

            code = gdev_prn_copy_scan_lines(pdev, lnum,
                                            (byte *) data, line_size);
            if (code < 0)
                break;
            /* Mask off 1-bits beyond the line width. */
            end_data[-1] &= rmask;
            /* Remove trailing 0s. */
            while (end_data > data_words && end_data[-1] == 0)
                end_data--;
            if (end_data == data_words) {	/* Blank line */
                num_blank_lines++;
                continue;
            }

            /* We've reached a non-blank line. */
            /* Put out a spacing command if necessary. */
            while (num_blank_lines > 0)
            {
                int this_blank = 255;
                if (num_blank_lines < this_blank)
                    this_blank = num_blank_lines;
                fprintf(prn_stream, "\033f\001%c", this_blank);
                num_blank_lines -= this_blank;
            }

            /* Perhaps add compression here later? */
            out_data = data;
            out_count = (byte *) end_data - data;

            /* For 2 inch model, max width is 56 bytes */
            if (out_count > 56)
                out_count = 56;
            /* Possible change the bytes per line */
            if (bytes_per_line != out_count)
            {
                fprintf(prn_stream, "\033D%c", out_count);
                bytes_per_line = out_count;
            }

            /* Transfer the data */
            fputs("\026", prn_stream);
            fwrite(out_data, sizeof(byte), out_count, prn_stream);
        }
    }

    /* eject page */
    fputs("\033E", prn_stream);

    /* free temporary storage */
    gs_free(pdev->memory, (char *)storage, storage_size_words, W, "coslw_print_page");

    return code;
}
Beispiel #19
0
/* This routine is used for all formats. */
static int
png_print_page(gx_device_printer * pdev, FILE * file)
{
    gs_memory_t *mem = pdev->memory;
    int raster = gdev_prn_raster(pdev);

    /* PNG structures */
    byte *row = gs_alloc_bytes(mem, raster, "png raster buffer");
    png_struct *png_ptr =
    png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    png_info *info_ptr =
    png_create_info_struct(png_ptr);
    int height = pdev->height;
    int depth = pdev->color_info.depth;
    int y;
    int code;			/* return code */
    char software_key[80];
    char software_text[256];
    png_text text_png;

    if (row == 0 || png_ptr == 0 || info_ptr == 0) {
	code = gs_note_error(gs_error_VMerror);
	goto done;
    }
    /* set error handling */
    if (setjmp(png_ptr->jmpbuf)) {
	/* If we get here, we had a problem reading the file */
	code = gs_note_error(gs_error_VMerror);
	goto done;
    }
    code = 0;			/* for normal path */
    /* set up the output control */
    png_init_io(png_ptr, file);

    /* set the file information here */
    info_ptr->width = pdev->width;
    info_ptr->height = pdev->height;
    /* resolution is in pixels per meter vs. dpi */
    info_ptr->x_pixels_per_unit =
	(png_uint_32) (pdev->HWResolution[0] * (100.0 / 2.54));
    info_ptr->y_pixels_per_unit =
	(png_uint_32) (pdev->HWResolution[1] * (100.0 / 2.54));
    info_ptr->phys_unit_type = PNG_RESOLUTION_METER;
    info_ptr->valid |= PNG_INFO_pHYs;
    switch (depth) {
	case 32:
	    info_ptr->bit_depth = 8;
	    info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
	    png_set_invert_alpha(png_ptr);
	    {   gx_device_pngalpha *ppdev = (gx_device_pngalpha *)pdev;
		png_color_16 background;
		background.index = 0;
		background.red =   (ppdev->background >> 16) & 0xff;
		background.green = (ppdev->background >> 8)  & 0xff;
		background.blue =  (ppdev->background)       & 0xff;
		background.gray = 0;
		png_set_bKGD(png_ptr, info_ptr, &background);
	    }
	    break;
	case 48:
	    info_ptr->bit_depth = 16;
	    info_ptr->color_type = PNG_COLOR_TYPE_RGB;
#if defined(ARCH_IS_BIG_ENDIAN) && (!ARCH_IS_BIG_ENDIAN) 
	    png_set_swap(png_ptr);
#endif
	    break;
	case 24:
	    info_ptr->bit_depth = 8;
	    info_ptr->color_type = PNG_COLOR_TYPE_RGB;
	    break;
	case 8:
	    info_ptr->bit_depth = 8;
	    if (gx_device_has_color(pdev))
		info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
	    else
		info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
	    break;
	case 4:
	    info_ptr->bit_depth = 4;
	    info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
	    break;
	case 1:
	    info_ptr->bit_depth = 1;
	    info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
	    /* invert monocrome pixels */
	    png_set_invert_mono(png_ptr);
	    break;
    }

    /* set the palette if there is one */
    if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
	int i;
	int num_colors = 1 << depth;
	gx_color_value rgb[3];

	info_ptr->palette =
	    (void *)gs_alloc_bytes(mem, 256 * sizeof(png_color),
				   "png palette");
	if (info_ptr->palette == 0) {
	    code = gs_note_error(gs_error_VMerror);
	    goto done;
	}
	info_ptr->num_palette = num_colors;
	info_ptr->valid |= PNG_INFO_PLTE;
	for (i = 0; i < num_colors; i++) {
	    (*dev_proc(pdev, map_color_rgb)) ((gx_device *) pdev,
					      (gx_color_index) i, rgb);
	    info_ptr->palette[i].red = gx_color_value_to_byte(rgb[0]);
	    info_ptr->palette[i].green = gx_color_value_to_byte(rgb[1]);
	    info_ptr->palette[i].blue = gx_color_value_to_byte(rgb[2]);
	}
    }
    /* add comment */
    strncpy(software_key, "Software", sizeof(software_key));
    sprintf(software_text, "%s %d.%02d", gs_product,
	    (int)(gs_revision / 100), (int)(gs_revision % 100));
    text_png.compression = -1;	/* uncompressed */
    text_png.key = software_key;
    text_png.text = software_text;
    text_png.text_length = strlen(software_text);
    info_ptr->text = &text_png;
    info_ptr->num_text = 1;

    /* write the file information */
    png_write_info(png_ptr, info_ptr);

    /* don't write the comments twice */
    info_ptr->num_text = 0;
    info_ptr->text = NULL;

    /* Write the contents of the image. */
    for (y = 0; y < height; y++) {
	gdev_prn_copy_scan_lines(pdev, y, row, raster);
	png_write_rows(png_ptr, &row, 1);
    }

    /* write the rest of the file */
    png_write_end(png_ptr, info_ptr);

    /* if you alloced the palette, free it here */
    gs_free_object(mem, info_ptr->palette, "png palette");

  done:
    /* free the structures */
    png_destroy_write_struct(&png_ptr, &info_ptr);
    gs_free_object(mem, row, "png raster buffer");

    return code;
}
Beispiel #20
0
/* Send the page to the printer. */
static int
jj100_print_page(gx_device_printer *pdev, FILE *prn_stream)
{	int line_size = gdev_prn_raster(pdev);
	int height = pdev->height;
	int bits_per_column = 48;
	int bytes_per_column = bits_per_column / 8;
	int chunk_size = bits_per_column * line_size;
	byte *in, *out;
	int lnum, skip;
	char prn_buf[16];

	in = (byte *)
		gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), bits_per_column, line_size, "jj100_print_page(in)");
	out = (byte *)
		gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), bits_per_column, line_size, "jj100_print_page(out)");
	if(in == 0 || out == 0)
		return -1;

	/* Initialize printer */
	fputs("\033P", pdev->file);	/* Proportional Mode */
        fputs("\033G", pdev->file);        /* 1/180 inch per line */
	fputs("\033T16", pdev->file);	/* 16/180 inch per line */

	/* Send Data to printer */
	lnum = 0;
	skip = 0;
	while(lnum < height) {
		byte *inp, *outp, *out_beg, *out_end;
		int x, y, num_lines, size, mod;

		/* Copy scan lines */
		if(gdev_prn_copy_scan_lines(pdev, lnum, in, chunk_size) < 0)
			break;

		/* The number of lines to process */
		if((num_lines = height - lnum) > bits_per_column)
			num_lines = bits_per_column;

		/* Test for all zero */
		size = line_size * num_lines;
		if(in[0] == 0 && 
		   !memcmp((char *)in, (char *)in + 1, size - 1)) {
			lnum += bits_per_column;
			skip ++;
			continue;
		}

		/* Fill zero */
		if(num_lines < bits_per_column) {
			size = line_size * (bits_per_column - num_lines);
			memset(in + line_size * num_lines, 0, size);
		}
		lnum += bits_per_column;

		/* Vertical tab to the appropriate position. */
		while(skip > 15) {
			sprintf(prn_buf, "\037%c", 16 + 15);
			fputs(prn_buf, pdev->file);
			skip -= 15;
		}
		if(skip > 0) {
			sprintf(prn_buf, "\037%c", 16 + skip);
			fputs(prn_buf, pdev->file);
		}

		/* Transpose in blocks of 8 scan lines. */
		for(y = 0; y < bytes_per_column; y ++) {
			inp = in + line_size * 8 * y;
			outp = out + y;
			for(x = 0; x < line_size; x ++) {
				jj100_transpose_8x8(inp, line_size,
						    outp, bytes_per_column);
				inp ++;
				outp += bits_per_column;
			}
		}

		/* Remove trailing 0s. */
		out_end = out + chunk_size - 1;
		while(out_end >= out) {
			if(*out_end)
				break;
			out_end --;
		}
		size = (out_end - out) + 1;
		if((mod = size % bytes_per_column) != 0)
			out_end += bytes_per_column - mod;

		/* Remove leading 0s. */
		out_beg = out;
		while(out_beg <= out_end) {
			if(*out_beg)
				break;
			out_beg ++;
		}
		out_beg -= (out_beg - out) % (bytes_per_column * 2);

		/* Dot addressing */
		sprintf(prn_buf, "\033F%04d", 
			(out_beg - out) / bytes_per_column / 2);
		fputs(prn_buf, pdev->file);

		/* Dot graphics */
		size = out_end - out_beg + 1;
		sprintf(prn_buf, "\034bP,48,%04d.", size / bytes_per_column);
		fputs(prn_buf, pdev->file);
		fwrite(out_beg, 1, size, pdev->file);

		/* Carriage Return */
		fputc('\r', pdev->file);
		skip = 1;
	}

	/* Form Feed */
	fputc('\f', pdev->file);
	fflush(pdev->file);

	gs_free(gs_lib_ctx_get_non_gc_memory_t(), (char *)out, 
		bits_per_column, line_size, "jj100_print_page(out)");
	gs_free(gs_lib_ctx_get_non_gc_memory_t(), (char *)in,
		bits_per_column, line_size, "jj100_print_page(in)");

	return 0;
}
Beispiel #21
0
/* Send the page to the printer. */
static int
tekink_print_page(gx_device_printer *pdev,FILE *prn_stream)
{
    int line_size,color_line_size,scan_line,num_bytes,scan_lines,color_plane;
    int roll_paper,out_line,micro_line,pending_micro_lines,line_blank,
        blank_lines;
    byte *outdata,*indata1,*bdata1,*mdata1,*ydata1,*cdata1;
    register byte *indata,*bdatap,*mdatap,*ydatap,*cdatap;
    register byte bdata,mdata,ydata,cdata;
    register byte mask,inbyte;
    register byte *indataend,*outdataend;

    /* Allocate a temporary buffer for color separation.
       The buffer is partitioned into an input buffer and four
       output buffers for the color planes. The output buffers
       are allocated with an extra sentinel byte. */

    line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
    color_line_size=(pdev->width+7)/8;
    indata1=(byte *)malloc(line_size+4*(color_line_size+1));
    if (indata1==NULL) return -1;
    /* pointers to the partions */
    indataend=indata1+line_size;
    bdata1=indataend;
    mdata1=bdata1+(color_line_size+1);
    ydata1=mdata1+(color_line_size+1);
    cdata1=ydata1+(color_line_size+1);

    /* Does this device use roll paper? */
    roll_paper=!strcmp(pdev->dname,"tek4696");

    out_line=0;
    blank_lines=0;
    scan_lines=pdev->height;
    for (scan_line=0;scan_line<scan_lines;scan_line++){
        /* get data */
        gdev_prn_copy_scan_lines(pdev,scan_line,indata1,line_size);
        /* Separate data into color planes */
        bdatap = bdata1+1;
        mdatap = mdata1+1;
        ydatap = ydata1+1;
        cdatap = cdata1+1;
        bdata=0;
        mdata=0;
        cdata=0;
        ydata=0;
        mask=0x80;
        memset(indataend,0,4*(color_line_size+1));
        for (indata=indata1;indata<indataend;indata++){
            inbyte = *indata;
            if (inbyte&0x01) bdata|=mask;
            if (inbyte&0x02) mdata|=mask;
            if (inbyte&0x04) ydata|=mask;
            if (inbyte&0x08) cdata|=mask;
            mask>>=1;
            if (!mask){
                *(bdatap++) = bdata;
                *(mdatap++) = mdata;
                *(cdatap++) = cdata;
                *(ydatap++) = ydata;
                bdata=0;
                mdata=0;
                cdata=0;
                ydata=0;
                mask=0x80;
            }
        }
        if (mask!=0x80){
            *bdatap = bdata;
            *mdatap = mdata;
            *cdatap = cdata;
            *ydatap = ydata;
        }
        line_blank=1;
        /* Output each of the four color planes */
        for (color_plane=0;color_plane<4;color_plane++){
            outdata=indataend+(color_plane*(color_line_size+1));
            outdataend=outdata+color_line_size;

            /* Remove trailing spaces and output the color line if it is
               not blank */
            *outdata=0xff;
            while (!(*outdataend)) outdataend--;
            num_bytes=(outdataend-outdata);
            if (num_bytes!=0){
                line_blank=0;
                /* On encountering the first non-blank data, output pending
                   blank lines */
                if (blank_lines){
                    pending_micro_lines=((out_line+blank_lines+1)/4)-
                        (out_line/4);
                    for (micro_line=0;micro_line<pending_micro_lines;
                        micro_line++){
                        fputs("\033A",prn_stream);
                    }
                    out_line+=blank_lines;
                    blank_lines=0;
                }
                fprintf(prn_stream,"\033I%c%03d",'0'+(out_line%4)+
                    4*color_plane,num_bytes);
                fwrite(outdata+1,1,num_bytes,prn_stream);
            }
        } /* loop over color planes */

        /* If this line is blank, and if it is a roll paper model,
           count the line. Otherwise output the line */
        if (line_blank&&roll_paper){
            /* Only increment the blank line count, if non blank lines
               have been encountered previously, i.e. skip leading blank
               lines. */
            if (out_line) blank_lines++;
        }
        else{
            if (out_line%4==3){
                /* Write micro line feed code */
                fputs("\033A",prn_stream);
            }
            out_line++;
        }
    } /* loop over scan lines */

    /* if the number of scan lines written is not a multiple of four,
       write the final micro line feed code */
    if (out_line%4){
        fputs("\033A",prn_stream);
    }
    /* Separate this plot from the next */
    if (roll_paper){
        fputs("\n\n\n\n\n",prn_stream);
    }
    else{
        fputs("\f",prn_stream);
    }

    /* Deallocate temp buffer */
    free(indata1);
    return 0;
}
Beispiel #22
0
/* one scan line at a time */
static int
win_pr2_print_page(gx_device_printer * pdev, FILE * file)
{
    int raster = gdev_prn_raster(pdev);

    /* BMP scan lines are padded to 32 bits. */
    ulong bmp_raster = raster + (-raster & 3);
    ulong bmp_raster_multi;
    int scan_lines, yslice, lines, i;
    int width;
    int depth = pdev->color_info.depth;
    byte *row;
    int y;
    int code = 0;		/* return code */
    MSG msg;
    char dlgtext[32];
    HGLOBAL hrow;
    int ratio = ((gx_device_win_pr2 *)pdev)->ratio;

    struct bmi_s {
	BITMAPINFOHEADER h;
	RGBQUAD pal[256];
    } bmi;

    scan_lines = dev_print_scan_lines(pdev);
    width = (int)(pdev->width - ((dev_l_margin(pdev) + dev_r_margin(pdev) -
				  dev_x_offset(pdev)) * pdev->x_pixels_per_inch));

    yslice = 65535 / bmp_raster;	/* max lines in 64k */
    bmp_raster_multi = bmp_raster * yslice;
    hrow = GlobalAlloc(0, bmp_raster_multi);
    row = GlobalLock(hrow);
    if (row == 0)		/* can't allocate row buffer */
	return_error(gs_error_VMerror);

    /* Write the info header. */

    bmi.h.biSize = sizeof(bmi.h);
    bmi.h.biWidth = pdev->width;	/* wdev->mdev.width; */
    bmi.h.biHeight = yslice;
    bmi.h.biPlanes = 1;
    bmi.h.biBitCount = pdev->color_info.depth;
    bmi.h.biCompression = 0;
    bmi.h.biSizeImage = 0;	/* default */
    bmi.h.biXPelsPerMeter = 0;	/* default */
    bmi.h.biYPelsPerMeter = 0;	/* default */

    StartPage(wdev->hdcprn);
    
    /* Write the palette. */

    if (depth <= 8) {
	int i;
	gx_color_value rgb[3];
	LPRGBQUAD pq;

	bmi.h.biClrUsed = 1 << depth;
	bmi.h.biClrImportant = 1 << depth;
	for (i = 0; i != 1 << depth; i++) {
	    (*dev_proc(pdev, map_color_rgb)) ((gx_device *) pdev,
					      (gx_color_index) i, rgb);
	    pq = &bmi.pal[i];
	    pq->rgbRed = gx_color_value_to_byte(rgb[0]);
	    pq->rgbGreen = gx_color_value_to_byte(rgb[1]);
	    pq->rgbBlue = gx_color_value_to_byte(rgb[2]);
	    pq->rgbReserved = 0;
	}
    } else {
	bmi.h.biClrUsed = 0;
	bmi.h.biClrImportant = 0;
    }

    if (!wdev->nocancel) {
	sprintf(dlgtext, "Printing page %d", (int)(pdev->PageCount) + 1);
	SetWindowText(GetDlgItem(wdev->hDlgModeless, CANCEL_PRINTING), dlgtext);
	ShowWindow(wdev->hDlgModeless, SW_SHOW);
    }
    for (y = 0; y < scan_lines;) {
	/* copy slice to row buffer */
	if (y > scan_lines - yslice)
	    lines = scan_lines - y;
	else
	    lines = yslice;
	for (i = 0; i < lines; i++)
	    gdev_prn_copy_scan_lines(pdev, y + i,
			      row + (bmp_raster * (lines - 1 - i)), raster);
	
	if (ratio > 1) {
	    StretchDIBits(wdev->hdcprn, 0, y*ratio, pdev->width*ratio, lines*ratio,
			  0, 0, pdev->width, lines,
			  row,
			  (BITMAPINFO FAR *) & bmi, DIB_RGB_COLORS, SRCCOPY);
	} else {
	    SetDIBitsToDevice(wdev->hdcprn, 0, y, pdev->width, lines,
			      0, 0, 0, lines,
			      row,
			      (BITMAPINFO FAR *) & bmi, DIB_RGB_COLORS);
	}
	y += lines;

	if (!wdev->nocancel) {
	    /* inform user of progress */
	    sprintf(dlgtext, "%d%% done", (int)(y * 100L / scan_lines));
	    SetWindowText(GetDlgItem(wdev->hDlgModeless, CANCEL_PCDONE), dlgtext);
	}
	/* process message loop */
	while (PeekMessage(&msg, wdev->hDlgModeless, 0, 0, PM_REMOVE)) {
	    if ((wdev->hDlgModeless == 0) || !IsDialogMessage(wdev->hDlgModeless, &msg)) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	    }
	}
	if ((!wdev->nocancel) && (wdev->hDlgModeless == 0)) {
	    /* user pressed cancel button */
	    break;
	}
    }

    if ((!wdev->nocancel) && (wdev->hDlgModeless == 0))
	code = gs_error_Fatal;	/* exit Ghostscript cleanly */
    else {
	/* push out the page */
	if (!wdev->nocancel)
	    SetWindowText(GetDlgItem(wdev->hDlgModeless, CANCEL_PCDONE),
			  "Ejecting page...");
	EndPage(wdev->hdcprn);
	if (!wdev->nocancel)
	    ShowWindow(wdev->hDlgModeless, SW_HIDE);
    }

    GlobalUnlock(hrow);
    GlobalFree(hrow);

    return code;
}
Beispiel #23
0
/* Send the page to the printer. */
static int
bj10e_print_page(gx_device_printer *pdev, FILE *prn_stream)
{	int line_size = gx_device_raster((gx_device *)pdev, 0);
        int xres = (int)pdev->x_pixels_per_inch;
        int yres = (int)pdev->y_pixels_per_inch;
        int mode = (yres == 180 ?
                        (xres == 180 ? 11 : 12) :
                        (xres == 180 ? 14 : 16));
        int bytes_per_column = (yres == 180) ? 3 : 6;
        int bits_per_column = bytes_per_column * 8;
        int skip_unit = bytes_per_column * 3;
        byte *in = (byte *)gs_malloc(pdev->memory, 8, line_size, "bj10e_print_page(in)");
        byte *out = (byte *)gs_malloc(pdev->memory, bits_per_column, line_size, "bj10e_print_page(out)");
        int lnum = 0;
        int skip = 0;
        int code = 0;
        int last_row = dev_print_scan_lines(pdev);
        int limit = last_row - bits_per_column;

        if ( in == 0 || out == 0 )
        {	code = gs_note_error(gs_error_VMerror);
                goto fin;
        }

        /* Initialize the printer. */
#ifdef USE_FACTORY_DEFAULTS
        /* Check for U.S. letter vs. A4 paper. */
        fwrite(( pdev->width / pdev->x_pixels_per_inch <= 8.4 ?
                "\033[K\002\000\000\044"	/*A4--DIP switch defaults*/ :
                "\033[K\002\000\004\044"	/*letter--factory defaults*/ ),
               1, 7, prn_stream);
#else
        fwrite("\033[K\002\000\000\044", 1, 7, prn_stream);
#endif

        /* Turn off automatic carriage return, otherwise we get line feeds. */
        fwrite("\0335\000", 1, 3, prn_stream);

        /* Set vertical spacing. */
        fwrite("\033[\\\004\000\000\000", 1, 7, prn_stream);
        fputc(yres & 0xff, prn_stream);
        fputc(yres >> 8, prn_stream);

        /* Set the page length.  This is the printable length, in inches. */
        fwrite("\033C\000", 1, 3, prn_stream);
        fputc((last_row + yres - 1)/yres, prn_stream);

        /* Transfer pixels to printer.  The last row we can print is defined
           by "last_row".  Only the bottom of the print head can print at the
           bottom margin, and so we align the final printing pass.  The print
           head is kept from moving below "limit", which is exactly one pass
           above the bottom margin.  Once it reaches this limit, we make our
           final printing pass of a full "bits_per_column" rows. */
        while ( lnum < last_row )
           {
                byte *in_data;
                byte *in_end = in + line_size;
                byte *out_beg = out;
                byte *out_end = out + bytes_per_column * pdev->width;
                byte *outl = out;
                int bnum;

                /* Copy 1 scan line and test for all zero. */
                code = gdev_prn_get_bits(pdev, lnum, in, &in_data);
                if ( code < 0 ) goto xit;
                /* The mem... or str... functions should be faster than */
                /* the following code, but all systems seem to implement */
                /* them so badly that this code is faster. */
                   {	register const long *zip = (const long *)in_data;
                        register int zcnt = line_size;
                        register const byte *zipb;
                        for ( ; zcnt >= 4 * sizeof(long); zip += 4, zcnt -= 4 * sizeof(long) )
                           {	if ( zip[0] | zip[1] | zip[2] | zip[3] )
                                        goto notz;
                           }
                        zipb = (const byte *)zip;
                        while ( --zcnt >= 0 )
                           {
                                if ( *zipb++ )
                                        goto notz;
                           }
                        /* Line is all zero, skip */
                        lnum++;
                        skip++;
                        continue;
notz:			;
                   }

                /* Vertical tab to the appropriate position.  Note here that
                   we make sure we don't move below limit. */
                if ( lnum > limit )
                    {	skip -= (lnum - limit);
                        lnum = limit;
                    }
                while ( skip > 255 )
                   {	fputs("\033J\377", prn_stream);
                        skip -= 255;
                   }
                if ( skip )
                        fprintf(prn_stream, "\033J%c", skip);

                /* If we've printed as far as "limit", then reset "limit"
                   to "last_row" for the final printing pass. */
                if ( lnum == limit )
                        limit = last_row;
                skip = 0;

                /* Transpose in blocks of 8 scan lines. */
                for ( bnum = 0; bnum < bits_per_column; bnum += 8 )
                   {	int lcnt = min(8, limit - lnum);
                        byte *inp = in;
                        byte *outp = outl;
                        lcnt = gdev_prn_copy_scan_lines(pdev,
                                lnum, in, lcnt * line_size);
                        if ( lcnt < 0 )
                           {	code = lcnt;
                                goto xit;
                           }
                        if ( lcnt < 8 )
                                memset(in + lcnt * line_size, 0,
                                       (8 - lcnt) * line_size);
                        for ( ; inp < in_end; inp++, outp += bits_per_column )
                           {	gdev_prn_transpose_8x8(inp, line_size,
                                        outp, bytes_per_column);
                           }
                        outl++;
                        lnum += lcnt;
                        skip += lcnt;
                   }

                /* Send the bits to the printer.  We alternate horizontal
                   skips with the data.  The horizontal skips are in units
                   of 1/120 inches, so we look at the data in groups of
                   3 columns, since 3/360 = 1/120, and 3/180 = 2/120.  */
                outl = out;
                do
                   {	int count;
                        int n;
                        byte *out_ptr;

                        /* First look for blank groups of columns. */
                        while(outl < out_end)
                           {	n = count = min(out_end - outl, skip_unit);
                                out_ptr = outl;
                                while ( --count >= 0 )
                                   {	if ( *out_ptr++ )
                                                break;
                                   }
                                if ( count >= 0 )
                                        break;
                                else
                                        outl = out_ptr;
                           }
                        if (outl >= out_end)
                                break;
                        if (outl > out_beg)
                           {	count = (outl - out_beg) / skip_unit;
                                if ( xres == 180 ) count <<= 1;
                                fprintf(prn_stream, "\033d%c%c",
                                        count & 0xff, count >> 8);
                           }

                        /* Next look for non-blank groups of columns. */
                        out_beg = outl;
                        outl += n;
                        while(outl < out_end)
                           {	n = count = min(out_end - outl, skip_unit);
                                out_ptr = outl;
                                while ( --count >= 0 )
                                   {	if ( *out_ptr++ )
                                                break;
                                   }
                                if ( count < 0 )
                                        break;
                                else
                                        outl += n;
                           }
                        count = outl - out_beg + 1;
                        fprintf(prn_stream, "\033[g%c%c%c",
                                count & 0xff, count >> 8, mode);
                        fwrite(out_beg, 1, count - 1, prn_stream);
                        out_beg = outl;
                        outl += n;
                   }
                while ( out_beg < out_end );

                fputc('\r', prn_stream);
           }
Beispiel #24
0
/* Send the page to the printer.  */
static int
ml600_print_page(
        gx_device_printer	*pdev,
        FILE	*prn_stream)
{
        int	ystep;
        byte	data[2][LINE_SIZE*2];
        byte	buf[LINE_SIZE*2];
        int	skip;
        int	current;
        int	c_size;
        int	lnum;
        int	line_size;
        byte	rmask;
        int	i;

#define LAST	((current ^ 1) & 1)

        /* initialize this page */
        ystep = page_header(pdev, prn_stream);
        ystep /= 300;

        /* clear last sent line buffer */
        skip = 0;
        current = 0;
        for (i = 0; i < LINE_SIZE*2; i++)
                data[LAST][i] = 0;

        /* Send each scan line */
        line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
        if (line_size > LINE_SIZE || line_size == 0)
                return 0;

        rmask = (byte)(0xff << (-pdev->width & 7));	/* right edge */

        for (lnum = 0; lnum < pdev->height; lnum++) {
                int	s;

                s = gdev_prn_copy_scan_lines(pdev, lnum, data[current],
                                                                line_size);
                /* Mask right edge bits */
                *(data[current] + line_size - 1) &= rmask;

                /* blank line ? */
                for (i = 0; i < line_size; i++)
                        if (data[current][i] != 0)
                                break;

                if (i == line_size) {
                        skip = 1;
                        current = LAST;
                        continue;
                }

                /* move position, if previous lines are skipped */
                if (skip) {
                        move_pos(prn_stream, lnum / ystep, lnum % ystep);
                        skip = 0;
                }

                /* create one line data */
                c_size = make_line_data(data[current], data[LAST],
                                                                line_size, buf);

                /* send one line data */
                send_line(buf, c_size, prn_stream);

                /* swap line buffer */
                current = LAST;
        }

        /* eject page */
        fprintf(prn_stream, "\014");

        return 0;
}
Beispiel #25
0
int
tiff_print_page(gx_device_printer *dev, TIFF *tif, int min_feature_size)
{
    int code = 0;
    byte *data;
    int size = gdev_mem_bytes_per_scan_line((gx_device *)dev);
    int max_size = max(size, TIFFScanlineSize(tif));
    int row;
    int bpc = dev->color_info.depth / dev->color_info.num_components;
    void *min_feature_data = NULL;
    int line_lag = 0;
    int filtered_count;

    data = gs_alloc_bytes(dev->memory, max_size, "tiff_print_page(data)");
    if (data == NULL)
        return_error(gs_error_VMerror);
    if (bpc != 1)
        min_feature_size = 1;
    if (min_feature_size > 1) {
        code = min_feature_size_init(dev->memory, min_feature_size,
                                     dev->width, dev->height,
                                     &min_feature_data);
        if (code < 0)
            goto cleanup;
    }

    code = TIFFCheckpointDirectory(tif);

    memset(data, 0, max_size);
    for (row = 0; row < dev->height && code >= 0; row++) {
        code = gdev_prn_copy_scan_lines(dev, row, data, size);
        if (code < 0)
            break;
        if (min_feature_size > 1) {
            filtered_count = min_feature_size_process(data, min_feature_data);
            if (filtered_count == 0)
                line_lag++;
        }

        if (row - line_lag >= 0) {
#if defined(ARCH_IS_BIG_ENDIAN) && (!ARCH_IS_BIG_ENDIAN)
            if (bpc == 16)
                TIFFSwabArrayOfShort((uint16 *)data,
                                     dev->width * dev->color_info.num_components);
#endif

            code = TIFFWriteScanline(tif, data, row - line_lag, 0);
        }
    }
    for (row -= line_lag ; row < dev->height && code >= 0; row++)
    {
        filtered_count = min_feature_size_process(data, min_feature_data);
        code = TIFFWriteScanline(tif, data, row, 0);
    }

    if (code >= 0)
        code = TIFFWriteDirectory(tif);
cleanup:
    if (min_feature_size > 1)
        min_feature_size_dnit(min_feature_data);
    gs_free_object(dev->memory, data, "tiff_print_page(data)");

    return code;
}
Beispiel #26
0
int
dljet_mono_print_page_copies(gx_device_printer * pdev, FILE * prn_stream,
			     int num_copies, int dots_per_inch, int features,
			     const char *odd_page_init, const char *even_page_init, bool tumble)
{
    int line_size = gdev_mem_bytes_per_scan_line((gx_device *) pdev);
    int line_size_words = (line_size + W - 1) / W;
    uint storage_size_words = line_size_words * 8;	/* data, out_row, out_row_alt, prev_row */
    word *storage;
    word
	*data_words,
	*out_row_words,
	*out_row_alt_words,
	*prev_row_words;
#define data ((byte *)data_words)
#define out_row ((byte *)out_row_words)
#define out_row_alt ((byte *)out_row_alt_words)
#define prev_row ((byte *)prev_row_words)
    byte *out_data;
    int x_dpi = (int)pdev->x_pixels_per_inch;
    int y_dpi = (int)pdev->y_pixels_per_inch;
    int y_dots_per_pixel = dots_per_inch / y_dpi;
    int num_rows = dev_print_scan_lines(pdev);

    int out_count;
    int compression = -1;
    static const char *const from2to3 = "\033*b3M";
    static const char *const from3to2 = "\033*b2M";
    int penalty_from2to3 = strlen(from2to3);
    int penalty_from3to2 = strlen(from3to2);
    int paper_size = gdev_pcl_paper_size((gx_device *) pdev);
    int code = 0;
    bool dup = pdev->Duplex;
    bool dupset = pdev->Duplex_set >= 0;

    if (num_copies != 1 && !(features & PCL_CAN_PRINT_COPIES))
	return gx_default_print_page_copies(pdev, prn_stream, num_copies);
    storage =
	(ulong *)gs_alloc_byte_array(pdev->memory, storage_size_words, W,
				     "hpjet_print_page");
    if (storage == 0)		/* can't allocate working area */
	return_error(gs_error_VMerror);
    data_words = storage;
    out_row_words = data_words + (line_size_words * 2);
    out_row_alt_words = out_row_words + (line_size_words * 2);
    prev_row_words = out_row_alt_words + (line_size_words * 2);
    /* Clear temp storage */
    memset(data, 0, storage_size_words * W);

    /* Initialize printer. */
    if (pdev->PageCount == 0) {
	if (features & HACK__IS_A_LJET4PJL) {
 	    fputs("\033%-12345X@PJL\r\n@PJL ENTER LANGUAGE = PCL\r\n",
  		  prn_stream);
	}
	fputs("\033E", prn_stream);	/* reset printer */
	/* If the printer supports it, set the paper size */
	/* based on the actual requested size. */
	if (features & PCL_CAN_SET_PAPER_SIZE) {
	    fprintf(prn_stream, "\033&l%dA", paper_size);
	}
	/* If printer can duplex, set duplex mode appropriately. */
	if (features & PCL_HAS_DUPLEX) {
	    if (dupset && dup && !tumble)
		fputs("\033&l1S", prn_stream);
       else if (dupset && dup && tumble)
		fputs("\033&l2S", prn_stream);
	    else if (dupset && !dup)
		fputs("\033&l0S", prn_stream);
	    else		/* default to duplex for this printer */
		fputs("\033&l1S", prn_stream);
	}
    }
    /* Put out per-page initialization. */
    if (features & PCL_CAN_SET_PAPER_SIZE){ 
        fprintf(prn_stream, "\033&l%dA", paper_size); 
    } 
    fputs("\033&l0o0l0E", prn_stream);
    if ((features & PCL_HAS_DUPLEX) && dupset && dup)
    {
       /* We are printing duplex, so change margins as needed */
       if ((pdev->PageCount%2)==0)
          fputs(odd_page_init, prn_stream);
       else
          fputs(even_page_init, prn_stream);
    }
    else
        fputs(odd_page_init, prn_stream);
    fprintf(prn_stream, "\033&l%dX", num_copies);	/* # of copies */

    /* End raster graphics, position cursor at top. */
    fputs("\033*rB\033*p0x0Y", prn_stream);

    /* The DeskJet and DeskJet Plus reset everything upon */
    /* receiving \033*rB, so we must reinitialize graphics mode. */
    if (features & PCL_END_GRAPHICS_DOES_RESET) {
	fputs(odd_page_init, prn_stream); /* Assume this does the right thing */
	fprintf(prn_stream, "\033&l%dX", num_copies);	/* # of copies */
    }

    /* Set resolution. */
    fprintf(prn_stream, "\033*t%dR", x_dpi);

    /* Send each scan line in turn */
    {
	int lnum;
	int num_blank_lines = 0;
	word rmask = ~(word) 0 << (-pdev->width & (W * 8 - 1));

	/* Transfer raster graphics. */
	for (lnum = 0; lnum < num_rows; lnum++) {
	    register word *end_data =
	    data_words + line_size_words;

	    code = gdev_prn_copy_scan_lines(pdev, lnum,
					    (byte *) data, line_size);
	    if (code < 0)
		break;
	    /* Mask off 1-bits beyond the line width. */
	    end_data[-1] &= rmask;
	    /* Remove trailing 0s. */
	    while (end_data > data_words && end_data[-1] == 0)
		end_data--;
	    if (end_data == data_words) {	/* Blank line */
		num_blank_lines++;
		continue;
	    }
	    /* We've reached a non-blank line. */
	    /* Put out a spacing command if necessary. */
	    if (num_blank_lines == lnum) {
		/* We're at the top of a page. */
		if (features & PCL_ANY_SPACING) {
		    if (num_blank_lines > 0)
			fprintf(prn_stream, "\033*p+%dY",
				num_blank_lines * y_dots_per_pixel);
		    /* Start raster graphics. */
		    fputs("\033*r1A", prn_stream);
		} else if (features & PCL_MODE_3_COMPRESSION) {
		    /* Start raster graphics. */
		    fputs("\033*r1A", prn_stream);
#if 1				/* don't waste paper */
		    if (num_blank_lines > 0)
			fputs("\033*b0W", prn_stream);
		    num_blank_lines = 0;
#else
		    for (; num_blank_lines; num_blank_lines--)
			fputs("\033*b0W", prn_stream);
#endif
		} else {
		    /* Start raster graphics. */
		    fputs("\033*r1A", prn_stream);
		    for (; num_blank_lines; num_blank_lines--)
			fputs("\033*bW", prn_stream);
		}
	    }
	    /* Skip blank lines if any */
	    else if (num_blank_lines != 0) {
		/*
		 * Moving down from current position causes head motion
		 * on the DeskJet, so if the number of lines is small,
		 * we're better off printing blanks.
		 */
		/*
		 * For Canon LBP4i and some others, <ESC>*b<n>Y doesn't
		 * properly clear the seed row if we are in compression mode
		 * 3.
		 */
		if ((num_blank_lines < MIN_SKIP_LINES && compression != 3) ||
		    !(features & PCL_ANY_SPACING)
		    ) {
		    bool mode_3ns =
			(features & PCL_MODE_3_COMPRESSION) &&
			!(features & PCL_ANY_SPACING);

		    if (mode_3ns && compression != 2) {
			/* Switch to mode 2 */
			fputs(from3to2, prn_stream);
			compression = 2;
		    }
		    if (features & PCL_MODE_3_COMPRESSION) {
			/* Must clear the seed row. */
			fputs("\033*b1Y", prn_stream);
			num_blank_lines--;
		    }
		    if (mode_3ns) {
			for (; num_blank_lines; num_blank_lines--)
			    fputs("\033*b0W", prn_stream);
		    } else {
			for (; num_blank_lines; num_blank_lines--)
			    fputs("\033*bW", prn_stream);
		    }
		} else if (features & PCL3_SPACING) {
		    fprintf(prn_stream, "\033*p+%dY",
			    num_blank_lines * y_dots_per_pixel);
		} else {
		    fprintf(prn_stream, "\033*b%dY",
			    num_blank_lines);
		}
		/* Clear the seed row (only matters for */
		/* mode 3 compression). */
		memset(prev_row, 0, line_size);
	    }
	    num_blank_lines = 0;

	    /* Choose the best compression mode */
	    /* for this particular line. */
	    if (features & PCL_MODE_3_COMPRESSION) {
		/* Compression modes 2 and 3 are both */
		/* available.  Try both and see which one */
		/* produces the least output data. */
		int count3 = gdev_pcl_mode3compress(line_size, data,
						    prev_row, out_row);
		int count2 = gdev_pcl_mode2compress(data_words, end_data,
						    out_row_alt);
		int penalty3 =
		    (compression == 3 ? 0 : penalty_from2to3);
		int penalty2 =
		    (compression == 2 ? 0 : penalty_from3to2);

		if (count3 + penalty3 < count2 + penalty2) {
		    if (compression != 3)
			fputs(from2to3, prn_stream);
		    compression = 3;
		    out_data = out_row;
		    out_count = count3;
		} else {
		    if (compression != 2)
			fputs(from3to2, prn_stream);
		    compression = 2;
		    out_data = out_row_alt;
		    out_count = count2;
		}
	    } else if (features & PCL_MODE_2_COMPRESSION) {
		out_data = out_row;
		out_count = gdev_pcl_mode2compress(data_words, end_data,
						   out_row);
	    } else {
		out_data = data;
		out_count = (byte *) end_data - data;
	    }

	    /* Transfer the data */
	    fprintf(prn_stream, "\033*b%dW", out_count);
	    fwrite(out_data, sizeof(byte), out_count,
		   prn_stream);
	}
    }

    /* end raster graphics and eject page */
    fputs("\033*rB\f", prn_stream);

    /* free temporary storage */
    gs_free_object(pdev->memory, storage, "hpjet_print_page");

    return code;
}
Beispiel #27
0
static int
sparc_print_page(gx_device_printer *pdev, FILE *prn)
  {
  struct lpvi_page lpvipage;
  struct lpvi_err lpvierr;
  char *out_buf;
  int out_size;
  if (ioctl(fileno(prn),LPVIIOC_GETPAGE,&lpvipage)!=0)
    {
    errprintf(pdev->memory, "sparc_print_page: LPVIIOC_GETPAGE failed\n");
    return -1;
    }
  lpvipage.bitmap_width=gdev_mem_bytes_per_scan_line((gx_device *)pdev);
  lpvipage.page_width=lpvipage.bitmap_width*8;
  lpvipage.page_length=pdev->height;
  lpvipage.resolution = (pdev->x_pixels_per_inch == 300 ? DPI300 : DPI400);
  if (ioctl(fileno(prn),LPVIIOC_SETPAGE,&lpvipage)!=0)
    {
    errprintf(pdev->memory, "sparc_print_page: LPVIIOC_SETPAGE failed\n");
    return -1;
    }
  out_size=lpvipage.bitmap_width*lpvipage.page_length;
  out_buf=gs_malloc(pdev->memory, out_size,1,"sparc_print_page: out_buf");
  gdev_prn_copy_scan_lines(pdev,0,out_buf,out_size);
  while (write(fileno(prn),out_buf,out_size)!=out_size)
    {
    if (ioctl(fileno(prn),LPVIIOC_GETERR,&lpvierr)!=0)
      {
      errprintf(pdev->memory, "sparc_print_page: LPVIIOC_GETERR failed\n");
      return -1;
      }
    switch (lpvierr.err_type)
      {
      case 0:
        if (warning==0)
          {
          errprintf(pdev->memory,
                    "sparc_print_page: Printer Problem with unknown reason...");
          dmflush(pdev->memory);
          warning=1;
          }
        sleep(5);
        break;
      case ENGWARN:
        errprintf(pdev->memory,
                  "sparc_print_page: Printer-Warning: %s...",
                  err_code_string(lpvierr.err_code));
        dmflush(pdev->memory);
        warning=1;
        sleep(5);
        break;
      case ENGFATL:
        errprintf(pdev->memory,
                  "sparc_print_page: Printer-Fatal: %s\n",
                  err_code_string(lpvierr.err_code));
        return -1;
      case EDRVR:
        errprintf(pdev->memory,
                  "sparc_print_page: Interface/driver error: %s\n",
                  err_code_string(lpvierr.err_code));
        return -1;
      default:
        errprintf(pdev->memory,
                  "sparc_print_page: Unknown err_type=%d(err_code=%d)\n",
                  lpvierr.err_type,lpvierr.err_code);
        return -1;
      }
    }
  if (warning==1)
    {
    errprintf(pdev->memory, "OK.\n");
    warning=0;
    }
  gs_free(pdev->memory, out_buf,out_size,1,"sparc_print_page: out_buf");
  return 0;
  }
Beispiel #28
0
/* since computer-to-printer communication time is often a bottleneck. */
static int
oki4w_print_page(gx_device_printer *pdev, FILE *prn_stream)
{
	int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
	int line_size_words = (line_size + W - 1) / W;
	uint storage_size_words = line_size_words * 8; /* data, out_row, out_row_alt, prev_row */
	word *storage = (ulong *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), storage_size_words, W,
					   "oki4w_print_page");
	word
	  *data_words,
	  *out_row_words,
	  *out_row_alt_words,
	  *prev_row_words;
#define data ((byte *)data_words)
#define out_row ((byte *)out_row_words)
#define out_row_alt ((byte *)out_row_alt_words)
#define prev_row ((byte *)prev_row_words)
	byte *out_data;
	int x_dpi = pdev->x_pixels_per_inch;
	int y_dpi = pdev->y_pixels_per_inch;
	int y_dots_per_pixel = x_dpi / y_dpi;
	int dpi_code, compress_code;
	int num_rows = dev_print_scan_lines(pdev);

	int out_count;
	int paper_size = oki_paper_size((gx_device *)pdev);
	int code = 0;
	/* bool dup = pdev->Duplex;
	bool dupset = pdev->Duplex_set >= 0; */

	if ( storage == 0 )	/* can't allocate working area */
		return_error(gs_error_VMerror);
	data_words = storage;
	out_row_words = data_words + (line_size_words * 2);
	out_row_alt_words = out_row_words + (line_size_words * 2);
	prev_row_words = out_row_alt_words + (line_size_words * 2);
	/* Clear temp storage */
	memset(data, 0, storage_size_words * W);

	out_data = out_row;

	if (y_dpi == 150) {
		dpi_code = 3;
		compress_code = 2;
	} else if (y_dpi == 300) {
		dpi_code = 5;
		compress_code = 2;
	} else {
		dpi_code = 7;
		compress_code = 2;
	}

	/* Initialize printer. */
/*	if ( pdev->PageCount == 0 ) { */
		/* Put out init string before page. */
		fprintf(prn_stream, "\x1B%%-98765X\x1C\x14\x03\x41i\x10\x1C"
			"\x14\x05\x41\x65%cf%c\x1C\x14\x09\x42\x61%cb\x02\x63"
			"\x01\x65%c\x1C\x7F\x39\x1B&B\x1B&A\x07%c\x01%c"
			"\x01%c%c%c%c\x1B$A",
			dpi_code, dpi_code, 0, 0, 0, paper_size,
			0, dpi_code, dpi_code, 0);
/*	} */

	/* Send each scan line in turn */
	   {	int lnum;
		int num_blank_lines = 0;
		word rmask = ~(word)0 << (-pdev->width & (W * 8 - 1));

		/* Transfer raster graphics. */
		for ( lnum = 0; lnum < num_rows; lnum++ )
		   {	register word *end_data =
				data_words + line_size_words;
			int i;
			code = gdev_prn_copy_scan_lines(pdev, lnum,
						 (byte *)data, line_size);
			if ( code < 0 )
				break;
		   	/* Mask off 1-bits beyond the line width. */
			end_data[-1] &= rmask;
			/* Remove trailing 0s. */
			while ( end_data > data_words && end_data[-1] == 0 )
			  end_data--;
			if ( end_data == data_words )
			   {	/* Blank line */
				num_blank_lines++;
				continue;
			   }

			/* We've reached a non-blank line. */
			/* Put out a spacing command if necessary. */
			if ( num_blank_lines == lnum )
			{	/* We're at the top of a page. */
				/* TODO: skip top_margin lines... */
				/* num_blank_lines += xxx */
				/* Skip blank lines if any */
				if (num_blank_lines > 0) {
					fprintf(prn_stream, "\x1b*B%c%c",
						num_blank_lines & 0xff,
						num_blank_lines >> 8);
				}
			}
			else if ( num_blank_lines != 0 )
			{
				/* Skip blank lines if any */
				fprintf(prn_stream, "\x1b*B%c%c",
					num_blank_lines & 0xff,
					num_blank_lines >> 8);
			}
Beispiel #29
0
/* Send the page to the printer.  */
static int
fmlbp_print_page(gx_device_printer *pdev, FILE *prn_stream)
{
  int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
#ifdef	FMLBP_NOPAPERSIZE
  char data[LINE_SIZE*2];
#else
  byte *data = (byte *)gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), 1, line_size, "fmlpr_print_page(data)");
  if(data == NULL) return_error(gs_error_VMerror);
#endif/*FMLBP_NOPAPERSIZE*/

  /* initialize */
  fwrite(can_inits, sizeof(can_inits), 1, prn_stream);
  fprintf(prn_stream, "%c%c%d!I", PU1, 0);	/* 100% */
#ifndef	OLD_FMLBP_400DPI
  fprintf(prn_stream, "%c%c%d!A", PU1,
	  (int)(pdev->x_pixels_per_inch));	/* 240dpi or 400dpi */
#endif/*!OLD_FMLBP_400DPI*/
#ifndef	FMLBP_NOPAPERSIZE
  fprintf(prn_stream, "%c%c%s!F", PU1,
	  gdev_fmlbp_paper_size(pdev));		/* Paper size */
#endif/*!FMLBP_NOPAPERSIZE*/

  /* Send each scan line in turn */
  {	int lnum;
	byte rmask = (byte)(0xff << (-pdev->width & 7));

	for ( lnum = 0; lnum < pdev->height; lnum++ )
	  {	byte *end_data = data + line_size;
		int s = gdev_prn_copy_scan_lines(pdev, lnum,
						(byte *)data, line_size);
		if(s < 0) return_error(s);
		/* Mask off 1-bits beyond the line width. */
		end_data[-1] &= rmask;
		/* Remove trailing 0s. */
		while ( end_data > data && end_data[-1] == 0 )
		  end_data--;
		if ( end_data != data ) {	
		  int num_cols = 0;
		  int out_count = 0;
		  byte *out_data = data;
		  
		  while(out_data < end_data && *out_data == 0) {
		    num_cols += 8;
		    out_data++;
		  }
		  out_count = end_data - out_data;

		  /* move down */ /* move across */
		  goto_xy(prn_stream, num_cols, lnum);

		  /* transfer raster graphics */
		  fprintf(prn_stream, "%c%c%d;%d;0!a",
			  PU1, out_count, out_count*8 );

		  /* send the row */
		  fwrite(out_data, sizeof(byte), out_count, prn_stream);
		}
	      }
      }
  /* eject page */
  fputc(0x0c,prn_stream);
  fflush(prn_stream);
#ifndef	FMLBP_NOPAPERSIZE
  gs_free(gs_lib_ctx_get_non_gc_memory_t(), (char *)data, line_size, sizeof(byte), "fmlbp_print_page(data)");
#endif/*!FMLBP_NOPAPERSIZE*/

  return 0;
}
Beispiel #30
0
/* Send the page to the printer. */
static int
pr201_print_page(gx_device_printer *pdev, FILE *prn_stream)
{	int line_size;
	int height;
	int bits_per_column;
	int bytes_per_column;
	int chunk_size;
	byte *in, *out;
	int lnum, skip;
	int head_pins, lr_pitch, x_dpi;
	
	switch (check_mode(pdev->dname)){
		case PR201:
			head_pins=24; lr_pitch=18; x_dpi=160; break;
		case PR1000:
			head_pins=40; lr_pitch=20; x_dpi=240; break;
		case PR150:
			head_pins=48; lr_pitch=18; x_dpi=320; break;
		case PR1K4:
			head_pins=60; lr_pitch=18; x_dpi=400; break;
	}

	line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
	height = pdev->height;
	bits_per_column	 = head_pins;
	bytes_per_column = bits_per_column / 8;
	chunk_size = bits_per_column * line_size;

	in = (byte *)
		gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), bits_per_column, line_size, "pr201_print_page(in)");
	out = (byte *)
		gs_malloc(gs_lib_ctx_get_non_gc_memory_t(), bits_per_column, line_size, "pr201_print_page(out)");
	if(in == 0 || out == 0)
		return -1;

	/* Initialize printer */
	fputs("\033cl", pdev->file);	/* Software Reset */
	fputs("\033P", pdev->file);	/* Proportional Mode */
	if (check_mode(pdev->dname)==PR150){
		fprintf(pdev->file, "\034d%d.", x_dpi); /* 320 dpi mode. */
	}
	fprintf(pdev->file, "\033T%d" , lr_pitch);
				/* 18/120 inch per line */

	/* Send Data to printer */
	lnum = 0;
	skip = 0;
	while(lnum < height) {
		byte *inp, *outp, *out_beg, *out_end;
		int x, y, num_lines, size, mod;

		/* Copy scan lines */
		if(gdev_prn_copy_scan_lines(pdev, lnum, in, chunk_size) < 0)
			break;

		/* The number of lines to process */
		if((num_lines = height - lnum) > bits_per_column)
			num_lines = bits_per_column;

		/* Test for all zero */
		size = line_size * num_lines;
		if(in[0] == 0 && 
		   !memcmp((char *)in, (char *)in + 1, size - 1)) {
			lnum += bits_per_column;
			skip ++;
			continue;
		}

		/* Fill zero */
		if(num_lines < bits_per_column) {
			size = line_size * (bits_per_column - num_lines);
			memset(in + line_size * num_lines, 0, size);
		}
		lnum += bits_per_column;

		/* Vertical tab to the appropriate position. */
		while(skip > 72) {
			fprintf(pdev->file, "\037%c", 16 + 72);
			skip -= 72;
		}
		if(skip > 0) {
			fprintf(pdev->file, "\037%c", 16 + skip);
		}

		/* Transpose in blocks of 8 scan lines. */
		for(y = 0; y < bytes_per_column; y ++) {
			inp = in + line_size * 8 * y;
			outp = out + y;
			for(x = 0; x < line_size; x ++) {
				pr201_transpose_8x8(inp, line_size,
						    outp, bytes_per_column);
				inp ++;
				outp += bits_per_column;
			}
		}

		/* Remove trailing 0s. */
		out_end = out + chunk_size - 1;
		while(out_end >= out) {
			if(*out_end)
				break;
			out_end --;
		}
		size = (out_end - out) + 1;
		if((mod = size % bytes_per_column) != 0)
			out_end += bytes_per_column - mod;

		/* Remove leading 0s. */
		out_beg = out;
		while(out_beg <= out_end) {
			if(*out_beg)
				break;
			out_beg ++;
		}
		out_beg -= (out_beg - out) % bytes_per_column;

		/* Dot addressing */
		fprintf(pdev->file, "\033F%04d", 
			(out_beg - out) / bytes_per_column);

		/* Dot graphics */
		size = out_end - out_beg + 1;
		if (check_mode(pdev->dname)==PR201){
			fprintf(pdev->file,"\033J%04d", size / bytes_per_column);
		}else{
			fprintf(pdev->file,"\034bP,48,%04d.",
			  size / bytes_per_column);
		}
		fwrite(out_beg, size, 1, pdev->file);

		/* Carriage Return */
		fputc('\r', pdev->file);
		skip = 1;
	}

	/* Form Feed */
	fputc('\f',pdev->file);
	fflush(pdev->file);

	gs_free(gs_lib_ctx_get_non_gc_memory_t(), (char *)out, 
		bits_per_column, line_size, "pr201_print_page(out)");
	gs_free(gs_lib_ctx_get_non_gc_memory_t(), (char *)in,
		bits_per_column, line_size, "pr201_print_page(in)");

	return 0;
}