add scale-by-color

This commit is contained in:
David Rose 2012-06-29 13:55:23 +00:00
parent 243339c080
commit 7aa44fe7e3
3 changed files with 55 additions and 14 deletions

View File

@ -1105,3 +1105,16 @@ operator * (double multiplier) const {
target *= multiplier;
return target;
}
////////////////////////////////////////////////////////////////////
// Function: PNMImage::operator *
// Access: Published
// Description: Returns a new PNMImage in which the provided color
// is multiplied to each pixel in the provided image.
////////////////////////////////////////////////////////////////////
INLINE PNMImage PNMImage::
operator * (const LColord &other) const {
PNMImage target (*this);
target *= other;
return target;
}

View File

@ -1595,10 +1595,9 @@ operator ~ () const {
////////////////////////////////////////////////////////////////////
// Function: PNMImage::operator +=
// Access: Published
// Description: Returns a new PNMImage in which each pixel value
// is the sum of the corresponding pixel values
// in the two given images.
// Only valid when both images have the same size.
// Description: Sets each pixel value to the sum of the corresponding
// pixel values in the two given images. Only valid
// when both images have the same size.
////////////////////////////////////////////////////////////////////
void PNMImage::
operator += (const PNMImage &other) {
@ -1629,8 +1628,7 @@ operator += (const PNMImage &other) {
////////////////////////////////////////////////////////////////////
// Function: PNMImage::operator +=
// Access: Published
// Description: Returns a new PNMImage in which the provided color
// is added to each pixel in the provided image.
// Description: Adds the provided color to each pixel in this image.
////////////////////////////////////////////////////////////////////
void PNMImage::
operator += (const LColord &other) {
@ -1664,10 +1662,9 @@ operator += (const LColord &other) {
////////////////////////////////////////////////////////////////////
// Function: PNMImage::operator -=
// Access: Published
// Description: Returns a new PNMImage in which each pixel value
// from the right image is subtracted from each
// pixel value from the left image.
// Only valid when both images have the same size.
// Description: Subtracts each pixel from the right image from each
// pixel value in this image. Only valid when both
// images have the same size.
////////////////////////////////////////////////////////////////////
void PNMImage::
operator -= (const PNMImage &other) {
@ -1698,8 +1695,8 @@ operator -= (const PNMImage &other) {
////////////////////////////////////////////////////////////////////
// Function: PNMImage::operator -=
// Access: Published
// Description: Returns a new PNMImage in which the provided color
// is subtracted from each pixel in the provided image.
// Description: Subtracts the provided color from each pixel in this
// image.
////////////////////////////////////////////////////////////////////
void PNMImage::
operator -= (const LColord &other) {
@ -1709,8 +1706,7 @@ operator -= (const LColord &other) {
////////////////////////////////////////////////////////////////////
// Function: PNMImage::operator *=
// Access: Published
// Description: Returns a new PNMImage in which each pixel value
// from the left image is multiplied by each
// Description: Multiples each pixel in this image by each
// pixel value from the right image. Note that the
// floating-point values in the 0..1 range are
// multiplied, not in the 0..maxval range.
@ -1771,3 +1767,33 @@ operator *= (double multiplier) {
}
}
////////////////////////////////////////////////////////////////////
// Function: PNMImage::operator *=
// Access: Published
// Description: Multiples the provided color to each pixel in this
// image.
////////////////////////////////////////////////////////////////////
void PNMImage::
operator *= (const LColord &other) {
size_t array_size = _x_size * _y_size;
if (_array != NULL && _alpha != NULL) {
for (size_t i = 0; i < array_size; ++i) {
_array[i].r = clamp_val(_array[i].r * other[0]);
_array[i].g = clamp_val(_array[i].g * other[1]);
_array[i].b = clamp_val(_array[i].b * other[2]);
_alpha[i] = clamp_val(_alpha[i] * other[3]);
}
} else if (_array != NULL) {
for (size_t i = 0; i < array_size; ++i) {
_array[i].r = clamp_val(_array[i].r * other[0]);
_array[i].g = clamp_val(_array[i].g * other[1]);
_array[i].b = clamp_val(_array[i].b * other[2]);
}
} else if (_alpha != NULL) {
for (size_t i = 0; i < array_size; ++i) {
_alpha[i] = clamp_val(_alpha[i] * other[3]);
}
}
}

View File

@ -278,12 +278,14 @@ PUBLISHED:
INLINE PNMImage operator - (const LColord &other) const;
INLINE PNMImage operator * (const PNMImage &other) const;
INLINE PNMImage operator * (double multiplier) const;
INLINE PNMImage operator * (const LColord &other) const;
void operator += (const PNMImage &other);
void operator += (const LColord &other);
void operator -= (const PNMImage &other);
void operator -= (const LColord &other);
void operator *= (const PNMImage &other);
void operator *= (double multiplier);
void operator *= (const LColord &other);
private:
xel *_array;