From 418cd0e9d7f901504e5829d34acdfc9c802f4c7e Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Mon, 30 Dec 2024 16:58:38 +0100 Subject: [PATCH] move find first header bytes into handler --- src/kds_s2000w_handler.c | 30 ++++++++++++++++++++++++++++++ src/kds_s2000w_net.c | 30 ------------------------------ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/kds_s2000w_handler.c b/src/kds_s2000w_handler.c index 3e0db0c..60e4241 100644 --- a/src/kds_s2000w_handler.c +++ b/src/kds_s2000w_handler.c @@ -8,6 +8,32 @@ #include "kds_s2000w_image_converter.h" #include "kds_s2000w_debug.h" +#define SPACE 0x0a + +int _sane_kds_s2000w_net_find_first_data_byte(imagedata* image) +{ + debug_printf(ALL, "sane_kds_s2000w_net_find_first_data_byte"); + + char* data = image->data; + int header_spaces = 3; + + if (strncmp(data, "P4", 2) == 0) + header_spaces = 2; + + int space_count = 0; + int byte_count = 0; + for (byte_count = 0; byte_count < image->size; byte_count++) { + if (data[byte_count] == SPACE) + space_count++; + + if (space_count >= header_spaces) + break; + } + + byte_count++; + return byte_count; +} + handler* init_handler() { debug_printf(ALL, "init handler"); @@ -75,6 +101,8 @@ void kds_s2000w_handler_get_current_metadata(handler* h, metadata* params) { debug_printf(ALL, "get_current_metadata"); + h->read_info->read_size = 0; + params->format = 1; params->last_frame = 1; params->bytes_per_line = 0; @@ -133,6 +161,8 @@ void kds_s2000w_handler_get_current_metadata(handler* h, metadata* params) else params->bytes_per_line = channels * params->pixels_per_line * params->depth / 8; + h->read_info->read_size = _sane_kds_s2000w_net_find_first_data_byte(h->image); + metadata = NULL; free(mdata); mdata = NULL; diff --git a/src/kds_s2000w_net.c b/src/kds_s2000w_net.c index b8a89ac..84d1a8a 100644 --- a/src/kds_s2000w_net.c +++ b/src/kds_s2000w_net.c @@ -9,32 +9,6 @@ #include "kds_s2000w_handler.h" #include "kds_s2000w_debug.h" -#define SPACE 0x0a - -int _sane_kds_s2000w_net_find_first_data_byte(imagedata* image) -{ - debug_printf(ALL, "sane_kds_s2000w_net_find_first_data_byte"); - - char* data = image->data; - int header_spaces = 3; - - if (strncmp(data, "P4", 2) == 0) - header_spaces = 2; - - int space_count = 0; - int byte_count = 0; - for (byte_count = 0; byte_count < image->size; byte_count++) { - if (data[byte_count] == SPACE) - space_count++; - - if (space_count >= header_spaces) - break; - } - - byte_count++; - return byte_count; -} - SANE_Status _sane_kds_s2000w_net_init(SANE_Int* version_code, SANE_Auth_Callback authorize) { debug_printf(ALL, "sane_kds_s2000w_net_init"); @@ -163,10 +137,6 @@ SANE_Status _sane_kds_s2000w_net_get_parameters(SANE_Handle handle, kds_s2000w_handler_get_current_metadata(h, (metadata*) params); - h->read_info->read_size = 0; - if (h->image->data != NULL) - h->read_info->read_size = _sane_kds_s2000w_net_find_first_data_byte(h->image); - return SANE_STATUS_GOOD; } -- 2.39.5