]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
round pixel to next step
authorBastian Dehn <hhaalo@arcor.de>
Wed, 8 Oct 2025 10:23:40 +0000 (12:23 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Wed, 8 Oct 2025 10:23:40 +0000 (12:23 +0200)
src/kds_s2000w_pixel_converter.c
tests/kds_s2000w_pixel_converter_tests.c

index 7b5717e4b1f2b4e6cece856d9c4b020cc3177e7d..96e8d259ec97ccce9079a2c84a6614a5a42d5607 100644 (file)
@@ -1,9 +1,21 @@
 #include "kds_s2000w_pixel_converter.h"
 
 #define TENTH 10
+#define ROUND_STEP 30
+
+uint32_t _kds_s2000w_pixel_converter_round_pixel(uint32_t pixel)
+{
+       uint32_t diff = pixel % 30;
+       diff = ROUND_STEP - diff;
+       if (diff < 30)
+               pixel = pixel + diff;
+
+       return pixel;
+}
 
 uint32_t kds_s2000w_pixel_converter_pixel_to_tenth_inch(uint32_t dpi, uint32_t pixel)
 {
+       pixel = _kds_s2000w_pixel_converter_round_pixel(pixel);
        return pixel * TENTH / dpi;
 }
 
index 49c34e0bf666accf1b45c3c59f34a7c99b12a438..5f61d5b532cbe0e9652f87e7f903c5ea817c6566 100644 (file)
@@ -15,6 +15,16 @@ void kds_s2000w_max_tl_x_pixel_to_tenth_inch_test()
        assert_int_equal(tenth_inch, 75);
 }
 
+void kds_s2000w_pixel_odd_to_tenth_inch_test()
+{
+       uint32_t dpi = 300;
+       uint32_t pixel = 2235;
+
+       uint32_t tenth_inch = kds_s2000w_pixel_converter_pixel_to_tenth_inch(dpi, pixel);
+
+       assert_int_equal(tenth_inch, 75);
+}
+
 void kds_s2000w_max_tl_x_tenth_inch_to_pixel_test()
 {
        uint32_t dpi = 300;
@@ -29,6 +39,7 @@ int main()
 {
        const struct CMUnitTest tests[] = {
                cmocka_unit_test(kds_s2000w_max_tl_x_pixel_to_tenth_inch_test),
+               cmocka_unit_test(kds_s2000w_pixel_odd_to_tenth_inch_test),
                cmocka_unit_test(kds_s2000w_max_tl_x_tenth_inch_to_pixel_test)
        };