From 9ff5277e965228fd90c4a5786073feec458ab27d Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Tue, 7 Oct 2025 18:09:18 +0200 Subject: [PATCH] add tenth inch to pixel --- src/kds_s2000w_pixel_converter.c | 5 +++++ src/kds_s2000w_pixel_converter.h | 1 + tests/kds_s2000w_pixel_converter_tests.c | 13 ++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/kds_s2000w_pixel_converter.c b/src/kds_s2000w_pixel_converter.c index 1cc3c52..e97d5db 100644 --- a/src/kds_s2000w_pixel_converter.c +++ b/src/kds_s2000w_pixel_converter.c @@ -5,4 +5,9 @@ uint32_t kds_s2000w_pixel_converter_pixel_to_tenth_of_inch(uint32_t dpi, uint32_t pixel) { return pixel * TENTH / dpi; +} + +uint32_t kds_s2000w_pixel_converter_tenth_of_inch_to_pixel(uint32_t dpi, uint32_t tenth_inch) +{ + return tenth_inch * dpi / TENTH; } \ No newline at end of file diff --git a/src/kds_s2000w_pixel_converter.h b/src/kds_s2000w_pixel_converter.h index 33e6c04..374f8e3 100644 --- a/src/kds_s2000w_pixel_converter.h +++ b/src/kds_s2000w_pixel_converter.h @@ -3,5 +3,6 @@ #include uint32_t kds_s2000w_pixel_converter_pixel_to_tenth_of_inch(uint32_t dpi, uint32_t pixel); +uint32_t kds_s2000w_pixel_converter_tenth_of_inch_to_pixel(uint32_t dpi, uint32_t tenth_inch); #endif \ No newline at end of file diff --git a/tests/kds_s2000w_pixel_converter_tests.c b/tests/kds_s2000w_pixel_converter_tests.c index 54adc4f..43afee4 100644 --- a/tests/kds_s2000w_pixel_converter_tests.c +++ b/tests/kds_s2000w_pixel_converter_tests.c @@ -15,10 +15,21 @@ void kds_s2000w_max_tl_x_pixel_to_tenth_inch_test() assert_int_equal(tenth_inch, 75); } +void kds_s2000w_max_tl_x_tenth_of_inch_to_pixel_test() +{ + uint32_t dpi = 300; + uint32_t tenth_inch = 75; + + uint32_t pixel = kds_s2000w_pixel_converter_tenth_of_inch_to_pixel(dpi, tenth_inch); + + assert_int_equal(pixel, 2250); +} + int main() { const struct CMUnitTest tests[] = { - cmocka_unit_test(kds_s2000w_max_tl_x_pixel_to_tenth_inch_test) + cmocka_unit_test(kds_s2000w_max_tl_x_pixel_to_tenth_inch_test), + cmocka_unit_test(kds_s2000w_max_tl_x_tenth_of_inch_to_pixel_test) }; return cmocka_run_group_tests(tests, NULL, NULL); -- 2.47.3