]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change move type check seperate file
authorBastian Dehn <hhaalo@arcor.de>
Sun, 26 Jan 2025 13:37:14 +0000 (14:37 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 26 Jan 2025 13:37:14 +0000 (14:37 +0100)
src/CMakeLists.txt
src/kds_s2000w_image_converter_magick.c
src/kds_s2000w_image_converter_netpbm.c
src/kds_s2000w_image_type_check.c [new file with mode: 0644]
src/kds_s2000w_image_type_check.h [new file with mode: 0644]

index 9314d49f19712b740a43740e6a0707cd8b4771f8..b29abff51d05ca9ef2d43d076b26ce8e686c8b8f 100644 (file)
@@ -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")
index 83d701cfe0d00668ad35728de38452d1f9401ed8..6da2dd7e5b9d11eb9134034d0191600ddb530fa6 100644 (file)
 #endif
 #include <string.h>
 #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");
index beb4b77b4950f725f728480f692ca4f335197421..e804b711d78b21537e05974e117ced591e2d51a6 100644 (file)
@@ -3,6 +3,7 @@
 #include <netpbm/pnm.h>
 #include <jpeglib.h>
 #include "kds_s2000w_image_converter.h"
+#include "kds_s2000w_image_type_check.h"
 #include "kds_s2000w_debug.h"
 
 #define SPACE 0x0a
 #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 (file)
index 0000000..e2989d4
--- /dev/null
@@ -0,0 +1,45 @@
+#include <string.h>
+#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 (file)
index 0000000..9de38ae
--- /dev/null
@@ -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