21 #define TACHYON_INTERNAL 1 29 int readjpeg(
const char *name,
int *xres,
int *yres,
unsigned char **imgdata) {
33 int writejpeg(
const char *name,
int xres,
int yres,
unsigned char *imgdata) {
41 int readjpeg(
const char *name,
int *xres,
int *yres,
unsigned char **imgdata) {
43 struct jpeg_decompress_struct cinfo;
44 struct jpeg_error_mgr jerr;
45 JSAMPROW row_pointer[1];
49 if ((ifp = fopen(name,
"rb")) == NULL)
63 cinfo.err = jpeg_std_error(&jerr);
65 jpeg_create_decompress(&cinfo);
66 jpeg_stdio_src(&cinfo, ifp);
67 jpeg_read_header(&cinfo, TRUE);
68 jpeg_start_decompress(&cinfo);
70 *xres = cinfo.output_width;
71 *yres = cinfo.output_height;
74 row_stride = cinfo.output_width * cinfo.output_components;
77 *imgdata = (
unsigned char *) malloc(row_stride * cinfo.output_height);
80 while (cinfo.output_scanline < cinfo.output_height) {
81 row_pointer[0] = &((*imgdata)[(cinfo.output_scanline)*row_stride]);
82 jpeg_read_scanlines(&cinfo, row_pointer, 1);
85 jpeg_finish_decompress(&cinfo);
86 jpeg_destroy_decompress(&cinfo);
94 int writejpeg(
const char *name,
int xres,
int yres,
unsigned char *imgdata) {
96 struct jpeg_compress_struct cinfo;
97 struct jpeg_error_mgr jerr;
98 JSAMPROW row_pointer[1];
101 if ((ofp = fopen(name,
"wb")) == NULL) {
105 cinfo.err = jpeg_std_error(&jerr);
106 jpeg_create_compress(&cinfo);
107 jpeg_stdio_dest(&cinfo, ofp);
109 cinfo.image_width = xres;
110 cinfo.image_height = yres;
111 cinfo.input_components = 3;
112 cinfo.in_color_space = JCS_RGB;
114 jpeg_set_defaults(&cinfo);
115 jpeg_set_quality(&cinfo, 95, 0);
117 jpeg_start_compress(&cinfo, TRUE);
120 row_stride = cinfo.image_width * cinfo.input_components;
123 while (cinfo.next_scanline < cinfo.image_height) {
124 row_pointer[0] = &(imgdata[(yres - cinfo.next_scanline - 1)*row_stride]);
125 jpeg_write_scanlines(&cinfo, row_pointer, 1);
128 jpeg_finish_compress(&cinfo);
129 jpeg_destroy_compress(&cinfo);
#define IMAGEUNSUP
the image file is an unsupported format
int readjpeg(const char *name, int *xres, int *yres, unsigned char **imgdata)
int writejpeg(const char *name, int xres, int yres, unsigned char *imgdata)
Tachyon cross-platform timers, special math function wrappers, and RNGs.
#define IMAGENOERR
no error
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