From: Bastian Dehn Date: Sat, 10 Feb 2024 08:00:41 +0000 (+0100) Subject: read color three bytes blocks X-Git-Tag: v1.0.0^2~314 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=e0596b0af6ff0d75391c4249911cee617931374d;p=sane-kds-s2000w-net.git read color three bytes blocks --- diff --git a/src/kds_s2000w_net.c b/src/kds_s2000w_net.c index 53fbd41..ff781e0 100644 --- a/src/kds_s2000w_net.c +++ b/src/kds_s2000w_net.c @@ -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);