tom@tnosoes.UUCP (Tom Vijlbrief) (09/16/88)
These are two programs to generate rasterfiles from output generated by the raytracer written by Mark VandeWettering. The first posting contained a bug. (Only for SunOS < 3.5). I also added dithering and a better colormap. #---cut here---cut here---cut here---cut here---cut here--- #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files. # This archive created: Fri Sep 16 09:47:18 MET DST 1988 # Archived by: tnosoes!tom@mcvax.cwi.nl export PATH; PATH=/bin:$PATH echo shar: extracting "'Makefile'" '(277 characters)' if test -f 'Makefile' then echo shar: will not over-write existing file "'Makefile'" else sed 's/^X//' << \SHAR_EOF > 'Makefile' XCFLAGS= -O -s X Xcray2sun: cray2sun.o X cc $(CFLAGS) -o $@ $? X Xgray2sun: gray2sun.o X cc $(CFLAGS) -o $@ $? X X# X#bwray2sun: bwray2sun.o X# cc $(CFLAGS) -o $@ $? X Xclean: X /bin/rm -f *.o ray2sun cray2sun X Xshar: X /bin/rm -f shar.out X shar ray2sun.c Makefile X Xlint: X lint -hap ray2sun.c SHAR_EOF if test 277 -ne "`wc -c < 'Makefile'`" then echo shar: error transmitting "'Makefile'" '(should have been 277 characters)' fi fi # end of overwriting check echo shar: extracting "'README'" '(1046 characters)' if test -f 'README' then echo shar: will not over-write existing file "'README'" else sed 's/^X//' << \SHAR_EOF > 'README' XThese two programs convert output from the raytracer written Xby Mark VanDeWettering to Sun rasterfiles. X Xgray2sun [file] This filter generates a rasterfile with grey scales. X Xcray2sun [-d] [file] This filter generates a color rasterfile. X XThe '-d' option disables dithering. This results in sharper pictures, X(less dithering noise), Xbut also results in hard color boundaries, where the original picture Xhas soft color changes. (Like the 'balls' example). X XCray2sun uses a 6 * 7 * 6 colormap. 6 Intensities for Red, 7 for Green Xand 6 for Blue. X XThe dithering algorithm is simple minded. Errors are propagated to the Xright neighbour pixel. X X X XSend suggestions, bugs, etc, to the address below. X XTom X=============================================================================== XTom Vijlbrief XTNO Institute for Perception XP.O. Box 23 Phone: +31 34 63 62 77 X3769 DE Soesterberg E-mail: tnosoes!tom@mcvax.cwi.nl XThe Netherlands or: uunet!mcvax!tnosoes!tom X=============================================================================== SHAR_EOF if test 1046 -ne "`wc -c < 'README'`" then echo shar: error transmitting "'README'" '(should have been 1046 characters)' fi fi # end of overwriting check echo shar: extracting "'cray2sun.c'" '(2417 characters)' if test -f 'cray2sun.c' then echo shar: will not over-write existing file "'cray2sun.c'" else sed 's/^X//' << \SHAR_EOF > 'cray2sun.c' X/* X * This filter converts ray tracing files to Sun rasterfiles. X * X * Tom Vijlbrief, Sep 1988 (tnosoes!tom@mcvax.cwi.nl or uunet!mcvax!tnosoes!tom) X */ X X#include <stdio.h> X#include <rasterfile.h> X Xstruct rasterfile header; X Xtypedef unsigned char byte; X Xchar *malloc(); XFILE *fopen(); X X#define BUFSIZE 6 X Xchar *malloc(); Xlong random(); X Xbyte colmap[256]; Xbyte buf[BUFSIZE]; X X Xint dflag= 0; X Xmain(argc, argv) X Xint argc; Xchar *argv[]; X{ X FILE *f; X register int i; X register int r=0,g=0,b=0,rnew,gnew,bnew; X int c; X int done; X int x, y; X char *progname= argv[0]; X X for (argc--,argv++; argc > 0 && argv[0][0] == '-'; argv++, argc--) { X switch (argv[0][1]) { X case 'd': dflag= 1; break; X } X } X if (argc == 0) X f= stdin; X else if (argc == 1) { X if ((f= fopen(argv[0], "r")) == NULL) { X perror(argv[0]); X exit(1); X } X } else { X fprintf(stderr, "Usage: %s -d [file]\n", progname); X exit(1); X } X X if (fscanf(f, "%d%d\n", &x, &y) != 2) { X fprintf(stderr, "%s: Ill formatted input file\n", progname); X exit(1); X } X X header.ras_magic= 0x59a66a95; X header.ras_width= x; X header.ras_height= y; X header.ras_depth= 8; X header.ras_length= x * y; X header.ras_type= RT_STANDARD; X header.ras_maptype= RMT_EQUAL_RGB; X header.ras_maplength= 3*256; X X if (fwrite(&header, sizeof(header), 1, stdout) == 0) { X perror(progname); X exit(1); X } X X colmap[255]= 255; X for (i= 0; i < 252; i++) X colmap[i]= (i / 42) * 51; X if (fwrite(colmap, sizeof(colmap), 1, stdout) == 0) { X perror(progname); X exit(1); X } X for (i= 0; i < 252; i++) X colmap[i]= ((i % 42) / 6) * 42; X if (fwrite(colmap, sizeof(colmap), 1, stdout) == 0) { X perror(progname); X exit(1); X } X for (i= 0; i < 252; i++) X colmap[i]= (i % 6) * 51; X if (fwrite(colmap, sizeof(colmap), 1, stdout) == 0) { X perror(progname); X exit(1); X } X X for (i= 0;; i++) { X if (!fread(buf, 3, 1, f)) X break;; X X if (!dflag) { X rnew= (buf[0]+r+25) % 51 - 25; X gnew= (buf[1]+g+21) % 42 - 21; X bnew= (buf[2]+b+25) % 51 - 25; X } X buf[0]= ((buf[0]+r+25) / 51) * 42 + ((buf[1]+g+21) / 42) * 6 + ((buf[2]+b+25) / 51); X if (!dflag) { X if ((i + 1) % y) { X r= rnew; g= gnew; b= bnew; X } else { X r= random() % 51 - 25; X g= random() % 42 - 21; X b= random() % 51 - 25; X } X } X X if (!fwrite(buf, 1, 1, stdout)) { X perror(progname); X exit(1); X } X } X if (i != x * y) { X fprintf(stderr, "%s: Ill formatted input file\n", progname); X exit(1); X } X exit(0); X} SHAR_EOF if test 2417 -ne "`wc -c < 'cray2sun.c'`" then echo shar: error transmitting "'cray2sun.c'" '(should have been 2417 characters)' fi fi # end of overwriting check echo shar: extracting "'gray2sun.c'" '(1588 characters)' if test -f 'gray2sun.c' then echo shar: will not over-write existing file "'gray2sun.c'" else sed 's/^X//' << \SHAR_EOF > 'gray2sun.c' X/* X * This filter converts ray tracing files to Sun rasterfiles. X * X * Tom Vijlbrief, Dec 1987 (tnosoes!tom@mcvax.cwi.nl or uunet!mcvax!tnosoes!tom) X */ X X#include <stdio.h> X#include <rasterfile.h> X Xstruct rasterfile header; X Xtypedef unsigned char byte; X Xchar *malloc(); XFILE *fopen(); X X#define BUFSIZE 3 X Xbyte colmap[256]; Xbyte buf[BUFSIZE]; X X Xmain(argc, argv) X Xint argc; Xchar *argv[]; X{ X FILE *f; X register int i,j; X int x, y; X X if (argc == 1) X f= stdin; X else if (argc == 2) { X if ((f= fopen(argv[1], "r")) == NULL) { X perror(argv[1]); X exit(1); X } X } else { X fprintf(stderr, "Usage: %s [file]\n", argv[0]); X exit(1); X } X X if (fscanf(f, "%d%d\n", &x, &y) != 2) { X fprintf(stderr, "%s: Ill formatted input file\n", argv[0]); X exit(1); X } X header.ras_magic= 0x59a66a95; X header.ras_width= x; X header.ras_height= y; X header.ras_depth= 8; X header.ras_length= x * y; X header.ras_type= RT_STANDARD; X header.ras_maptype= RMT_EQUAL_RGB; X header.ras_maplength= 3*256; X X if (fwrite(&header, sizeof(header), 1, stdout) == 0) { X perror(argv[0]); X exit(1); X } X X for (i= 0; i < 256; i++) X colmap[i]= i; X X if (fwrite(colmap, sizeof(colmap), 1, stdout) == 0 X || fwrite(colmap, sizeof(colmap), 1, stdout) == 0 X || fwrite(colmap, sizeof(colmap), 1, stdout) == 0) { X perror(argv[0]); X exit(1); X } X X for (i= 0;; i++) { X if (!fread(buf, 3, 1, f)) X break; X buf[0]= (buf[0] + buf[1] + buf[2]) / 3; X if (!fwrite(buf, 1, 1, stdout)) { X perror(argv[0]); X exit(1); X } X } X if (i != x * y) { X fprintf(stderr, "%s: Ill formatted input file\n", argv[0]); X exit(1); X } X} SHAR_EOF if test 1588 -ne "`wc -c < 'gray2sun.c'`" then echo shar: error transmitting "'gray2sun.c'" '(should have been 1588 characters)' fi fi # end of overwriting check # End of shell archive exit 0 =============================================================================== Tom Vijlbrief TNO Institute for Perception P.O. Box 23 Phone: +31 34 63 62 77 3769 DE Soesterberg E-mail: tnosoes!tom@mcvax.cwi.nl The Netherlands or: uunet!mcvax!tnosoes!tom ===============================================================================