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