📄 la75.c
字号:
break; case '\f': lineno = length; case '\n': if (maxrep < 0) maxrep = 0; linedone = 1; break; case '\b': if (--col < indent) col = indent; break; case '\r': col = indent; break; case '\t': col = ((col - indent) | 07) + indent + 1; break; case '\031': /* * lpd needs to use a different filter to * print data so stop what we are doing and * wait for lpd to restart us. */ ch = globi < in ? filestorage[globi++] : getc(p); if ( ch == '\1') { fflush(stdout); kill(getpid(), SIGSTOP); break; } else { if ( globi <= in ) globi--; else ungetc(ch,p); ch = '\031'; } default: /*everything else */ addtobuf(ch); break; } } /* print out lines */ for (i = 0; i <= maxrep; i++) { for (cp = buf[i], limit = cp+maxcol[i]; cp <= limit;) { putc(*cp, o); *cp++ = ' '; } if (i < maxrep) putc('\r', o); else putc(ch, o); if (++lineno >= length) { npages++; lineno = 0; } maxcol[i] = -1; } } if (lineno) { /* be sure to end on a page boundary */ putc('\f',o); npages++; } fprintf(o,"\033c"); /* RIS */ fflush(o); sleep(6); /* some printers eat lines during reset so wait */ break; } return(0);}/**************************************************************** Adds the character specified to buffer - if it will fit on line*****************************************************************/addtobuf (ch)register char ch;{ register char *cp; int i; if ((col >= (width + esclen) || iscntrl(ch)) && ch != ESC){ col++; return(0); } cp = &buf[0][col]; for (i = 0; i < MAXREP; i++) { if (i > maxrep) maxrep = i; if (*cp == ' ') { *cp = ch; if (col > maxcol[i]) maxcol[i] = col; break; } cp += BUFWIDTH; } col++; return(1);}/****************************************************************//* *//* eschdl - escape sequence handler *//* *//* This routine intercepts escape sequences for the purpose*//* of pass through. *//* *//****************************************************************/eschdl(o,c)int c;FILE *o;{if(escflg==0) { /* set escflg=1 => ready to receive 2nd seqchar*/ escflg=1; }else switch(escflg) { case 1: /* second character of escseq */ switch(c) { case E_NINE: addtobuf (ESC); addtobuf (PLD); esclen += 2; escflg = 0; break; case E_EIGHT: addtobuf (ESC); addtobuf (PLU); esclen += 2; escflg = 0; break; case UCP: escflg=2; /*ctrl str pass thru mode=8 */ lstchr=c; putc(ESC,o); putc(c,o); break; default: escflg=3; /* set seq pass thru mode*/ putc(ESC,o); putc(c,o); break; } break; case 2: /* ctrl string pass through mode */ if((lstchr==ESC) && (c==BSLH)) { escflg=0; lstchr=0; } else lstchr=c; /* save it for next pass */ putc(c,o); break; case 3: if(escend(c)) escflg=0;/* turn off esc handler if at end */ putc(c,o); break; }return(0);}/* If the file stream is of the XIMAGE_FILE type this routine is called from la75of. The routine creates a sixel output stream to send the printer based on the input data from an image file. Currently, only a frame buffer image of raw red, green, blue points or a GPX workstation "savimg" image are valid data streams. Sixel output is initialized and then the processing begins. The current design of the algorithm dithers the data to a 3 x 3 matrix of points using the structure sixmap.*/dosixel(){ register int i; int xcnt,ycnt,n = 1,iindex,ij=0; unsigned char *srcptr; unsigned char *nxtptr; unsigned short sl; unsigned int temp; struct sixmap *Sixmap; struct sixmap *Sixmap_offset; char *base_band,*pb; int base_band_length = 0; int count = 1; char lastc = 0; register char *cp; srcptr=(unsigned char *)imgptr; ycnt=im.spbynm; if(im.format != ITS) nxtptr=srcptr+im.spbxnm * n; else nxtptr=srcptr+(im.spbxnm * n * 3); pb = base_band = (char *)malloc((unsigned int) 6 *im.spbxnm); Sixmap = base_sixmap; Sixmap_offset = offset_sixmap; while((ycnt/n) * n) { xcnt=im.spbxnm; base_band_length = 0; base_band = pb; while(xcnt>0) { if(MAXP_PIX_WIDTH - xcnt < 0) { if(im.format != ITS) srcptr+=n; else srcptr+=n*3; xcnt-=n; continue; } if(im.format != ITS) { sl = *(cmpptr + 3*(*srcptr)); } else { /* need to convert to YIQ */ temp= *srcptr++ * .30; temp+= *srcptr++ * .59; temp+= *srcptr * .11; temp=(255-temp); sl = (unsigned short)temp; } iindex = (sl * 9) / 255; for(i=0;i<3;i++) { *(base_band+i) = SOFF; } if(!ij) { *base_band++ = Sixmap[iindex].s0; *base_band++ = Sixmap[iindex].s1; *base_band++ = Sixmap[iindex].s2; } else { *base_band++ = Sixmap_offset[iindex].s0; *base_band++ = Sixmap_offset[iindex].s1; *base_band++ = Sixmap_offset[iindex].s2; } base_band_length+=3; srcptr+=n; xcnt-=n; } if(!ij) { cp = pb; lastc = *cp++; for(i=0;i < base_band_length;i++) { if(*cp != lastc) { if(count >= 4) fprintf(o,"!%d%c",count,lastc); else while(count--)putc(lastc,o); count = 1; lastc = *cp; } else count++; cp++; } fprintf(o,"$"); count = 1; ij++; } else { cp = pb; lastc = *cp++; for(i=0;i < base_band_length;i++) { if(*cp != lastc) { if(count >= 4) fprintf(o,"!%d%c",count,lastc); else while(count--) putc(lastc,o); count = 1; lastc = *cp; } else count++; cp++; } count = 1; ij = 0; fprintf(o,"-"); } srcptr=nxtptr; if(im.format != ITS) nxtptr=srcptr+im.spbxnm * n; else nxtptr=srcptr+(im.spbxnm * n * 3); ycnt-= n; if(tmppagecount) { tmplinecount--; if(tmplinecount == 0) { fprintf(o,"+"); tmppagecount--; if(im.spbynm > MAXP_PIX_HEIGHT) tmplinecount = MAXP_PIX_HEIGHT; } } } fprintf(o,"+"); fprintf(o,"\033\\"); return(0);}readXimghdr(){ register int tmp; size=HEDLEN*512; bcopy(&filestorage[globi],(char *)&im, (int)size); globi = globi + size; if(im.imgflg != IMGFLG) return(1); if(im.format != QDSS || im.spbgnm != 1) { if(im.format != ITS) return(1); } if(im.format == ITS) { tmp = im.spbxnm; im.spbxnm = im.spbynm; im.spbynm = tmp; im.spblen = im.spblen * 3; } return(0);}readXimgcmp(){ if(im.format == ITS) return(0); size=im.cmplen*512; if(size==0) return(1); if((cmpptr=(short *) malloc(size))==NULL) return(1); bcopy(&filestorage[globi], (char *)cmpptr, (int)size); globi = globi + size; return(0);}readXimgdat(){ size=im.spblen*512; if((imgptr=(char *) malloc(size))==NULL) return(1); bcopy(filestorage+globi,imgptr,in-globi); fread(imgptr+(in-globi),(char)size-(in-globi),1,p); return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -