#ifndef lint static char SCCSid[] = "$SunId$ LBL"; #endif /* rad2pict - Convert an Radiance image to APPLE pict format. School of Architecture, Auckland University, Private Bag Auckland, New Zealand */ #include #include "pict.h" #include "color.h" #include "resolu.h" extern char *malloc(); char cbuf[8192*5]; char pbuf[8192]; int outbytes; FILE *outf, *inf; char **gargv; putrect(xorg,yorg,xsize,ysize) int xorg, yorg, xsize, ysize; { putashort(yorg); putashort(xorg); putashort(ysize); putashort(xsize); } putfprect(xorg,yorg,xsize,ysize) int xorg, yorg, xsize, ysize; { putalong(yorg<<16); putalong(xorg<<16); putalong(ysize<<16); putalong(xsize<<16); } putalong(l) long l; { putbyte((l>>24)&0xff); putbyte((l>>16)&0xff); putbyte((l>>8)&0xff); putbyte((l>>0)&0xff); } putashort(s) short s; { putbyte((s>>8)&0xff); putbyte((s>>0)&0xff); } putbyte(b) unsigned char b; { char c[1]; c[0] = b; if(!fwrite(c,1,1,outf)) { fprintf(stderr,"%s: error on write\n", gargv[0]); exit(1); } outbytes++; } putbytes(buf,n) unsigned char *buf; int n; { if(!fwrite(buf,n,1,outf)) { fprintf(stderr,"topict: error on write\n"); exit(1); } outbytes+=n; } main(argc,argv) int argc; char **argv; { int xsize, ysize; int i, picsize; int ssizepos, lsizepos; gargv = argv; if( argc<3 ) { fprintf(stderr, "Usage: %s inimage out.pict\n", gargv[0]); exit(1); } if( (inf=fopen(gargv[1],"rb")) == NULL ) { fprintf(stderr,"%s: can't open input file %s\n",gargv[0], gargv[1]); exit(1); } if( (outf=fopen(gargv[2],"wb")) == NULL ) { fprintf(stderr,"%s: can't open output file %s\n", gargv[0], gargv[1]); exit(1); } if (checkheader(inf, COLRFMT, NULL) < 0 || fgetresolu(&xsize, &ysize, inf) < 0) { fprintf(stderr, "%s: not a radiance picture\n", argv[1]); exit(1); } setcolrgam(2.0); for(i=0; i250) putashort(nbytes); else putbyte(nbytes); putbytes(pbuf,nbytes); } if(outbytes&1) putbyte(0); } int getrow(in, mybuff, xsize) FILE *in; char *mybuff; int xsize; { COLOR color; COLR *scanin = (COLR*) malloc(xsize * sizeof(COLR)); int x; if (scanin == NULL) { printf("scanin null"); } if (freadcolrs(scanin, xsize, in) < 0) { fprintf(stderr, " read error\n"); exit(1); } colrs_gambs(scanin, xsize); for (x = 0; x < xsize; x++) { colr_color(color, scanin[x]); cbuf[xsize * 0 + x] = color[RED] * 255; cbuf[xsize * 1 + x] = color[GRN] * 255; cbuf[xsize * 2 + x] = color[BLU] * 255; } free(scanin); } packbits(ibits,pbits,nbits) unsigned char *ibits, *pbits; int nbits; { int bytes; unsigned char *sptr; unsigned char *ibitsend; unsigned char *optr = pbits; int nbytes, todo, cc, count; nbytes = ((nbits-1)/8)+1; ibitsend = ibits+nbytes; while (ibits127 ? 127:count; count -= todo; *optr++ = todo-1; while(todo--) *optr++ = *sptr++; } if(ibits == ibitsend) break; sptr = ibits; cc = *ibits++; while( (ibits128 ? 128:count; count -= todo; *optr++ = 257-todo; *optr++ = cc; } } return optr-pbits; }