From 79b0f7768e2d82c54547f6eceb130cc77bcb3ef4 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Thu, 1 Aug 2024 09:42:56 +0200 Subject: [PATCH] refactor image converter --- src/kds_s2000w_image_converter.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/kds_s2000w_image_converter.c b/src/kds_s2000w_image_converter.c index 42d6cb1..ef36412 100644 --- a/src/kds_s2000w_image_converter.c +++ b/src/kds_s2000w_image_converter.c @@ -18,13 +18,9 @@ void kds_s2000w_convert_to_pnm_with_depth(blobdata* in, #ifndef NODEBUG debug_printf(ALL, "kds_s2000w_convert_to_pnm_With_depth"); #endif - - ExceptionInfo* exception = NULL; - Image* input_image = NULL; - ImageInfo* image_info = NULL; - exception = AcquireExceptionInfo(); - image_info = CloneImageInfo(NULL); + ExceptionInfo* exception = AcquireExceptionInfo(); + ImageInfo* image_info = CloneImageInfo(NULL); sprintf(image_info->filename, "streamin.%s", format); @@ -32,7 +28,7 @@ void kds_s2000w_convert_to_pnm_with_depth(blobdata* in, debug_printf(DEBUG, image_info->filename); #endif - input_image = BlobToImage(image_info, in->data, in->size , exception); + Image* input_image = BlobToImage(image_info, in->data, in->size , exception); if (exception->severity != UndefinedException) { fprintf(stderr, "%s\n", GetExceptionMessage(exception->error_number)); @@ -59,8 +55,11 @@ void kds_s2000w_convert_to_pnm_with_depth(blobdata* in, out->data = ImageToBlob(image_info, input_image, &out->size, exception); DestroyImageInfo(image_info); + image_info = NULL; DestroyImage(input_image); + input_image = NULL; DestroyExceptionInfo(exception); + exception = NULL; } void kds_s2000w_convert_jpg_to_pnm_with_depth(blobdata* in, blobdata* out, int depth) @@ -89,15 +88,11 @@ void kds_s2000w_metadata_from_image(blobdata* image, image_metadata* mdata) debug_printf(ALL, "kds_s2000w_metadata_from_image"); #endif - ExceptionInfo* exception = NULL; - Image* input_image = NULL; - ImageInfo* image_info = NULL; - - exception = AcquireExceptionInfo(); - image_info = CloneImageInfo(NULL); + ExceptionInfo* exception = AcquireExceptionInfo(); + ImageInfo* image_info = CloneImageInfo(NULL); sprintf(image_info->filename, "image.pnm"); - input_image = BlobToImage(image_info, image->data, image->size , exception); + Image* input_image = BlobToImage(image_info, image->data, image->size , exception); if (exception->severity != UndefinedException) { fprintf(stderr, "%s\n", GetExceptionMessage(exception->error_number)); @@ -109,6 +104,9 @@ void kds_s2000w_metadata_from_image(blobdata* image, image_metadata* mdata) mdata->depth = input_image->depth; DestroyImageInfo(image_info); + image_info = NULL; DestroyImage(input_image); + input_image = NULL; DestroyExceptionInfo(exception); + exception = NULL; } \ No newline at end of file -- 2.39.5