]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add check tiff format
authorBastian Dehn <hhaalo@arcor.de>
Sun, 26 Jan 2025 13:23:33 +0000 (14:23 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 26 Jan 2025 13:23:33 +0000 (14:23 +0100)
src/kds_s2000w_image_converter_magick.c
src/kds_s2000w_image_converter_netpbm.c

index 98f53779609ca500902d32765e054d9202673e40..83d701cfe0d00668ad35728de38452d1f9401ed8 100644 (file)
 #include "kds_s2000w_image_converter.h"
 #include "kds_s2000w_debug.h"
 
+int _kds_s2000w_image_converter_is_tiff(blobdata* image)
+{
+       kds_s2000w_debug_printf(ALL, "kds_s2000w_image_converter_is_tiff");
+
+       if (image->size < 4)
+               return 0;
+
+       char* image_data = (char*) image->data;
+
+       int result = image_data[0] == (char)0x49;
+       result = result && image_data[1] == (char)0x49;
+       result = result && image_data[2] == (char)0x2A;
+       return result && image_data[3] == (char)0x00;
+}
+
 int _kds_s2000w_image_converter_is_pnm(blobdata* image)
 {
        kds_s2000w_debug_printf(ALL, "kds_s2000w_image_converter_is_pnm");
@@ -31,18 +46,18 @@ int _kds_s2000w_image_converter_is_pnm(blobdata* image)
 
 int _kds_s2000w_image_converter_is_jpeg(blobdata* image)
 {
-       kds_s2000w_debug_printf(ALL, "_kds_s2000w_image_converter_is_jpeg");
+       kds_s2000w_debug_printf(ALL, "kds_s2000w_image_converter_is_jpeg");
 
        if (image->size < 2)
                return 0;
 
-       const char first_byte = 0xff;
-       const char second_byte = 0xd8;
-
        char* image_data = (char*) image->data;
-       return image_data[0] == first_byte && image_data[1] == second_byte;
+
+       int result = image_data[0] == (char)0xff;
+       return result && image_data[1] == (char)0xd8;
 }
 
+
 void _kds_s2000w_image_converter_to_pnm_depth(blobdata* in,
        blobdata* out,
        int depth,
@@ -136,7 +151,7 @@ void kds_s2000w_image_converter_tiff_to_pnm(blobdata* in, blobdata* out)
 {
        kds_s2000w_debug_printf(ALL, "kds_s2000w_convert_tiff_to_pnm");
 
-       if (_kds_s2000w_image_converter_is_jpeg(in))
+       if (!_kds_s2000w_image_converter_is_tiff(in))
                return;
 
        _kds_s2000w_image_converter_to_pnm_depth(in, out, -1, "tiff");
index 544134e9a34a597f1c06c6610699ecede082fcdb..beb4b77b4950f725f728480f692ca4f335197421 100644 (file)
 #define RGB 3
 #define GRAY 1
 
+int _kds_s2000w_image_converter_is_tiff(blobdata* image)
+{
+       kds_s2000w_debug_printf(ALL, "kds_s2000w_image_converter_is_tiff");
+
+       if (image->size < 4)
+               return 0;
+
+       char* image_data = (char*) image->data;
+
+       int result = image_data[0] == (char)0x49;
+       result = result && image_data[1] == (char)0x49;
+       result = result && image_data[2] == (char)0x2A;
+       return result && image_data[3] == (char)0x00;
+}
+
 int _kds_s2000w_image_converter_is_pnm(blobdata* image)
 {
-       kds_s2000w_debug_printf(ALL, "_kds_s2000w_image_converter_is_pnm");
+       kds_s2000w_debug_printf(ALL, "kds_s2000w_image_converter_is_pnm");
 
        if (image->size < 2)
                return 0;
@@ -32,11 +47,10 @@ int _kds_s2000w_image_converter_is_jpeg(blobdata* image)
        if (image->size < 2)
                return 0;
 
-       const char first_byte = 0xff;
-       const char second_byte = 0xd8;
-
        char* image_data = (char*) image->data;
-       return image_data[0] == first_byte && image_data[1] == second_byte;
+
+       int result = image_data[0] == (char)0xff;
+       return result && image_data[1] == (char)0xd8;
 }
 
 int _kds_s2000w_image_converter_find_char(blobdata* image, int start, const char cfind)
@@ -264,7 +278,7 @@ void kds_s2000w_image_converter_tiff_to_pnm(blobdata* in, blobdata* out)
 {
        kds_s2000w_debug_printf(ALL, "kds_s2000w_image_converter_tiff_to_pnm");
 
-       if (_kds_s2000w_image_converter_is_jpeg(in))
+       if (!_kds_s2000w_image_converter_is_tiff(in))
                return;
 
        return;