]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add convert from pixel to tenth inch
authorBastian Dehn <hhaalo@arcor.de>
Tue, 7 Oct 2025 16:04:30 +0000 (18:04 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Tue, 7 Oct 2025 16:04:30 +0000 (18:04 +0200)
src/CMakeLists.txt
src/kds_s2000w_pixel_converter.c [new file with mode: 0644]
src/kds_s2000w_pixel_converter.h [new file with mode: 0644]
tests/CMakeLists.txt
tests/kds_s2000w_pixel_converter_tests.c [new file with mode: 0644]

index 305874ef6728c8aa0a8299c6d2b2fd40427b7600..de9032059c1cc9073f8bd9fc7419022f236e1470 100644 (file)
@@ -85,7 +85,8 @@ SET(SOURCES
        "kds_s2000w_debug.c"
        "kds_s2000w_config.c"
        "kds_s2000w_heartbeat.c"
-       "kds_s2000w_image_type_check.c")
+       "kds_s2000w_image_type_check.c"
+       "kds_s2000w_pixel_converter.c")
 
 IF(IMAGEMAGICK)
        LIST(APPEND SOURCES "kds_s2000w_image_converter_magick.c")
diff --git a/src/kds_s2000w_pixel_converter.c b/src/kds_s2000w_pixel_converter.c
new file mode 100644 (file)
index 0000000..1cc3c52
--- /dev/null
@@ -0,0 +1,8 @@
+#include "kds_s2000w_pixel_converter.h"
+
+#define TENTH 10
+
+uint32_t kds_s2000w_pixel_converter_pixel_to_tenth_of_inch(uint32_t dpi, uint32_t pixel)
+{
+       return pixel * TENTH / dpi;
+}
\ No newline at end of file
diff --git a/src/kds_s2000w_pixel_converter.h b/src/kds_s2000w_pixel_converter.h
new file mode 100644 (file)
index 0000000..33e6c04
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef KDS_S2000W_PIXEL_CONVERTER_H
+#define KDS_S2000W_PIXEL_CONVERTER_H
+#include <stdint.h>
+
+uint32_t kds_s2000w_pixel_converter_pixel_to_tenth_of_inch(uint32_t dpi, uint32_t pixel);
+
+#endif
\ No newline at end of file
index a68dbd3d72c8a2d10e7ff0b920b17bdf5f1e52d8..2c9795ae741a57c086868a64e42739ba7f90e3bf 100644 (file)
@@ -59,6 +59,13 @@ TARGET_LINK_LIBRARIES("kds_s2000w_image_type_check_tests"
        ${CMOCKA_LIBRARY}
        sane-kds_s2000w_net-static)
 
+ADD_EXECUTABLE("kds_s2000w_pixel_converter_tests"
+       "kds_s2000w_pixel_converter_tests.c")
+ADD_DEPENDENCIES("kds_s2000w_pixel_converter_tests" sane-kds_s2000w_net-static)
+TARGET_LINK_LIBRARIES("kds_s2000w_pixel_converter_tests"
+       ${CMOCKA_LIBRARY}
+       sane-kds_s2000w_net-static)
+
 ADD_CUSTOM_TARGET("runningtests"
        ALL ./kds_s2000w_read_config_tests
        COMMAND ./kds_s2000w_option_descriptor_tests
@@ -67,6 +74,7 @@ ADD_CUSTOM_TARGET("runningtests"
        COMMAND ./kds_s2000w_net_read_tests
        COMMAND ./kds_s2000w_image_type_check_tests
        COMMAND ./kds_s2000w_image_converter_tests
+       COMMAND ./kds_s2000w_pixel_converter_tests
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        DEPENDS "kds_s2000w_read_config_tests"
        "kds_s2000w_option_descriptor_tests"
@@ -74,7 +82,8 @@ ADD_CUSTOM_TARGET("runningtests"
        "kds_s2000w_net_tests"
        "kds_s2000w_net_read_tests"
        "kds_s2000w_image_type_check_tests"
-       "kds_s2000w_image_converter_tests")
+       "kds_s2000w_image_converter_tests"
+       "kds_s2000w_pixel_converter_tests")
 
 ADD_CUSTOM_TARGET("generate_gcov_coverage"
        ALL gcov ${CMAKE_BINARY_DIR}/src/CMakeFiles/sane-kds_s2000w_net-static.dir/*.c.o
diff --git a/tests/kds_s2000w_pixel_converter_tests.c b/tests/kds_s2000w_pixel_converter_tests.c
new file mode 100644 (file)
index 0000000..54adc4f
--- /dev/null
@@ -0,0 +1,25 @@
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "../src/kds_s2000w_pixel_converter.h"
+
+void kds_s2000w_max_tl_x_pixel_to_tenth_inch_test()
+{
+       uint32_t dpi = 300;
+       uint32_t pixel = 2250;
+
+       uint32_t tenth_inch = kds_s2000w_pixel_converter_pixel_to_tenth_of_inch(dpi, pixel);
+
+       assert_int_equal(tenth_inch, 75);
+}
+
+int main()
+{
+       const struct CMUnitTest tests[] = {
+               cmocka_unit_test(kds_s2000w_max_tl_x_pixel_to_tenth_inch_test)
+       };
+
+       return cmocka_run_group_tests(tests, NULL, NULL);
+}
\ No newline at end of file