ona/source/coral/image.cpp

59 lines
1.0 KiB
C++

export module coral.image;
import coral;
export namespace coral {
/**
* All-purpose color value for red, green, blue, alpha channel-encoded values.
*/
struct color {
/**
* Red channel.
*/
float r;
/**
* Green channel.
*/
float g;
/**
* Blue channel.
*/
float b;
/**
* Alpha channel.
*/
float a;
/**
* Red channel represented in an 8-bit unsigned value.
*/
u8 to_r8() const {
return static_cast<u8>(round32(clamp(this->r, 0.0f, 1.0f) * u8_max));
}
/**
* Green channel represented in an 8-bit unsigned value.
*/
u8 to_g8() const {
return static_cast<u8>(round32(clamp(this->g, 0.0f, 1.0f) * u8_max));
}
/**
* Blue channel represented in an 8-bit unsigned value.
*/
u8 to_b8() const {
return static_cast<u8>(round32(clamp(this->b, 0.0f, 1.0f) * u8_max));
}
/**
* Alpha channel represented in an 8-bit unsigned value.
*/
u8 to_a8() const {
return static_cast<u8>(round32(clamp(this->a, 0.0f, 1.0f) * u8_max));
}
};
}