From 86678c0cfefe45e561f8ef3bbd4465d15a798199 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Tue, 11 Mar 2014 16:40:31 -0400 Subject: [PATCH] Add 4-value pixel constructor --- Base/include/Pixel.h | 7 +++++++ Base/test/TestPixel.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Base/include/Pixel.h b/Base/include/Pixel.h index 2f02b64..92aa414 100644 --- a/Base/include/Pixel.h +++ b/Base/include/Pixel.h @@ -70,6 +70,13 @@ class Pixel : public Vector4 { 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; diff --git a/Base/test/TestPixel.cpp b/Base/test/TestPixel.cpp index fc97dca..770b597 100644 --- a/Base/test/TestPixel.cpp +++ b/Base/test/TestPixel.cpp @@ -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(1 << 16), 6, -2, 5, 4); + EXPECT_EQ(q.R(), 6); + EXPECT_EQ(q.G(), static_cast(-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];