]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change bit with bw convert
authorBastian Dehn <hhaalo@arcor.de>
Thu, 30 Jan 2025 20:32:13 +0000 (21:32 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Thu, 30 Jan 2025 20:32:13 +0000 (21:32 +0100)
src/kds_s2000w_image_converter_netpbm.c

index e362195eaf3db4bf5e064cb4a0cb2d6c2ab288c0..a6112ca240a7a81e0a79e24e5fee80d96d5446d8 100644 (file)
@@ -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++) {