Add 4-value pixel constructor

This commit is contained in:
Pavel Krajcevski 2014-03-11 16:40:31 -04:00
parent f0110360c4
commit 86678c0cfe
2 changed files with 34 additions and 0 deletions

View file

@ -70,6 +70,13 @@ class Pixel : public Vector4<uint16> {
m_BitDepth[i] = 8;
}
Pixel(ChannelType a, ChannelType r, ChannelType g, ChannelType b, unsigned bitDepth = 8)
: VectorType(a, r, g, b)
{
for(int i = 0; i < 4; i++)
m_BitDepth[i] = bitDepth;
}
explicit Pixel(uint32 rgba) : VectorType() {
for(int i = 0; i < 4; i++)
m_BitDepth[i] = 8;

View file

@ -68,6 +68,33 @@ TEST(Pixel, DefaultConstructor) {
}
}
TEST(Pixel, FourWideConstructor) {
FasTC::Pixel p(1, 2, 3, 4);
EXPECT_EQ(p.R(), 2);
EXPECT_EQ(p.G(), 3);
EXPECT_EQ(p.B(), 4);
EXPECT_EQ(p.A(), 1);
uint8 depth[4];
p.GetBitDepth(depth);
for(int i = 0; i < 4; i++) {
EXPECT_EQ(depth[i], 8);
}
FasTC::Pixel q(static_cast<uint16>(1 << 16), 6, -2, 5, 4);
EXPECT_EQ(q.R(), 6);
EXPECT_EQ(q.G(), static_cast<uint16>(-2));
EXPECT_EQ(q.B(), 5);
EXPECT_EQ(q.A(), 0);
q.GetBitDepth(depth);
for(int i = 0; i < 4; i++) {
EXPECT_EQ(depth[i], 4);
}
}
TEST(Pixel, FromBitsAndAssociatedConstructor) {
const uint8 bits[8] = { 0xA8, 0xB3, 0x7C, 0x21, 0xBD, 0xD4, 0x09, 0x92 };
FasTC::Pixel ps[2];