From: Bastian Dehn Date: Sun, 10 Mar 2024 15:02:31 +0000 (+0100) Subject: change image data to jpg and pnm in handler X-Git-Tag: v1.0.0^2~115 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=ef93572d5228c397ac62aaef83dee13ff0aab1f9;p=sane-kds-s2000w-net.git change image data to jpg and pnm in handler --- diff --git a/src/kds_s2000w_handler.c b/src/kds_s2000w_handler.c index 866f335..577cfb1 100644 --- a/src/kds_s2000w_handler.c +++ b/src/kds_s2000w_handler.c @@ -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; diff --git a/src/kds_s2000w_handler.h b/src/kds_s2000w_handler.h index c334fbd..1fd9ca7 100644 --- a/src/kds_s2000w_handler.h +++ b/src/kds_s2000w_handler.h @@ -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;