KJB
|
Wrapped version of the C struct Pixel, with Alpha (opacity). More...
#include <i_pixel.h>
Public Member Functions | |
PixelRGBA () | |
Default ctor, which leaves all fields uninitialized. More... | |
PixelRGBA (const kjb_c::Pixel &p) | |
This builds a valid pixel from another. More... | |
PixelRGBA (float rr, float gg, float bb, float aa=255.0f) | |
This builds a valid pixel with given values for color channels. More... | |
PixelRGBA & | ow_clamp () |
Clamp all channels of the pixel to the range 0..255 inclusive. More... | |
PixelRGBA & | ow_clamp (float minval, float maxval) |
Clamp all channels to a specified range, overwriting. More... | |
PixelRGBA | clamp () const |
Return a new pixel with all channels clamped to range 0..255. More... | |
PixelRGBA | clamp (float minval, float maxval) const |
Return a new pixel with all channels clamped; non-overwriting. More... | |
PixelRGBA & | ow_floor () |
Truncate pixel channel values to integers; overwriting. More... | |
PixelRGBA | floor () const |
Return new pixel with integer channel values. More... | |
PixelRGBA & | operator+= (const kjb_c::Pixel &p) |
Adds another pixel (channel-wise) to this pixel, overwriting. More... | |
PixelRGBA | operator+ (const kjb_c::Pixel &p) const |
This will add corresponding channels, creating a new pixel. More... | |
PixelRGBA & | operator*= (const PixelRGBA &p) |
Overwrite a pixel by multiplying it by p. More... | |
PixelRGBA & | operator*= (float k) |
Overwrite a pixel by scaling its value (r, g, b, and alpha too) More... | |
bool | operator== (const kjb_c::Pixel &p) const |
Test for EXACT pixel equality in all channels. More... | |
bool | operator!= (const kjb_c::Pixel &p) const |
Test for ANY pixel inequality in any channel. More... | |
std::string | as_hex_triplet () const |
express RGB values in an HTML-style string More... | |
Static Public Member Functions | |
static PixelRGBA | create_gray (float f) |
A "named constructor" to build a single opaque grayscale pixel. More... | |
static void | ow_clamp_channel (float *chan) |
Clamp one channel of the Pixel to the range 0..255 inclusive. More... | |
static void | ow_clamp_channel (float *chan, float minval, float maxval) |
Clamp one channel to a specified range. More... | |
Wrapped version of the C struct Pixel, with Alpha (opacity).
This is a struct since there is (currently) no need to make such a simple item have anything private. The advantage of wrapping this at all is that there are commonly-performed operations that are naturally expressed as methods. Namely:
Example: given pixels p, q this yields a Pixel: 0.5*(p.clamp()+q)
This struct assumes the user is not interested in the "Invalid Pixel" structure, and is perhaps (but not necessarily) using alpha (opacity). That's why the name has the RGBA suffix.
Remember that if you add pixels or scale pixels, the alpha channels also add and scale. So for the common case (opaque pixels, and 8-bit channels), the alpha channel is already at 255.0, so you might need to clamp() or to ow_clamp() after an add or scale operation, otherwise alpha could go overrange.
[CODE POLICE] TODO: Rename this class to follow kjb standard for type names (No camelcase Only first letter may be capitalized): Pixel_rgba
|
inline |
Default ctor, which leaves all fields uninitialized.
|
inline |
This builds a valid pixel from another.
Build a pixel from another. It receives a kjb_c::Pixel so as to work with PixelRGBA as well.
|
inline |
This builds a valid pixel with given values for color channels.
Note that despite our massive dynamic range, the default value of aa (the alpha channel) is a mere 255.0f. This is the most common use-case, that of 8 bits of alpha, maximum opacity. However, it is ugly. For high dynamic range images, this is probably not your preferred value for the default opacity.
|
inline |
express RGB values in an HTML-style string
|
inline |
Return a new pixel with all channels clamped to range 0..255.
Observe that this routine does not, however, truncate pixels to integer values. If you need that, use the floor() method.
|
inline |
Return a new pixel with all channels clamped; non-overwriting.
|
inlinestatic |
A "named constructor" to build a single opaque grayscale pixel.
|
inline |
Return new pixel with integer channel values.
|
inline |
Overwrite a pixel by multiplying it by p.
This performs a simple channel-wise product.
|
inline |
Overwrite a pixel by scaling its value (r, g, b, and alpha too)
|
inline |
This will add corresponding channels, creating a new pixel.
|
inline |
Adds another pixel (channel-wise) to this pixel, overwriting.
|
inline |
|
inline |
Clamp all channels of the pixel to the range 0..255 inclusive.
Observe that this routine does not, however, truncate pixels to integer values. If you need that, use the ow_floor() or floor() method. This method has overwriting semantics.
|
inline |
Clamp all channels to a specified range, overwriting.
|
inlinestatic |
Clamp one channel of the Pixel to the range 0..255 inclusive.
Observe that this routine does not, however, truncate pixels to integer values. If you need that, use the ow_floor() or floor() method. The 0..255 range is hardcoded in since it is such a common use case.
|
inlinestatic |
Clamp one channel to a specified range.
|
inline |
Truncate pixel channel values to integers; overwriting.