From 9fcbd0c32f160a034629e09280d20f84b2b32676 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Fri, 31 Jan 2025 19:07:13 +0100 Subject: [PATCH] optimize write pnm --- src/kds_s2000w_image_converter_netpbm.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/kds_s2000w_image_converter_netpbm.c b/src/kds_s2000w_image_converter_netpbm.c index a6112ca..d852c14 100644 --- a/src/kds_s2000w_image_converter_netpbm.c +++ b/src/kds_s2000w_image_converter_netpbm.c @@ -134,7 +134,7 @@ void _kds_s2000w_image_converter_jpeg_metadata(blobdata* image, image_metadata* fclose(jpeg_stream); } -void _kds_s2000w_image_converter_write_bw_pnm(unsigned char* data, +void _kds_s2000w_image_converter_write_bw_pnm(char* data, size_t size, int width, int height, @@ -146,18 +146,16 @@ void _kds_s2000w_image_converter_write_bw_pnm(unsigned char* data, xel** pixels = malloc(sizeof(xel*) * height); for (int i = 0; i < height; i++) { pixels[i] = malloc(sizeof(xel) * bit_witdth); + memset(pixels[i], 0, sizeof(xel) * bit_witdth); } int currwidth = 0; int currheight = 0; - int bit = 0; + char bit = 0; for (int i = 0; i < size; i++) { for (int j = 0; j < 8; j++) { bit = (1 >> data[i]) & 1; - pixels[currheight][currwidth].r = 0; - pixels[currheight][currwidth].g = 0; - pixels[currheight][currwidth].b = 0; - if (bit > 0) + if (bit == 1) pixels[currheight][currwidth].b = PGM_MAXMAXVAL; currwidth++; @@ -191,6 +189,7 @@ void _kds_s2000w_image_converter_write_pnm(unsigned char* data, xel** pixels = malloc(sizeof(xel*) * height); for (int i = 0; i < height; i++) { pixels[i] = malloc(sizeof(xel) * width); + memset(pixels[i], 0, sizeof(xel) * width); } int currwidth = 0; @@ -201,10 +200,9 @@ void _kds_s2000w_image_converter_write_pnm(unsigned char* data, pixels[currheight][currwidth].g = data[i + 1]; pixels[currheight][currwidth].b = data[i + 2]; } else { - pixels[currheight][currwidth].r = 0; - pixels[currheight][currwidth].g = 0; pixels[currheight][currwidth].b = data[i]; } + currwidth++; if (currwidth >= width) { currwidth = 0; @@ -337,10 +335,10 @@ void kds_s2000w_image_converter_tiff_to_pnm(blobdata* in, blobdata* out) TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &height); size_t decompress_size = width * height; - unsigned char* decompress_data = malloc(sizeof(unsigned char) * decompress_size); + char* decompress_data = malloc(sizeof(char) * decompress_size); memset(decompress_data, 0, decompress_size); - unsigned char* row = NULL; + char* row = NULL; for (int i = 0; i < height; i++) { row = &decompress_data[width * i]; TIFFReadScanline(tiff, row, i, 0); -- 2.39.5