2 * Create normal map textures from regular textures.
3 * Created by: Erik Hofman
5 * This file is in public domain.
7 #include <simgear/compiler.h>
13 #include "texture.hxx"
16 static float contrast = 1.0;
17 static float brightness = 1.0;
18 static char *texture_file = NULL, *normalmap_file = NULL;
19 static SGTexture texture;
21 int parse_option(char **args, int n) {
29 if ((arg = strchr(opt, '=')) != NULL)
38 if (!strncmp(opt, "-contrast", sz)) {
42 if (!strncmp(opt, "-brightness", sz)) {
43 brightness = atof(arg);
46 if (!strncmp(opt, "-texture", sz) ||
47 !strncmp(opt, "-input", sz)) {
48 texture_file = strdup(arg);
51 if (!strncmp(opt, "-normalmap", sz) ||
52 !strncmp(opt, "-output", sz)) {
53 normalmap_file = strdup(arg);
56 if (!strncmp(opt, "-help", sz)) {
57 printf("usage:\n normalmap [-c=contrast] [-b=brightness]");
58 printf(" --i=file [--o=file]\n\n");
65 int main (int argc, char **argv)
70 i += parse_option(argv, i);
74 printf("Error: texture file not specified.\n");
75 printf("usage:\n normalmap [-c=contrast] [-b=brightness]");
76 printf(" --i=file [--o=file]\n\n");
80 texture.read_rgb_texture(texture_file);
81 if ( !texture.texture() )
83 printf("Error: unable to process input file: %s\n", texture_file);
84 printf(" (%s)\n\n", texture.err_str());
88 if ( !normalmap_file )
91 for (i=strlen(texture_file); i>=0; --i)
92 if (texture_file[i] == '.')
95 normalmap_file = (char *)malloc( i+8 );
96 memcpy(normalmap_file, texture_file, i);
97 memcpy(normalmap_file+i, "_n.rgb\0", 7);
100 texture.make_normalmap(brightness, contrast);
101 texture.write_texture(normalmap_file);
103 free( normalmap_file );
104 free( texture_file );