]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change image data to jpg and pnm in handler
authorBastian Dehn <hhaalo@arcor.de>
Sun, 10 Mar 2024 15:02:31 +0000 (16:02 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 10 Mar 2024 15:02:31 +0000 (16:02 +0100)
src/kds_s2000w_handler.c
src/kds_s2000w_handler.h

index 866f335c3860470c2ae3316b1bc1a49903f3b899..577cfb1e2724dd7b99f84013237fb353d44c18b4 100644 (file)
@@ -11,7 +11,6 @@
 
 json_object* resp_config = NULL;
 json_object* config = NULL;
-blobdata image;
 
 void _get_current_metadata(handler* h)
 {
@@ -19,6 +18,7 @@ void _get_current_metadata(handler* h)
        json_object* metadataResp = NULL;
        json_object* metadata = NULL;
        json_object* mdata_value = NULL;
+       blobdata* jpg_image = NULL;
        blobdata* pnm_image = NULL;
        response* resp = NULL;
 
@@ -42,7 +42,7 @@ void _get_current_metadata(handler* h)
        mdata_value = NULL;
 
        mdata_value = json_object_object_get(metadata, "ImageSize");
-       h->pnm_image->size = json_object_get_int(mdata_value); // TODO
+       h->jpg_image->size = json_object_get_int(mdata_value);
        mdata_value = NULL;
 
        mdata_value = json_object_object_get(metadata, "ImageWidth");
@@ -71,13 +71,13 @@ void _get_current_metadata(handler* h)
        if (h->current_metadata->format == 1)
                h->current_metadata->channels = 3;
 
+       jpg_image = (blobdata*) h->jpg_image;
+       pnm_image = (blobdata*) h->pnm_image;
        if (h->current_metadata->depth > 8) {
                h->current_metadata->depth = 8;
-               pnm_image = (blobdata*) h->pnm_image;
-               kds_s2000w_convert_jpg_to_pnm_with_depth(&image, pnm_image, h->current_metadata->depth);
+               kds_s2000w_convert_jpg_to_pnm_with_depth(jpg_image, pnm_image, h->current_metadata->depth);
        } else {
-               pnm_image = (blobdata*) h->pnm_image;
-               kds_s2000w_convert_jpg_to_pnm(&image, pnm_image);
+               kds_s2000w_convert_jpg_to_pnm(jpg_image, pnm_image);
        }
 
        debug_printf_int(DEBUG, "size of pnm image", h->pnm_image->size);
@@ -116,10 +116,10 @@ void _download_current_image(handler* h)
        debug_printf(ALL, "download_current_image");
        response* resp = NULL;
 
-       if (image.size > 0) {
-               free(image.data);
-               image.data = NULL;
-               image.size = 0;
+       if (h->jpg_image->size > 0) {
+               free(h->jpg_image->data);
+               h->jpg_image->data = NULL;
+               h->jpg_image->size = 0;
        }
 
        resp = kds_s2000w_client_response_init();
@@ -127,9 +127,9 @@ void _download_current_image(handler* h)
        if (resp->code != 200)
                debug_printf_int(ERROR, "download current image response code", resp->code);
 
-       image.size = resp->size;
-       image.data = malloc(sizeof(char) * resp->size);
-       memcpy(image.data, resp->data, resp->size);
+       h->jpg_image->size = resp->size;
+       h->jpg_image->data = malloc(sizeof(char) * resp->size);
+       memcpy(h->jpg_image->data, resp->data, resp->size);
        kds_s2000w_client_response_free(resp);
        resp = NULL;
        h->current_scan_status->downloaded_images++;
@@ -171,6 +171,7 @@ handler* init_handler()
        h->current_scan_status = malloc(sizeof(scanstatus));
        h->current_metadata = malloc(sizeof(metadata));
        h->read_info = malloc(sizeof(readinfo));
+       h->jpg_image = malloc(sizeof(imagedata));
        h->pnm_image = malloc(sizeof(imagedata));
 
        h->sessionid = 0;
@@ -193,6 +194,8 @@ handler* init_handler()
        h->read_info->read_size = 0;
        h->read_info->readed_bytes_per_line = 0;
        h->read_info->readed_lines = 0;
+       h->jpg_image->size = 0;
+       h->jpg_image->data = NULL;
        h->pnm_image->size = 0;
        h->pnm_image->data = NULL;
 
@@ -208,6 +211,10 @@ void free_handler(handler* h)
        h->current_metadata = NULL;
        free(h->read_info);
        h->read_info = NULL;
+       free(h->jpg_image->data);
+       h->jpg_image->data = NULL;
+       free(h->jpg_image);
+       h->jpg_image = NULL;
        free(h->pnm_image->data);
        h->pnm_image->data = NULL;
        free(h->pnm_image);
@@ -293,8 +300,8 @@ void kds_s2000w_handler_open(const char* devicename, void** handle)
        h = init_handler();
        *handle = h;
 
-       image.size = 0;
-       image.data = NULL;
+       h->jpg_image->size = 0;
+       h->jpg_image->data = NULL;
        h->pnm_image->size = 0;
        h->pnm_image->data = NULL;
 
@@ -341,8 +348,6 @@ void kds_s2000w_handler_close(handler* h)
        debug_printf(ALL, "kds_s2000w_handler_close");
        json_object_put(resp_config);
        resp_config = NULL;
-       free(image.data);
-       image.data = NULL;
 
        if (h == NULL)
                return;
index c334fbd6dc1c2f30fa43f6071cda4f6366a48ee8..1fd9ca7846ba15864d04997dec2f5e4754940ee7 100644 (file)
@@ -12,7 +12,7 @@ enum {
 };
 
 typedef struct {
-       int size;
+       size_t size;
        void* data;
 } imagedata;
 
@@ -49,6 +49,7 @@ typedef struct {
        scanstatus* current_scan_status;
        metadata* current_metadata;
        readinfo* read_info;
+       imagedata* jpg_image;
        imagedata* pnm_image;
 } handler;