Path: utzoo!attcan!uunet!mcvax!hp4nl!tnosoes!tom From: tom@tnosoes.UUCP (Tom Vijlbrief) Newsgroups: comp.graphics Subject: Re: My Raytracer, Questions Answered, and a Bug fix! Message-ID: <397@tnosoes.UUCP> Date: 7 Sep 88 12:25:32 GMT References: <2683@uoregon.uoregon.edu> Reply-To: tom@sunray.UUCP (Tom Vijlbrief) Organization: TNO Institute for Perception, Soesterberg, The Netherlands Lines: 277 In article <2683@uoregon.uoregon.edu> markv@drizzle.UUCP (Mark VandeWettering) writes: > > My advice: Don't bother hacking pic.c too much. Write a > program to display general raster images of an rgb bitmap to > whatever device you have on hand. Use dithering if you want > black and white. And then POST such programs, so that others > can use/improve them. This is a posting of two programs which convert the output of the raytracing program to Sun rasterfile format. Ray2sun maps to greyscale. Cray2sun maps to color (3 bit red, 3 bit green and 2 bit blue) The program Ray2sun works fine, but Cray2sun should be much smarter to produce better quality pictures. (E.g. use dithering...) Tom =============================================================================== 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 =============================================================================== #---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: Wed Sep 7 13:59:00 MET DST 1988 # Archived by: tnosoes!tom@mcvax.cwi.nl export PATH; PATH=/bin:$PATH echo shar: extracting "'Makefile'" '(195 characters)' if test -f 'Makefile' then echo shar: will not over-write existing file "'Makefile'" else sed 's/^X//' << \SHAR_EOF > 'Makefile' XCFLAGS= -O X Xcray2sun: cray2sun.o X cc -o $@ $? X Xray2sun: ray2sun.o X cc -o $@ $? X Xclean: X /bin/rm ray2sun.o ray2sun X Xshar: X /bin/rm -f shar.out X shar ray2sun.c Makefile X Xlint: X lint -hap ray2sun.c SHAR_EOF if test 195 -ne "`wc -c < 'Makefile'`" then echo shar: error transmitting "'Makefile'" '(should have been 195 characters)' fi fi # end of overwriting check echo shar: extracting "'cray2sun.c'" '(1815 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, Dec 1987 (tnosoes!tom@mcvax.cwi.nl or uunet!mcvax!tnosoes!tom) X */ X X#include X#include 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= 100 * 100; 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 >> 5) * 36; X if (fwrite(colmap, sizeof(colmap), 1, stdout) == 0) { X perror(argv[0]); X exit(1); X } X for (i= 0; i < 256; i++) X colmap[i]= ((i >> 2) & 0x7) * 36; X if (fwrite(colmap, sizeof(colmap), 1, stdout) == 0) { X perror(argv[0]); X exit(1); X } X for (i= 0; i < 256; i++) X colmap[i]= (i & 0x3) * 85; X if (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] & ~0x1F) + ((buf[1] >> 3) & ~0x3) + (buf[2] >> 6); 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 1815 -ne "`wc -c < 'cray2sun.c'`" then echo shar: error transmitting "'cray2sun.c'" '(should have been 1815 characters)' fi fi # end of overwriting check echo shar: extracting "'ray2sun.c'" '(1592 characters)' if test -f 'ray2sun.c' then echo shar: will not over-write existing file "'ray2sun.c'" else sed 's/^X//' << \SHAR_EOF > 'ray2sun.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 X#include 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= 100 * 100; 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 1592 -ne "`wc -c < 'ray2sun.c'`" then echo shar: error transmitting "'ray2sun.c'" '(should have been 1592 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 ===============================================================================