Add a make_grayscale function and call it from make_normalmap automatically, removing the need to do it make_grayscale prior to calling make_normalmap.

This commit is contained in:
ehofman
2005-01-14 13:36:38 +00:00
parent cd11a5dc27
commit dfc23c3528
2 changed files with 30 additions and 4 deletions

View File

@@ -795,7 +795,7 @@ SGTexture::ConvertUint(unsigned *array, unsigned int length) {
void
SGTexture::make_monochrome(GLubyte r, GLubyte g, GLubyte b) {
SGTexture::make_monochrome(float contrast, GLubyte r, GLubyte g, GLubyte b) {
if (num_colors >= 3)
return;
@@ -815,8 +815,32 @@ SGTexture::make_monochrome(GLubyte r, GLubyte g, GLubyte b) {
}
}
void
SGTexture::make_normalmap(float brightness) {
SGTexture::make_grayscale(float contrast) {
if (num_colors >= 3)
return;
GLubyte *map = (GLubyte *)malloc (texture_width * texture_height);
for (int y=0; y<texture_height; y++)
for (int x=0; x<texture_width; x++)
{
GLubyte *rgb = get_pixel(x,y);
GLubyte avg = (rgb[0] + rgb[1] + rgb[2]) / 3;
map[x +y*texture_height] = avg;
}
free (texture_data);
texture_data = map;
num_colors = 1;
}
void
SGTexture::make_normalmap(float brightness, float contrast) {
make_grayscale(contrast);
GLubyte *map = (GLubyte *)malloc (texture_width * texture_height * 3);
for (int y=0; y<texture_height; y++)

View File

@@ -140,8 +140,10 @@ public:
inline const char *err_str() { return errstr; }
inline void clear_err_str() { errstr = ""; }
void make_monochrome(GLubyte r=255, GLubyte g=255, GLubyte b=255);
void make_normalmap(float brightness = 1.0);
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);
};
#endif