20 #define TACHYON_INTERNAL 1 35 int fakeimage(
char * name,
int * xres,
int * yres,
unsigned char ** imgdata) {
40 sprintf(msgtxt,
"Error loading image %s. Faking it using solid gray.", name);
46 imgsize = 3 * (*xres) * (*yres);
47 *imgdata = malloc(imgsize);
48 for (i=0; i<imgsize; i++) {
59 unsigned char * imgdata;
60 char * name = img->name;
67 if (strstr(name,
".ppm")) {
68 rc =
readppm(name, &xres, &yres, &imgdata);
69 }
else if (strstr(name,
".tga")) {
70 rc =
readtga(name, &xres, &yres, &imgdata);
71 }
else if (strstr(name,
".jpg")) {
72 rc =
readjpeg(name, &xres, &yres, &imgdata);
73 }
else if (strstr(name,
".png")) {
74 rc =
readpng(name, &xres, &yres, &imgdata);
75 }
else if (strstr(name,
".gif")) {
77 }
else if (strstr(name,
".tiff")) {
79 }
else if (strstr(name,
".rgb")) {
81 }
else if (strstr(name,
".xpm")) {
84 rc =
readppm(name, &xres, &yres, &imgdata);
90 sprintf(msgtxt,
"Short read encountered while loading image %s", name);
98 sprintf(msgtxt,
"Cannot read unsupported format for image %s", name);
107 rc =
fakeimage(name, &xres, &yres, &imgdata);
124 float *min,
float *max) {
126 float minval, maxval;
128 minval=maxval=fimg[0];
130 sz = xres * yres * 3;
131 for (i=0; i<sz; i++) {
132 if (fimg[i] > maxval)
134 if (fimg[i] < minval)
148 float min, max, scale;
149 sz = xres * yres * 3;
151 scale = 1.0f / (max-min);
153 fimg[i] = (fimg[i]-min) * scale;
158 float invgamma = 1.0f / gamma;
160 sz = xres * yres * 3;
162 fimg[i] =
POW(fimg[i], invgamma);
169 img = (
unsigned char *) malloc(xres * yres * 3);
171 for (y=0; y<yres; y++) {
172 for (x=0; x<xres; x++) {
173 int addr = (xres * y + x) * 3;
174 R = (int) (fimg[addr ] * 255.0f);
175 G = (int) (fimg[addr + 1] * 255.0f);
176 B = (int) (fimg[addr + 2] * 255.0f);
178 if (R > 255) R = 255;
180 img[addr ] = (byte) R;
182 if (G > 255) G = 255;
184 img[addr + 1] = (byte) G;
186 if (B > 255) B = 255;
188 img[addr + 2] = (byte) B;
197 int szx,
int szy,
int sx,
int sy) {
201 cropped = (
float *) malloc(szx * szy * 3 *
sizeof(
float));
202 memset(cropped, 0, szx * szy * 3 *
sizeof(
float));
204 for (y=0; y<szy; y++) {
205 int oaddr = ((y+sy) * xres + sx) * 3;
206 if ((y+sy >= 0) && (y+sy < yres)) {
207 for (x=0; x<szx; x++) {
208 if ((x+sx >= 0) && (x+sx < xres)) {
209 int addr = (szx * y + x) * 3;
210 cropped[addr ] = fimg[oaddr + (x*3) ];
211 cropped[addr + 1] = fimg[oaddr + (x*3) + 1];
212 cropped[addr + 2] = fimg[oaddr + (x*3) + 2];
223 int szx,
int szy,
int sx,
int sy) {
224 unsigned char *cropped;
227 cropped = (
unsigned char *) malloc(szx * szy * 3 *
sizeof(
unsigned char));
228 memset(cropped, 0, szx * szy * 3 *
sizeof(
unsigned char));
230 for (y=0; y<szy; y++) {
231 int oaddr = ((y+sy) * xres + sx) * 3;
232 if ((y+sy >= 0) && (y+sy < yres)) {
233 for (x=0; x<szx; x++) {
234 if ((x+sx >= 0) && (x+sx < xres)) {
235 int addr = (szx * y + x) * 3;
236 cropped[addr ] = img[oaddr + (x*3) ];
237 cropped[addr + 1] = img[oaddr + (x*3) + 1];
238 cropped[addr + 2] = img[oaddr + (x*3) + 2];
250 unsigned char *img = (
unsigned char *) malloc(xres * yres * 6);
252 for (y=0; y<yres; y++) {
253 for (x=0; x<xres; x++) {
254 int faddr = (xres * y + x) * 3;
255 int iaddr = faddr * 2;
257 R = (int) (fimg[faddr ] * 65535.0f);
258 G = (int) (fimg[faddr + 1] * 65535.0f);
259 B = (int) (fimg[faddr + 2] * 65535.0f);
261 if (R > 65535) R = 65535;
263 img[iaddr ] = (byte) ((R >> 8) & 0xff);
264 img[iaddr + 1] = (byte) (R & 0xff);
266 if (G > 65535) G = 65535;
268 img[iaddr + 2] = (byte) ((G >> 8) & 0xff);
269 img[iaddr + 3] = (byte) (G & 0xff);
271 if (B > 65535) B = 65535;
273 img[iaddr + 4] = (byte) ((B >> 8) & 0xff);
274 img[iaddr + 5] = (byte) (B & 0xff);
283 int x, y, R, G, B, sz;
284 unsigned char *img = (
unsigned char *) malloc(xres * yres * 6);
286 sz = xres * yres * 2;
287 for (y=0; y<yres; y++) {
288 for (x=0; x<xres; x++) {
289 int addr = xres * y + x;
290 int faddr = addr * 3;
291 int iaddr = addr * 2;
293 int gaddr = iaddr + sz;
294 int baddr = iaddr + (sz * 2);
296 R = (int) (fimg[faddr ] * 65535.0f);
297 G = (int) (fimg[faddr + 1] * 65535.0f);
298 B = (int) (fimg[faddr + 2] * 65535.0f);
300 if (R > 65535) R = 65535;
302 img[raddr ] = (byte) ((R >> 8) & 0xff);
303 img[raddr + 1] = (byte) (R & 0xff);
305 if (G > 65535) G = 65535;
307 img[gaddr ] = (byte) ((G >> 8) & 0xff);
308 img[gaddr + 1] = (byte) (G & 0xff);
310 if (B > 65535) B = 65535;
312 img[baddr ] = (byte) ((B >> 8) & 0xff);
313 img[baddr + 1] = (byte) (B & 0xff);
322 int imgbufferformat,
int fileformat) {
326 if (imgbufferformat == RT_IMAGE_BUFFER_RGB24) {
327 unsigned char *imgbuf = (
unsigned char *) img;
329 switch (fileformat) {
331 return writeppm(name, xres, yres, imgbuf);
334 return writergb(name, xres, yres, imgbuf);
337 return writejpeg(name, xres, yres, imgbuf);
340 return writepng(name, xres, yres, imgbuf);
343 return writebmp(name, xres, yres, imgbuf);
346 return writetga(name, xres, yres, imgbuf);
349 printf(
"Unsupported image format combination\n");
353 unsigned char *imgbuf = (
unsigned char *) img;
356 switch (fileformat) {
359 rc =
writeppm(name, xres, yres, imgbuf);
365 rc =
writergb(name, xres, yres, imgbuf);
371 rc =
writejpeg(name, xres, yres, imgbuf);
377 rc =
writepng(name, xres, yres, imgbuf);
383 rc =
writebmp(name, xres, yres, imgbuf);
389 rc =
writetga(name, xres, yres, imgbuf);
406 printf(
"Unsupported image format combination\n");
int readpng(const char *name, int *xres, int *yres, unsigned char **imgdata)
#define RT_FORMAT_PPM
24-bit NetPBM PPM file
#define IMAGEUNSUP
the image file is an unsupported format
int readjpeg(const char *name, int *xres, int *yres, unsigned char **imgdata)
void minmax_rgb96f(int xres, int yres, const float *fimg, float *min, float *max)
int readimage(rawimage *img)
int writepng(const char *name, int xres, int yres, unsigned char *imgdata)
int writepsd48(char *name, int xres, int yres, unsigned char *imgdata)
void rt_ui_message(int level, char *msg)
unsigned char * image_crop_rgb24(int xres, int yres, unsigned char *img, int szx, int szy, int sx, int sy)
#define RT_FORMAT_JPEG
24-bit JPEG file
int writejpeg(const char *name, int xres, int yres, unsigned char *imgdata)
static int fakeimage(char *name, int *xres, int *yres, unsigned char **imgdata)
int writeppm(const char *name, int xres, int yres, unsigned char *imgdata)
int writergb(char *name, int xres, int yres, unsigned char *imgdata)
int writeimage(char *name, int xres, int yres, void *img, int imgbufferformat, int fileformat)
int rt_mynode(void)
distributed memory parallel node rank
#define RT_FORMAT_TARGA
24-bit Targa file
Tachyon cross-platform timers, special math function wrappers, and RNGs.
int writeppm48(const char *name, int xres, int yres, unsigned char *imgdata)
#define RT_FORMAT_SGIRGB
24-bit SGI RGB file
#define RT_FORMAT_WINBMP
24-bit Windows BMP file
int readtga(char *name, int *xres, int *yres, unsigned char **imgdata)
#define IMAGENOERR
no error
#define IMAGEREADERR
failed read, short reads etc
void normalize_rgb96f(int xres, int yres, float *fimg)
unsigned char * image_rgb48bepl_from_rgb96f(int xres, int yres, float *fimg)
#define IMAGENULLDATA
image to write was a null pointer
int writetga(char *name, int xres, int yres, unsigned char *imgdata)
#define RT_FORMAT_PPM48
48-bit NetPBM PPM file
unsigned char * image_rgb24_from_rgb96f(int xres, int yres, float *fimg)
#define RT_FORMAT_PNG
24-bit PNG file
int writebmp(char *filename, int xs, int ys, unsigned char *img)
float * image_crop_rgb96f(int xres, int yres, float *fimg, int szx, int szy, int sx, int sy)
Tachyon public API function prototypes and declarations used to drive the ray tracing engine...
#define RT_FORMAT_PSD48
48-bit Photoshop PSD file
void gamma_rgb96f(int xres, int yres, float *fimg, float gamma)
int readppm(const char *name, int *xres, int *yres, unsigned char **imgdata)
unsigned char * image_rgb48be_from_rgb96f(int xres, int yres, float *fimg)