From: Bastian Dehn Date: Sun, 26 Jan 2025 13:37:14 +0000 (+0100) Subject: change move type check seperate file X-Git-Tag: v1.0.29^2~3^2~19 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=b86a9e391fd88785d18a68bf424b06c7165cc2ea;p=sane-kds-s2000w-net.git change move type check seperate file --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9314d49..b29abff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -78,7 +78,8 @@ SET(SOURCES "kds_s2000w_client.c" "kds_s2000w_debug.c" "kds_s2000w_config.c" - "kds_s2000w_heartbeat.c") + "kds_s2000w_heartbeat.c" + "kds_s2000w_image_type_check.c") IF(NOT WITHOUT_IMAGEMAGICK) LIST(APPEND SOURCES "kds_s2000w_image_converter_magick.c") diff --git a/src/kds_s2000w_image_converter_magick.c b/src/kds_s2000w_image_converter_magick.c index 83d701c..6da2dd7 100644 --- a/src/kds_s2000w_image_converter_magick.c +++ b/src/kds_s2000w_image_converter_magick.c @@ -13,51 +13,9 @@ #endif #include #include "kds_s2000w_image_converter.h" +#include "kds_s2000w_image_type_check.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"); - - if (image->size < 2) - return 0; - - char* image_data = (char*) image->data; - if (strncmp(image_data, "P6", 2) == 0) - return 1; - - return strncmp(image_data, "P4", 2) == 0; -} - -int _kds_s2000w_image_converter_is_jpeg(blobdata* image) -{ - kds_s2000w_debug_printf(ALL, "kds_s2000w_image_converter_is_jpeg"); - - if (image->size < 2) - return 0; - - char* image_data = (char*) image->data; - - 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, @@ -141,7 +99,7 @@ void kds_s2000w_image_converter_jpg_to_pnm(blobdata* in, blobdata* out, int dept { kds_s2000w_debug_printf(ALL, "kds_s2000w_convert_jpg_to_pnm_With_depth"); - if (!_kds_s2000w_image_converter_is_jpeg(in)) + if (!kds_s2000w_image_type_check_is_jpeg(in)) return; _kds_s2000w_image_converter_to_pnm_depth(in, out, depth, "jpg"); @@ -151,7 +109,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_tiff(in)) + if (!kds_s2000w_image_type_check_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 beb4b77..e804b71 100644 --- a/src/kds_s2000w_image_converter_netpbm.c +++ b/src/kds_s2000w_image_converter_netpbm.c @@ -3,6 +3,7 @@ #include #include #include "kds_s2000w_image_converter.h" +#include "kds_s2000w_image_type_check.h" #include "kds_s2000w_debug.h" #define SPACE 0x0a @@ -11,48 +12,6 @@ #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"); - - if (image->size < 2) - return 0; - - char* image_data = (char*) image->data; - if (strncmp(image_data, "P6", 2) == 0) - return 1; - - return strncmp(image_data, "P4", 2) == 0; -} - -int _kds_s2000w_image_converter_is_jpeg(blobdata* image) -{ - kds_s2000w_debug_printf(ALL, "kds_s2000w_image_converter_is_jpeg"); - - if (image->size < 2) - return 0; - - char* image_data = (char*) image->data; - - 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) { kds_s2000w_debug_printf(ALL, "kds_s2000w_image_converter_find_char"); @@ -222,12 +181,12 @@ void kds_s2000w_image_converter_metadata_from_scanner_image(blobdata* image, ima if (image->size < 2) return; - if (_kds_s2000w_image_converter_is_pnm(image)) { + if (kds_s2000w_image_type_check_is_pnm(image)) { _kds_s2000w_image_converter_pnm_metadata(image, mdata); return; } - if (_kds_s2000w_image_converter_is_jpeg(image)) { + if (kds_s2000w_image_type_check_is_jpeg(image)) { _kds_s2000w_image_converter_jpeg_metadata(image, mdata); return; } @@ -239,7 +198,7 @@ void kds_s2000w_image_converter_jpg_to_pnm(blobdata* in, blobdata* out, int dept { kds_s2000w_debug_printf(ALL, "kds_s2000w_image_converter_jpg_to_pnm"); - if (!_kds_s2000w_image_converter_is_jpeg(in)) + if (!kds_s2000w_image_type_check_is_jpeg(in)) return; FILE* jpeg_stream = fmemopen(in->data, in->size, "r"); @@ -278,7 +237,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_tiff(in)) + if (!kds_s2000w_image_type_check_is_tiff(in)) return; return; diff --git a/src/kds_s2000w_image_type_check.c b/src/kds_s2000w_image_type_check.c new file mode 100644 index 0000000..e2989d4 --- /dev/null +++ b/src/kds_s2000w_image_type_check.c @@ -0,0 +1,45 @@ +#include +#include "kds_s2000w_debug.h" +#include "kds_s2000w_image_type_check.h" + +int kds_s2000w_image_type_check_is_tiff(blobdata* image) +{ + kds_s2000w_debug_printf(ALL, "kds_s2000w_image_type_check_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_type_check_is_pnm(blobdata* image) +{ + kds_s2000w_debug_printf(ALL, "kds_s2000w_image_type_check_is_pnm"); + + if (image->size < 2) + return 0; + + char* image_data = (char*) image->data; + if (strncmp(image_data, "P6", 2) == 0) + return 1; + + return strncmp(image_data, "P4", 2) == 0; +} + +int kds_s2000w_image_type_check_is_jpeg(blobdata* image) +{ + kds_s2000w_debug_printf(ALL, "kds_s2000w_image_type_check_is_jpeg"); + + if (image->size < 2) + return 0; + + char* image_data = (char*) image->data; + + int result = image_data[0] == (char)0xff; + return result && image_data[1] == (char)0xd8; +} \ No newline at end of file diff --git a/src/kds_s2000w_image_type_check.h b/src/kds_s2000w_image_type_check.h new file mode 100644 index 0000000..9de38ae --- /dev/null +++ b/src/kds_s2000w_image_type_check.h @@ -0,0 +1,9 @@ +#ifndef KDS_S2000W_IMAGE_TYPE_CHECK_H +#define KDS_S2000W_IMAGE_TYPE_CHECK_H +#include "kds_s2000w_image_converter.h" + +int kds_s2000w_image_type_check_is_tiff(blobdata* image); +int kds_s2000w_image_type_check_is_pnm(blobdata* image); +int kds_s2000w_image_type_check_is_jpeg(blobdata* image); + +#endif \ No newline at end of file