From: Bastian Dehn Date: Sun, 4 Feb 2024 21:07:24 +0000 (+0100) Subject: WIP write to blob X-Git-Tag: v1.0.0^2~344^2~9 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=6e3be1d274c4ed10d724f48433b21eea1ac3c2dc;p=sane-kds-s2000w-net.git WIP write to blob --- diff --git a/src/kds_s2000w_image_converter.c b/src/kds_s2000w_image_converter.c index 25da8a6..0425edf 100644 --- a/src/kds_s2000w_image_converter.c +++ b/src/kds_s2000w_image_converter.c @@ -16,32 +16,33 @@ void kds_s2000w_convert_terminate() MagickCoreTerminus(); } -void kds_s2000w_convert_jpg_to_pnm(void* blob, size_t size) +blob* kds_s2000w_convert_jpg_to_pnm(blob* blob) { ExceptionInfo* exception = NULL; Image* input_image = NULL; - Image* output_image = NULL; ImageInfo* image_info = NULL; exception = AcquireExceptionInfo(); image_info = CloneImageInfo(NULL); - const char* streamname = "stream.jpg"; - strcpy(image_info->filename, streamname); - input_image = BlobToImage(image_info, blob, size , exception); + const char* in_streamname = "stream.jpg"; + strcpy(image_info->filename, in_streamname); + input_image = BlobToImage(image_info, (void*) blob->data, *blob->size , exception); - if (exception->severity != UndefinedException) - CatchException(exception); - if (input_image == NULL) - exit(1); - - DestroyImageInfo(image_info); DestroyExceptionInfo(exception); - exception = AcquireExceptionInfo(); + exception = NULL; + DestroyImageInfo(image_info); + image_info = NULL; + image_info = CloneImageInfo(NULL); - strcpy(image_info->filename, "output_test.jpg"); - WriteImages(image_info, input_image, "output.pnm", exception); + const char* out_streamname = "stream.pnm"; + strcpy(image_info->filename, out_streamname); + blob* output_blob = malloc(sizeof(blob)); + output_blob->size = malloc(sizeof(size_t)); + output_blob = ImageToBlob(image_info, input_image, blob->size, exception); DestroyImageInfo(image_info); DestroyImage(input_image); DestroyExceptionInfo(exception); + + return output_blob; } \ No newline at end of file diff --git a/src/kds_s2000w_image_converter.h b/src/kds_s2000w_image_converter.h index 2ba11b9..a59696a 100644 --- a/src/kds_s2000w_image_converter.h +++ b/src/kds_s2000w_image_converter.h @@ -1,6 +1,12 @@ #ifndef KDS_S2000W_IMAGE_CONVERTER_H + +typedef struct { + size_t* size; + char* data; +} blob; + void kds_s2000w_convert_init(); void kds_s2000w_convert_terminate(); -void kds_s2000w_convert_jpg_to_pnm(); +blob* kds_s2000w_convert_jpg_to_pnm(blob* blob); #endif \ No newline at end of file diff --git a/tools/convert.c b/tools/convert.c index 2f05710..a1ce920 100644 --- a/tools/convert.c +++ b/tools/convert.c @@ -4,28 +4,41 @@ int main(int argc, char* argv[]) { + blob* out_blob = NULL; + blob* blob = NULL; FILE* fptr = NULL; - size_t size = 0; - char* buf = malloc(sizeof(char)); + blob = malloc(sizeof(blob)); + blob->size = malloc(sizeof(size_t)); + blob->data = malloc(sizeof(char)); fptr = fopen("test.jpg", "r"); - while(fread(buf, sizeof(char), 1, fptr)) { - size++; + while(fread(blob->data, sizeof(char), 1, fptr)) { + *blob->size++; } fseek(fptr, 0L, SEEK_SET); - printf("file size in bufs: %i\n", size); - free(buf); - buf = NULL; + printf("file size in bufs: %i\n", *blob->size); + free(blob->data); + blob->data = NULL; - buf = malloc(sizeof(char) * size); - fread(buf, size, 1, fptr); + blob->data = malloc(sizeof(char) * *blob->size); + fread(blob->data, *blob->size, 1, fptr); fclose(fptr); kds_s2000w_convert_init(); - kds_s2000w_convert_jpg_to_pnm(buf, size); + out_blob = kds_s2000w_convert_jpg_to_pnm(blob); kds_s2000w_convert_terminate(); - free(buf); - buf = NULL; + free(blob->size); + blob->size = NULL; + free(blob->data); + blob->data = NULL; + free(blob); + blob = NULL; + free(out_blob->size); + out_blob->size = NULL; + free(out_blob->data); + out_blob->data = NULL; + free(out_blob); + out_blob = NULL; return 0; } \ No newline at end of file