19 #define TACHYON_INTERNAL 1 32 if (fscanf(dfile,
"%255s", ch) == 1) {
34 fgets(ch,
sizeof(ch), dfile);
37 num=sscanf(ch,
"%d", &i);
42 int readppm(
const char * name,
int * xres,
int * yres,
unsigned char **imgdata) {
45 int i, bytesread, cnt;
53 cnt = fscanf(ifp,
"%255s", data);
55 if (cnt != 1 || strcmp(data,
"P6")) {
65 if (fread(&i, 1, 1, ifp) != 1) {
70 datasize = 3 * (*xres) * (*yres);
72 *imgdata=malloc(datasize);
74 bytesread=fread(*imgdata, 1, datasize, ifp);
78 if (bytesread != datasize)
85 int writeppm(
const char *name,
int xres,
int yres,
unsigned char *imgdata) {
91 ofp=fopen(name,
"wb");
96 fprintf(ofp,
"%d %d\n", xres, yres);
97 fprintf(ofp,
"255\n");
99 for (y=0; y<yres; y++) {
100 if (fwrite(&imgdata[(yres - y - 1)*xbytes], 1, xbytes, ofp) != xbytes) {
111 int writeppm48(
const char *name,
int xres,
int yres,
unsigned char *imgdata) {
117 ofp=fopen(name,
"wb");
121 fprintf(ofp,
"P6\n");
122 fprintf(ofp,
"%d %d\n", xres, yres);
123 fprintf(ofp,
"65535\n");
125 for (y=0; y<yres; y++) {
126 if (fwrite(&imgdata[(yres - y - 1)*xbytes], 1, xbytes, ofp) != xbytes) {
#define IMAGEUNSUP
the image file is an unsupported format
int writeppm(const char *name, int xres, int yres, unsigned char *imgdata)
Tachyon cross-platform timers, special math function wrappers, and RNGs.
int writeppm48(const char *name, int xres, int yres, unsigned char *imgdata)
static int getint(FILE *dfile)
#define IMAGENOERR
no error
#define IMAGEREADERR
failed read, short reads etc
#define IMAGEWRITEERR
failed write, short writes etc
Tachyon public API function prototypes and declarations used to drive the ray tracing engine...
#define IMAGEBADFILE
can't find or can't open the file
int readppm(const char *name, int *xres, int *yres, unsigned char **imgdata)