static void Cputprim( /* put out compressed primary from scanline */ COLR *scn, int pri ) { register int c; register int x; int lastc, cnt; lastc = -1; cnt = 0; for (x = 0; x < xmax; x++) { if (pri == GRY) c = normbright(scn[x]) + 2; else c = scn[x][pri] + 2; if (c > 255) c = 255; c = code[c>>2]; if (c == lastc && cnt < MAXRUN) cnt++; else { putrle(cnt, lastc); lastc = c; cnt = 1; } } putrle(cnt, lastc); }
static int getgifpix( /* get a single pixel from our picture */ int x, int y ) { getrow(y); if (greyscale) return((normbright(scanln[x])*ncolors)>>8); if (pixscan != NULL) return(pixscan[x]); return(samplefac ? neu_map_pixel(scanln[x]) : map_pixel(scanln[x])); }
static int cmpcolr( /* compare COLR to luminance */ register COLR c1, double lv2 ) { double lv1 = .0; if (c1[EXP]) lv1 = ldexp((double)normbright(c1), (int)c1[EXP]-(COLXS+8)); if (lv1 < lv2) return(-1); if (lv1 > lv2) return(1); return(0); }
static void ra2ppm( /* convert Radiance picture to 1-byte/sample Pixmap */ int binary, int grey ) { COLR *scanin; register int x; int y; /* allocate scanline */ scanin = (COLR *)malloc(xmax*sizeof(COLR)); if (scanin == NULL) quiterr("out of memory in ra2ppm"); /* convert image */ for (y = ymax-1; y >= 0; y--) { if (freadcolrs(scanin, xmax, stdin) < 0) quiterr("error reading Radiance picture"); if (bradj) shiftcolrs(scanin, xmax, bradj); for (x = grey?xmax:0; x--; ) scanin[x][GRN] = normbright(scanin[x]); colrs_gambs(scanin, xmax); if (grey) if (binary) for (x = 0; x < xmax; x++) putc(scanin[x][GRN], stdout); else for (x = 0; x < xmax; x++) printf("%d\n", scanin[x][GRN]); else if (binary) for (x = 0; x < xmax; x++) { putc(scanin[x][RED], stdout); putc(scanin[x][GRN], stdout); putc(scanin[x][BLU], stdout); } else for (x = 0; x < xmax; x++) printf("%d %d %d\n", scanin[x][RED], scanin[x][GRN], scanin[x][BLU]); if (ferror(stdout)) quiterr("error writing Pixmap"); } /* free scanline */ free((void *)scanin); }
static void Bputprim( /* put out binary primary from scanline */ COLR *scn, int pri ) { register int x, c; for (x = 0; x < xmax; x++) { if (pri == GRY) c = normbright(scn[x]); else c = scn[x][pri]; if (c > 255) c = 255; putchar(c); } }
static void Aputprim( /* put out hex ASCII primary from scanline */ COLR *scn, int pri ) { static char hexdigit[] = "0123456789ABCDEF"; static int col = 0; register int x, c; for (x = 0; x < xmax; x++) { if (pri == GRY) c = normbright(scn[x]); else c = scn[x][pri]; if (c > 255) c = 255; putchar(hexdigit[c>>4]); putchar(hexdigit[c&0xf]); if ((col += 2) >= 72) { putchar('\n'); col = 0; } } }