ona/source/coral/image.cpp

59 lines
1.0 KiB
C++
Raw Normal View History

2023-02-19 17:50:29 +01:00
export module coral.image;
2023-02-18 04:34:40 +01:00
2023-02-19 17:50:29 +01:00
import coral;
2023-02-18 04:34:40 +01:00
2023-02-19 17:50:29 +01:00
export namespace coral {
2023-02-18 20:40:12 +01:00
/**
* All-purpose color value for red, green, blue, alpha channel-encoded values.
*/
2023-02-18 04:34:40 +01:00
struct color {
2023-02-18 20:40:12 +01:00
/**
* Red channel.
*/
2023-02-18 04:34:40 +01:00
float r;
2023-02-18 20:40:12 +01:00
/**
* Green channel.
*/
2023-02-18 04:34:40 +01:00
float g;
2023-02-18 20:40:12 +01:00
/**
* Blue channel.
*/
2023-02-18 04:34:40 +01:00
float b;
2023-02-18 20:40:12 +01:00
/**
* Alpha channel.
*/
2023-02-18 04:34:40 +01:00
float a;
2023-02-18 20:40:12 +01:00
/**
* Red channel represented in an 8-bit unsigned value.
*/
2023-02-18 04:34:40 +01:00
u8 to_r8() const {
return static_cast<u8>(round32(clamp(this->r, 0.0f, 1.0f) * u8_max));
}
2023-02-18 20:40:12 +01:00
/**
* Green channel represented in an 8-bit unsigned value.
*/
2023-02-18 04:34:40 +01:00
u8 to_g8() const {
return static_cast<u8>(round32(clamp(this->g, 0.0f, 1.0f) * u8_max));
}
2023-02-18 20:40:12 +01:00
/**
* Blue channel represented in an 8-bit unsigned value.
*/
2023-02-18 04:34:40 +01:00
u8 to_b8() const {
return static_cast<u8>(round32(clamp(this->b, 0.0f, 1.0f) * u8_max));
}
2023-02-18 20:40:12 +01:00
/**
* Alpha channel represented in an 8-bit unsigned value.
*/
2023-02-18 04:34:40 +01:00
u8 to_a8() const {
return static_cast<u8>(round32(clamp(this->a, 0.0f, 1.0f) * u8_max));
}
};
}