예제 #1
0
파일: gdevespg.c 프로젝트: hackqiang/gs
static int
lp2000_print_page_copies(gx_device_printer * pdev, FILE * fp, int num_coipes)
{
    gx_device_lprn *const lprn = (gx_device_lprn *) pdev;
    int code = 0;
    int bpl = gdev_mem_bytes_per_scan_line(pdev);
    int maxY = lprn->BlockLine / lprn->nBh * lprn->nBh;

    /* printer initialize */
    if (pdev->PageCount == 0)
        escpage_printer_initialize(pdev, fp, num_coipes);

    if (!(lprn->CompBuf = gs_malloc(pdev->memory->non_gc_memory, bpl * 3 / 2 + 1, maxY, "lp2000_print_page_copies(CompBuf)")))
        return_error(gs_error_VMerror);

    if (lprn->NegativePrint) {
        fprintf(fp, "%c1dmG", GS);
        fprintf(fp, "%c0;0;%d;%d;0rG", GS, pdev->width, pdev->height);
        fprintf(fp, "%c2owE", GS);
    }
    code = lprn_print_image(pdev, fp);
    if (code < 0)
        return code;

    gs_free(pdev->memory->non_gc_memory, lprn->CompBuf, bpl * 3 / 2 + 1, maxY, "lp2000_print_page_copies(CompBuf)");

    if (pdev->Duplex)
        fprintf(fp, "%c0dpsE", GS);
    else
        fprintf(fp, "\014");	/* eject page */
    return code;
}
예제 #2
0
/* 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;
}
예제 #3
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");
}
예제 #4
0
/* Special version, called with 8 bit grey input to be downsampled to 1bpp
 * output. */
int
tiff_downscale_and_print_page(gx_device_printer *dev, TIFF *tif, int factor,
                              int mfs, int aw, int bpc, int num_comps)
{
    int code = 0;
    byte *data = NULL;
    int size = gdev_mem_bytes_per_scan_line((gx_device *)dev);
    int max_size = max(size, TIFFScanlineSize(tif));
    int row;
    int width  = dev->width/factor;
    int height = dev->height/factor;
    gx_downscaler_t ds;

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

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

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

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

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

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

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

    return code;
}
예제 #5
0
int tiff_set_compression(gx_device_printer *pdev,
                         TIFF *tif,
                         uint compression,
                         long max_strip_size)
{
    TIFFSetField(tif, TIFFTAG_COMPRESSION, compression);

    if (max_strip_size == 0) {
        TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, pdev->height);
    }
    else {
        int rows = max_strip_size /
            gdev_mem_bytes_per_scan_line((gx_device *)pdev);
        TIFFSetField(tif,
                     TIFFTAG_ROWSPERSTRIP,
                     TIFFDefaultStripSize(tif, max(1, rows)));
    }

    return 0;
}
예제 #6
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;
}
예제 #7
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;
}
예제 #8
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;
}
예제 #9
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;
}
예제 #10
0
/* Send the page to the file. */
static int
jbig2_print_page(gx_device_printer * pdev, FILE * prn_stream)
{
    gx_device_jbig2 *jdev = (gx_device_jbig2 *) pdev;
    gs_memory_t *mem = jdev->memory;
    int line_size = gdev_mem_bytes_per_scan_line((gx_device *) pdev);
    byte *in = gs_alloc_bytes(mem, line_size, "jbig2_print_page(in)");
    byte *fbuf = 0;
    uint fbuf_size;
    byte *jbuf = 0;
    uint jbuf_size;
    int lnum;
    int code = 0;
    stream_jbig2encode_state state;
    stream fstrm, cstrm;

    if (in == 0) {
        code = gs_note_error(gs_error_VMerror);
        goto fail;
    }
    /* Create the jbig2encode state. */
    s_init_state((stream_state *)&state, &s_jbig2encode_template, 0);
    if (state.templat->set_defaults)
        (*state.templat->set_defaults) ((stream_state *) & state);
    state.width = jdev->width;
    state.height = jdev->height;
    /* Set up the streams. */
    fbuf_size = max(512 /* arbitrary */ , state.templat->min_out_size);
    jbuf_size = state.templat->min_in_size;
    if ((fbuf = gs_alloc_bytes(mem, fbuf_size, "jbig2_print_page(fbuf)")) == 0 ||
        (jbuf = gs_alloc_bytes(mem, jbuf_size, "jbig2_print_page(jbuf)")) == 0
        ) {
        code = gs_note_error(gs_error_VMerror);
        goto done;
    }
    s_init(&fstrm, mem);
    swrite_file(&fstrm, prn_stream, fbuf, fbuf_size);
    s_init(&cstrm, mem);
    s_std_init(&cstrm, jbuf, jbuf_size, &s_filter_write_procs,
               s_mode_write);
    cstrm.state = (stream_state *) & state;
    cstrm.procs.process = state.templat->process;
    cstrm.strm = &fstrm;
    if (state.templat->init)
        (*state.templat->init) (cstrm.state);

    /* Copy the data to the output. */
    for (lnum = 0; lnum < jdev->height; ++lnum) {
        byte *data;
        uint ignore_used;

        if (cstrm.end_status) {
            code = gs_note_error(gs_error_ioerror);
            goto done;
        }
        gdev_prn_get_bits(pdev, lnum, in, &data);
        sputs(&cstrm, data, state.stride, &ignore_used);
    }

    /* Wrap up. */
    sclose(&cstrm);
    sflush(&fstrm);
  done:
    gs_free_object(mem, jbuf, "jbig2_print_page(jbuf)");
    gs_free_object(mem, fbuf, "jbig2_print_page(fbuf)");
    gs_free_object(mem, in, "jbig2_print_page(in)");
    return code;
  fail:
    gs_free_object(mem, in, "jbig2_print_page(in)");
    return code;
}
예제 #11
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;
}
예제 #12
0
static int
ds32_print_page(gx_device_printer * pdev, FILE * file)
{
    gx_device_ds32 *const dsdev = (gx_device_ds32 *)pdev;
    int code = 0;
    byte *data = NULL;
    int size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
    int row;
    int factor = dsdev->downscale.downscale_factor;
    int height = pdev->height / factor;
    int bpc = 8;
    int num_comps = 4;
    int trap_w = dsdev->downscale.trap_w;
    int trap_h = dsdev->downscale.trap_h;
    int *trap_order = dsdev->downscale.trap_order;
    gx_downscaler_t ds;

    if (num_comps == 4) {
        if (dsdev->icclink == NULL) {
            code = gx_downscaler_init_trapped(&ds, (gx_device *)pdev, 8, bpc, num_comps,
                factor, 0 /*mfs*/, &fax_adjusted_width, 0 /*aw*/, trap_w, trap_h, trap_order);
        } else {
            code = gx_downscaler_init_trapped_cm(&ds, (gx_device *)pdev, 8, bpc, num_comps,
                factor, 0 /*mfs*/, &fax_adjusted_width, 0 /*aw*/, trap_w, trap_h, trap_order,
                ds32_chunky_post_cm, dsdev->icclink, dsdev->icclink->num_output);
        }
    }
    if (code < 0)
        return code;

    data = gs_alloc_bytes(pdev->memory, size, "ds32_print_page(data)");
    if (data == NULL) {
        gx_downscaler_fin(&ds);
        return_error(gs_error_VMerror);
    }

    for (row = 0; row < height && code >= 0; row++) {
        code = gx_downscaler_getbits(&ds, data, row);
        if (code < 0)
            break;
#ifdef WRITE_PAM32	/* debugging code to write a PAM 32 file. */
        if ((code = debug_write_pam_32(dsdev, data, row, file)) < 0)
            break;
#endif
        /*************************************************************/
        /* User code to handle the row of data (dsdev->width bytes)  */
        /* Set code to a negative value (e.g. gs_error_ioerror) if a */
        /* problem occurs.                                           */
        /* Note that nothing needs to be written to 'file' and this  */
        /* can be set to '-' (stdout) to avoid leaving an empty file */
        /* if (row == 0) can be used to perform any initialization   */
        /*     needed to process the user data                       */
        /*************************************************************/

        if (code < 0)
            break;
    }

    /**************************************************************/
    /* User code to finish writing and perform any cleanup needed */
    /**************************************************************/

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

    return code;
}
예제 #13
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;
}
예제 #14
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;
}
예제 #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;
}
예제 #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;
		}
	}
예제 #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;
}
예제 #18
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;
}
예제 #19
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;
}
예제 #20
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;
}
예제 #21
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;
}
예제 #22
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;
  }
예제 #23
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);
			}
예제 #24
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;
}
예제 #25
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;
}