From: ehofman Date: Sat, 15 Jan 2005 10:48:40 +0000 (+0000) Subject: Add a make_bumpmap and a make_maxcolorwindow function, modify the make_normalmap... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a26271e46e2d87f49c57f9e08509b87185cb4179;p=simgear.git Add a make_bumpmap and a make_maxcolorwindow function, modify the make_normalmap function to maximize the color window before proceding. --- diff --git a/simgear/screen/texture.cxx b/simgear/screen/texture.cxx index cc27c83f..892e6bdb 100644 --- a/simgear/screen/texture.cxx +++ b/simgear/screen/texture.cxx @@ -826,7 +826,8 @@ SGTexture::make_grayscale(float contrast) { if (num_colors < 3) return; - GLubyte *map = (GLubyte *)malloc (texture_width * texture_height); + int colors = (num_colors == 3) ? 1 : 2; + GLubyte *map = (GLubyte *)malloc (texture_width * texture_height * colors); for (int y=0; y 1) + map[pos+1] = rgb[3]; } free (texture_data); texture_data = map; - num_colors = 1; + num_colors = colors; +} + + +void +SGTexture::make_maxcolorwindow() { + GLubyte minmaxc[2] = {255, 0}; + + unsigned int pos = 0; + unsigned int max = num_colors; + if (num_colors == 2) max = 1; + if (num_colors == 4) max = 3; + while (pos < texture_width * texture_height * num_colors) { + for (int i=0; i < max; i++) { + GLubyte c = texture_data[pos+i]; + if (c < minmaxc[0]) minmaxc[0] = c; + if (c > minmaxc[1]) minmaxc[1] = c; + } + pos += num_colors; + } + + GLubyte offs = minmaxc[0]; + float factor = 255.0 / float(minmaxc[1] - minmaxc[0]); + // printf("Min: %i, Max: %i, Factor: %f\n", offs, minmaxc[1], factor); + + pos = 0; + while (pos < texture_width * texture_height * num_colors) { + for (int i=0; i < max; i++) { + texture_data[pos+i] -= offs; + texture_data[pos+i] *= factor; + } + pos += num_colors; + } } void SGTexture::make_normalmap(float brightness, float contrast) { make_grayscale(contrast); + make_maxcolorwindow(); + + int colors = (num_colors == 1) ? 3 : 4; + bool alpha = (colors > 3); + int tsize = texture_width * texture_height * colors; + GLubyte *map = (GLubyte *)malloc (tsize); + + int mpos = 0, dpos = 0; + for (int y=0; y 1) + map[mpos+1] = texture_data[dpos+1]; } free (texture_data); texture_data = map; - num_colors = 3; + num_colors = colors; } + diff --git a/simgear/screen/texture.hxx b/simgear/screen/texture.hxx index bfcb0781..00265336 100644 --- a/simgear/screen/texture.hxx +++ b/simgear/screen/texture.hxx @@ -140,10 +140,12 @@ public: inline const char *err_str() { return errstr; } inline void clear_err_str() { errstr = ""; } + void make_maxcolorwindow(); void make_grayscale(float contrast = 1.0); void make_monochrome(float contrast = 1.0, GLubyte r=255, GLubyte g=255, GLubyte b=255); void make_normalmap(float brightness = 1.0, float contrast = 1.0); + void make_bumpmap(float brightness = 1.0, float contrast = 1.0); }; #endif