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

View File

@ -1,23 +1,11 @@
#include <blah/numerics/color.h>
#include <blah/numerics/vec3.h>
#include <blah/numerics/vec4.h>
using namespace Blah;
char const hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
Vec3 Color::to_vec3() const
{
return Vec3(r / 255.0f, g / 255.0f, b / 255.0f);
}
Vec4 Color::to_vec4() const
{
return Vec4(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
}
String Color::to_hex_rgba() const
{
static const char* hex = "0123456789ABCDEF";
String str = "00000000";
str[0] = hex[(r & 0xF0) >> 4];
str[1] = hex[(r & 0x0F) >> 0];
@ -32,6 +20,8 @@ String Color::to_hex_rgba() const
String Color::to_hex_rgb() const
{
static const char* hex = "0123456789ABCDEF";
String str = "000000";
str[0] = hex[(r & 0xF0) >> 4];
str[1] = hex[(r & 0x0F) >> 0];