49 lines
1.8 KiB
C++
49 lines
1.8 KiB
C++
#include "graphics/Monochrome.hpp"
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
TEST(basic_test, Monochrome_convertGrayscale_yieldsMonochrome) {
|
|
const std::vector<uint8_t> pixels({0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
|
|
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00});
|
|
|
|
const std::vector<uint8_t> expected({0b10101010, 0b10101010});
|
|
auto mono = ptprnt::graphics::Monochrome(pixels);
|
|
auto out = mono.get();
|
|
|
|
EXPECT_EQ(out, expected);
|
|
}
|
|
|
|
TEST(basic_test, Monochrome_convertInvertedGrayscale_yieldsInvertedMonochrome) {
|
|
const std::vector<uint8_t> pixels({0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
|
|
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00});
|
|
|
|
const std::vector<uint8_t> expected({0b01010101, 0b01010101});
|
|
auto mono = ptprnt::graphics::Monochrome(pixels);
|
|
mono.invert(true);
|
|
auto out = mono.get();
|
|
|
|
EXPECT_EQ(out, expected);
|
|
}
|
|
|
|
TEST(basic_test, Monochrome_convertWithCustomThreshhold_yieldsMonochromeRespectingThreshhold) {
|
|
const std::vector<uint8_t> pixels({0x0F, 0x11, 0x0F, 0x11, 0x0F, 0x11, 0x0F, 0x11, 0x0F, 0x11,
|
|
0x0F, 0x11, 0x0F, 0x11, 0x0F, 0x11});
|
|
|
|
const std::vector<uint8_t> expected({0b01010101, 0b01010101});
|
|
auto mono = ptprnt::graphics::Monochrome(pixels);
|
|
mono.setThreshold(16);
|
|
auto out = mono.get();
|
|
|
|
EXPECT_EQ(out, expected);
|
|
}
|
|
|
|
TEST(basic_test, Monochrome_convertNonAlignedPixels_spillsOverIntoNewByte) {
|
|
const std::vector<uint8_t> pixels({0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
|
|
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF});
|
|
|
|
const std::vector<uint8_t> expected({0b10101010, 0b10101010, 0b10000000});
|
|
auto mono = ptprnt::graphics::Monochrome(pixels);
|
|
auto out = mono.get();
|
|
|
|
EXPECT_EQ(out, expected);
|
|
} |