diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index fb3a7f968..9828a797d 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -3,11 +3,9 @@ { "name": "Mac", "includePath": [ - "${workspaceFolder}/**", + "${workspaceFolder}/packages/image-process/src/**", "/usr/local/include/**", - "${env:chaxus}/.conan2/p/b/libvic605da2cdc04b/b/build-release/libvips/include", - "${env:chaxus}/.conan2/p/b/libvic605da2cdc04b/b/src/libvips/include", - "${env:chaxus}/.conan2/p/libvi6bda2a423e65b/s/src/libvips/include" + "${env:chaxus}/.conan2/p/b/**" ], "defines": [], "macFrameworkPath": ["/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"], diff --git a/.vscode/settings.json b/.vscode/settings.json index c418b880d..bf0b7c11e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -104,7 +104,8 @@ "vips.h": "c", "stdio.h": "c", "gmodule.h": "c", - "glib.h": "c" + "glib.h": "c", + "image_processing.h": "c" }, "cmake.ignoreCMakeListsMissing": true } diff --git a/packages/image-process/CMakeLists.txt b/packages/image-process/CMakeLists.txt index 514bfdc49..ff41b4945 100644 --- a/packages/image-process/CMakeLists.txt +++ b/packages/image-process/CMakeLists.txt @@ -4,8 +4,11 @@ project(image-process) # Set directory for Conan's generated files set(CONAN_CMAKE_DIR ${CMAKE_BINARY_DIR}/conan) +# Glob all .c and .h files in the src directory +file(GLOB_RECURSE SOURCE_FILES src/*.c src/*.h) + # Add your project files -add_executable(image-process main.c) +add_executable(image-process main.c ${SOURCE_FILES}) # Find and link Conan dependencies find_package(libvips REQUIRED) diff --git a/packages/image-process/main.c b/packages/image-process/main.c index 872dcbc8e..a8d409caa 100644 --- a/packages/image-process/main.c +++ b/packages/image-process/main.c @@ -1,38 +1,19 @@ #include #include +#include "image_processing.h" -int -main(int argc, char **argv) -{ - VipsImage *in; - double mean; - VipsImage *out; - - if (VIPS_INIT(argv[0])) +int main(int argc, char **argv) { + if (VIPS_INIT(argv[0])) { vips_error_exit(NULL); + } - if (argc != 3) + if (argc != 3) { vips_error_exit("usage: %s infile outfile", argv[0]); + } - if (!(in = vips_image_new_from_file(argv[1], NULL))) - vips_error_exit(NULL); - - printf("image width = %d\n", vips_image_get_width(in)); - - if (vips_avg(in, &mean, NULL)) - vips_error_exit(NULL); - - printf("mean pixel value = %g\n", mean); - - if (vips_invert(in, &out, NULL)) - vips_error_exit(NULL); - - g_object_unref(in); - - if (vips_image_write_to_file(out, argv[2], NULL)) - vips_error_exit(NULL); - - g_object_unref(out); + if (process_image(argv[1], argv[2]) != 0) { + vips_error_exit("Failed to process image"); + } return 0; } diff --git a/packages/image-process/src/image_processing.c b/packages/image-process/src/image_processing.c new file mode 100644 index 000000000..445e979e1 --- /dev/null +++ b/packages/image-process/src/image_processing.c @@ -0,0 +1,43 @@ +// image_processing.c +#include +#include +#include "image_processing.h" + +int process_image(const char *infile, const char *outfile) { + VipsImage *in; + double mean; + VipsImage *out; + + if (!(in = vips_image_new_from_file(infile, NULL))) { + vips_error_exit(NULL); + return -1; + } + + printf("image width = %d\n", vips_image_get_width(in)); + + if (vips_avg(in, &mean, NULL)) { + vips_error_exit(NULL); + g_object_unref(in); + return -1; + } + + printf("mean pixel value = %g\n", mean); + + if (vips_invert(in, &out, NULL)) { + vips_error_exit(NULL); + g_object_unref(in); + return -1; + } + + g_object_unref(in); + + if (vips_image_write_to_file(out, outfile, NULL)) { + vips_error_exit(NULL); + g_object_unref(out); + return -1; + } + + g_object_unref(out); + + return 0; +} diff --git a/packages/image-process/src/image_processing.h b/packages/image-process/src/image_processing.h new file mode 100644 index 000000000..7fd89cb26 --- /dev/null +++ b/packages/image-process/src/image_processing.h @@ -0,0 +1,9 @@ +// image_processing.h +#ifndef IMAGE_PROCESSING_H +#define IMAGE_PROCESSING_H + +#include + +int process_image(const char *infile, const char *outfile); + +#endif // IMAGE_PROCESSING_H