]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
read last frame faster
authorBastian Dehn <hhaalo@arcor.de>
Sat, 24 Feb 2024 07:29:56 +0000 (08:29 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 24 Feb 2024 07:29:56 +0000 (08:29 +0100)
src/kds_s2000w_net.c

index febce6cca66d0f19b83411168d83c3ef19761818..6a71f8f38feb328a6bec83df41f95834469b2ccb 100644 (file)
@@ -125,6 +125,25 @@ SANE_Status _sane_kds_s2000w_net_get_parameters(SANE_Handle handle,
        if (!h->read_info->scan_started)
                return SANE_STATUS_INVAL;
 
+       metadata mdata;
+       if (h->current_metadata->is_last) {
+               memcpy(&mdata, h->current_metadata, sizeof(metadata));
+
+               params->format = mdata.format;
+               params->last_frame = mdata.is_last;
+               params->bytes_per_line = mdata.bytes_per_line;
+               params->pixels_per_line = mdata.pixels_per_line;
+               params->lines = mdata.lines;
+               params->depth = mdata.depth;
+               h->current_metadata->is_last = 0;
+
+               h->read_info->read_size = 0;
+               h->read_info->readed_bytes_per_line = 0;
+               h->read_info->readed_lines = 0;
+
+               return SANE_STATUS_GOOD;
+       }
+
        for (int i = 0; i < 10; i++) {
                sleep(1);
                kds_s2000w_handler_get_parameters(h);
@@ -135,7 +154,6 @@ SANE_Status _sane_kds_s2000w_net_get_parameters(SANE_Handle handle,
        if (!h->current_metadata->valid)
                return SANE_STATUS_UNSUPPORTED;
 
-       metadata mdata;
        memcpy(&mdata, h->current_metadata, sizeof(metadata));
 
        params->format = mdata.format;
@@ -144,6 +162,7 @@ SANE_Status _sane_kds_s2000w_net_get_parameters(SANE_Handle handle,
        params->pixels_per_line = mdata.pixels_per_line;
        params->lines = mdata.lines;
        params->depth = mdata.depth;
+
        h->read_info->read_size = 0;
        h->read_info->readed_bytes_per_line = 0;
        h->read_info->readed_lines = 0;
@@ -173,6 +192,7 @@ SANE_Status _sane_kds_s2000w_net_read(SANE_Handle handle, SANE_Byte* data,
 {
        debug_printf(ALL, "sane_kds_s2000w_net_read");
        handler* h = (handler*) handle;
+       // cancel
        if (h->read_info->cancel) {
                h->read_info->scan_started = 0;
                *length = 0;
@@ -182,14 +202,9 @@ SANE_Status _sane_kds_s2000w_net_read(SANE_Handle handle, SANE_Byte* data,
                sleep(1);
                kds_s2000w_handler_open("kds_s2000w_net", handle);
                return SANE_STATUS_CANCELLED;
-       }       
-
-       if (h->current_metadata->image != NULL) {
-               int skip_header_bytes = _sane_kds_s2000w_net_find_first_data_byte(h->current_metadata->image);
-               if (h->read_info->read_size <= 0)
-                       h->read_info->read_size += skip_header_bytes;
        }
 
+       // last frame
        if (h->read_info->readed_lines >= h->current_metadata->lines) {
                *length = 0;
                h->current_metadata->is_last = 1;
@@ -197,16 +212,25 @@ SANE_Status _sane_kds_s2000w_net_read(SANE_Handle handle, SANE_Byte* data,
                return SANE_STATUS_EOF;
        }
 
+       // calc max length
        int maxlen = max_length;
        if (h->current_metadata->bytes_per_line - h->read_info->readed_bytes_per_line < max_length)
                maxlen = h->current_metadata->bytes_per_line - h->read_info->readed_bytes_per_line;
 
+       // read image
+       if (h->current_metadata->image != NULL) {
+               int skip_header_bytes = _sane_kds_s2000w_net_find_first_data_byte(h->current_metadata->image);
+               if (h->read_info->read_size <= 0)
+                       h->read_info->read_size += skip_header_bytes;
+       }
+
        *length = maxlen;
        memcpy(data, h->current_metadata->image + h->read_info->read_size, *length);
 
        h->read_info->readed_bytes_per_line += *length;
        h->read_info->read_size += *length;
 
+       // check is all bytes readed in one line
        if (h->read_info->readed_bytes_per_line >= h->current_metadata->bytes_per_line) {
                h->read_info->readed_bytes_per_line = 0;
                h->read_info->readed_lines++;