json_object* config = json_object_object_get(h->current_scanner_config, "Configuration");
json_object* metadata = json_object_object_get(config, "ColorMode");
const char* color_value = json_object_get_string(metadata);
- blobdata* scanner_image = (blobdata*) h->scanner_image;
- blobdata* pnm_image = (blobdata*) h->pnm_image;
+ blobdata* image = (blobdata*) h->image;
+ blobdata* scanner_image = malloc(sizeof(blobdata));
+ scanner_image->data = malloc(sizeof(char) * image->size);
+ scanner_image->size = image->size;
+ memcpy(scanner_image->data, image->data, image->size);
h->current_metadata->valid = 0;
h->current_metadata->channels = 1;
if (h->current_metadata->depth > 8) {
h->current_metadata->depth = 8;
- kds_s2000w_convert_jpg_to_pnm_with_depth(scanner_image, pnm_image, h->current_metadata->depth);
+ kds_s2000w_convert_jpg_to_pnm_with_depth(scanner_image, image, h->current_metadata->depth);
} else {
- kds_s2000w_convert_tiff_to_pnm(scanner_image, pnm_image);
+ kds_s2000w_convert_tiff_to_pnm(scanner_image, image);
}
#ifndef NODEBUG
- debug_printf_int(DEBUG, "size of pnm image", h->pnm_image->size);
+ debug_printf_int(DEBUG, "size of pnm image", image->size);
#endif
if (h->current_metadata->depth == 1)
metadata = NULL;
free(mdata);
mdata = NULL;
+ free(scanner_image->data);
+ scanner_image->data = NULL;
+ free(scanner_image);
+ scanner_image = NULL;
}
void _delete_current_image(handler* h)
debug_printf(ALL, "download_current_image");
#endif
- if (h->scanner_image->size > 0) {
- free(h->scanner_image->data);
- h->scanner_image->data = NULL;
- h->scanner_image->size = 0;
- }
+ free(h->image->data);
+ h->image->data = NULL;
+ h->image->size = 0;
response* resp = kds_s2000w_client_response_init();
kds_s2000w_client_get_image(h->sessionid, h->current_scan_status->current_image_number, resp);
if (resp->error_size > 0)
fprintf(stderr, "%s\n", resp->error_status);
- h->scanner_image->size = resp->size;
- h->scanner_image->data = malloc(sizeof(char) * resp->size);
- memcpy(h->scanner_image->data, resp->data, resp->size);
+ h->image->size = resp->size;
+ h->image->data = malloc(sizeof(char) * resp->size);
+ memcpy(h->image->data, resp->data, resp->size);
kds_s2000w_client_response_free(resp);
resp = NULL;
h->current_scan_status = malloc(sizeof(scanstatus));
h->current_metadata = malloc(sizeof(metadata));
h->read_info = malloc(sizeof(readinfo));
- h->scanner_image = malloc(sizeof(imagedata));
- h->pnm_image = malloc(sizeof(imagedata));
+ h->image = malloc(sizeof(imagedata));
h->sessionid = 0;
h->state = NOTCONNECTED;
h->read_info->read_size = 0;
h->read_info->readed_bytes_per_line = 0;
h->read_info->readed_lines = 0;
- h->scanner_image->size = 0;
- h->scanner_image->data = NULL;
- h->pnm_image->size = 0;
- h->pnm_image->data = NULL;
+ h->image->size = 0;
+ h->image->data = NULL;
return h;
}
h->current_metadata = NULL;
free(h->read_info);
h->read_info = NULL;
- free(h->scanner_image->data);
- h->scanner_image->data = NULL;
- free(h->scanner_image);
- h->scanner_image = NULL;
- free(h->pnm_image);
- h->pnm_image = NULL;
+ free(h->image->data);
+ h->image->data = NULL;
+ free(h->image);
+ h->image = NULL;
free(h);
h = NULL;
}
debug_printf(ALL, "reset handler");
#endif
- free(h->pnm_image->data);
- h->pnm_image->data = NULL;
- free(h->scanner_image->data);
- h->scanner_image->data = NULL;
+ free(h->image->data);
+ h->image->data = NULL;
h->state = NOTCONNECTED;
h->current_scan_status->load_options = 0;
return;
}
- h->scanner_image->size = 0;
- h->scanner_image->data = NULL;
- h->pnm_image->size = 0;
- h->pnm_image->data = NULL;
+
+ h->image->size = 0;
+ h->image->data = NULL;
h->current_scanner_config = json_tokener_parse(resp->data);
json_object* value_object = NULL;
scanstatus* current_scan_status;
metadata* current_metadata;
readinfo* read_info;
- imagedata* scanner_image;
- imagedata* pnm_image;
+ imagedata* image;
} handler;
handler* init_handler();
break;
}
- if (h->current_metadata->valid == 0 || h->scanner_image->size == 0) {
+ if (h->current_metadata->valid == 0 || h->image->size == 0) {
kds_s2000w_handler_recreate_session(h);
return SANE_STATUS_NO_DOCS;
}
}
// calc max length
- *length = h->pnm_image->size - h->read_info->read_size;
+ *length = h->image->size - h->read_info->read_size;
if (*length > max_length)
*length = max_length;
// read image
- if (h->pnm_image->data != NULL && h->read_info->read_size <= 0)
- h->read_info->read_size += _sane_kds_s2000w_net_find_first_data_byte(h->pnm_image);
+ if (h->image->data != NULL && h->read_info->read_size <= 0)
+ h->read_info->read_size += _sane_kds_s2000w_net_find_first_data_byte(h->image);
- if (h->read_info->read_size < h->pnm_image->size) {
- memcpy(data, h->pnm_image->data + h->read_info->read_size, *length);
+ if (h->read_info->read_size < h->image->size) {
+ memcpy(data, h->image->data + h->read_info->read_size, *length);
h->read_info->read_size += *length;
return SANE_STATUS_GOOD;
}
// last frame
- free(h->scanner_image->data);
- h->scanner_image->data = NULL;
- h->scanner_image->size = 0;
-
- free(h->pnm_image->data);
- h->pnm_image->data = NULL;
- h->pnm_image->size = 0;
+ free(h->image->data);
+ h->image->data = NULL;
+ h->image->size = 0;
*length = 0;
return SANE_STATUS_EOF;
{
int length = 0;
handler* h = init_handler();
- h->pnm_image->data = malloc(sizeof(char));
- h->pnm_image->size = 0;
+ h->image->data = malloc(sizeof(char));
+ h->image->size = 0;
char* dataptr = malloc(sizeof(char));
SANE_Status status = _sane_kds_s2000w_net_read(h, (void*) dataptr, 65536, &length);
assert_int_equal(status, SANE_STATUS_EOF);
- free(h->pnm_image->data);
- h->pnm_image->data = NULL;
+ free(h->image->data);
+ h->image->data = NULL;
free(dataptr);
dataptr = NULL;
free_handler(h);
void sane_kds_s2000w_net_read_without_header_test()
{
handler* h = init_handler();
- h->pnm_image->size = 65536;
- h->pnm_image->data = malloc(sizeof(char) * 65536);
- char* imagedata = (char*) h->pnm_image->data;
+ h->image->size = 65536;
+ h->image->data = malloc(sizeof(char) * 65536);
+ char* imagedata = (char*) h->image->data;
for (int i = 0; i < 65536; i++) {
imagedata[i] = 0xff;
}
SANE_Status status = _sane_kds_s2000w_net_read(h, (void*) dataptr, maxlen, length);
assert_int_equal(*length, 0);
- assert_null(h->pnm_image->data);
+ assert_null(h->image->data);
assert_int_equal(h->read_info->read_size, 65536);
assert_int_equal(status, SANE_STATUS_EOF);
dataptr = NULL;
free(length);
length = NULL;
- free(h->pnm_image->data);
- h->pnm_image->data = NULL;
+ free(h->image->data);
+ h->image->data = NULL;
free_handler(h);
h = NULL;
}
void sane_kds_s2000w_net_read_test()
{
handler* h = init_handler();
- h->pnm_image->size = 65539;
- h->pnm_image->data = malloc(sizeof(char) * 65539);
- char* imagedata = (char*) h->pnm_image->data;
+ h->image->size = 65539;
+ h->image->data = malloc(sizeof(char) * 65539);
+ char* imagedata = (char*) h->image->data;
for (int i = 0; i < 3; i++) {
imagedata[i] = 0x0a;
}
_sane_kds_s2000w_net_read(h, (void*) dataptr, maxlen, length);
assert_int_equal(*length, 65536);
- assert_memory_equal(dataptr, h->pnm_image->data + 3, 65536);
+ assert_memory_equal(dataptr, h->image->data + 3, 65536);
assert_int_equal(h->read_info->read_size, 65539);
free(dataptr);
dataptr = NULL;
free(length);
length = NULL;
- free(h->pnm_image->data);
- h->pnm_image->data = NULL;
+ free(h->image->data);
+ h->image->data = NULL;
free_handler(h);
h = NULL;
}
void sane_kds_s2000w_net_read_bw_test()
{
handler* h = init_handler();
- h->pnm_image->size = 655541;
- h->pnm_image->data = malloc(sizeof(char) * 65541);
- char* imagedata = (char*) h->pnm_image->data;
+ h->image->size = 655541;
+ h->image->data = malloc(sizeof(char) * 65541);
+ char* imagedata = (char*) h->image->data;
imagedata[0] = 'P';
imagedata[1] = '4';
for (int i = 2; i < 4; i++) {
_sane_kds_s2000w_net_read(h, (void*) dataptr, maxlen, length);
assert_int_equal(*length, 65536);
- assert_memory_equal(dataptr, h->pnm_image->data + 5, 65536);
+ assert_memory_equal(dataptr, h->image->data + 5, 65536);
assert_int_equal(h->read_info->read_size, 65540);
free(dataptr);
dataptr = NULL;
free(length);
length = NULL;
- free(h->pnm_image->data);
- h->pnm_image->data = NULL;
+ free(h->image->data);
+ h->image->data = NULL;
free_handler(h);
h = NULL;
}
h->read_info->cancel = 0;
h->read_info->read_size = 0;
h->current_metadata->format = 0;
- h->pnm_image->size = 95003;
- h->pnm_image->data = malloc(sizeof(char) * 95003);
- char* image = (char*) h->pnm_image->data;
+ h->image->size = 95003;
+ h->image->data = malloc(sizeof(char) * 95003);
+ char* image = (char*) h->image->data;
for (int i = 0; i < 3; i++) {
image[i] = 0x0a;
}
dataptr = NULL;
free(length);
length = NULL;
- free(h->pnm_image->data);
- h->pnm_image->data = NULL;
+ free(h->image->data);
+ h->image->data = NULL;
free_handler(h);
h = NULL;
}
\ No newline at end of file