From: Bastian Dehn Date: Thu, 30 Jan 2025 20:32:13 +0000 (+0100) Subject: change bit with bw convert X-Git-Tag: v1.0.29^2~3^2~11 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=91ca2ee93145a0611283b4d63bfb8772c567a592;p=sane-kds-s2000w-net.git change bit with bw convert --- diff --git a/src/kds_s2000w_image_converter_netpbm.c b/src/kds_s2000w_image_converter_netpbm.c index e362195..a6112ca 100644 --- a/src/kds_s2000w_image_converter_netpbm.c +++ b/src/kds_s2000w_image_converter_netpbm.c @@ -10,6 +10,7 @@ #define SPACE 0x0a #define SPACE_WIDTH_HEIGHT 0x20 #define MAXBUFFER 6 +#define BYTE_BITS 8 enum imgformat { BW = 0, @@ -141,22 +142,28 @@ void _kds_s2000w_image_converter_write_bw_pnm(unsigned char* data, { kds_s2000w_debug_printf(ALL, "kds_s2000w_image_converter_write_bw_pnm"); + int bit_witdth = width * BYTE_BITS; xel** pixels = malloc(sizeof(xel*) * height); for (int i = 0; i < height; i++) { - pixels[i] = malloc(sizeof(xel) * width); + pixels[i] = malloc(sizeof(xel) * bit_witdth); } int currwidth = 0; int currheight = 0; + int bit = 0; for (int i = 0; i < size; i++) { - pixels[currheight][currwidth].r = 0; - pixels[currheight][currwidth].g = 0; - pixels[currheight][currwidth].b = 0; - if (data[i] < 1) - pixels[currheight][currwidth].b = PGM_MAXMAXVAL; + 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) + pixels[currheight][currwidth].b = PGM_MAXMAXVAL; - currwidth++; - if (currwidth >= width) { + currwidth++; + } + + if (currwidth >= bit_witdth) { currwidth = 0; currheight++; } @@ -331,6 +338,7 @@ void kds_s2000w_image_converter_tiff_to_pnm(blobdata* in, blobdata* out) size_t decompress_size = width * height; unsigned char* decompress_data = malloc(sizeof(unsigned char) * decompress_size); + memset(decompress_data, 0, decompress_size); unsigned char* row = NULL; for (int i = 0; i < height; i++) {