mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 18:31:55 -04:00
add -cscale
This commit is contained in:
parent
60c571f684
commit
0f01f99d2a
@ -41,7 +41,13 @@ ImageTrans() : ImageFilter(true) {
|
||||
"image.",
|
||||
&ImageTrans::dispatch_channels, NULL, &_channels);
|
||||
|
||||
add_option
|
||||
("cscale", "r,g,b[,a]", 50,
|
||||
"Apply the indicated color scale to each pixel of the image.",
|
||||
&ImageTrans::dispatch_color, &_has_color_scale, &_color_scale);
|
||||
|
||||
_channels = C_default;
|
||||
_color_scale.set(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -82,6 +88,30 @@ run() {
|
||||
break;
|
||||
}
|
||||
|
||||
if (_has_color_scale) {
|
||||
if (_color_scale[0] != 1.0f ||
|
||||
_color_scale[1] != 1.0f ||
|
||||
_color_scale[2] != 1.0f) {
|
||||
for (int yi = 0; yi < _image.get_y_size(); ++yi) {
|
||||
for (int xi = 0; xi < _image.get_x_size(); ++xi) {
|
||||
RGBColord rgb = _image.get_xel(xi, yi);
|
||||
_image.set_xel(xi, yi,
|
||||
rgb[0] * _color_scale[0],
|
||||
rgb[1] * _color_scale[1],
|
||||
rgb[2] * _color_scale[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_image.has_alpha() && _color_scale[3] != 1.0f) {
|
||||
for (int yi = 0; yi < _image.get_y_size(); ++yi) {
|
||||
for (int xi = 0; xi < _image.get_x_size(); ++xi) {
|
||||
float a = _image.get_alpha(xi, yi);
|
||||
_image.set_alpha(xi, yi, a * _color_scale[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
write_image();
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,8 @@ private:
|
||||
};
|
||||
|
||||
Channels _channels;
|
||||
Colorf _color_scale;
|
||||
bool _has_color_scale;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user