--- ray/src/px/ra_t8.c 1994/02/27 10:17:23 2.6 +++ ray/src/px/ra_t8.c 2003/06/05 19:29:34 2.12 @@ -1,9 +1,6 @@ -/* Copyright (c) 1992 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: ra_t8.c,v 2.12 2003/06/05 19:29:34 schorsch Exp $"; #endif - /* * ra_t8.c - program to convert between RADIANCE and * Targa 8-bit color-mapped images. @@ -12,24 +9,15 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include +#include +#include +#include "platform.h" #include "color.h" - #include "resolu.h" - #include "targa.h" -#ifdef MSDOS -#include -#endif -#include - -#ifndef BSD -#define bcopy(s,d,n) (void)memcpy(d,s,n) -extern char *memcpy(); -#endif - #define goodpic(h) (my_imType(h) && my_mapType(h)) #define my_imType(h) (((h)->dataType==IM_CMAP || (h)->dataType==IM_CCMAP) \ && (h)->dataBits==8 && (h)->imType==0) @@ -38,8 +26,10 @@ extern char *memcpy(); #define taralloc(h) (BYTE *)emalloc((h)->x*(h)->y) -extern BYTE clrtab[][3]; +BYTE clrtab[256][3]; +extern int samplefac; + extern char *ecalloc(), *emalloc(); extern long ftell(); @@ -69,13 +59,11 @@ char *argv[]; int ncolors = 256; int greyscale = 0; int i; -#ifdef MSDOS - extern int _fmode; - _fmode = O_BINARY; - setmode(fileno(stdin), O_BINARY); - setmode(fileno(stdout), O_BINARY); -#endif + SET_DEFAULT_BINARY(); + SET_FILE_BINARY(stdin); + SET_FILE_BINARY(stdout); progname = argv[0]; + samplefac = 0; for (i = 1; i < argc; i++) if (argv[i][0] == '-') @@ -100,6 +88,9 @@ char *argv[]; case 'c': ncolors = atoi(argv[++i]); break; + case 'n': + samplefac = atoi(argv[++i]); + break; default: goto userr; } @@ -148,7 +139,7 @@ char *argv[]; quiterr(NULL); userr: fprintf(stderr, - "Usage: %s [-d][-c ncolors][-b][-g gamv][-e +/-stops] input [output]\n", + "Usage: %s [-d][-n samp][-c ncolors][-b][-g gamv][-e +/-stops] input [output]\n", progname); fprintf(stderr, " Or: %s -r [-g gamv][-e +/-stops] [input [output]]\n", progname); @@ -189,6 +180,7 @@ char *err; } +void eputs(s) char *s; { @@ -196,6 +188,7 @@ char *s; } +void quit(code) int code; { @@ -338,8 +331,8 @@ struct hdStruct *hp; if (fwritecolrs(scanline, xmax, stdout) < 0) quiterr("error writing RADIANCE file"); } - free((char *)scanline); - free((char *)tarData); + free((void *)scanline); + free((void *)tarData); } @@ -352,28 +345,41 @@ int dith; /* use dithering? */ setcolrgam(gamv); fpos = ftell(stdin); - new_histo(); /* build histogram */ + if ((samplefac ? neu_init(xmax*ymax) : new_histo(xmax*ymax)) == -1) + quiterr("cannot initialized histogram"); for (y = ymax-1; y >= 0; y--) { if (freadcolrs(inl, xmax, stdin) < 0) quiterr("error reading Radiance input"); if (bradj) shiftcolrs(inl, xmax, bradj); colrs_gambs(inl, xmax); - cnt_colrs(inl, xmax); + if (samplefac) + neu_colrs(inl, xmax); + else + cnt_colrs(inl, xmax); } if (fseek(stdin, fpos, 0) == EOF) quiterr("Radiance input must be from a file"); - new_clrtab(nc); /* map colors */ + if (samplefac) /* map colors */ + neu_clrtab(nc); + else + new_clrtab(nc); for (y = ymax-1; y >= 0; y--) { if (freadcolrs(inl, xmax, stdin) < 0) quiterr("error reading Radiance input"); if (bradj) shiftcolrs(inl, xmax, bradj); colrs_gambs(inl, xmax); - if (dith) - dith_colrs(tarData+y*xmax, inl, xmax); + if (samplefac) + if (dith) + neu_dith_colrs(tarData+y*xmax, inl, xmax); + else + neu_map_colrs(tarData+y*xmax, inl, xmax); else - map_colrs(tarData+y*xmax, inl, xmax); + if (dith) + dith_colrs(tarData+y*xmax, inl, xmax); + else + map_colrs(tarData+y*xmax, inl, xmax); } }