diff options
Diffstat (limited to '')
-rw-r--r-- | src/others/mimesh/libg3d-0.0.8/tests/test_imgdump.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/others/mimesh/libg3d-0.0.8/tests/test_imgdump.c b/src/others/mimesh/libg3d-0.0.8/tests/test_imgdump.c new file mode 100644 index 0000000..530d20f --- /dev/null +++ b/src/others/mimesh/libg3d-0.0.8/tests/test_imgdump.c | |||
@@ -0,0 +1,72 @@ | |||
1 | /* $Id$ */ | ||
2 | |||
3 | /* | ||
4 | libg3d - 3D object loading library | ||
5 | |||
6 | Copyright (C) 2005-2009 Markus Dahms <mad@automagically.de> | ||
7 | |||
8 | This library is free software; you can redistribute it and/or | ||
9 | modify it under the terms of the GNU Lesser General Public | ||
10 | License as published by the Free Software Foundation; either | ||
11 | version 2.1 of the License, or (at your option) any later version. | ||
12 | |||
13 | This library is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | Lesser General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU Lesser General Public | ||
19 | License along with this library; if not, write to the Free Software | ||
20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | |||
23 | #include <stdio.h> | ||
24 | #include <stdlib.h> | ||
25 | |||
26 | #include <g3d/g3d.h> | ||
27 | #include <g3d/texture.h> | ||
28 | |||
29 | int main(int argc, char *argv[]) | ||
30 | { | ||
31 | G3DContext *context; | ||
32 | G3DImage *tex; | ||
33 | FILE *ppm; | ||
34 | gchar *outfile; | ||
35 | guint32 x, y; | ||
36 | |||
37 | context = g3d_context_new(); | ||
38 | |||
39 | if(argc > 1) { | ||
40 | /* tex = g3d_texture_load(context, argv[1]); */ | ||
41 | tex = NULL; | ||
42 | if(tex != NULL) { | ||
43 | outfile = g_strdup_printf("%s.ppm", argv[1]); | ||
44 | ppm = fopen(outfile, "w"); | ||
45 | if(ppm != NULL) { | ||
46 | fprintf(ppm, "P3\n%u %u\n255\n", | ||
47 | tex->width, tex->height); | ||
48 | for(y = 0; y < tex->height; y ++) { | ||
49 | for(x = 0; x < tex->width; x ++) { | ||
50 | fprintf(ppm, "%u %u %u\n", | ||
51 | tex->pixeldata[(y * tex->width + x) * 4 + 0], | ||
52 | tex->pixeldata[(y * tex->width + x) * 4 + 1], | ||
53 | tex->pixeldata[(y * tex->width + x) * 4 + 2]); | ||
54 | } | ||
55 | } | ||
56 | fclose(ppm); | ||
57 | } else { | ||
58 | fprintf(stderr, "%s: failed to write to '%s'\n", | ||
59 | argv[0], outfile); | ||
60 | } | ||
61 | g3d_texture_free(tex); | ||
62 | g_free(outfile); | ||
63 | } else { | ||
64 | fprintf(stderr, "%s: failed to load image '%s'\n", | ||
65 | argv[0], argv[1]); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | g3d_context_free(context); | ||
70 | |||
71 | return EXIT_SUCCESS; | ||
72 | } | ||