From: Bastian Dehn Date: Sun, 26 Jan 2025 13:23:33 +0000 (+0100) Subject: add check tiff format X-Git-Tag: v1.0.29^2~3^2~20 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=4f982f3fae3684f0d23feb107eb298fbd533b390;p=sane-kds-s2000w-net.git add check tiff format --- diff --git a/src/kds_s2000w_image_converter_magick.c b/src/kds_s2000w_image_converter_magick.c index 98f5377..83d701c 100644 --- a/src/kds_s2000w_image_converter_magick.c +++ b/src/kds_s2000w_image_converter_magick.c @@ -15,6 +15,21 @@ #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"); diff --git a/src/kds_s2000w_image_converter_netpbm.c b/src/kds_s2000w_image_converter_netpbm.c index 544134e..beb4b77 100644 --- a/src/kds_s2000w_image_converter_netpbm.c +++ b/src/kds_s2000w_image_converter_netpbm.c @@ -11,9 +11,24 @@ #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;