From 7ee50de85404a2310f1fd3fd653b3bafaa4d91af Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Tue, 7 Oct 2025 18:04:30 +0200 Subject: [PATCH] add convert from pixel to tenth inch --- src/CMakeLists.txt | 3 ++- src/kds_s2000w_pixel_converter.c | 8 ++++++++ src/kds_s2000w_pixel_converter.h | 7 +++++++ tests/CMakeLists.txt | 11 ++++++++++- tests/kds_s2000w_pixel_converter_tests.c | 25 ++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/kds_s2000w_pixel_converter.c create mode 100644 src/kds_s2000w_pixel_converter.h create mode 100644 tests/kds_s2000w_pixel_converter_tests.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 305874e..de90320 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 index 0000000..1cc3c52 --- /dev/null +++ b/src/kds_s2000w_pixel_converter.c @@ -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 index 0000000..33e6c04 --- /dev/null +++ b/src/kds_s2000w_pixel_converter.h @@ -0,0 +1,7 @@ +#ifndef KDS_S2000W_PIXEL_CONVERTER_H +#define KDS_S2000W_PIXEL_CONVERTER_H +#include + +uint32_t kds_s2000w_pixel_converter_pixel_to_tenth_of_inch(uint32_t dpi, uint32_t pixel); + +#endif \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a68dbd3..2c9795a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 index 0000000..54adc4f --- /dev/null +++ b/tests/kds_s2000w_pixel_converter_tests.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include +#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 -- 2.47.3