]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
read color three bytes blocks
authorBastian Dehn <hhaalo@arcor.de>
Sat, 10 Feb 2024 08:00:41 +0000 (09:00 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 10 Feb 2024 08:00:41 +0000 (09:00 +0100)
src/kds_s2000w_net.c

index 53fbd413c41549d1fac287a0712e23817b43cc31..ff781e0ca393a1bdc5b5f9ed4986d2a432341a24 100644 (file)
@@ -31,6 +31,14 @@ int _sane_kds_s2000w_net_find_first_data_byte(const char* data)
        return byte_count;
 }
 
+int _sane_kds_s2000w_net_get_max_length(int max_length) {
+       while (max_length % 3 != 0) {
+               max_length--;
+       }
+
+       return max_length;
+}
+
 SANE_Status _sane_kds_s2000w_net_init(SANE_Int* version_code, SANE_Auth_Callback authorize)
 {
        *version_code = SANE_VERSION_CODE(1, 0, 0);
@@ -249,7 +257,7 @@ SANE_Status _sane_kds_s2000w_net_read(SANE_Handle handle, SANE_Byte* data,
                read_size += skip_header_bytes;
        }
 
-       if (readed_lines >= current_metadata.lines ) {
+       if (readed_lines >= current_metadata.lines) {
                printf("Image is loaded\n");
                read_size = 0;
                *length = 0;
@@ -268,7 +276,6 @@ SANE_Status _sane_kds_s2000w_net_read(SANE_Handle handle, SANE_Byte* data,
                return SANE_STATUS_CANCELLED;
        }
 
-
        int maxlen = 0;
        if (current_metadata.bytes_per_line < max_length) {
                maxlen = current_metadata.bytes_per_line - readed_bytes_per_line;
@@ -276,6 +283,9 @@ SANE_Status _sane_kds_s2000w_net_read(SANE_Handle handle, SANE_Byte* data,
                maxlen = max_length - readed_bytes_per_line;
        }
 
+       if (current_metadata.format == 1)
+               maxlen = _sane_kds_s2000w_net_get_max_length(maxlen);
+
        *length = maxlen;
        memcpy(data, current_metadata.image + skip_header_bytes + read_size, *length);