DolphinCColor imps, only Lerp(u32, u32, float) isn't matching

This commit is contained in:
2022-08-13 05:57:38 -07:00
parent e418784c51
commit d36775e76a
5 changed files with 167 additions and 1 deletions

View File

@@ -0,0 +1,13 @@
#ifndef _OSFASTCAST_H_
#define _OSFASTCAST_H_
#ifdef __cplusplus
extern "C" {
#endif
#define OS_FASTCAST_U8 2
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,29 @@
#ifndef __CCAST_HPP__
#define __CCAST_HPP__
#include "types.h"
#include "Dolphin/os/OSFastCast.h"
namespace CCast {
inline u8 ToUint8(register f32 in) {
u8 a;
register u8* ptr = &a;
register u8 r;
asm {
psq_st in, 0(ptr), 1, OS_FASTCAST_U8
lbz r, 0(ptr)
}
return r;
}
inline f32 ToReal32(register const u8& in) {
register f32 r;
asm {
psq_l r, 0(in), 1, 2
}
return r;
}
} // namespace CCast
#endif

View File

@@ -3,12 +3,40 @@
#include "types.h"
#include "Kyoto/Basics/CCast.hpp"
#pragma cpp_extensions on
class CInputStream;
class CColor {
public:
CColor() {}
CColor(u32 col) : mRgba(col) {}
CColor(f32 r, f32 g, f32 b, f32 a = 1.f) : mR(r * 255.f), mG(g * 255.f), mB(b * 255.f), mA(a * 255.f) {}
CColor(CInputStream& in);
CColor(f32 r, f32 g, f32 b, f32 a = 1.f);
CColor(u8 r, u8 g, u8 b, u8 a = 255) {
mR = r;
mG = g;
mB = b;
mA = a;
}
void Set(float r, float g, float b, float a);
void Get(float& r, float& g, float& b, float& a) const;
void Get(float& r, float& g, float& b) const;
static CColor Lerp(const CColor& a, const CColor& b, float t);
static u32 Lerp(u32 a, u32 b, float t);
static CColor Modulate(const CColor& a, const CColor& b);
static CColor Add(const CColor& a, const CColor& b);
f32 GetRed() const { return CCast::ToReal32(mR) * (1/255.f); }
f32 GetGreen() const { return CCast::ToReal32(mG) * (1/255.f); }
f32 GetBlue() const { return CCast::ToReal32(mB) * (1/255.f); }
f32 GetAlpha() const { return CCast::ToReal32(mA) * (1/255.f); }
u8 GetRedu8() const { return mR; }
u8 GetGreenu8() const { return mG; }
u8 GetBlueu8() const { return mB; }
u8 GetAlphau8() const { return mA; }
u16 ToRGB5A3() const;
static const CColor& Black();
static const CColor& White();

View File

@@ -0,0 +1,15 @@
#ifndef _RSTL_MATH_HPP
#define _RSTL_MATH_HPP
namespace rstl {
template <typename T>
inline const T& min_val(const T& a, const T& b) {
return (b < a) ? b : a;
}
template <typename T>
inline const T& max_val(const T& a, const T& b) {
return (a < b) ? b : a;
}
}
#endif // _RSTL_MATH_HPP