]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
move find first header bytes into handler
authorBastian Dehn <hhaalo@arcor.de>
Mon, 30 Dec 2024 15:58:38 +0000 (16:58 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Mon, 30 Dec 2024 15:58:38 +0000 (16:58 +0100)
src/kds_s2000w_handler.c
src/kds_s2000w_net.c

index 3e0db0ca912cdf05ebd6d18dbf3d68a01abe45c8..60e4241bdf9712f05e6cb60b86e0cf6d7030be1c 100644 (file)
@@ -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;
index b8a89acfc0d1b5f989156acfae9391b51b34edbc..84d1a8abeba664146eb295c31fc8532eec03a195 100644 (file)
@@ -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;
 }