Add class for converting Bitmaps to monochrome bytes representation
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
tests = [['bitmap_test', 'bitmap_test_exe', ['bitmap_test/bitmap_test.cpp']],
|
||||
['image_test', 'image_test_exe', ['image_test/image_test.cpp']]
|
||||
['image_test', 'image_test_exe', ['image_test/image_test.cpp']],
|
||||
['monochrome_test', 'monochrome_test_exe', ['monochrome_test/monochrome_test.cpp']]
|
||||
]
|
||||
|
||||
foreach test : tests
|
||||
|
49
tests/monochrome_test/monochrome_test.cpp
Normal file
49
tests/monochrome_test/monochrome_test.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#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);
|
||||
}
|
Reference in New Issue
Block a user