]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add mirror bits
authorBastian Dehn <hhaalo@arcor.de>
Sat, 1 Feb 2025 09:29:31 +0000 (10:29 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 1 Feb 2025 09:29:31 +0000 (10:29 +0100)
src/kds_s2000w_image_converter_netpbm.c

index 5a157a103c8cad33ba13befd9179105da3b0e4a7..7017b35722c82fc7699d60cb4c6d7b29a2dbf017 100644 (file)
@@ -134,7 +134,21 @@ void _kds_s2000w_image_converter_jpeg_metadata(blobdata* image, image_metadata*
        fclose(jpeg_stream);
 }
 
-void _kds_s2000w_image_converter_write_bw_pnm(char* data,
+unsigned char _kds_s2000w_image_converter_mirror_bits(unsigned char data)
+{
+       char tmp = data;
+       data = 0;
+
+       for (int j = 0; j < BYTE_BITS; j++) {
+               data += tmp & 1;
+               data <<= 1;
+               tmp >>= 1;
+       }
+
+       return data;
+}
+
+void _kds_s2000w_image_converter_write_bw_pnm(unsigned char* data,
        size_t size,
        int width,
        int height,
@@ -151,10 +165,12 @@ void _kds_s2000w_image_converter_write_bw_pnm(char* data,
 
        int currwidth = 0;
        int currheight = 0;
-       char bit = 0;
+       unsigned char bit = 0;
        for (int i = 0; i < size; i++) {
+               data[i] = _kds_s2000w_image_converter_mirror_bits(data[i]);
+
                for (int j = 0; j < BYTE_BITS; j++) {
-                       bit = data[i] & 0x01;
+                       bit = data[i] & 1;
                        if (bit == 0)
                                pixels[currheight][currwidth].b = PNM_MAXMAXVAL;
 
@@ -336,10 +352,10 @@ void kds_s2000w_image_converter_tiff_to_pnm(blobdata* in, blobdata* out)
        TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &height);
 
        size_t decompress_size = width * height;
-       char* decompress_data = malloc(sizeof(char) * decompress_size);
+       unsigned char* decompress_data = malloc(sizeof(unsigned char) * decompress_size);
        memset(decompress_data, 0, decompress_size);
 
-       char* row = NULL;
+       unsigned char* row = NULL;
        for (int i = 0; i < height; i++) {
                row = &decompress_data[width * i];
                TIFFReadScanline(tiff, row, i, 0);