cleaning up color struct

This commit is contained in:
Noel Berry
2021-05-25 21:31:18 -07:00
parent 6f0ac3e8c2
commit 5ba620c066
3 changed files with 17 additions and 21 deletions

View File

@ -34,8 +34,8 @@ namespace Blah
Image& operator=(Image&& src) noexcept;
~Image();
// disposes the existing image and recreates it from a stream
void from_stream(Stream& stream);
// creates the image from a stream, and returns true if successful
bool from_stream(Stream& stream);
// disposes the image and resets its values to defaults
void dispose();

View File

@ -73,15 +73,15 @@ namespace Blah
while (len < 8 && *(hex_string + len) != '\0')
len++;
if (len >= 8)
a = (BLAH_HEX_VALUE(hex_string[6]) << 4) + BLAH_HEX_VALUE(hex_string[7]);
if (len >= 6)
{
r = (BLAH_HEX_VALUE(hex_string[0]) << 4) + BLAH_HEX_VALUE(hex_string[1]);
g = (BLAH_HEX_VALUE(hex_string[2]) << 4) + BLAH_HEX_VALUE(hex_string[3]);
b = (BLAH_HEX_VALUE(hex_string[4]) << 4) + BLAH_HEX_VALUE(hex_string[5]);
}
if (len >= 8)
a = (BLAH_HEX_VALUE(hex_string[6]) << 4) + BLAH_HEX_VALUE(hex_string[7]);
}
// Premultiplies the Color
@ -99,10 +99,16 @@ namespace Blah
String to_hex_rgb() const;
// Converts the Color to a Vec3 (RGB)
Vec3 to_vec3() const;
constexpr Vec3 to_vec3() const
{
return Vec3(r / 255.0f, g / 255.0f, b / 255.0f);
}
// Converts the Color to a Vec4 (RGBA)
Vec4 to_vec4() const;
constexpr Vec4 to_vec4() const
{
return Vec4(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
}
// Convers the Color to a u32
constexpr u32 to_rgba() const