From: Bastian Dehn Date: Sat, 25 Jan 2025 19:09:03 +0000 (+0100) Subject: add option without image magick X-Git-Tag: v1.0.29^2~3^2~36 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=008f42a37d3496e235fb8b0bb2505e6c5fc84508;p=sane-kds-s2000w-net.git add option without image magick --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3924421..7b5c2fc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,9 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.25.1) PROJECT("sane-kds-s2000w-net" VERSION "1.0.28") +OPTION(WITHOUT_IMAGEMAGICK "without ImageMagick library" OFF) +MESSAGE(STATUS "WITHOUT_IMAGEMAGICK: " ${WITHOUT_IMAGEMAGICK}) + FIND_PACKAGE(Git) IF(GIT_FOUND) EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} branch --show-current @@ -32,16 +35,18 @@ MESSAGE(STATUS "find curl: " ${CURL_LIBRARY}) FIND_PACKAGE(JSON-C REQUIRED) MESSAGE(STATUS "find json-c: " ${JSON\-C_DIR}) -FIND_PACKAGE(ImageMagick COMPONENTS MagickCore REQUIRED) -MESSAGE(STATUS "find ImageMagick: " ${ImageMagick_LIBRARIES}) -MESSAGE(STATUS "ImageMagick_VERSION_STRING: " ${ImageMagick_VERSION_STRING}) -STRING(SUBSTRING ${ImageMagick_VERSION_STRING} 0 1 IMAGE_MAGICK_MAJOR) -MESSAGE(STATUS "define IMAGE_MAGICK_MAJOR: " ${IMAGE_MAGICK_MAJOR}) -ADD_COMPILE_DEFINITIONS(IMAGE_MAGICK_MAJOR=${IMAGE_MAGICK_MAJOR}) -IF(${IMAGE_MAGICK_MAJOR} EQUAL 7) - LIST(APPEND ImageMagick_INCLUDE_DIRS "/usr/include/x86_64-linux-gnu/ImageMagick-7") +IF(NOT WITHOUT_IMAGEMAGICK) + FIND_PACKAGE(ImageMagick COMPONENTS MagickCore REQUIRED) + MESSAGE(STATUS "find ImageMagick: " ${ImageMagick_LIBRARIES}) + MESSAGE(STATUS "ImageMagick_VERSION_STRING: " ${ImageMagick_VERSION_STRING}) + STRING(SUBSTRING ${ImageMagick_VERSION_STRING} 0 1 IMAGE_MAGICK_MAJOR) + MESSAGE(STATUS "define IMAGE_MAGICK_MAJOR: " ${IMAGE_MAGICK_MAJOR}) + ADD_COMPILE_DEFINITIONS(IMAGE_MAGICK_MAJOR=${IMAGE_MAGICK_MAJOR}) + IF(${IMAGE_MAGICK_MAJOR} EQUAL 7) + LIST(APPEND ImageMagick_INCLUDE_DIRS "/usr/include/x86_64-linux-gnu/ImageMagick-7") + ENDIF() + MESSAGE(STATUS "ImageMagick_INCLUDE_DIRS: " ${ImageMagick_INCLUDE_DIRS}) ENDIF() -MESSAGE(STATUS "ImageMagick_INCLUDE_DIRS: " ${ImageMagick_INCLUDE_DIRS}) IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) SET(CMAKE_INSTALL_PREFIX "/" CACHE PATH "install prefix" FORCE) @@ -64,25 +69,36 @@ SET(SOURCES "kds_s2000w_handler.c" "kds_s2000w_handler_opts.c" "kds_s2000w_client.c" - "kds_s2000w_image_converter.c" "kds_s2000w_debug.c" "kds_s2000w_config.c" "kds_s2000w_heartbeat.c") +IF(NOT WITHOUT_IMAGEMAGICK) + LIST(APPEND SOURCES "kds_s2000w_image_converter_magick.c") +ELSE() + LIST(APPEND SOURCES "kds_s2000w_image_converter_netpbm.c") +ENDIF() + ADD_LIBRARY("sane-kds_s2000w_net" SHARED ${SOURCES}) SET_TARGET_PROPERTIES("sane-kds_s2000w_net" PROPERTIES VERSION 1) TARGET_INCLUDE_DIRECTORIES("sane-kds_s2000w_net" PRIVATE - ${CMAKE_CURRENT_BINARY_DIR} - ${ImageMagick_INCLUDE_DIRS}) + ${CMAKE_CURRENT_BINARY_DIR}) TARGET_LINK_LIBRARIES("sane-kds_s2000w_net" ${MATH} ${PTHREAD} ${CONFUSE} ${CURL_LIBRARY} - ${ImageMagick_LIBRARIES} json-c) +IF(NOT WITHOUT_IMAGEMAGICK) + TARGET_INCLUDE_DIRECTORIES("sane-kds_s2000w_net" + PRIVATE + ${ImageMagick_INCLUDE_DIRS}) + TARGET_LINK_LIBRARIES("sane-kds_s2000w_net" + ${ImageMagick_LIBRARIES}) +ENDIF() + ADD_LIBRARY("sane-kds_s2000w_net-static" STATIC ${SOURCES} @@ -90,16 +106,22 @@ ADD_LIBRARY("sane-kds_s2000w_net-static" SET_TARGET_PROPERTIES("sane-kds_s2000w_net-static" PROPERTIES OUTPUT_NAME "sane-kds_s2000w_net") TARGET_INCLUDE_DIRECTORIES("sane-kds_s2000w_net-static" PRIVATE - ${CMAKE_CURRENT_BINARY_DIR} - ${ImageMagick_INCLUDE_DIRS}) + ${CMAKE_CURRENT_BINARY_DIR}) TARGET_LINK_LIBRARIES("sane-kds_s2000w_net-static" ${MATH} ${PTHREAD} ${CONFUSE} ${CURL_LIBRARY} - ${ImageMagick_LIBRARIES} json-c) +IF(NOT WITHOUT_IMAGEMAGICK) + TARGET_INCLUDE_DIRECTORIES("sane-kds_s2000w_net-static" + PRIVATE + ${ImageMagick_INCLUDE_DIRS}) + TARGET_LINK_LIBRARIES("sane-kds_s2000w_net-static" + ${ImageMagick_LIBRARIES}) +ENDIF() + INSTALL(TARGETS "sane-kds_s2000w_net" "sane-kds_s2000w_net-static" DESTINATION ${CMAKE_LIBRARY_PATH}/sane) install(FILES "kds_s2000w_net.conf" diff --git a/src/kds_s2000w_image_converter.c b/src/kds_s2000w_image_converter.c deleted file mode 100644 index 2a35e46..0000000 --- a/src/kds_s2000w_image_converter.c +++ /dev/null @@ -1,108 +0,0 @@ -#define MAGICKCORE_QUANTUM_DEPTH 16 -#define MAGICKCORE_HDRI_ENABLE 0 - -#ifndef IMAGE_MAGICK_MAJOR -#define IMAGE_MAGICK_MAJOR 6 -#endif - -#if IMAGE_MAGICK_MAJOR == 6 -#include -#endif -#if IMAGE_MAGICK_MAJOR == 7 -#include -#endif -#include "kds_s2000w_image_converter.h" -#include "kds_s2000w_debug.h" - -void _kds_s2000w_image_converter_to_pnm_depth(blobdata* in, - blobdata* out, - int depth, - const char* format) -{ - kds_s2000w_debug_printf(ALL, "kds_s2000w_convert_to_pnm_With_depth"); - - ExceptionInfo* exception = AcquireExceptionInfo(); - ImageInfo* image_info = CloneImageInfo(NULL); - - sprintf(image_info->filename, "streamin.%s", format); - kds_s2000w_debug_printf(DEBUG, image_info->filename); - - Image* input_image = BlobToImage(image_info, in->data, in->size , exception); - - if (exception->severity != UndefinedException) { - kds_s2000w_debug_printf(ERROR, GetExceptionMessage(exception->error_number)); - CatchException(exception); - } - - if (input_image == NULL) { - DestroyImageInfo(image_info); - DestroyExceptionInfo(exception); - return; - } - - input_image->properties = NULL; - - DestroyImageInfo(image_info); - DestroyExceptionInfo(exception); - exception = AcquireExceptionInfo(); - image_info = CloneImageInfo(NULL); - sprintf(image_info->filename, "streamout.pnm"); - - if (depth > -1) -#if IMAGE_MAGICK_MAJOR == 6 - SetImageDepth(input_image, depth); -#endif -#if IMAGE_MAGICK_MAJOR == 7 - SetImageDepth(input_image, depth, exception); -#endif - - out->data = ImageToBlob(image_info, input_image, &out->size, exception); - - DestroyImageInfo(image_info); - image_info = NULL; - DestroyImage(input_image); - input_image = NULL; - DestroyExceptionInfo(exception); - exception = NULL; -} - -void kds_s2000w_image_converter_metadata_from_jpg(blobdata* image, image_metadata* mdata) -{ - kds_s2000w_debug_printf(ALL, "kds_s2000w_metadata_from_image"); - - ExceptionInfo* exception = AcquireExceptionInfo(); - ImageInfo* image_info = CloneImageInfo(NULL); - sprintf(image_info->filename, "image.pnm"); - - Image* input_image = BlobToImage(image_info, image->data, image->size , exception); - - if (exception->severity != UndefinedException) { - kds_s2000w_debug_printf(ERROR, GetExceptionMessage(exception->error_number)); - CatchException(exception); - } - - mdata->width = input_image->columns; - mdata->height = input_image->rows; - mdata->depth = input_image->depth; - - DestroyImageInfo(image_info); - image_info = NULL; - DestroyImage(input_image); - input_image = NULL; - DestroyExceptionInfo(exception); - exception = NULL; -} - -void kds_s2000w_image_converter_jpg_to_pnm(blobdata* in, blobdata* out, int depth) -{ - kds_s2000w_debug_printf(ALL, "kds_s2000w_convert_jpg_to_pnm_With_depth"); - - _kds_s2000w_image_converter_to_pnm_depth(in, out, depth, "jpg"); -} - -void kds_s2000w_image_converter_tiff_to_pnm(blobdata* in, blobdata* out) -{ - kds_s2000w_debug_printf(ALL, "kds_s2000w_convert_tiff_to_pnm"); - - _kds_s2000w_image_converter_to_pnm_depth(in, out, -1, "tiff"); -} \ No newline at end of file diff --git a/src/kds_s2000w_image_converter_magick.c b/src/kds_s2000w_image_converter_magick.c new file mode 100644 index 0000000..2a35e46 --- /dev/null +++ b/src/kds_s2000w_image_converter_magick.c @@ -0,0 +1,108 @@ +#define MAGICKCORE_QUANTUM_DEPTH 16 +#define MAGICKCORE_HDRI_ENABLE 0 + +#ifndef IMAGE_MAGICK_MAJOR +#define IMAGE_MAGICK_MAJOR 6 +#endif + +#if IMAGE_MAGICK_MAJOR == 6 +#include +#endif +#if IMAGE_MAGICK_MAJOR == 7 +#include +#endif +#include "kds_s2000w_image_converter.h" +#include "kds_s2000w_debug.h" + +void _kds_s2000w_image_converter_to_pnm_depth(blobdata* in, + blobdata* out, + int depth, + const char* format) +{ + kds_s2000w_debug_printf(ALL, "kds_s2000w_convert_to_pnm_With_depth"); + + ExceptionInfo* exception = AcquireExceptionInfo(); + ImageInfo* image_info = CloneImageInfo(NULL); + + sprintf(image_info->filename, "streamin.%s", format); + kds_s2000w_debug_printf(DEBUG, image_info->filename); + + Image* input_image = BlobToImage(image_info, in->data, in->size , exception); + + if (exception->severity != UndefinedException) { + kds_s2000w_debug_printf(ERROR, GetExceptionMessage(exception->error_number)); + CatchException(exception); + } + + if (input_image == NULL) { + DestroyImageInfo(image_info); + DestroyExceptionInfo(exception); + return; + } + + input_image->properties = NULL; + + DestroyImageInfo(image_info); + DestroyExceptionInfo(exception); + exception = AcquireExceptionInfo(); + image_info = CloneImageInfo(NULL); + sprintf(image_info->filename, "streamout.pnm"); + + if (depth > -1) +#if IMAGE_MAGICK_MAJOR == 6 + SetImageDepth(input_image, depth); +#endif +#if IMAGE_MAGICK_MAJOR == 7 + SetImageDepth(input_image, depth, exception); +#endif + + out->data = ImageToBlob(image_info, input_image, &out->size, exception); + + DestroyImageInfo(image_info); + image_info = NULL; + DestroyImage(input_image); + input_image = NULL; + DestroyExceptionInfo(exception); + exception = NULL; +} + +void kds_s2000w_image_converter_metadata_from_jpg(blobdata* image, image_metadata* mdata) +{ + kds_s2000w_debug_printf(ALL, "kds_s2000w_metadata_from_image"); + + ExceptionInfo* exception = AcquireExceptionInfo(); + ImageInfo* image_info = CloneImageInfo(NULL); + sprintf(image_info->filename, "image.pnm"); + + Image* input_image = BlobToImage(image_info, image->data, image->size , exception); + + if (exception->severity != UndefinedException) { + kds_s2000w_debug_printf(ERROR, GetExceptionMessage(exception->error_number)); + CatchException(exception); + } + + mdata->width = input_image->columns; + mdata->height = input_image->rows; + mdata->depth = input_image->depth; + + DestroyImageInfo(image_info); + image_info = NULL; + DestroyImage(input_image); + input_image = NULL; + DestroyExceptionInfo(exception); + exception = NULL; +} + +void kds_s2000w_image_converter_jpg_to_pnm(blobdata* in, blobdata* out, int depth) +{ + kds_s2000w_debug_printf(ALL, "kds_s2000w_convert_jpg_to_pnm_With_depth"); + + _kds_s2000w_image_converter_to_pnm_depth(in, out, depth, "jpg"); +} + +void kds_s2000w_image_converter_tiff_to_pnm(blobdata* in, blobdata* out) +{ + kds_s2000w_debug_printf(ALL, "kds_s2000w_convert_tiff_to_pnm"); + + _kds_s2000w_image_converter_to_pnm_depth(in, out, -1, "tiff"); +} \ No newline at end of file diff --git a/src/kds_s2000w_image_converter_netpbm.c b/src/kds_s2000w_image_converter_netpbm.c new file mode 100644 index 0000000..9ce1bbd --- /dev/null +++ b/src/kds_s2000w_image_converter_netpbm.c @@ -0,0 +1,16 @@ +#include "kds_s2000w_image_converter.h" + +void kds_s2000w_image_converter_metadata_from_jpg(blobdata* image, image_metadata* mdata) +{ + return; +} + +void kds_s2000w_image_converter_jpg_to_pnm(blobdata* in, blobdata* out, int depth) +{ + return; +} + +void kds_s2000w_image_converter_tiff_to_pnm(blobdata* in, blobdata* out) +{ + return; +}