Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorenricoturri1966 <enricoturri@seznam.cz>2020-08-28 13:30:45 +0300
committerenricoturri1966 <enricoturri@seznam.cz>2020-08-28 13:30:45 +0300
commitb563010bf10ad26d34f31d6c9830baf8a8b7ab43 (patch)
treeb5c5ee38474468d9b457c857baacda6575326e15 /tests
parent1c2ef87cfa088adc37119118f9014d6174bc355f (diff)
parent143e3a6a3588fe467e3cb3940cf78df30af56f96 (diff)
Merge branch 'master' of https://github.com/prusa3d/PrusaSlicer into et_gcode_viewer
Diffstat (limited to 'tests')
-rw-r--r--tests/libslic3r/CMakeLists.txt2
-rw-r--r--tests/libslic3r/test_png_io.cpp55
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/libslic3r/CMakeLists.txt b/tests/libslic3r/CMakeLists.txt
index 5a1e8f18b..30b93eafc 100644
--- a/tests/libslic3r/CMakeLists.txt
+++ b/tests/libslic3r/CMakeLists.txt
@@ -17,6 +17,8 @@ add_executable(${_TEST_NAME}_tests
test_marchingsquares.cpp
test_timeutils.cpp
test_voronoi.cpp
+ test_png_io.cpp
+ test_timeutils.cpp
)
if (TARGET OpenVDB::openvdb)
diff --git a/tests/libslic3r/test_png_io.cpp b/tests/libslic3r/test_png_io.cpp
new file mode 100644
index 000000000..51f94be32
--- /dev/null
+++ b/tests/libslic3r/test_png_io.cpp
@@ -0,0 +1,55 @@
+#define NOMINMAX
+#include <catch2/catch.hpp>
+
+#include <numeric>
+
+#include "libslic3r/PNGRead.hpp"
+#include "libslic3r/SLA/AGGRaster.hpp"
+#include "libslic3r/BoundingBox.hpp"
+
+using namespace Slic3r;
+
+static sla::RasterGrayscaleAA create_raster(const sla::RasterBase::Resolution &res)
+{
+ sla::RasterBase::PixelDim pixdim{1., 1.};
+
+ auto bb = BoundingBox({0, 0}, {scaled(1.), scaled(1.)});
+ sla::RasterBase::Trafo trafo;
+ trafo.center_x = bb.center().x();
+ trafo.center_y = bb.center().y();
+
+ return sla::RasterGrayscaleAA{res, pixdim, trafo, agg::gamma_threshold(.5)};
+}
+
+TEST_CASE("PNG read", "[PNG]") {
+ auto rst = create_raster({100, 100});
+
+ size_t rstsum = 0;
+ for (size_t r = 0; r < rst.resolution().height_px; ++r)
+ for (size_t c = 0; c < rst.resolution().width_px; ++c)
+ rstsum += rst.read_pixel(c, r);
+
+ SECTION("Correct png buffer should be recognized as such.") {
+ auto enc_rst = rst.encode(sla::PNGRasterEncoder{});
+ REQUIRE(Slic3r::png::is_png({enc_rst.data(), enc_rst.size()}));
+ }
+
+ SECTION("Fake png buffer should be recognized as such.") {
+ std::vector<uint8_t> fake(10, '\0');
+ REQUIRE(!Slic3r::png::is_png({fake.data(), fake.size()}));
+ }
+
+ SECTION("Decoded PNG buffer resolution should match the original") {
+ auto enc_rst = rst.encode(sla::PNGRasterEncoder{});
+
+ png::ImageGreyscale img;
+ png::decode_png({enc_rst.data(), enc_rst.size()}, img);
+
+ REQUIRE(img.rows == rst.resolution().height_px);
+ REQUIRE(img.cols == rst.resolution().width_px);
+
+ size_t sum = std::accumulate(img.buf.begin(), img.buf.end(), size_t(0));
+
+ REQUIRE(sum == rstsum);
+ }
+}