]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change converter netpbm with stdint
authorBastian Dehn <hhaalo@arcor.de>
Sat, 8 Feb 2025 18:56:36 +0000 (19:56 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 8 Feb 2025 18:56:36 +0000 (19:56 +0100)
src/kds_s2000w_image_converter.h
src/kds_s2000w_image_converter_netpbm.c

index dfa932011a0e8d19ab1ae114e094408a70b85ef1..fbde4fab0dc8ec30eddc9aee465bb385ff34d8d9 100644 (file)
@@ -1,5 +1,6 @@
 #ifndef KDS_S2000W_IMAGE_CONVERTER_H
 #define KDS_S2000W_IMAGE_CONVERTER_H
+#include <stdint.h>
 #include <stddef.h>
 
 typedef struct {
@@ -8,9 +9,9 @@ typedef struct {
 } blobdata;
 
 typedef struct {
-       int width;
-       int height;
-       int depth;
+       uint32_t width;
+       uint32_t height;
+       uint8_t depth;
 } image_metadata;
 
 void kds_s2000w_image_converter_metadata_from_scanner_image(blobdata* image, image_metadata* mdata);
index e0e44d1386a8287ac290e37691f7acdfba66f060..1569731901b72a8962932fc105193271af24067b 100644 (file)
@@ -44,13 +44,13 @@ toff_t _kds_s2000w_image_converter_tiff_size(thandle_t handler)
        return ftell(handler);
 }
 
-int _kds_s2000w_image_converter_find_char(blobdata* image, int start, const char cfind)
+uint32_t _kds_s2000w_image_converter_find_char(blobdata* image, uint32_t start, const char cfind)
 {
        kds_s2000w_debug_printf(ALL, "kds_s2000w_image_converter_find_char");
 
        char* image_data = (char*) image->data;
 
-       for (int i = start; i < image->size; i++) {
+       for (uint32_t i = start; i < image->size; i++) {
                if (image_data[i] == cfind)
                        return i;
        }
@@ -58,11 +58,11 @@ int _kds_s2000w_image_converter_find_char(blobdata* image, int start, const char
        return 0;
 }
 
-int _kds_s2000w_image_converter_get_number_from_substring(char* data, int start, int end)
+uint32_t _kds_s2000w_image_converter_get_number_from_substring(char* data, uint32_t start, uint32_t end)
 {
        kds_s2000w_debug_printf(ALL, "kds_s2000w_image_converter_get_number_from_substring");
 
-       int number = 0;
+       uint32_t number = 0;
 
        char* number_buffer = malloc(sizeof(char) * MAXBUFFER);
        memset(number_buffer, 0, MAXBUFFER);
@@ -103,9 +103,9 @@ void _kds_s2000w_image_converter_pnm_metadata(blobdata* image, image_metadata* m
        if (strncmp(image_data, "P4", 2) == 0)
                mdata->depth = 1;
 
-       int start = _kds_s2000w_image_converter_find_char(image, 0, SPACE);
-       int middle = _kds_s2000w_image_converter_find_char(image, start, SPACE_WIDTH_HEIGHT);
-       int end = _kds_s2000w_image_converter_find_char(image, middle, SPACE);
+       uint32_t start = _kds_s2000w_image_converter_find_char(image, 0, SPACE);
+       uint32_t middle = _kds_s2000w_image_converter_find_char(image, start, SPACE_WIDTH_HEIGHT);
+       uint32_t end = _kds_s2000w_image_converter_find_char(image, middle, SPACE);
 
        mdata->width = _kds_s2000w_image_converter_get_number_from_substring(image_data, start, middle);
        mdata->height = _kds_s2000w_image_converter_get_number_from_substring(image_data, middle, end);
@@ -134,11 +134,11 @@ void _kds_s2000w_image_converter_jpeg_metadata(blobdata* image, image_metadata*
        fclose(jpeg_stream);
 }
 
-unsigned char _kds_s2000w_image_converter_mirror_bits(unsigned char data)
+uint8_t _kds_s2000w_image_converter_mirror_bits(uint8_t data)
 {
-       unsigned char mirrored = 0;
+       uint8_t mirrored = 0;
 
-       for (int i = 0; i < BYTE_BITS; i++) {
+       for (uint32_t i = 0; i < BYTE_BITS; i++) {
                mirrored <<= 1;
                mirrored += data >> i & 1;
        }
@@ -146,34 +146,34 @@ unsigned char _kds_s2000w_image_converter_mirror_bits(unsigned char data)
        return mirrored;
 }
 
-void _kds_s2000w_image_converter_set_pixels(unsigned char data_byte, xel* pixels)
+void _kds_s2000w_image_converter_set_pixels(uint8_t data_byte, xel* pixels)
 {
-       unsigned char bit = 0;
-       for (int i = 0; i < BYTE_BITS; i++) {
+       uint8_t bit = 0;
+       for (uint32_t i = 0; i < BYTE_BITS; i++) {
                bit = data_byte >> i & 1;
                if (bit == 0)
                        pixels[i].b = PNM_MAXMAXVAL;
        }
 }
 
-void _kds_s2000w_image_converter_write_bw_pnm(unsigned char* data,
+void _kds_s2000w_image_converter_write_bw_pnm(uint8_t* data,
        size_t size,
-       int width,
-       int height,
+       uint32_t width,
+       uint32_t height,
        FILE* pnm_stream)
 {
        kds_s2000w_debug_printf(ALL, "kds_s2000w_image_converter_write_bw_pnm");
 
-       int bit_witdth = width * BYTE_BITS;
+       uint32_t bit_witdth = width * BYTE_BITS;
        xel** pixels = malloc(sizeof(xel*) * height);
-       for (int i = 0; i < height; i++) {
+       for (uint32_t 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;
-       for (int i = 0; i < size; i++) {
+       uint32_t currwidth = 0;
+       uint32_t currheight = 0;
+       for (uint32_t i = 0; i < size; i++) {
                data[i] = _kds_s2000w_image_converter_mirror_bits(data[i]);
 
                _kds_s2000w_image_converter_set_pixels(data[i], &pixels[currheight][currwidth]);
@@ -187,7 +187,7 @@ void _kds_s2000w_image_converter_write_bw_pnm(unsigned char* data,
 
        pnm_writepnm(pnm_stream, pixels, width, height, PNM_MAXMAXVAL, PBM_FORMAT, 0);
 
-       for (int i = 0; i < height; i++) {
+       for (uint32_t i = 0; i < height; i++) {
                free(pixels[i]);
                pixels[i] = NULL;
        }
@@ -195,24 +195,24 @@ void _kds_s2000w_image_converter_write_bw_pnm(unsigned char* data,
        pixels = NULL;
 }
 
-void _kds_s2000w_image_converter_write_pnm(unsigned char* data,
+void _kds_s2000w_image_converter_write_pnm(uint8_t* data,
        size_t size,
-       int width,
-       int height,
+       uint32_t width,
+       uint32_t height,
        enum imgformat format,
        FILE* pnm_stream)
 {
        kds_s2000w_debug_printf(ALL, "kds_s2000w_image_converter_write_pnm");
 
        xel** pixels = malloc(sizeof(xel*) * height);
-       for (int i = 0; i < height; i++) {
+       for (uint32_t i = 0; i < height; i++) {
                pixels[i] = malloc(sizeof(xel) * width);
                memset(pixels[i], 0, sizeof(xel) * width);
        }
 
-       int currwidth = 0;
-       int currheight = 0;
-       for (int i = 0; i < size; i += format) {
+       uint32_t currwidth = 0;
+       uint32_t currheight = 0;
+       for (uint32_t i = 0; i < size; i += format) {
                if (format == RGB) {
                        pixels[currheight][currwidth].r = data[i];
                        pixels[currheight][currwidth].g = data[i + 1];
@@ -233,7 +233,7 @@ void _kds_s2000w_image_converter_write_pnm(unsigned char* data,
        else
                pnm_writepnm(pnm_stream, pixels, width, height, PGM_MAXMAXVAL, PGM_FORMAT, 0);
 
-       for (int i = 0; i < height; i++) {
+       for (uint32_t i = 0; i < height; i++) {
                free(pixels[i]);
                pixels[i] = NULL;
        }
@@ -249,9 +249,9 @@ void _kds_s2000w_image_converter_gray_or_color_jpg_to_pnm(j_decompress_ptr cinfo
        kds_s2000w_debug_printf(ALL, "kds_s2000w_image_converter_jpg_to_pnm");
 
        size_t decompress_size = format * cinfo->output_width * cinfo->output_height;
-       unsigned char* decompress_data = malloc(sizeof(unsigned char) * decompress_size);
+       uint8_t* decompress_data = malloc(sizeof(uint8_t) * decompress_size);
 
-       unsigned char* row = NULL;
+       uint8_t* row = NULL;
        while (cinfo->output_scanline < cinfo->output_height) {
                row = &decompress_data[cinfo->output_width * cinfo->output_scanline * format];
                jpeg_read_scanlines(cinfo, &row, 1);
@@ -344,17 +344,17 @@ void _kds_s2000w_image_converter_tiff_to_pnm(blobdata* in, blobdata* out)
                _kds_s2000w_image_converter_tiff_size,
                NULL, NULL);
 
-       int width = 0;
-       int height = 0;
+       uint32_t width = 0;
+       uint32_t height = 0;
        TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &width);
        TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &height);
 
        size_t decompress_size = width * height;
-       unsigned char* decompress_data = malloc(sizeof(unsigned char) * decompress_size);
+       uint8_t* decompress_data = malloc(sizeof(uint8_t) * decompress_size);
        memset(decompress_data, 0, decompress_size);
 
-       unsigned char* row = NULL;
-       for (int i = 0; i < height; i++) {
+       uint8_t* row = NULL;
+       for (uint32_t i = 0; i < height; i++) {
                row = &decompress_data[width * i];
                TIFFReadScanline(tiff, row, i, 0);
        }