⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcg01of.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 2 页
字号:
			error = readXimgdat();			if(error) {				syslog(LOG_INFO,"Failed to use image data");				return(1);			}			if(im.spbxnm > MAXP_PIX_WIDTH || im.spbynm > MAXP_PIX_HEIGHT) {				fprintf(output,"\033[1 J");				if(im.spbxnm > MAXP_PIX_HEIGHT || im.spbynm > MAXP_PIX_WIDTH) {					fprintf(output,"\033P9;0;1q\"1;1;%d;%d",						MAXL_PIX_WIDTH,MAXL_PIX_HEIGHT);					if(im.spbynm > MAXL_PIX_HEIGHT) {						tmppagecount = im.spbynm/MAXL_PIX_HEIGHT;						tmplinecount = MAXL_PIX_HEIGHT;					}				} else {					fprintf(output,"\033[7 I\033P9;0;2q\"1;1;%d;%d",						MAXP_PIX_HEIGHT,MAXP_PIX_WIDTH);				}			} else {				fprintf(output,"\033[7 I\033P9;0;2q\"1;1;%d;%d",					MAXP_PIX_WIDTH,MAXP_PIX_HEIGHT);			}			error = docsixel();			if(error) {				syslog(LOG_INFO,"Failed to 'sixelize' data");				fprintf(output, "\033\\");				fprintf(output, "\033c");				sleep(5);				fprintf(output, "\014");				fflush(output);				return(1);			}			free((char *)cmpptr);			free((char *)imgptr);			break;		case TEXT_FILE:		case CTEXT_FILE:		case ATEXT_FILE:		case RTEXT_FILE:		case FTEXT_FILE:		default:			if(width > MAXLWIDTH) {				fprintf(output,"\033[1 J");			}			for(globi=0;globi<in;globi++) {				putc(filestorage[globi],output);				if(filestorage[globi] == '\012') {					putc('\015',output);					counter++;				}				if((counter%4) == 0)					fflush(output);				counter++;			}			while((ch = getc(input)) != EOF) {				putc(ch,output);				if(ch == '\012') {					putc('\015',output);					counter++;				}				if((counter%4) == 0)					fflush(output);				counter++;			}			break;	}	fprintf(output, "\014");	fflush(output);	retrycnt = 0;	lpinc = 0;	fprintf(output,"\033[c");	fflush(output);	sleep(5);	while(!lpinc) {		ioctl(fileno(output),FIONREAD, (char *)&lpinc);		lpinc = read(fileno(output),lpin,lpinc);		if(lpinc == 0) {			retrycnt++;			sleep(10);			if(retrycnt > 20)				return(1);		}	}	fflush(output);	return(0);}/* If the file stream is of the XIMAGE_FILE type this routine is called   from lcg01of.  The routine creates a color 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.  Color   sixel output is initialized and then the processing begins.   The current design of the algorithm does not attempt to dither   the image data but rather sends color values to the LCG01 which performs   a hardware dither.  There 256 colors per page available.  The algorithm   used here employs the Hue, Lightness, and Saturation color model   in determining the correct sixels to send to the printer.*/docsixel(){	register int i;	int xcnt,ycnt,n = 1,ij=0,tmpycnt=0;	unsigned char	*srcptr;	unsigned char	*nxtptr;	short sh,sl,ss;	unsigned short sr,sg,sb;	char *base_band,*pb;	int lastcol = -1;	int tmpcol = 0;	char tmpbuf[30];	int base_band_length = 0;	int count = 1;	char lastc = 0;	register char *cp;	int didload[256];	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) 12 * im.spbxnm);	for(i=0;i<256;i++)		didload[i] = 0;	while((ycnt/n) * n) {		xcnt=im.spbxnm;		base_band_length = 0;		base_band = pb;		while(xcnt>0) {			if(MAXL_PIX_WIDTH - xcnt < 0) {				if(im.format != ITS)					srcptr+=n;				else					srcptr+=n*3;				xcnt-=n;				continue;			}			if(im.format != ITS) {				sh = *((cmpptr + 3*(*srcptr))+0);				sl = *((cmpptr + 3*(*srcptr))+1);				ss = *((cmpptr + 3*(*srcptr))+2);			} else {				sr = (unsigned short)*srcptr++;				sg = (unsigned short)*srcptr++;				sb = (unsigned short)*srcptr;				rgbtohls(sr,sg,sb,&sh,&sl,&ss);			}			for(i=0;i<2;i++) {				*(base_band+i) = SOFF;			}			tmpcol = -1;			if(lastcol != (unsigned short)*srcptr) {				lastcol = (unsigned short)*srcptr;				tmpcol = lastcol;			}			if(tmpcol >= 0) {				if(!didload[lastcol]) {					if(sh == -1)						sh = 0;					sprintf(&tmpbuf[0],"#%d;1;%d;%d;%d",lastcol,sh,sl,ss);					strcpy(base_band,tmpbuf);					base_band += strlen(tmpbuf);					base_band_length += strlen(tmpbuf);					didload[lastcol]++;				}				*base_band++ = '#';				sprintf(&tmpbuf[0],"%d",lastcol);				strcpy(base_band,tmpbuf);				base_band += strlen(tmpbuf);				base_band_length += 1 + strlen(tmpbuf);			}			*base_band++ = (1<<(tmpycnt%6)) + SOFF;			ij = tmpycnt%6;			base_band_length++;			srcptr+=n;			xcnt-=n;		}		if(ij != 5) {			cp = pb;			lastc = *cp++;			for(i=0;i < base_band_length;i++) {			    if(*cp != lastc) {				if(count >= 4)				    fprintf(output,"!%d%c",count,lastc);				else				    while(count--)putc(lastc,output);				count = 1;				lastc = *cp;			    } else count++;			    cp++;			}			fprintf(output,"$");		} else {			cp = pb;			lastc = *cp++;			for(i=0;i < base_band_length;i++) {			    if(*cp != lastc) {				if(count >= 4)				    fprintf(output,"!%d%c",count,lastc);				else				    while(count--)putc(lastc,output);				count = 1;				lastc = *cp;			    } else count++;			    cp++;			}			fprintf(output,"-");		}		count=1;		srcptr=nxtptr;		if(im.format != ITS)			nxtptr=srcptr+im.spbxnm * n;		else			nxtptr=srcptr+(im.spbxnm * n * 3);		ycnt-= n;		tmpycnt++;		lastcol = -1;		if(tmppagecount) {			tmplinecount--;			if(tmplinecount == 0) {				fprintf(output,"+");				tmppagecount--;				tmplinecount = MAXL_PIX_HEIGHT;			}		}	}	fprintf(output,"+");	fprintf(output,"\033\\");	free(base_band);	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,input);	return(0);}rgbtohls(sr,sg,sb,sh,sl,ss)	unsigned short sr,sg,sb;	short *sh,*sl,*ss;{	double r,g,b,h,l,s;	double rc,gc,bc;	double max,min;	r = ((double)sr)/255.0;	g = ((double)sg)/255.0;	b = ((double)sb)/255.0;	max = MAXIMUM(r,g,b);	min = MINIMUM(r,g,b);	l = (max+min)/2.0;	if(max == min) {		s = 0.0;		h = -1.0;	} else {		if(l <= 0.5) {			s = (max - min)/(max + min);		} else {			s = (max - min)/(2.0 - max - min);		}		rc = 1.0-(max - r)/(max - min);		gc = 1.0-(max - g)/(max - min);		bc = 1.0-(max - b)/(max - min);		if(b == max) {			h =  rc - gc;			goto done;		}		if(g == max) {			h = 4.0 + bc - rc;			goto done;		}		if(r == max) {			h = 2.0 + gc - bc;			goto done;		}done:		h = h*60.0;		if(h < 0.0) {			h = h + 360.0;		}	}	*sh = (short)h;	*sl = (short)(l * 100.0);	*ss = (short)(s * 100.0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -