Add get_average_xel, get_average_xel_a, get_average_gray

This commit is contained in:
rdb 2010-05-17 13:11:43 +00:00
parent 76f2f2b0ba
commit a617a5cb97
2 changed files with 76 additions and 0 deletions

View File

@ -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 ~
// Access: Published

View File

@ -236,6 +236,10 @@ PUBLISHED:
unsigned long seed = 0);
void perlin_noise_fill(StackedPerlinNoise2 &perlin);
RGBColord get_average_xel() const;
Colord get_average_xel_a() const;
double get_average_gray() const;
private:
INLINE void allocate_array();
INLINE void allocate_alpha();