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:
@@ -795,7 +795,7 @@ SGTexture::ConvertUint(unsigned *array, unsigned int length) {
|
|||||||
|
|
||||||
|
|
||||||
void
|
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)
|
if (num_colors >= 3)
|
||||||
return;
|
return;
|
||||||
@@ -815,8 +815,32 @@ SGTexture::make_monochrome(GLubyte r, GLubyte g, GLubyte b) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
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);
|
GLubyte *map = (GLubyte *)malloc (texture_width * texture_height * 3);
|
||||||
|
|
||||||
for (int y=0; y<texture_height; y++)
|
for (int y=0; y<texture_height; y++)
|
||||||
|
|||||||
@@ -140,8 +140,10 @@ public:
|
|||||||
inline const char *err_str() { return errstr; }
|
inline const char *err_str() { return errstr; }
|
||||||
inline void clear_err_str() { errstr = ""; }
|
inline void clear_err_str() { errstr = ""; }
|
||||||
|
|
||||||
void make_monochrome(GLubyte r=255, GLubyte g=255, GLubyte b=255);
|
void make_grayscale(float contrast = 1.0);
|
||||||
void make_normalmap(float brightness = 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
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user