mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
Add get_average_xel, get_average_xel_a, get_average_gray
This commit is contained in:
parent
76f2f2b0ba
commit
a617a5cb97
@ -1317,6 +1317,78 @@ setup_rc() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PNMImage::get_average_xel
|
||||||
|
// Access: Published
|
||||||
|
// Description: Returns the average color of all of the pixels
|
||||||
|
// in the image.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
RGBColord PNMImage::
|
||||||
|
get_average_xel() const {
|
||||||
|
RGBColord color (RGBColord::zero());
|
||||||
|
if (_x_size == 0 || _y_size == 0) {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x, y;
|
||||||
|
for (x = 0; x < _x_size; ++x) {
|
||||||
|
for (y = 0; y < _y_size; ++y) {
|
||||||
|
color += get_xel(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
color *= 1.0 / (_x_size * _y_size);
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PNMImage::get_average_xel_a
|
||||||
|
// Access: Published
|
||||||
|
// Description: Returns the average color of all of the pixels
|
||||||
|
// in the image, including the alpha channel.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
Colord PNMImage::
|
||||||
|
get_average_xel_a() const {
|
||||||
|
Colord color (Colord::zero());
|
||||||
|
if (_x_size == 0 || _y_size == 0) {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x, y;
|
||||||
|
for (x = 0; x < _x_size; ++x) {
|
||||||
|
for (y = 0; y < _y_size; ++y) {
|
||||||
|
color += get_xel_a(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
color *= 1.0 / (_x_size * _y_size);
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PNMImage::get_average_gray
|
||||||
|
// Access: Published
|
||||||
|
// Description: Returns the average grayscale component of all of
|
||||||
|
// the pixels in the image.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
double PNMImage::
|
||||||
|
get_average_gray() const {
|
||||||
|
double color = 0.0;
|
||||||
|
if (_x_size == 0 || _y_size == 0) {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
int x, y;
|
||||||
|
for (x = 0; x < _x_size; ++x) {
|
||||||
|
for (y = 0; y < _y_size; ++y) {
|
||||||
|
color += get_gray(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
color *= 1.0 / (_x_size * _y_size);
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: PNMImage::operator ~
|
// Function: PNMImage::operator ~
|
||||||
// Access: Published
|
// Access: Published
|
||||||
|
@ -236,6 +236,10 @@ PUBLISHED:
|
|||||||
unsigned long seed = 0);
|
unsigned long seed = 0);
|
||||||
void perlin_noise_fill(StackedPerlinNoise2 &perlin);
|
void perlin_noise_fill(StackedPerlinNoise2 &perlin);
|
||||||
|
|
||||||
|
RGBColord get_average_xel() const;
|
||||||
|
Colord get_average_xel_a() const;
|
||||||
|
double get_average_gray() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
INLINE void allocate_array();
|
INLINE void allocate_array();
|
||||||
INLINE void allocate_alpha();
|
INLINE void allocate_alpha();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user