From a8cfc6a26bfa89a6e3541d9cf0e1cdbf410fc201 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Thu, 3 Apr 2025 16:34:12 +0200 Subject: [PATCH] Move image lib to utils.cpp --- CMakeLists.txt | 7 ++++++- src/image.h | 19 +++++++++++++++++++ src/seam-carving.cpp | 6 ++---- src/utils.cpp | 5 +++++ 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 src/image.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 483fb68..674f775 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,4 +17,9 @@ target_include_directories(seam-carving PRIVATE ${PROJECT_SOURCE_DIR}/deps ) -target_link_libraries(seam-carving utils) \ No newline at end of file +target_link_libraries(seam-carving utils) + +target_include_directories(utils + PRIVATE + ${PROJECT_SOURCE_DIR}/deps +) \ No newline at end of file diff --git a/src/image.h b/src/image.h new file mode 100644 index 0000000..d123c54 --- /dev/null +++ b/src/image.h @@ -0,0 +1,19 @@ +#ifndef STBIDEF +#ifdef STB_IMAGE_WRITE_STATIC +#define STBIDEF static +#else +#ifdef __cplusplus +#define STBIDEF extern "C" +#else +#define STBIDEF extern +#endif +#endif +#endif + +typedef unsigned char stbi_uc; + +STBIDEF int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes); + +STBIDEF stbi_uc *stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp); + +STBIDEF void stbi_image_free (void *retval_from_stbi_load); diff --git a/src/seam-carving.cpp b/src/seam-carving.cpp index f28498e..c70701b 100644 --- a/src/seam-carving.cpp +++ b/src/seam-carving.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -6,12 +7,9 @@ #include // Image filtering and I/O -#define STB_IMAGE_IMPLEMENTATION -#include -#define STB_IMAGE_WRITE_IMPLEMENTATION #include -#include #include "utils.hpp" +#include "image.h" #define DEFAULT_SEAMS 1 diff --git a/src/utils.cpp b/src/utils.cpp index 3344a94..64ac8c8 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,3 +1,8 @@ +#define STB_IMAGE_IMPLEMENTATION +#include +#define STB_IMAGE_WRITE_IMPLEMENTATION +#include + #include #include #include