void sgiWritFB(ppf rgb[4], int dX, int dY, unt dW, unt dH, unt dD, char *path) { IMAGE *sgim; int k,y,yI; flt *sr, *sg, *sb ; pus dr, dg, db, rr, gg, bb; mallocAss(rr,ush,dW); mallocAss(gg,ush,dW); mallocAss(bb,ush,dW); wrn("sgiWritFB dD: %u path: %s", dD,path); if (dD < 3 || rgb[1] == NULL) { sgiWritFlt(rgb[0],dX,dY,dW,dH,path); return; } sgim = iopen(path,"w",RLE(1),3,dW,dH,3); /* WHAT'S the 1st 3? */ for (y = 0, yI = dH+dY; yI > dY ; y++) { sr = &rgb[1][--yI][dX]; sg = &rgb[2][ yI][dX]; sb = &rgb[3][ yI][dX]; for (dr = rr, dg = gg, db = bb, k = dW; k; k--) { *dr++ = 0.5F + *sr++; *dg++ = 0.5F + *sg++; *db++ = 0.5F + *sb++; } putrow(sgim,rr,y,0); putrow(sgim,gg,y,1); putrow(sgim,bb,y,2); } iclose(sgim); free(rr); free(gg); free(bb); }
void saveSGIImage(char *name, int doAlphaToo) { IMAGE *img; FILE *fp; GLubyte *pixels; int x, y; int numComp = doAlphaToo ? 4 : 3; pixels = malloc(winWidth * winHeight * numComp * sizeof(GLubyte)); glReadPixels(0, 0, winWidth, winHeight, doAlphaToo ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, pixels); img = iopen(name, "w", RLE(1), numComp, winWidth, winHeight, numComp); for(y = 0; y < winHeight; y++) { for(x = 0; x < winWidth; x++) { rrow[x] = pixels[(y * winWidth + x) * numComp + 0]; grow[x] = pixels[(y * winWidth + x) * numComp + 1]; brow[x] = pixels[(y * winWidth + x) * numComp + 2]; if(doAlphaToo) arow[x] = pixels[(y * winWidth + x) * numComp + 3]; } putrow(img, rrow, y, 0); putrow(img, grow, y, 1); putrow(img, brow, y, 2); if(doAlphaToo) putrow(img, arow, y, 3); } iclose(img); free(pixels); }
void sgiWritUB(ppu rgb[4], unt dW, unt dH, char *path) { IMAGE *sgim; int k,y,yI; unc *sr, *sg, *sb ; ush *dr, *dg, *db, rr[512], gg[512], bb[512]; assert(dW <= 512); sgim = iopen(path,"w",RLE(1),3,dW,dH,3); /* WHAT'S the 1st 3? */ for (y = 0, yI = dH; yI ; y++) { sr = rgb[1][--yI]; sg = rgb[2][ yI]; sb = rgb[3][ yI]; for (dr = rr, dg = gg, db = bb, k = dW; k; k--) { *dr++ = *sr++; *dg++ = *sg++; *db++ = *sb++; } putrow(sgim,rr,y,0); putrow(sgim,gg,y,1); putrow(sgim,bb,y,2); } iclose(sgim); }
void writSgiUsh(ppus rgb[4], unt dW, unt dH, char *path) { IMAGE *sgim; unt y,yI; sgim = iopen(path,"w",RLE(1),3,dW,dH,3); /* WHAT'S the 1st 3? */ for (y = 0, yI = dH; yI-- ; y++) { putrow(sgim,rgb[1][yI],y,0); putrow(sgim,rgb[2][yI],y,1); putrow(sgim,rgb[3][yI],y,2); } iclose(sgim); }
unsigned int iflsbuf(RGB_IMAGE *image, unsigned int c) { register unsigned short *base; register int n, rn; int size; if ((image->flags&_IOWRT)==0) return(EOF); if ((base=image->base)==NULL) { size = IBUFSIZE(image->xsize); if ((image->base=base=ibufalloc(image)) == NULL) { i_errhdlr("flsbuf: error on buf alloc\n",0,0,0,0); return EOF; } rn = n = 0; } else if ((rn = n = image->ptr - base) > 0) { n = putrow(image,base,image->y,image->z); if (++image->y >= image->ysize) { image->y = 0; if (++image->z >= image->zsize) { image->z = image->zsize-1; image->flags |= _IOEOF; return -1; } } } image->cnt = image->xsize-1; *base++ = c; image->ptr = base; if (rn != n) { image->flags |= _IOERR; return(EOF); } return(c); }
int iflush(RGB_IMAGE *image) { unsigned short *base; if ( (image->flags&_IOWRT) && (base=image->base)!=NULL && (image->ptr-base)>0) { if (putrow(image, base, image->y,image->z)!=image->xsize) { image->flags |= _IOERR; return(EOF); } } return(0); }
void rgbWriteSGI(ppf rgb, int dX, int dY, unt dW, unt dH, char *path) { IMAGE *sgim; int k,y,yI; flt *sp; ush *rp, *gp, *bp, rr[1024], gg[1024], bb[1024]; assert(dW <= 1024); sgim = iopen(path,"w",RLE(1),3,dW,dH,3); /* WHAT'S the 1st 3? */ for (dX *= 3, y = 0, yI = dH+dY; yI > dY ; y++) { sp = &rgb[--yI][dX]; for (rp = rr, gp = gg, bp = bb, k = dW; k; k--) { *rp++ = 0.5F + *sp++; *gp++ = 0.5F + *sp++; *bp++ = 0.5F + *sp++; } putrow(sgim,rr,y,0); putrow(sgim,gg,y,1); putrow(sgim,bb,y,2); } iclose(sgim); }
void rgbWriteSGIn(ppf rgb, int dX, int dY, unt dW, unt dH, char *path) { IMAGE *sgim; int k,y; flt *sp; ush *rp, *gp, *bp, rr[1280], gg[1280], bb[1280]; assert(dW <= 1280); sgim = iopen(path,"w",RLE(1),3,dW,dH,3); /* WHAT'S the 1st 3? */ for (rgb += dY, dX *= 3, y = 0; y < dH; y++) { sp = *rgb++ + dX; for (rp = rr, gp = gg, bp = bb, k = dW; k; k--) { *rp++ = 0.5F + *sp++; *gp++ = 0.5F + *sp++; *bp++ = 0.5F + *sp++; } putrow(sgim,rr,y,0); putrow(sgim,gg,y,1); putrow(sgim,bb,y,2); } iclose(sgim); }
static void ffty( void ) { fint l, lp2; float row1[2*SIZE], row2[2*SIZE]; lp2 = 2 * NPTX; /* number of points in row */ /* * separate the data into even and odd subsequences, * transform each, phase shift the odd transform and * add them. this recursive formulation of the FFT is * here written iteratively, from the innermost * subtransform outward. */ for ( l = 0; l < LOGP2Y; l++ ) { fint i, i2l, istep, q; i2l = POWTAB[l]; istep = 2 * i2l; q = POWTAB[ MAXP2 - l - 1 ]; for ( i = 0; i < i2l; i++ ) { fint ia, ib, itab; float wr, wi; itab = i * q; /* get table entry */ wr = COSTAB[itab]; /* get cosine from table */ wi = SINTAB[itab] * SIGN; /* get sine from table */ for ( ia = i; ia < NPTY; ia += istep ) { ib = ia + i2l; getrow( row1, lp2, ia ); getrow( row2, lp2, ib ); fxcx( wr, wi, row1, row2, NPTX ); putrow( row1, lp2, ia ); putrow( row2, lp2, ib ); } } } }
void sgiWritFlt (ppf src, int sX, int sY, unt sW, unt sH, char *path) { IMAGE *image; int k; unsigned short *rowp, *row; pfl srcp; if (! (image = iopen(path,"w",RLE(1),2,sW,sH))) die("sgiWritFlt: iopen(%s)", path); mallocAss(row,unsigned short,sW); for (src += sY; sH; ) { for (rowp = row, srcp = *src++ + sX, k = sW; k-- ; ) *rowp++ = 0.5F + *srcp++; /* Not IRINTF */ putrow(image,row,--sH,0); } iclose(image); free(row); }
int main( int argc, char* argv[]) { FILE* ifp; bit* bitrow; int rows, cols, format, row, col; pbm_init( &argc, argv ); if ( argc > 2 ) pm_usage( "[pbmfile]" ); if ( argc == 2 ) ifp = pm_openr( argv[1] ); else ifp = stdin; pbm_readpbminit( ifp, &cols, &rows, &format ); if( rows>INT16MAX || cols>INT16MAX ) pm_error ("Input image is too large."); bitrow = pbm_allocrow( cols ); putinit (rows, cols); for ( row = 0; row < rows; ++row ) { #ifdef DEBUG fprintf (stderr, "row %d\n", row); #endif pbm_readpbmrow( ifp, bitrow, cols, format ); for ( col = 0; col < cols; ++col ) putbit( bitrow[col] ); putrow( ); } flushrow (); pm_close( ifp ); exit( 0 ); }
int /** replaced rowWriteSGIN **/ rowWritSGImU(ppu *srcU, int dX, int dY, unt dW, unt dH, unt chan, char *path) { ush sbuf[1536]; ppu srcp; int q,j,yI; IMAGE *sgim = iopen(path,"w",RLE(1),3,dW,dH,chan); if (!sgim) { warn("rowWritSGImU: iopen failed"); return -1; } for (q = 0; q < chan; q++) { for (srcp = &srcU[q][dY], j = dH, yI = dY; j-- ; ) { ushUnc(sbuf,*srcp++ + dX,dW); putrow(sgim,sbuf,j,q); } } return iclose(sgim); }
void rowWriteSGI(ppf src, int sX, int sY, unt sW, unt sH, char *path) { IMAGE *sgim; int k,y,yI; flt *fp; ush *up, *urow; mallocAss(urow,unsigned short,sW); sgim = iopen(path,"w",RLE(1),2,sW,sH,1); for (y = 0, yI = sH+sY; yI > sY ; y++) { fp = &src[--yI][sX]; for (up = urow, k = sW; k-- ; ) { *up++ = 0.5F + *fp++; } putrow(sgim,urow,y,0); } iclose(sgim); }
int /* DOES NOT FLIP IMAGE AROUND X-AXIS -- ORIGIN AT BOTTOM LEFT */ rowWritSgiU(ppu *srcU, int dX, int dY, unt dW, unt dH, unt chan, char *path) { ush sbuf[1024]; ppu srcp; int j,q; IMAGE *sgim = iopen(path,"w",RLE(1),3,dW,dH,chan); if (!sgim) { warn("rowWritSgiU: iopen failed"); return -1; } for (q = 0; q < chan; q++) { for (srcp = &srcU[q][dY], j = 0; j < dH; j++) { ushUnc(sbuf,*srcp++ + dX,dW); putrow(sgim, sbuf,j,q); } } return iclose(sgim); /* 0:success, -1:stdlib close err (check errno), EOF:sgi err */ }
void rowGraySGI (ppu src, int sX, int sY, unt sW, unt sH, char *path) { IMAGE *image; int k; unsigned short *rowp, *row; puc ucp; mallocAss(row,unsigned short,sW); if (! (image = iopen(path,"w",RLE(1),2,sW,sH))) die("rowGraySGI: iopen(%s)", path); for (src += sY; sH; ) { for (rowp = row, ucp = *src++ + sX, k = 0; k < sW; k++) *rowp++ = *ucp++; putrow(image,row,--sH,0); } iclose(image); free(row); }
static void matrix(void) { int count; /* pattern repeats this many times */ long total; /* expect this many patterns */ /* * * Reads a matrix from *fp_in, translates it into a PostScript gray scale image, * and writes the result on stdout. For now only one matrix is allowed per input * file. Matrix elements are floating point numbers arranged in row major order * in the input file. In addition each input file may contain an optional header * that defines special things like the dimension of the matrix, a window into * the matrix that will be displayed, and an interval list. * * If we're reading from stdin we first make a copy in a temporary file so we can * can properly position ourselves after we've looked for the header. Originally * wasn't always making a copy of stdin, but I've added a few things to what's * accepted in the header and this simplifies the job. An alternative would be * to always require a header and mark the end of it by some string. Didn't like * that approach much - may fix things up later. * */ if ( fp_in == stdin ) /* make a copy so we can seek etc. */ copystdin(); rows = dfltrows; /* new dimensions for the next matrix */ columns = dfltcols; buildilist(interval); /* build the default ilist[] */ addcolormap(colormap); /* add the colormap - if not NULL */ setwindow(window); /* and setup the initial matrix window */ nmstat = dostats; /* want statistics? */ getheader(); /* matrix dimensions at the very least */ dimensions(); /* make sure we have the dimensions etc. */ patcount = 0; total = rows * columns; eptr = rptr + (wlist[2] - wlist[0] + 1); redirect(++page); fprintf(fp_out, "%s %d %d\n", PAGE, page, printed+1); fprintf(fp_out, "save\n"); writerequest(printed+1, fp_out); fprintf(fp_out, "%d %d bitmap\n", wlist[2] - wlist[0] + 1, wlist[3] - wlist[1] + 1); while ( patcount != total && fscanf(fp_in, "%f", &element) != EOF ) { if ( inwindow() ) *rptr++ = mapfloat(element); if ( ++patcount % columns == 0 ) if ( inrange() ) putrow(); } /* End while */ if ( total != patcount ) error(FATAL, "matrix format error"); labelmatrix(); if ( fp_out == stdout ) printed++; fprintf(fp_out, "showpage\n"); fprintf(fp_out, "restore\n"); fprintf(fp_out, "%s %d %d\n", ENDPAGE, page, printed); } /* End of matrix */
static void outmap( fint lpt , /* number of points in X */ fint mpt , /* number of points in Y */ fint lmin , /* lower x map coordinate */ fint mmin , /* lower y map coordinate */ fchar set[] , /* set name */ fint sub[] , /* subset levels */ fint nset , /* number of sets */ fint modo ) /* output mode, amp./pha. or cos./sin. */ { fint i, itab, k, m, md, mi, mj, ms, mph, mphh; fint q, r, ri, rj, rs, row; fint n; fint count[MAXSET], nblank[MAXSET]; float rbuf[2*SIZE], cbuf[2*SIZE]; float datamax[MAXSET], datamin[MAXSET]; float fr, fi, zr, zi; for ( k = 0; k < nset; count[k++] = 0 ); if ( FORM == -1 ) { /* complex ---FFT---> real */ k = 0; /* set number */ rs = MIN( mpt, ( 2 * SIZE ) / lpt ); /* number of rows per pass */ for ( r = 0 ; r < mpt; r += rs ) {/* loop to get data from scratch file */ getrow( rbuf, rs * lpt, r / rs ); md = 0; do { m = shiftr( mmin, mpt, r + md ); ms = MIN( rs - md, mpt + mmin - m ); i = md * lpt; writxy( set[k], sub[k], lmin, m, &rbuf[i], lpt, ms ); md = md + ms; } while ( md != rs ); n = lpt * rs; minmax3_c( rbuf, &n, &datamin[k], &datamax[k], &nblank[k], &count[k] ); } } else if ( FORM == 0 ) { /* real ---FFT---> complex */ q = POWTAB[ MAXP2 - LOGP2Y - 1 ]; /* table offset factor */ mph = mpt / 2; /* y-dimension of transform */ mphh = mph / 2 + 1; getrow( cbuf, 2 * lpt, 0 ); /* create row MPH */ putrow( cbuf, 2 * lpt, mph ); fr = 0.5 * SIGN; fi = 0.5; for ( ri = 0; ri < mphh; ri++ ) { rj = mph - ri; itab = ri * q; /* calculate table position */ zr = 0.5 - fr * SINTAB[itab]; zi = fi * COSTAB[itab]; getrow( cbuf, 2 * lpt, ri ); getrow( rbuf, 2 * lpt, rj ); fxrl( zr, zi, cbuf, rbuf, ri, rj, lpt ); /* fixup real ---> complex */ fftx( cbuf ); /* do the FFT in x-direction */ vector( cbuf, lpt, 1, modo ); mi = shiftr( mmin, mpt, ri ); for ( k = 0; k < nset; k++ ) { i = k * lpt; writxy( set[k], sub[k], lmin, mi, &cbuf[i], lpt , 1 ); minmax3_c( &cbuf[i], &lpt, &datamin[k], &datamax[k], &nblank[k], &count[k] ); } if ( ri > 0 ) { /* do not double lines */ mirror( cbuf, lpt, -lmin ); mi = shiftr( mmin, mpt, mpt - ri ); for ( k = 0; k < nset; k++ ) { i = k * lpt; writxy( set[k], sub[k], lmin, mi, &cbuf[i], lpt, 1 ); minmax3_c( &cbuf[i], &lpt, &datamin[k], &datamax[k], &nblank[k], &count[k] ); } } if ( ri == rj ) break; /* we've done it */ fftx( rbuf ); /* do the FFT in x-direction */ vector( rbuf, lpt, 1, modo ); mj = shiftr( mmin, mpt, rj ); for ( k = 0; k < nset; k++ ) { i = k * lpt; writxy( set[k], sub[k], lmin, mj, &rbuf[i], lpt, 1 ); minmax3_c( &rbuf[i], &lpt, &datamin[k], &datamax[k], &nblank[k], &count[k] ); } if ( rj < mph ) { /* do not double lines */ mirror( rbuf, lpt, -lmin ); mj = shiftr( mmin, mpt, mpt - rj ); for ( k = 0; k < nset; k++ ) { i = k * lpt; writxy( set[k], sub[k], lmin, mj, &rbuf[i], lpt, 1 ); minmax3_c( &rbuf[i], &lpt, &datamin[k], &datamax[k], &nblank[k], &count[k] ); } } } } else if ( FORM == 1 ) { /* complex ---FFT---> complex */ for ( row = 0; row < mpt; row++ ) { getrow( cbuf, 2 * lpt, row ); vector( cbuf, lpt, 1, modo ); m = shiftr( mmin, mpt, row ); for ( k = 0; k < nset; k++ ) { i = k * lpt; writxy( set[k], sub[k], lmin, m, &cbuf[i], lpt, 1 ); minmax3_c( &cbuf[i], &lpt, &datamin[k], &datamax[k], &nblank[k], &count[k] ); } } } { fint change = 1; fint one = 1; for ( k = 0; k < nset; k++ ) { wminmax_c( set[k], &sub[k], &datamin[k], &datamax[k], &nblank[k], &one, &change ); } } }
static void inpmap( fint lpt , /* number of points in X */ fint mpt , /* number of points in Y */ fint lmin , /* left most x map coordinate */ fint mmin , /* lower most y map coordinate */ fchar set[] , /* input set name */ fint sub[] , /* subsets */ fint nset , /* number of sets */ fint modi ) /* input mode, amp./pha. or cos./sin. */ { fint i, itab, k, m, md, mi, mj, mph, mphh, ms; fint q, r, ri, rj, row, rs, wor; float rbuf[2*SIZE], cbuf[2*SIZE]; float fr, fi, zr, zi; if ( FORM == -1 ) { /* complex ---FFT---> real */ q = POWTAB[ MAXP2 - LOGP2Y - 1 ]; /* table offset factor */ mph = mpt / 2; /* number of rows to load */ mphh = mph / 2 + 1; fr = -0.5 * SIGN; /* calculate factors */ fi = -0.5; for ( ri = 0 ; ri < mphh; ri++ ) { /* loop to load data */ rj = mph - ri; itab = ri * q; /* get table position */ zr = 0.5 - fr * SINTAB[itab]; zi = fi * COSTAB[itab]; mi = shiftr( mmin, mpt, ri ); for ( k = 0; k < nset; k++ ) { /* get data */ i= k * lpt; readxy( set[k], sub[k], lmin, mi, &cbuf[i], lpt, 1 ); } mj = shiftr( mmin, mpt, rj ); for ( k = 0; k < nset; k++ ) { /* get data */ i = k * lpt; readxy( set[k], sub[k], lmin, mj, &rbuf[i], lpt, 1 ); } vector( cbuf, lpt, modi, 1 ); vector( rbuf, lpt, modi, 1 ); fftx( cbuf ); /* do the FFT */ fftx( rbuf ); /* fixup for complex to real transform */ fxrl( zr, zi, cbuf, rbuf, ri, rj, lpt ); /* store in scratch file */ wor = bitrev( ri, LOGP2Y ); putrow( cbuf, 2 * lpt, wor ); if ( ( ri != rj ) && ( ri != 0 ) ) { wor = bitrev( rj, LOGP2Y ); putrow( rbuf, 2 * lpt, wor ); } } } else if ( FORM == 0 ) { /* real ---FFT---> complex */ rs = MIN( mpt, ( 2 * SIZE ) / lpt ); /* number of rows in one pass */ k = 0; /* subset number */ for ( r = 0; r < mpt; r += rs ) {/* loop to load data */ md = 0; do { m = shiftr( mmin, mpt, r + md ); ms = MIN( rs - md, mpt + mmin - m ); i = md * lpt; readxy( set[k], sub[k], lmin, m, &cbuf[i], lpt, ms ); md = md + ms; } while ( md != rs ); for ( row = r; row < ( r + rs ); row += 2 ) { i = ( row - r ) * lpt; wor = bitrev( row / 2, LOGP2Y ); putrow( &cbuf[i], 2 * lpt, wor ); } } } else if ( FORM == 1 ) { /* complex ---FFT---> complex */ for ( row = 0; row < mpt; row++ ) { m = shiftr( mmin, mpt, row ); /* get data from disk */ for ( k = 0; k < nset; k++ ) { i = k * lpt; readxy( set[k], sub[k], lmin, m, &cbuf[i], lpt, 1 ); } vector( cbuf, lpt, modi, 1 ); fftx( cbuf ); wor = bitrev( row, LOGP2Y ); putrow( cbuf, 2 * lpt, wor ); } } }