mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
Merge pull request #33 from eswartz/pr-pnmimage-premultiply
Add PNMImage premultiply/unpremultiply methods.
This commit is contained in:
commit
a73b5b3fd1
@ -622,6 +622,63 @@ make_grayscale(float rc, float gc, float bc) {
|
|||||||
setup_rc();
|
setup_rc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PNMImage::premultiply_alpha
|
||||||
|
// Access: Published
|
||||||
|
// Description: Converts an image in-place to its "premultiplied"
|
||||||
|
// form, where, for every pixel in the image, the
|
||||||
|
// red, green, and blue components are multiplied by
|
||||||
|
// that pixel's alpha value.
|
||||||
|
//
|
||||||
|
// This does not modify any alpha values.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void PNMImage::
|
||||||
|
premultiply_alpha() {
|
||||||
|
if (!has_alpha()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int y = 0; y < get_y_size(); y++) {
|
||||||
|
for (int x = 0; x < get_x_size(); x++) {
|
||||||
|
float alpha = get_alpha(x, y);
|
||||||
|
float r = get_red(x, y) * alpha;
|
||||||
|
float g = get_green(x, y) * alpha;
|
||||||
|
float b = get_blue(x, y) * alpha;
|
||||||
|
set_xel(x, y, r, g, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: PNMImage::unpremultiply_alpha
|
||||||
|
// Access: Published
|
||||||
|
// Description: Converts an image in-place to its "straight alpha"
|
||||||
|
// form (presumably from a "premultiplied" form),
|
||||||
|
// where, for every pixel in the image, the red,
|
||||||
|
// green, and blue components are divided by that
|
||||||
|
// pixel's alpha value.
|
||||||
|
//
|
||||||
|
// This does not modify any alpha values.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void PNMImage::
|
||||||
|
unpremultiply_alpha() {
|
||||||
|
if (!has_alpha()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int y = 0; y < get_y_size(); y++) {
|
||||||
|
for (int x = 0; x < get_x_size(); x++) {
|
||||||
|
float alpha = get_alpha(x, y);
|
||||||
|
if (alpha > 0) {
|
||||||
|
float r = get_red(x, y) / alpha;
|
||||||
|
float g = get_green(x, y) / alpha;
|
||||||
|
float b = get_blue(x, y) / alpha;
|
||||||
|
set_xel(x, y, r, g, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: PNMImage::reverse_rows
|
// Function: PNMImage::reverse_rows
|
||||||
// Access: Published
|
// Access: Published
|
||||||
|
@ -133,6 +133,9 @@ PUBLISHED:
|
|||||||
void make_grayscale(float rc, float gc, float bc);
|
void make_grayscale(float rc, float gc, float bc);
|
||||||
INLINE void make_rgb();
|
INLINE void make_rgb();
|
||||||
|
|
||||||
|
void premultiply_alpha();
|
||||||
|
void unpremultiply_alpha();
|
||||||
|
|
||||||
BLOCKING void reverse_rows();
|
BLOCKING void reverse_rows();
|
||||||
BLOCKING void flip(bool flip_x, bool flip_y, bool transpose);
|
BLOCKING void flip(bool flip_x, bool flip_y, bool transpose);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user