7 typedef void (*mapfunc_t) (double x_in, double y_in, double *x_out, double *y_out, double *z_out);
8 typedef void (*colorfunc_t) (double x, double y, double z, double *r, double *g, double *b);
10 void color_test(double x, double y, double z, double *r, double *g, double *b)
12 // put in a nice function here
18 void map_back(double x_in, double y_in, double *x_out, double *y_out, double *z_out)
20 *x_out = 2 * x_in - 1;
22 *z_out = 1 - 2 * y_in;
25 void map_right(double x_in, double y_in, double *x_out, double *y_out, double *z_out)
28 *y_out = 1 - 2 * x_in;
29 *z_out = 1 - 2 * y_in;
32 void map_front(double x_in, double y_in, double *x_out, double *y_out, double *z_out)
34 *x_out = 1 - 2 * x_in;
36 *z_out = 1 - 2 * y_in;
39 void map_left(double x_in, double y_in, double *x_out, double *y_out, double *z_out)
42 *y_out = 2 * x_in - 1;
43 *z_out = 1 - 2 * y_in;
46 void map_up(double x_in, double y_in, double *x_out, double *y_out, double *z_out)
48 *x_out = 2 * y_in - 1;
49 *y_out = 1 - 2 * x_in;
53 void map_down(double x_in, double y_in, double *x_out, double *y_out, double *z_out)
55 *x_out = 1 - 2 * y_in;
56 *y_out = 1 - 2 * x_in;
63 void writepic(colorfunc_t f, mapfunc_t m, const char *fn)
68 FILE *file = fopen(fn, "wb");
70 err(1, "fopen %s", fn);
72 memset(tga, 0, sizeof(tga));
73 tga[2] = 2; // uncompressed type
74 tga[12] = (WIDTH >> 0) & 0xFF;
75 tga[13] = (WIDTH >> 8) & 0xFF;
76 tga[14] = (HEIGHT >> 0) & 0xFF;
77 tga[15] = (HEIGHT >> 8) & 0xFF;
78 tga[16] = 24; // pixel size
80 fwrite(&tga, sizeof(tga), 1, file);
81 for(y = HEIGHT-1; y >= 0; --y)
82 for(x = 0; x < WIDTH; ++x)
89 xx = (x + 0.5) / WIDTH;
90 yy = (y + 0.5) / HEIGHT;
91 m(xx, yy, &xxx, &yyy, &zzz);
92 r = sqrt(xxx*xxx + yyy*yyy + zzz*zzz);
96 f(xxx, yyy, zzz, &rr, &gg, &bb);
97 rgb[0] = floor(0.5 + rr * 255);
98 rgb[1] = floor(0.5 + gg * 255);
99 rgb[2] = floor(0.5 + bb * 255);
100 fwrite(rgb, sizeof(rgb), 1, file);
106 void map_all(const char *fn, colorfunc_t f)
109 snprintf(buf, sizeof(buf), "%s_bk.tga", fn); buf[sizeof(buf) - 1] = 0; writepic(f, map_back, buf);
110 snprintf(buf, sizeof(buf), "%s_ft.tga", fn); buf[sizeof(buf) - 1] = 0; writepic(f, map_front, buf);
111 snprintf(buf, sizeof(buf), "%s_rt.tga", fn); buf[sizeof(buf) - 1] = 0; writepic(f, map_right, buf);
112 snprintf(buf, sizeof(buf), "%s_lf.tga", fn); buf[sizeof(buf) - 1] = 0; writepic(f, map_left, buf);
113 snprintf(buf, sizeof(buf), "%s_up.tga", fn); buf[sizeof(buf) - 1] = 0; writepic(f, map_up, buf);
114 snprintf(buf, sizeof(buf), "%s_dn.tga", fn); buf[sizeof(buf) - 1] = 0; writepic(f, map_down, buf);
117 int main(int argc, char **argv)
120 errx(1, "file name argument missing");
121 map_all(argv[1], color_test);