Add clamping to our pixels

This commit is contained in:
Pavel Krajcevski 2014-03-11 16:48:25 -04:00
parent 86678c0cfe
commit 3dd1444ff6
2 changed files with 17 additions and 0 deletions

View file

@ -163,6 +163,13 @@ class Pixel : public Vector4<uint16> {
// Tests for equality by comparing the values and the bit depths.
bool operator==(const Pixel &) const;
// Clamps the pixel to the range [0,255]
void ClampByte() {
for(uint32 i = 0; i < 4; i++) {
vec[i] = (vec[i] < 0)? 0 : ((vec[i] > 255)? 255 : vec[i]);
}
}
};
REGISTER_VECTOR_TYPE(Pixel);

View file

@ -306,6 +306,16 @@ TEST(Pixel, ScaleColor) {
}
}
TEST(Pixel, ByteClamp) {
FasTC::Pixel p(256, 3, -2, 10);
p.ClampByte();
EXPECT_EQ(p.A(), 255);
EXPECT_EQ(p.R(), 3);
EXPECT_EQ(p.G(), 255);
EXPECT_EQ(p.B(), 10);
}
TEST(YCoCgPixel, Conversion) {
FasTC::Pixel p;