From 308d526867f67aa4b09b2d67d69547cd57ebd0fe Mon Sep 17 00:00:00 2001 From: parker Date: Wed, 29 May 2024 01:30:38 -0700 Subject: [PATCH 01/27] Kam rev --- c/CMakeLists.txt | 9 +++++++++ c/f3d_c_api.c | 19 +++++++++++++++++++ c/f3d_c_api.h | 31 +++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 c/CMakeLists.txt create mode 100644 c/f3d_c_api.c create mode 100644 c/f3d_c_api.h diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt new file mode 100644 index 0000000000..8d5e5400dd --- /dev/null +++ b/c/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.21) + +project(f3d_c_api) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) + +add_library(f3d_c_api SHARED f3d_c_api.c) + +target_link_libraries(f3d_c_api PRIVATE f3d::libf3d) \ No newline at end of file diff --git a/c/f3d_c_api.c b/c/f3d_c_api.c new file mode 100644 index 0000000000..3009d6e5e2 --- /dev/null +++ b/c/f3d_c_api.c @@ -0,0 +1,19 @@ +// f3d_c_api.c +#include "f3d_c_api.h" +#include "image.h" + +struct f3d_image { + f3d::image img; +}; + +f3d_image_t* f3d_image_new(void) { + return new f3d_image_t(); +} + +void f3d_image_delete(f3d_image_t* img) { + delete img; +} + +void f3d_image_set_resolution(f3d_image_t* img, unsigned int width, unsigned int height) { + img->img.setResolution(width, height); +} diff --git a/c/f3d_c_api.h b/c/f3d_c_api.h new file mode 100644 index 0000000000..cd03012b6f --- /dev/null +++ b/c/f3d_c_api.h @@ -0,0 +1,31 @@ + +#ifndef F3D_C_API_H +#define F3D_C_API_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + float x; + float y; + float z; +} f3d_point3_t; + +typedef struct { + float x; + float y; + float z; +} f3d_vector3_t; + +typedef struct f3d_image f3d_image_t; + +f3d_image_t* f3d_image_new(void); +void f3d_image_delete(f3d_image_t* img); +void f3d_image_set_resolution(f3d_image_t* img, unsigned int width, unsigned int height); + +#ifdef __cplusplus +} +#endif + +#endif From 3c654e0fd8531cbab1ccd8022edcbbc45fae8650 Mon Sep 17 00:00:00 2001 From: parker Date: Thu, 30 May 2024 18:24:15 -0700 Subject: [PATCH 02/27] Moved dirs --- c/CMakeLists.txt | 9 --------- c/f3d_c_api.c | 19 ------------------- c/f3d_c_api.h | 31 ------------------------------- 3 files changed, 59 deletions(-) delete mode 100644 c/CMakeLists.txt delete mode 100644 c/f3d_c_api.c delete mode 100644 c/f3d_c_api.h diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt deleted file mode 100644 index 8d5e5400dd..0000000000 --- a/c/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -cmake_minimum_required(VERSION 3.21) - -project(f3d_c_api) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) - -add_library(f3d_c_api SHARED f3d_c_api.c) - -target_link_libraries(f3d_c_api PRIVATE f3d::libf3d) \ No newline at end of file diff --git a/c/f3d_c_api.c b/c/f3d_c_api.c deleted file mode 100644 index 3009d6e5e2..0000000000 --- a/c/f3d_c_api.c +++ /dev/null @@ -1,19 +0,0 @@ -// f3d_c_api.c -#include "f3d_c_api.h" -#include "image.h" - -struct f3d_image { - f3d::image img; -}; - -f3d_image_t* f3d_image_new(void) { - return new f3d_image_t(); -} - -void f3d_image_delete(f3d_image_t* img) { - delete img; -} - -void f3d_image_set_resolution(f3d_image_t* img, unsigned int width, unsigned int height) { - img->img.setResolution(width, height); -} diff --git a/c/f3d_c_api.h b/c/f3d_c_api.h deleted file mode 100644 index cd03012b6f..0000000000 --- a/c/f3d_c_api.h +++ /dev/null @@ -1,31 +0,0 @@ - -#ifndef F3D_C_API_H -#define F3D_C_API_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - float x; - float y; - float z; -} f3d_point3_t; - -typedef struct { - float x; - float y; - float z; -} f3d_vector3_t; - -typedef struct f3d_image f3d_image_t; - -f3d_image_t* f3d_image_new(void); -void f3d_image_delete(f3d_image_t* img); -void f3d_image_set_resolution(f3d_image_t* img, unsigned int width, unsigned int height); - -#ifdef __cplusplus -} -#endif - -#endif From 451ae18b41cc93bd86cef0e90df1599fd6e71d98 Mon Sep 17 00:00:00 2001 From: parker Date: Thu, 30 May 2024 18:25:39 -0700 Subject: [PATCH 03/27] Update c api --- library/public/image.h | 1 + library/public/image_c_api.h | 44 ++++++++++++++ library/src/image_c_api.c | 107 +++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 library/public/image_c_api.h create mode 100644 library/src/image_c_api.c diff --git a/library/public/image.h b/library/public/image.h index 3dcd593017..be6c509d25 100644 --- a/library/public/image.h +++ b/library/public/image.h @@ -3,6 +3,7 @@ #include "exception.h" #include "export.h" +#include "image_c_api.h" #include #include diff --git a/library/public/image_c_api.h b/library/public/image_c_api.h new file mode 100644 index 0000000000..a4c97fe8f9 --- /dev/null +++ b/library/public/image_c_api.h @@ -0,0 +1,44 @@ +#ifndef F3D_C_API_H +#define F3D_C_API_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + float x; + float y; + float z; +} f3d_point3_t; + +typedef struct { + float x; + float y; + float z; +} f3d_vector3_t; + +typedef struct f3d_image f3d_image_t; + +f3d_image_t* f3d_image_new(void); +void f3d_image_delete(f3d_image_t* img); +void f3d_image_set_resolution(f3d_image_t* img, unsigned int width, unsigned int height); +unsigned int f3d_image_get_width(f3d_image_t* img); +unsigned int f3d_image_get_height(f3d_image_t* img); +unsigned int f3d_image_get_channel_count(f3d_image_t* img); +unsigned int f3d_image_get_channel_type(f3d_image_t* img); +unsigned int f3d_image_get_channel_type_size(f3d_image_t* img); +void f3d_image_set_content(f3d_image_t* img, void* buffer); +void* f3d_image_get_content(f3d_image_t* img); +int f3d_image_compare(f3d_image_t* img, f3d_image_t* reference, double threshold, f3d_image_t* diff, double* error); +void f3d_image_save(f3d_image_t* img, const char* path, int format); +unsigned char* f3d_image_save_buffer(f3d_image_t* img, int format, unsigned int* size); +const char* f3d_image_to_terminal_text(f3d_image_t* img); +void f3d_image_set_metadata(f3d_image_t* img, const char* key, const char* value); +const char* f3d_image_get_metadata(f3d_image_t* img, const char* key); +char** f3d_image_all_metadata(f3d_image_t* img, unsigned int* count); + +#ifdef __cplusplus +} +#endif + +#endif // F3D_C_API_H diff --git a/library/src/image_c_api.c b/library/src/image_c_api.c new file mode 100644 index 0000000000..1c71345dad --- /dev/null +++ b/library/src/image_c_api.c @@ -0,0 +1,107 @@ +#include "image_c_api.h" +#include "image.h" + +struct f3d_image { + f3d::image img; +}; + +f3d_image_t* f3d_image_new(void) { + return new f3d_image_t(); +} + +void f3d_image_delete(f3d_image_t* img) { + delete img; +} + +void f3d_image_set_resolution(f3d_image_t* img, unsigned int width, unsigned int height) { + img->img.setResolution(width, height); +} + +unsigned int f3d_image_get_width(f3d_image_t* img) { + return img->img.getWidth(); +} + +unsigned int f3d_image_get_height(f3d_image_t* img) { + return img->img.getHeight(); +} + +unsigned int f3d_image_get_channel_count(f3d_image_t* img) { + return img->img.getChannelCount(); +} + +unsigned int f3d_image_get_channel_type(f3d_image_t* img) { + return static_cast(img->img.getChannelType()); +} + +unsigned int f3d_image_get_channel_type_size(f3d_image_t* img) { + return img->img.getChannelTypeSize(); +} + +void f3d_image_set_content(f3d_image_t* img, void* buffer) { + img->img.setContent(buffer); +} + +void* f3d_image_get_content(f3d_image_t* img) { + return img->img.getContent(); +} + +int f3d_image_compare(f3d_image_t* img, f3d_image_t* reference, double threshold, f3d_image_t* diff, double* error) { + return img->img.compare(reference->img, threshold, diff->img, *error); +} + +void f3d_image_save(f3d_image_t* img, const char* path, int format) { + f3d::image::SaveFormat save_format; + switch (format) { + case 0: + save_format = f3d::image::SaveFormat::PNG; + break; + case 1: + save_format = f3d::image::SaveFormat::JPG; + break; + case 2: + save_format = f3d::image::SaveFormat::TIF; + break; + case 3: + save_format = f3d::image::SaveFormat::BMP; + break; + default: + save_format = f3d::image::SaveFormat::PNG; // Default to PNG + break; + } + img->img.save(path, save_format); +} + +unsigned char* f3d_image_save_buffer(f3d_image_t* img, int format, unsigned int* size) { + std::vector buffer = img->img.saveBuffer(static_cast(format)); + unsigned char* c_buffer = new unsigned char[buffer.size()]; + std::copy(buffer.begin(), buffer.end(), c_buffer); + *size = buffer.size(); + return c_buffer; +} + +const char* f3d_image_to_terminal_text(f3d_image_t* img) { + static std::string result; + result = img->img.toTerminalText(); + return result.c_str(); +} + +void f3d_image_set_metadata(f3d_image_t* img, const char* key, const char* value) { + img->img.setMetadata(key, value); +} + +const char* f3d_image_get_metadata(f3d_image_t* img, const char* key) { + static std::string result; + result = img->img.getMetadata(key); + return result.c_str(); +} + +char** f3d_image_all_metadata(f3d_image_t* img, unsigned int* count) { + std::vector metadata_keys = img->img.allMetadata(); + *count = metadata_keys.size(); + char** keys = new char*[metadata_keys.size()]; + for (size_t i = 0; i < metadata_keys.size(); ++i) { + keys[i] = new char[metadata_keys[i].size() + 1]; + strcpy(keys[i], metadata_keys[i].c_str()); + } + return keys; +} From c6bb170a0ea470f4c53eedeb9bdc63839036fa72 Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Sat, 1 Jun 2024 18:59:26 -0700 Subject: [PATCH 04/27] Update C api --- library/public/image_c_api.h | 43 +++++++++++++++---------- library/src/image_c_api.c | 59 ++++++++++++++++++++++++++++++++++ library/testing/CMakeLists.txt | 29 +++++++++++++++++ 3 files changed, 114 insertions(+), 17 deletions(-) diff --git a/library/public/image_c_api.h b/library/public/image_c_api.h index a4c97fe8f9..8d0f164741 100644 --- a/library/public/image_c_api.h +++ b/library/public/image_c_api.h @@ -1,6 +1,8 @@ #ifndef F3D_C_API_H #define F3D_C_API_H +#include "export.h" // Ensure F3D_EXPORT is defined + #ifdef __cplusplus extern "C" { #endif @@ -19,23 +21,30 @@ typedef struct { typedef struct f3d_image f3d_image_t; -f3d_image_t* f3d_image_new(void); -void f3d_image_delete(f3d_image_t* img); -void f3d_image_set_resolution(f3d_image_t* img, unsigned int width, unsigned int height); -unsigned int f3d_image_get_width(f3d_image_t* img); -unsigned int f3d_image_get_height(f3d_image_t* img); -unsigned int f3d_image_get_channel_count(f3d_image_t* img); -unsigned int f3d_image_get_channel_type(f3d_image_t* img); -unsigned int f3d_image_get_channel_type_size(f3d_image_t* img); -void f3d_image_set_content(f3d_image_t* img, void* buffer); -void* f3d_image_get_content(f3d_image_t* img); -int f3d_image_compare(f3d_image_t* img, f3d_image_t* reference, double threshold, f3d_image_t* diff, double* error); -void f3d_image_save(f3d_image_t* img, const char* path, int format); -unsigned char* f3d_image_save_buffer(f3d_image_t* img, int format, unsigned int* size); -const char* f3d_image_to_terminal_text(f3d_image_t* img); -void f3d_image_set_metadata(f3d_image_t* img, const char* key, const char* value); -const char* f3d_image_get_metadata(f3d_image_t* img, const char* key); -char** f3d_image_all_metadata(f3d_image_t* img, unsigned int* count); +F3D_EXPORT f3d_image_t* f3d_image_new(void); +F3D_EXPORT void f3d_image_delete(f3d_image_t* img); +F3D_EXPORT void f3d_image_set_resolution(f3d_image_t* img, unsigned int width, unsigned int height); +F3D_EXPORT unsigned int f3d_image_get_width(f3d_image_t* img); +F3D_EXPORT unsigned int f3d_image_get_height(f3d_image_t* img); +F3D_EXPORT unsigned int f3d_image_get_channel_count(f3d_image_t* img); +F3D_EXPORT unsigned int f3d_image_get_channel_type(f3d_image_t* img); +F3D_EXPORT unsigned int f3d_image_get_channel_type_size(f3d_image_t* img); +F3D_EXPORT void f3d_image_set_content(f3d_image_t* img, void* buffer); +F3D_EXPORT void* f3d_image_get_content(f3d_image_t* img); +F3D_EXPORT int f3d_image_compare(f3d_image_t* img, f3d_image_t* reference, double threshold, f3d_image_t* diff, double* error); +F3D_EXPORT void f3d_image_save(f3d_image_t* img, const char* path, int format); +F3D_EXPORT unsigned char* f3d_image_save_buffer(f3d_image_t* img, int format, unsigned int* size); +F3D_EXPORT const char* f3d_image_to_terminal_text(f3d_image_t* img); +F3D_EXPORT void f3d_image_set_metadata(f3d_image_t* img, const char* key, const char* value); +F3D_EXPORT const char* f3d_image_get_metadata(f3d_image_t* img, const char* key); +F3D_EXPORT char** f3d_image_all_metadata(f3d_image_t* img, unsigned int* count); +F3D_EXPORT void f3d_image_free_metadata_keys(char** keys, unsigned int count); +F3D_EXPORT f3d_image_t* f3d_image_create_from_file(const char* path); +F3D_EXPORT f3d_image_t* f3d_image_create_with_params(unsigned int width, unsigned int height, unsigned int channelCount, unsigned int type); +F3D_EXPORT unsigned int f3d_image_get_supported_formats_count(); +F3D_EXPORT const char** f3d_image_get_supported_formats(); +F3D_EXPORT double* f3d_image_get_normalized_pixel(f3d_image_t* img, int x, int y, unsigned int* count); +F3D_EXPORT void f3d_image_free_normalized_pixel(double* pixel); #ifdef __cplusplus } diff --git a/library/src/image_c_api.c b/library/src/image_c_api.c index 1c71345dad..3815b360bb 100644 --- a/library/src/image_c_api.c +++ b/library/src/image_c_api.c @@ -1,5 +1,6 @@ #include "image_c_api.h" #include "image.h" +#include struct f3d_image { f3d::image img; @@ -105,3 +106,61 @@ char** f3d_image_all_metadata(f3d_image_t* img, unsigned int* count) { } return keys; } + +void f3d_image_free_metadata_keys(char** keys, unsigned int count) { + for (unsigned int i = 0; i < count; ++i) { + delete[] keys[i]; + } + delete[] keys; +} + +// Additional functions to match all functionalities from image.cxx +f3d_image_t* f3d_image_create_from_file(const char* path) { + return new f3d_image_t{ f3d::image(path) }; +} + +f3d_image_t* f3d_image_create_with_params(unsigned int width, unsigned int height, unsigned int channelCount, unsigned int type) { + f3d::image::ChannelType channel_type; + switch (type) { + case 0: + channel_type = f3d::image::ChannelType::BYTE; + break; + case 1: + channel_type = f3d::image::ChannelType::SHORT; + break; + case 2: + channel_type = f3d::image::ChannelType::FLOAT; + break; + default: + channel_type = f3d::image::ChannelType::BYTE; // Default to BYTE + break; + } + return new f3d_image_t{ f3d::image(width, height, channelCount, channel_type) }; +} + +unsigned int f3d_image_get_supported_formats_count() { + std::vector formats = f3d::image::getSupportedFormats(); + return formats.size(); +} + +const char** f3d_image_get_supported_formats() { + static std::vector formats = f3d::image::getSupportedFormats(); + static std::vector c_formats; + c_formats.clear(); + for (const auto& format : formats) { + c_formats.push_back(format.c_str()); + } + return c_formats.data(); +} + +double* f3d_image_get_normalized_pixel(f3d_image_t* img, int x, int y, unsigned int* count) { + std::vector pixel = img->img.getNormalizedPixel({x, y}); + *count = pixel.size(); + double* c_pixel = new double[pixel.size()]; + std::copy(pixel.begin(), pixel.end(), c_pixel); + return c_pixel; +} + +void f3d_image_free_normalized_pixel(double* pixel) { + delete[] pixel; +} diff --git a/library/testing/CMakeLists.txt b/library/testing/CMakeLists.txt index 37d0d5d07d..30770e3fd1 100644 --- a/library/testing/CMakeLists.txt +++ b/library/testing/CMakeLists.txt @@ -138,3 +138,32 @@ endif() # make sure the libf3d API is compatible with C++11 set_target_properties(libf3dSDKTests PROPERTIES CXX_STANDARD 11) + +# C API integration + +# Include the C API files +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) + +add_library(f3d_c_api SHARED f3d_c_api.c) + +target_link_libraries(f3d_c_api PRIVATE f3d::libf3d) + +# Ensure public headers are installed +install(FILES include/image_c_api.h DESTINATION include) + +# Add C test +add_executable(test_image_c_api f3d/library/testing/test_image_c_api.c) +target_link_libraries(test_image_c_api PRIVATE f3d_c_api) +add_test(NAME test_image_c_api COMMAND test_image_c_api) + +list(APPEND libf3dSDKTestsNoRender_list + test_image_c_api) + +foreach (test ${libf3dSDKTests_list}) + get_filename_component (TName ${test} NAME_WE) + add_test (NAME libf3d::${TName} COMMAND libf3dSDKTests ${TName} "${F3D_SOURCE_DIR}/testing/" "${CMAKE_BINARY_DIR}/Testing/Temporary/" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") + set_tests_properties(libf3d::${TName} PROPERTIES TIMEOUT 30) + if (NOT F3D_TESTING_ENABLE_RENDERING_TESTS AND NOT ${TName} IN_LIST libf3dSDKTestsNoRender_list) + set_tests_properties(libf3d::${TName} PROPERTIES DISABLED ON) + endif () +endforeach () From 8f6f136cf5c86b04bbf5956b8fae1fa368b7e0a4 Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Sat, 1 Jun 2024 19:34:59 -0700 Subject: [PATCH 05/27] Added C api to CMake --- library/CMakeLists.txt | 31 +++++++++++++++++++++++++++++++ library/testing/CMakeLists.txt | 31 +------------------------------ 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 5f46f3d01a..fc9292b62f 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -51,6 +51,7 @@ set(F3D_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/types.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/window_impl.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.c # Include the C API implementation ) # List of headers that will be installed @@ -69,6 +70,7 @@ set(F3D_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/public/types.h ${CMAKE_CURRENT_SOURCE_DIR}/public/utils.h ${CMAKE_CURRENT_SOURCE_DIR}/public/window.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/image_c_api.h # Include the C API header ) set(F3D_PLUGIN_HEADERS @@ -279,3 +281,32 @@ if(BUILD_SHARED_LIBS) EXCLUDE_FROM_ALL) endif() + +# C API integration + +# Include the C API files +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) + +add_library(f3d_c_api SHARED src/image_c_api.c) + +target_link_libraries(f3d_c_api PRIVATE f3d::libf3d) + +# Ensure public headers are installed +install(FILES include/image_c_api.h DESTINATION include) + +# Add C test +add_executable(test_image_c_api testing/test_image_c_api.c) +target_link_libraries(test_image_c_api PRIVATE f3d_c_api) +add_test(NAME test_image_c_api COMMAND test_image_c_api) + +list(APPEND libf3dSDKTestsNoRender_list + test_image_c_api) + +foreach (test ${libf3dSDKTests_list}) + get_filename_component (TName ${test} NAME_WE) + add_test (NAME libf3d::${TName} COMMAND libf3dSDKTests ${TName} "${F3D_SOURCE_DIR}/testing/" "${CMAKE_BINARY_DIR}/Testing/Temporary/" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") + set_tests_properties(libf3d::${TName} PROPERTIES TIMEOUT 30) + if (NOT F3D_TESTING_ENABLE_RENDERING_TESTS AND NOT ${TName} IN_LIST libf3dSDKTestsNoRender_list) + set_tests_properties(libf3d::${TName} PROPERTIES DISABLED ON) + endif () +endforeach () diff --git a/library/testing/CMakeLists.txt b/library/testing/CMakeLists.txt index 30770e3fd1..d6ea1fded0 100644 --- a/library/testing/CMakeLists.txt +++ b/library/testing/CMakeLists.txt @@ -137,33 +137,4 @@ if(Qt5_FOUND) endif() # make sure the libf3d API is compatible with C++11 -set_target_properties(libf3dSDKTests PROPERTIES CXX_STANDARD 11) - -# C API integration - -# Include the C API files -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) - -add_library(f3d_c_api SHARED f3d_c_api.c) - -target_link_libraries(f3d_c_api PRIVATE f3d::libf3d) - -# Ensure public headers are installed -install(FILES include/image_c_api.h DESTINATION include) - -# Add C test -add_executable(test_image_c_api f3d/library/testing/test_image_c_api.c) -target_link_libraries(test_image_c_api PRIVATE f3d_c_api) -add_test(NAME test_image_c_api COMMAND test_image_c_api) - -list(APPEND libf3dSDKTestsNoRender_list - test_image_c_api) - -foreach (test ${libf3dSDKTests_list}) - get_filename_component (TName ${test} NAME_WE) - add_test (NAME libf3d::${TName} COMMAND libf3dSDKTests ${TName} "${F3D_SOURCE_DIR}/testing/" "${CMAKE_BINARY_DIR}/Testing/Temporary/" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") - set_tests_properties(libf3d::${TName} PROPERTIES TIMEOUT 30) - if (NOT F3D_TESTING_ENABLE_RENDERING_TESTS AND NOT ${TName} IN_LIST libf3dSDKTestsNoRender_list) - set_tests_properties(libf3d::${TName} PROPERTIES DISABLED ON) - endif () -endforeach () +set_target_properties(libf3dSDKTests PROPERTIES CXX_STANDARD 11) \ No newline at end of file From 75e28156cc9d2d2d21e59cf94f7df15cf2b8a9ee Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Sat, 1 Jun 2024 19:43:22 -0700 Subject: [PATCH 06/27] Rm image_c_api.h from image.h --- library/CMakeLists.txt | 31 +------------------------------ library/public/image.h | 1 - 2 files changed, 1 insertion(+), 31 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index fc9292b62f..0a9f76fe11 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -280,33 +280,4 @@ if(BUILD_SHARED_LIBS) COMPONENT plugin_sdk EXCLUDE_FROM_ALL) -endif() - -# C API integration - -# Include the C API files -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) - -add_library(f3d_c_api SHARED src/image_c_api.c) - -target_link_libraries(f3d_c_api PRIVATE f3d::libf3d) - -# Ensure public headers are installed -install(FILES include/image_c_api.h DESTINATION include) - -# Add C test -add_executable(test_image_c_api testing/test_image_c_api.c) -target_link_libraries(test_image_c_api PRIVATE f3d_c_api) -add_test(NAME test_image_c_api COMMAND test_image_c_api) - -list(APPEND libf3dSDKTestsNoRender_list - test_image_c_api) - -foreach (test ${libf3dSDKTests_list}) - get_filename_component (TName ${test} NAME_WE) - add_test (NAME libf3d::${TName} COMMAND libf3dSDKTests ${TName} "${F3D_SOURCE_DIR}/testing/" "${CMAKE_BINARY_DIR}/Testing/Temporary/" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") - set_tests_properties(libf3d::${TName} PROPERTIES TIMEOUT 30) - if (NOT F3D_TESTING_ENABLE_RENDERING_TESTS AND NOT ${TName} IN_LIST libf3dSDKTestsNoRender_list) - set_tests_properties(libf3d::${TName} PROPERTIES DISABLED ON) - endif () -endforeach () +endif() \ No newline at end of file diff --git a/library/public/image.h b/library/public/image.h index be6c509d25..3dcd593017 100644 --- a/library/public/image.h +++ b/library/public/image.h @@ -3,7 +3,6 @@ #include "exception.h" #include "export.h" -#include "image_c_api.h" #include #include From 86d10edb90bd43adc6f5c7f4fc457f8220ee54dc Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Sat, 1 Jun 2024 20:40:36 -0700 Subject: [PATCH 07/27] Create test_image_c_api.c --- library/testing/test_image_c_api.c | 97 ++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 library/testing/test_image_c_api.c diff --git a/library/testing/test_image_c_api.c b/library/testing/test_image_c_api.c new file mode 100644 index 0000000000..e3def48a02 --- /dev/null +++ b/library/testing/test_image_c_api.c @@ -0,0 +1,97 @@ +#include +#include +#include +#include + +int main() { + + f3d_image_t* img = f3d_image_new(); + + f3d_image_set_resolution(img, 800, 600); + printf("Image resolution set to 800x600.\n"); + + unsigned int width = f3d_image_get_width(img); + unsigned int height = f3d_image_get_height(img); + printf("Image width: %u, height: %u\n", width, height); + + unsigned int channels = f3d_image_get_channel_count(img); + printf("Image channel count: %u\n", channels); + + size_t buffer_size = width * height * channels; + unsigned char* buffer = (unsigned char*)malloc(buffer_size); + if (!buffer) { + printf("Failed to allocate buffer.\n"); + f3d_image_delete(img); + return 1; + } + memset(buffer, 255, buffer_size); // Set all pixels to white + f3d_image_set_content(img, buffer); + printf("Image content set to white.\n"); + + f3d_image_save(img, "output.png", 0); + printf("Image saved as output.png\n"); + + // Save image to buffer + unsigned int size; + unsigned char* save_buffer = f3d_image_save_buffer(img, 0, &size); + if (save_buffer) { + printf("Image saved to buffer, size: %u bytes.\n", size); + free(save_buffer); + } else { + printf("Failed to save image to buffer.\n"); + } + + // Set metadata + f3d_image_set_metadata(img, "Author", "TestUser"); + printf("Metadata 'Author' set to 'TestUser'.\n"); + + // Get metadata + const char* author = f3d_image_get_metadata(img, "Author"); + if (author) { + printf("Metadata 'Author': %s\n", author); + } else { + printf("Failed to get metadata 'Author'.\n"); + } + + // List all metadata + unsigned int count; + char** metadata_keys = f3d_image_all_metadata(img, &count); + if (metadata_keys) { + printf("Metadata keys (%u):\n", count); + for (unsigned int i = 0; i < count; ++i) { + printf(" %s\n", metadata_keys[i]); + free(metadata_keys[i]); + } + free(metadata_keys); + } else { + printf("Failed to list metadata keys.\n"); + } + + // Create a reference image for comparison + f3d_image_t* ref_img = f3d_image_new(); + if (ref_img) { + f3d_image_set_resolution(ref_img, 800, 600); + f3d_image_set_content(ref_img, buffer); + + // Compare images + double error; + f3d_image_t* diff_img = f3d_image_new(); + int result = f3d_image_compare(img, ref_img, 0.0, diff_img, &error); + if (result == 0) { + printf("Images are identical.\n"); + } else { + printf("Images differ with error: %f\n", error); + } + + f3d_image_delete(diff_img); + f3d_image_delete(ref_img); + } else { + printf("Failed to create reference image.\n"); + } + + // Clean up + free(buffer); + f3d_image_delete(img); + + return 0; +} From 131fa4220b566b400a3149eafe424b1e0fe37483 Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Sun, 2 Jun 2024 14:08:28 -0700 Subject: [PATCH 08/27] Fix CI --- library/CMakeLists.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 0a9f76fe11..76f5bef6c5 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -91,6 +91,7 @@ target_include_directories(libf3d $ $ $ + $ # Include the C API header directory ) if (F3D_USE_EXTERNAL_NLOHMANN_JSON) target_link_libraries(libf3d PRIVATE nlohmann_json::nlohmann_json) @@ -191,6 +192,15 @@ if(UNIX AND NOT APPLE) endif() endif() +# C API integration +add_library(f3d_c_api SHARED ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.c) +target_link_libraries(f3d_c_api PRIVATE libf3d) +target_include_directories(f3d_c_api + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/public + ${CMAKE_CURRENT_SOURCE_DIR}/include +) + # Testing if(BUILD_TESTING) add_subdirectory(testing) @@ -280,4 +290,4 @@ if(BUILD_SHARED_LIBS) COMPONENT plugin_sdk EXCLUDE_FROM_ALL) -endif() \ No newline at end of file +endif() From 49f9dca5aa97c289dbc19f3970cb748664236a2c Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Sun, 2 Jun 2024 14:17:57 -0700 Subject: [PATCH 09/27] Fix web assembly --- library/CMakeLists.txt | 48 ++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 76f5bef6c5..825f0c4d34 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -51,8 +51,13 @@ set(F3D_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/types.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/window_impl.cxx - ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.c # Include the C API implementation +) + +if(NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + list(APPEND F3D_SOURCE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.c # Include the C API implementation ) +endif() # List of headers that will be installed set(F3D_PUBLIC_HEADERS @@ -70,17 +75,22 @@ set(F3D_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/public/types.h ${CMAKE_CURRENT_SOURCE_DIR}/public/utils.h ${CMAKE_CURRENT_SOURCE_DIR}/public/window.h - ${CMAKE_CURRENT_SOURCE_DIR}/include/image_c_api.h # Include the C API header +) + +if(NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + list(APPEND F3D_PUBLIC_HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/include/image_c_api.h # Include the C API header ) +endif() set(F3D_PLUGIN_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/plugin/reader.h ${CMAKE_CURRENT_SOURCE_DIR}/plugin/plugin.h - ) +) add_library(libf3d ${F3D_SOURCE_FILES} - ) +) target_include_directories(libf3d PUBLIC @@ -92,7 +102,8 @@ target_include_directories(libf3d $ $ $ # Include the C API header directory - ) +) + if (F3D_USE_EXTERNAL_NLOHMANN_JSON) target_link_libraries(libf3d PRIVATE nlohmann_json::nlohmann_json) else () @@ -110,7 +121,7 @@ set_target_properties(libf3d PROPERTIES POSITION_INDEPENDENT_CODE ON OUTPUT_NAME "f3d" PDB_NAME "libf3d" - ) +) # It can be useful to disable soversion in case the links are duplicated # It happens with Python wheels for example @@ -137,7 +148,7 @@ generate_export_header(libf3d target_include_directories(libf3d INTERFACE $ - ) +) vtk_module_autoinit(TARGETS libf3d MODULES ${F3D_VTK_MODULES}) @@ -192,14 +203,23 @@ if(UNIX AND NOT APPLE) endif() endif() +# WebAssembly specific settings +if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + set_target_properties(libf3d PROPERTIES + LINK_FLAGS "--bind" + ) +endif() + # C API integration -add_library(f3d_c_api SHARED ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.c) -target_link_libraries(f3d_c_api PRIVATE libf3d) -target_include_directories(f3d_c_api - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/public - ${CMAKE_CURRENT_SOURCE_DIR}/include -) +if(NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + add_library(f3d_c_api SHARED ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.c) + target_link_libraries(f3d_c_api PRIVATE libf3d) + target_include_directories(f3d_c_api + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/public + ${CMAKE_CURRENT_SOURCE_DIR}/include + ) +endif() # Testing if(BUILD_TESTING) From 290232d7d32196f4fdbbd7909372de9599604f1a Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Sun, 2 Jun 2024 19:44:41 -0700 Subject: [PATCH 10/27] Update CMakeLists.txt --- library/CMakeLists.txt | 44 ++++++------------------------------------ 1 file changed, 6 insertions(+), 38 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 825f0c4d34..83eb92e0af 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -51,13 +51,7 @@ set(F3D_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/types.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/window_impl.cxx -) - -if(NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") - list(APPEND F3D_SOURCE_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.c # Include the C API implementation ) -endif() # List of headers that will be installed set(F3D_PUBLIC_HEADERS @@ -75,22 +69,16 @@ set(F3D_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/public/types.h ${CMAKE_CURRENT_SOURCE_DIR}/public/utils.h ${CMAKE_CURRENT_SOURCE_DIR}/public/window.h -) - -if(NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") - list(APPEND F3D_PUBLIC_HEADERS - ${CMAKE_CURRENT_SOURCE_DIR}/include/image_c_api.h # Include the C API header ) -endif() set(F3D_PLUGIN_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/plugin/reader.h ${CMAKE_CURRENT_SOURCE_DIR}/plugin/plugin.h -) + ) add_library(libf3d ${F3D_SOURCE_FILES} -) + ) target_include_directories(libf3d PUBLIC @@ -101,9 +89,7 @@ target_include_directories(libf3d $ $ $ - $ # Include the C API header directory -) - + ) if (F3D_USE_EXTERNAL_NLOHMANN_JSON) target_link_libraries(libf3d PRIVATE nlohmann_json::nlohmann_json) else () @@ -121,7 +107,7 @@ set_target_properties(libf3d PROPERTIES POSITION_INDEPENDENT_CODE ON OUTPUT_NAME "f3d" PDB_NAME "libf3d" -) + ) # It can be useful to disable soversion in case the links are duplicated # It happens with Python wheels for example @@ -148,7 +134,7 @@ generate_export_header(libf3d target_include_directories(libf3d INTERFACE $ -) + ) vtk_module_autoinit(TARGETS libf3d MODULES ${F3D_VTK_MODULES}) @@ -203,24 +189,6 @@ if(UNIX AND NOT APPLE) endif() endif() -# WebAssembly specific settings -if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten") - set_target_properties(libf3d PROPERTIES - LINK_FLAGS "--bind" - ) -endif() - -# C API integration -if(NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") - add_library(f3d_c_api SHARED ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.c) - target_link_libraries(f3d_c_api PRIVATE libf3d) - target_include_directories(f3d_c_api - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/public - ${CMAKE_CURRENT_SOURCE_DIR}/include - ) -endif() - # Testing if(BUILD_TESTING) add_subdirectory(testing) @@ -310,4 +278,4 @@ if(BUILD_SHARED_LIBS) COMPONENT plugin_sdk EXCLUDE_FROM_ALL) -endif() +endif() \ No newline at end of file From 00e0f0e417a5854a149ac21eec41f862f05fe668 Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Sun, 2 Jun 2024 20:38:03 -0700 Subject: [PATCH 11/27] Added c bindings to cmakelists --- library/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 83eb92e0af..438676826f 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -51,6 +51,7 @@ set(F3D_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/types.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/window_impl.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.c # Add this line ) # List of headers that will be installed @@ -89,6 +90,7 @@ target_include_directories(libf3d $ $ $ + $ # Add this line ) if (F3D_USE_EXTERNAL_NLOHMANN_JSON) target_link_libraries(libf3d PRIVATE nlohmann_json::nlohmann_json) @@ -278,4 +280,4 @@ if(BUILD_SHARED_LIBS) COMPONENT plugin_sdk EXCLUDE_FROM_ALL) -endif() \ No newline at end of file +endif() From f619e12fe7631a80c9cc4ab9eb15e6c9142050e7 Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Sun, 2 Jun 2024 20:45:46 -0700 Subject: [PATCH 12/27] Added header --- library/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 438676826f..150a6db498 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -51,7 +51,7 @@ set(F3D_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/types.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/window_impl.cxx - ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.c # Add this line + ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.c ) # List of headers that will be installed @@ -70,6 +70,7 @@ set(F3D_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/public/types.h ${CMAKE_CURRENT_SOURCE_DIR}/public/utils.h ${CMAKE_CURRENT_SOURCE_DIR}/public/window.h + ${CMAKE_CURRENT_SOURCE_DIR}/public/image_c_api.h ) set(F3D_PLUGIN_HEADERS @@ -90,7 +91,6 @@ target_include_directories(libf3d $ $ $ - $ # Add this line ) if (F3D_USE_EXTERNAL_NLOHMANN_JSON) target_link_libraries(libf3d PRIVATE nlohmann_json::nlohmann_json) From 6d967aee154ed2e45929b20413d96817bc3ac13c Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Sun, 2 Jun 2024 20:52:02 -0700 Subject: [PATCH 13/27] Rm c from CMakeLists --- library/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 150a6db498..5f46f3d01a 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -51,7 +51,6 @@ set(F3D_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/types.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/window_impl.cxx - ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.c ) # List of headers that will be installed @@ -70,7 +69,6 @@ set(F3D_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/public/types.h ${CMAKE_CURRENT_SOURCE_DIR}/public/utils.h ${CMAKE_CURRENT_SOURCE_DIR}/public/window.h - ${CMAKE_CURRENT_SOURCE_DIR}/public/image_c_api.h ) set(F3D_PLUGIN_HEADERS From 4e691dbe6c5203c5a39c7c279471ff93c766d76f Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Mon, 3 Jun 2024 19:40:33 -0700 Subject: [PATCH 14/27] Added comments to image_c_api.h --- library/public/image_c_api.h | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/library/public/image_c_api.h b/library/public/image_c_api.h index 8d0f164741..d18912769b 100644 --- a/library/public/image_c_api.h +++ b/library/public/image_c_api.h @@ -7,43 +7,93 @@ extern "C" { #endif +// Structure representing a 3D point typedef struct { float x; float y; float z; } f3d_point3_t; +// Structure representing a 3D vector typedef struct { float x; float y; float z; } f3d_vector3_t; +// Forward declaration of the f3d_image structure typedef struct f3d_image f3d_image_t; +// Function to create a new image object F3D_EXPORT f3d_image_t* f3d_image_new(void); + +// Function to delete an image object F3D_EXPORT void f3d_image_delete(f3d_image_t* img); + +// Function to set the resolution of an image F3D_EXPORT void f3d_image_set_resolution(f3d_image_t* img, unsigned int width, unsigned int height); + +// Function to get the width of an image F3D_EXPORT unsigned int f3d_image_get_width(f3d_image_t* img); + +// Function to get the height of an image F3D_EXPORT unsigned int f3d_image_get_height(f3d_image_t* img); + +// Function to get the number of channels in an image F3D_EXPORT unsigned int f3d_image_get_channel_count(f3d_image_t* img); + +// Function to get the type of channels in an image F3D_EXPORT unsigned int f3d_image_get_channel_type(f3d_image_t* img); + +// Function to get the size of the channel type in an image F3D_EXPORT unsigned int f3d_image_get_channel_type_size(f3d_image_t* img); + +// Function to set the content of an image from a buffer F3D_EXPORT void f3d_image_set_content(f3d_image_t* img, void* buffer); + +// Function to get the content of an image as a buffer F3D_EXPORT void* f3d_image_get_content(f3d_image_t* img); + +// Function to compare two images and return the difference F3D_EXPORT int f3d_image_compare(f3d_image_t* img, f3d_image_t* reference, double threshold, f3d_image_t* diff, double* error); + +// Function to save an image to a file F3D_EXPORT void f3d_image_save(f3d_image_t* img, const char* path, int format); + +// Function to save an image to a buffer F3D_EXPORT unsigned char* f3d_image_save_buffer(f3d_image_t* img, int format, unsigned int* size); + +// Function to convert an image to a string representation for terminal output F3D_EXPORT const char* f3d_image_to_terminal_text(f3d_image_t* img); + +// Function to set metadata for an image F3D_EXPORT void f3d_image_set_metadata(f3d_image_t* img, const char* key, const char* value); + +// Function to get metadata from an image F3D_EXPORT const char* f3d_image_get_metadata(f3d_image_t* img, const char* key); + +// Function to get all metadata keys from an image F3D_EXPORT char** f3d_image_all_metadata(f3d_image_t* img, unsigned int* count); + +// Function to free metadata keys obtained from an image F3D_EXPORT void f3d_image_free_metadata_keys(char** keys, unsigned int count); + +// Function to create an image from a file F3D_EXPORT f3d_image_t* f3d_image_create_from_file(const char* path); + +// Function to create an image with specified parameters F3D_EXPORT f3d_image_t* f3d_image_create_with_params(unsigned int width, unsigned int height, unsigned int channelCount, unsigned int type); + +// Function to get the count of supported image formats F3D_EXPORT unsigned int f3d_image_get_supported_formats_count(); + +// Function to get the list of supported image formats F3D_EXPORT const char** f3d_image_get_supported_formats(); + +// Function to get a normalized pixel value from an image F3D_EXPORT double* f3d_image_get_normalized_pixel(f3d_image_t* img, int x, int y, unsigned int* count); + +// Function to free a normalized pixel value obtained from an image F3D_EXPORT void f3d_image_free_normalized_pixel(double* pixel); #ifdef __cplusplus From 9189fd3460fc1659638ece20d054272fabf8b28c Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Mon, 3 Jun 2024 19:44:09 -0700 Subject: [PATCH 15/27] Make comments multi line comments --- library/public/image_c_api.h | 54 ++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/library/public/image_c_api.h b/library/public/image_c_api.h index d18912769b..41a6d434fd 100644 --- a/library/public/image_c_api.h +++ b/library/public/image_c_api.h @@ -7,93 +7,93 @@ extern "C" { #endif -// Structure representing a 3D point +/* Structure representing a 3D point */ typedef struct { float x; float y; float z; } f3d_point3_t; -// Structure representing a 3D vector +/* Structure representing a 3D vector */ typedef struct { float x; float y; float z; } f3d_vector3_t; -// Forward declaration of the f3d_image structure +/* Forward declaration of the f3d_image structure */ typedef struct f3d_image f3d_image_t; -// Function to create a new image object +/* Function to create a new image object */ F3D_EXPORT f3d_image_t* f3d_image_new(void); -// Function to delete an image object +/* Function to delete an image object */ F3D_EXPORT void f3d_image_delete(f3d_image_t* img); -// Function to set the resolution of an image +/* Function to set the resolution of an image */ F3D_EXPORT void f3d_image_set_resolution(f3d_image_t* img, unsigned int width, unsigned int height); -// Function to get the width of an image +/* Function to get the width of an image */ F3D_EXPORT unsigned int f3d_image_get_width(f3d_image_t* img); -// Function to get the height of an image +/* Function to get the height of an image */ F3D_EXPORT unsigned int f3d_image_get_height(f3d_image_t* img); -// Function to get the number of channels in an image +/* Function to get the number of channels in an image */ F3D_EXPORT unsigned int f3d_image_get_channel_count(f3d_image_t* img); -// Function to get the type of channels in an image +/* Function to get the type of channels in an image */ F3D_EXPORT unsigned int f3d_image_get_channel_type(f3d_image_t* img); -// Function to get the size of the channel type in an image +/* Function to get the size of the channel type in an image */ F3D_EXPORT unsigned int f3d_image_get_channel_type_size(f3d_image_t* img); -// Function to set the content of an image from a buffer +/* Function to set the content of an image from a buffer */ F3D_EXPORT void f3d_image_set_content(f3d_image_t* img, void* buffer); -// Function to get the content of an image as a buffer +/* Function to get the content of an image as a buffer */ F3D_EXPORT void* f3d_image_get_content(f3d_image_t* img); -// Function to compare two images and return the difference +/* Function to compare two images and return the difference */ F3D_EXPORT int f3d_image_compare(f3d_image_t* img, f3d_image_t* reference, double threshold, f3d_image_t* diff, double* error); -// Function to save an image to a file +/* Function to save an image to a file */ F3D_EXPORT void f3d_image_save(f3d_image_t* img, const char* path, int format); -// Function to save an image to a buffer +/* Function to save an image to a buffer */ F3D_EXPORT unsigned char* f3d_image_save_buffer(f3d_image_t* img, int format, unsigned int* size); -// Function to convert an image to a string representation for terminal output +/* Function to convert an image to a string representation for terminal output */ F3D_EXPORT const char* f3d_image_to_terminal_text(f3d_image_t* img); -// Function to set metadata for an image +/* Function to set metadata for an image */ F3D_EXPORT void f3d_image_set_metadata(f3d_image_t* img, const char* key, const char* value); -// Function to get metadata from an image +/* Function to get metadata from an image */ F3D_EXPORT const char* f3d_image_get_metadata(f3d_image_t* img, const char* key); -// Function to get all metadata keys from an image +/* Function to get all metadata keys from an image */ F3D_EXPORT char** f3d_image_all_metadata(f3d_image_t* img, unsigned int* count); -// Function to free metadata keys obtained from an image +/* Function to free metadata keys obtained from an image */ F3D_EXPORT void f3d_image_free_metadata_keys(char** keys, unsigned int count); -// Function to create an image from a file +/* Function to create an image from a file */ F3D_EXPORT f3d_image_t* f3d_image_create_from_file(const char* path); -// Function to create an image with specified parameters +/* Function to create an image with specified parameters */ F3D_EXPORT f3d_image_t* f3d_image_create_with_params(unsigned int width, unsigned int height, unsigned int channelCount, unsigned int type); -// Function to get the count of supported image formats +/* Function to get the count of supported image formats */ F3D_EXPORT unsigned int f3d_image_get_supported_formats_count(); -// Function to get the list of supported image formats +/* Function to get the list of supported image formats */ F3D_EXPORT const char** f3d_image_get_supported_formats(); -// Function to get a normalized pixel value from an image +/* Function to get a normalized pixel value from an image */ F3D_EXPORT double* f3d_image_get_normalized_pixel(f3d_image_t* img, int x, int y, unsigned int* count); -// Function to free a normalized pixel value obtained from an image +/* Function to free a normalized pixel value obtained from an image */ F3D_EXPORT void f3d_image_free_normalized_pixel(double* pixel); #ifdef __cplusplus From 223e3738191cd3bf894d93d06d7ac1ffe535572a Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Mon, 3 Jun 2024 20:04:43 -0700 Subject: [PATCH 16/27] Add C to CMakeLists.txt --- library/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 5f46f3d01a..b450d55043 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -51,6 +51,7 @@ set(F3D_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/types.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/window_impl.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.c ) # List of headers that will be installed @@ -69,6 +70,7 @@ set(F3D_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/public/types.h ${CMAKE_CURRENT_SOURCE_DIR}/public/utils.h ${CMAKE_CURRENT_SOURCE_DIR}/public/window.h + ${CMAKE_CURRENT_SOURCE_DIR}/public/image_c_api.h ) set(F3D_PLUGIN_HEADERS @@ -89,6 +91,7 @@ target_include_directories(libf3d $ $ $ + $ ) if (F3D_USE_EXTERNAL_NLOHMANN_JSON) target_link_libraries(libf3d PRIVATE nlohmann_json::nlohmann_json) From 0b35e91b819f0cb39a54c1960831e5ef9ea0f340 Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Mon, 3 Jun 2024 20:32:07 -0700 Subject: [PATCH 17/27] Rm C --- library/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index b450d55043..5172fea3e3 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -51,7 +51,6 @@ set(F3D_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/types.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/window_impl.cxx - ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.c ) # List of headers that will be installed @@ -70,7 +69,6 @@ set(F3D_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/public/types.h ${CMAKE_CURRENT_SOURCE_DIR}/public/utils.h ${CMAKE_CURRENT_SOURCE_DIR}/public/window.h - ${CMAKE_CURRENT_SOURCE_DIR}/public/image_c_api.h ) set(F3D_PLUGIN_HEADERS From 20039ada4104bf9a17516b9b2c8b20927678be57 Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Tue, 4 Jun 2024 19:23:08 -0700 Subject: [PATCH 18/27] Update c api file to cxx file --- library/src/{image_c_api.c => image_c_api.cxx} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename library/src/{image_c_api.c => image_c_api.cxx} (100%) diff --git a/library/src/image_c_api.c b/library/src/image_c_api.cxx similarity index 100% rename from library/src/image_c_api.c rename to library/src/image_c_api.cxx From 7f023aef52b3991404937720e15dcf8b2c7db031 Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Tue, 4 Jun 2024 19:23:32 -0700 Subject: [PATCH 19/27] Update comment styling --- library/src/image_c_api.cxx | 386 ++++++++++++++++++++---------------- 1 file changed, 220 insertions(+), 166 deletions(-) diff --git a/library/src/image_c_api.cxx b/library/src/image_c_api.cxx index 3815b360bb..e8b5236ee2 100644 --- a/library/src/image_c_api.cxx +++ b/library/src/image_c_api.cxx @@ -1,166 +1,220 @@ -#include "image_c_api.h" -#include "image.h" -#include - -struct f3d_image { - f3d::image img; -}; - -f3d_image_t* f3d_image_new(void) { - return new f3d_image_t(); -} - -void f3d_image_delete(f3d_image_t* img) { - delete img; -} - -void f3d_image_set_resolution(f3d_image_t* img, unsigned int width, unsigned int height) { - img->img.setResolution(width, height); -} - -unsigned int f3d_image_get_width(f3d_image_t* img) { - return img->img.getWidth(); -} - -unsigned int f3d_image_get_height(f3d_image_t* img) { - return img->img.getHeight(); -} - -unsigned int f3d_image_get_channel_count(f3d_image_t* img) { - return img->img.getChannelCount(); -} - -unsigned int f3d_image_get_channel_type(f3d_image_t* img) { - return static_cast(img->img.getChannelType()); -} - -unsigned int f3d_image_get_channel_type_size(f3d_image_t* img) { - return img->img.getChannelTypeSize(); -} - -void f3d_image_set_content(f3d_image_t* img, void* buffer) { - img->img.setContent(buffer); -} - -void* f3d_image_get_content(f3d_image_t* img) { - return img->img.getContent(); -} - -int f3d_image_compare(f3d_image_t* img, f3d_image_t* reference, double threshold, f3d_image_t* diff, double* error) { - return img->img.compare(reference->img, threshold, diff->img, *error); -} - -void f3d_image_save(f3d_image_t* img, const char* path, int format) { - f3d::image::SaveFormat save_format; - switch (format) { - case 0: - save_format = f3d::image::SaveFormat::PNG; - break; - case 1: - save_format = f3d::image::SaveFormat::JPG; - break; - case 2: - save_format = f3d::image::SaveFormat::TIF; - break; - case 3: - save_format = f3d::image::SaveFormat::BMP; - break; - default: - save_format = f3d::image::SaveFormat::PNG; // Default to PNG - break; - } - img->img.save(path, save_format); -} - -unsigned char* f3d_image_save_buffer(f3d_image_t* img, int format, unsigned int* size) { - std::vector buffer = img->img.saveBuffer(static_cast(format)); - unsigned char* c_buffer = new unsigned char[buffer.size()]; - std::copy(buffer.begin(), buffer.end(), c_buffer); - *size = buffer.size(); - return c_buffer; -} - -const char* f3d_image_to_terminal_text(f3d_image_t* img) { - static std::string result; - result = img->img.toTerminalText(); - return result.c_str(); -} - -void f3d_image_set_metadata(f3d_image_t* img, const char* key, const char* value) { - img->img.setMetadata(key, value); -} - -const char* f3d_image_get_metadata(f3d_image_t* img, const char* key) { - static std::string result; - result = img->img.getMetadata(key); - return result.c_str(); -} - -char** f3d_image_all_metadata(f3d_image_t* img, unsigned int* count) { - std::vector metadata_keys = img->img.allMetadata(); - *count = metadata_keys.size(); - char** keys = new char*[metadata_keys.size()]; - for (size_t i = 0; i < metadata_keys.size(); ++i) { - keys[i] = new char[metadata_keys[i].size() + 1]; - strcpy(keys[i], metadata_keys[i].c_str()); - } - return keys; -} - -void f3d_image_free_metadata_keys(char** keys, unsigned int count) { - for (unsigned int i = 0; i < count; ++i) { - delete[] keys[i]; - } - delete[] keys; -} - -// Additional functions to match all functionalities from image.cxx -f3d_image_t* f3d_image_create_from_file(const char* path) { - return new f3d_image_t{ f3d::image(path) }; -} - -f3d_image_t* f3d_image_create_with_params(unsigned int width, unsigned int height, unsigned int channelCount, unsigned int type) { - f3d::image::ChannelType channel_type; - switch (type) { - case 0: - channel_type = f3d::image::ChannelType::BYTE; - break; - case 1: - channel_type = f3d::image::ChannelType::SHORT; - break; - case 2: - channel_type = f3d::image::ChannelType::FLOAT; - break; - default: - channel_type = f3d::image::ChannelType::BYTE; // Default to BYTE - break; - } - return new f3d_image_t{ f3d::image(width, height, channelCount, channel_type) }; -} - -unsigned int f3d_image_get_supported_formats_count() { - std::vector formats = f3d::image::getSupportedFormats(); - return formats.size(); -} - -const char** f3d_image_get_supported_formats() { - static std::vector formats = f3d::image::getSupportedFormats(); - static std::vector c_formats; - c_formats.clear(); - for (const auto& format : formats) { - c_formats.push_back(format.c_str()); - } - return c_formats.data(); -} - -double* f3d_image_get_normalized_pixel(f3d_image_t* img, int x, int y, unsigned int* count) { - std::vector pixel = img->img.getNormalizedPixel({x, y}); - *count = pixel.size(); - double* c_pixel = new double[pixel.size()]; - std::copy(pixel.begin(), pixel.end(), c_pixel); - return c_pixel; -} - -void f3d_image_free_normalized_pixel(double* pixel) { - delete[] pixel; -} +#ifndef F3D_C_API_H +#define F3D_C_API_H + +#include "export.h" // Ensure F3D_EXPORT is defined + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @struct f3d_point3_t + * @brief Structure representing a 3D point + */ +typedef struct { + float x; + float y; + float z; +} f3d_point3_t; + +/** + * @struct f3d_vector3_t + * @brief Structure representing a 3D vector + */ +typedef struct { + float x; + float y; + float z; +} f3d_vector3_t; + +/** + * @struct f3d_image_t + * @brief Forward declaration of the f3d_image structure + */ +typedef struct f3d_image f3d_image_t; + +/** + * @brief Create a new image object + * @return Pointer to the newly created image object + */ +F3D_EXPORT f3d_image_t* f3d_image_new(void); + +/** + * @brief Delete an image object + * @param img Pointer to the image object to be deleted + */ +F3D_EXPORT void f3d_image_delete(f3d_image_t* img); + +/** + * @brief Set the resolution of an image + * @param img Pointer to the image object + * @param width Width of the image + * @param height Height of the image + */ +F3D_EXPORT void f3d_image_set_resolution(f3d_image_t* img, unsigned int width, unsigned int height); + +/** + * @brief Get the width of an image + * @param img Pointer to the image object + * @return Width of the image + */ +F3D_EXPORT unsigned int f3d_image_get_width(f3d_image_t* img); + +/** + * @brief Get the height of an image + * @param img Pointer to the image object + * @return Height of the image + */ +F3D_EXPORT unsigned int f3d_image_get_height(f3d_image_t* img); + +/** + * @brief Get the number of channels in an image + * @param img Pointer to the image object + * @return Number of channels in the image + */ +F3D_EXPORT unsigned int f3d_image_get_channel_count(f3d_image_t* img); + +/** + * @brief Get the type of channels in an image + * @param img Pointer to the image object + * @return Type of channels in the image + */ +F3D_EXPORT unsigned int f3d_image_get_channel_type(f3d_image_t* img); + +/** + * @brief Get the size of the channel type in an image + * @param img Pointer to the image object + * @return Size of the channel type in the image + */ +F3D_EXPORT unsigned int f3d_image_get_channel_type_size(f3d_image_t* img); + +/** + * @brief Set the content of an image from a buffer + * @param img Pointer to the image object + * @param buffer Pointer to the buffer containing the image content + */ +F3D_EXPORT void f3d_image_set_content(f3d_image_t* img, void* buffer); + +/** + * @brief Get the content of an image as a buffer + * @param img Pointer to the image object + * @return Pointer to the buffer containing the image content + */ +F3D_EXPORT void* f3d_image_get_content(f3d_image_t* img); + +/** + * @brief Compare two images and return the difference + * @param img Pointer to the image object + * @param reference Pointer to the reference image object + * @param threshold Comparison threshold + * @param diff Pointer to the image object to store the difference + * @param error Pointer to store the error value + * @return 0 if the images are identical, non-zero otherwise + */ +F3D_EXPORT int f3d_image_compare(f3d_image_t* img, f3d_image_t* reference, double threshold, f3d_image_t* diff, double* error); + +/** + * @brief Save an image to a file + * @param img Pointer to the image object + * @param path Path to the file where the image will be saved + * @param format Format in which the image will be saved + */ +F3D_EXPORT void f3d_image_save(f3d_image_t* img, const char* path, int format); + +/** + * @brief Save an image to a buffer + * @param img Pointer to the image object + * @param format Format in which the image will be saved + * @param size Pointer to store the size of the saved buffer + * @return Pointer to the buffer containing the saved image + */ +F3D_EXPORT unsigned char* f3d_image_save_buffer(f3d_image_t* img, int format, unsigned int* size); + +/** + * @brief Convert an image to a string representation for terminal output + * @param img Pointer to the image object + * @return Pointer to the string representation of the image + */ +F3D_EXPORT const char* f3d_image_to_terminal_text(f3d_image_t* img); + +/** + * @brief Set metadata for an image + * @param img Pointer to the image object + * @param key Metadata key + * @param value Metadata value + */ +F3D_EXPORT void f3d_image_set_metadata(f3d_image_t* img, const char* key, const char* value); + +/** + * @brief Get metadata from an image + * @param img Pointer to the image object + * @param key Metadata key + * @return Metadata value + */ +F3D_EXPORT const char* f3d_image_get_metadata(f3d_image_t* img, const char* key); + +/** + * @brief Get all metadata keys from an image + * @param img Pointer to the image object + * @param count Pointer to store the count of metadata keys + * @return Pointer to the array of metadata keys + */ +F3D_EXPORT char** f3d_image_all_metadata(f3d_image_t* img, unsigned int* count); + +/** + * @brief Free metadata keys obtained from an image + * @param keys Pointer to the array of metadata keys + * @param count Count of metadata keys + */ +F3D_EXPORT void f3d_image_free_metadata_keys(char** keys, unsigned int count); + +/** + * @brief Create an image from a file + * @param path Path to the image file + * @return Pointer to the created image object + */ +F3D_EXPORT f3d_image_t* f3d_image_create_from_file(const char* path); + +/** + * @brief Create an image with specified parameters + * @param width Width of the image + * @param height Height of the image + * @param channelCount Number of channels in the image + * @param type Type of channels in the image + * @return Pointer to the created image object + */ +F3D_EXPORT f3d_image_t* f3d_image_create_with_params(unsigned int width, unsigned int height, unsigned int channelCount, unsigned int type); + +/** + * @brief Get the count of supported image formats + * @return Count of supported image formats + */ +F3D_EXPORT unsigned int f3d_image_get_supported_formats_count(); + +/** + * @brief Get the list of supported image formats + * @return Pointer to the array of supported image formats + */ +F3D_EXPORT const char** f3d_image_get_supported_formats(); + +/** + * @brief Get a normalized pixel value from an image + * @param img Pointer to the image object + * @param x X-coordinate of the pixel + * @param y Y-coordinate of the pixel + * @param count Pointer to store the count of pixel values + * @return Pointer to the array of normalized pixel values + */ +F3D_EXPORT double* f3d_image_get_normalized_pixel(f3d_image_t* img, int x, int y, unsigned int* count); + +/** + * @brief Free a normalized pixel value obtained from an image + * @param pixel Pointer to the array of normalized pixel values + */ +F3D_EXPORT void f3d_image_free_normalized_pixel(double* pixel); + +#ifdef __cplusplus +} +#endif + +#endif // F3D_C_API_H From 9887032b697911db7b384e9c496a5279e9418083 Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Tue, 4 Jun 2024 19:32:16 -0700 Subject: [PATCH 20/27] Added c to cmake --- library/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 5172fea3e3..691d99248b 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -51,6 +51,7 @@ set(F3D_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/types.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/window_impl.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.cxx ) # List of headers that will be installed @@ -69,6 +70,7 @@ set(F3D_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/public/types.h ${CMAKE_CURRENT_SOURCE_DIR}/public/utils.h ${CMAKE_CURRENT_SOURCE_DIR}/public/window.h + ${CMAKE_CURRENT_SOURCE_DIR}/public/image_c_api.h ) set(F3D_PLUGIN_HEADERS From cdc2aac15bab1ba2aac7a00b9accd5b86b53fef5 Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Thu, 6 Jun 2024 19:11:20 -0700 Subject: [PATCH 21/27] Revert "Update comment styling" This reverts commit 7f023aef52b3991404937720e15dcf8b2c7db031. --- library/src/image_c_api.cxx | 386 ++++++++++++++++-------------------- 1 file changed, 166 insertions(+), 220 deletions(-) diff --git a/library/src/image_c_api.cxx b/library/src/image_c_api.cxx index e8b5236ee2..3815b360bb 100644 --- a/library/src/image_c_api.cxx +++ b/library/src/image_c_api.cxx @@ -1,220 +1,166 @@ -#ifndef F3D_C_API_H -#define F3D_C_API_H - -#include "export.h" // Ensure F3D_EXPORT is defined - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @struct f3d_point3_t - * @brief Structure representing a 3D point - */ -typedef struct { - float x; - float y; - float z; -} f3d_point3_t; - -/** - * @struct f3d_vector3_t - * @brief Structure representing a 3D vector - */ -typedef struct { - float x; - float y; - float z; -} f3d_vector3_t; - -/** - * @struct f3d_image_t - * @brief Forward declaration of the f3d_image structure - */ -typedef struct f3d_image f3d_image_t; - -/** - * @brief Create a new image object - * @return Pointer to the newly created image object - */ -F3D_EXPORT f3d_image_t* f3d_image_new(void); - -/** - * @brief Delete an image object - * @param img Pointer to the image object to be deleted - */ -F3D_EXPORT void f3d_image_delete(f3d_image_t* img); - -/** - * @brief Set the resolution of an image - * @param img Pointer to the image object - * @param width Width of the image - * @param height Height of the image - */ -F3D_EXPORT void f3d_image_set_resolution(f3d_image_t* img, unsigned int width, unsigned int height); - -/** - * @brief Get the width of an image - * @param img Pointer to the image object - * @return Width of the image - */ -F3D_EXPORT unsigned int f3d_image_get_width(f3d_image_t* img); - -/** - * @brief Get the height of an image - * @param img Pointer to the image object - * @return Height of the image - */ -F3D_EXPORT unsigned int f3d_image_get_height(f3d_image_t* img); - -/** - * @brief Get the number of channels in an image - * @param img Pointer to the image object - * @return Number of channels in the image - */ -F3D_EXPORT unsigned int f3d_image_get_channel_count(f3d_image_t* img); - -/** - * @brief Get the type of channels in an image - * @param img Pointer to the image object - * @return Type of channels in the image - */ -F3D_EXPORT unsigned int f3d_image_get_channel_type(f3d_image_t* img); - -/** - * @brief Get the size of the channel type in an image - * @param img Pointer to the image object - * @return Size of the channel type in the image - */ -F3D_EXPORT unsigned int f3d_image_get_channel_type_size(f3d_image_t* img); - -/** - * @brief Set the content of an image from a buffer - * @param img Pointer to the image object - * @param buffer Pointer to the buffer containing the image content - */ -F3D_EXPORT void f3d_image_set_content(f3d_image_t* img, void* buffer); - -/** - * @brief Get the content of an image as a buffer - * @param img Pointer to the image object - * @return Pointer to the buffer containing the image content - */ -F3D_EXPORT void* f3d_image_get_content(f3d_image_t* img); - -/** - * @brief Compare two images and return the difference - * @param img Pointer to the image object - * @param reference Pointer to the reference image object - * @param threshold Comparison threshold - * @param diff Pointer to the image object to store the difference - * @param error Pointer to store the error value - * @return 0 if the images are identical, non-zero otherwise - */ -F3D_EXPORT int f3d_image_compare(f3d_image_t* img, f3d_image_t* reference, double threshold, f3d_image_t* diff, double* error); - -/** - * @brief Save an image to a file - * @param img Pointer to the image object - * @param path Path to the file where the image will be saved - * @param format Format in which the image will be saved - */ -F3D_EXPORT void f3d_image_save(f3d_image_t* img, const char* path, int format); - -/** - * @brief Save an image to a buffer - * @param img Pointer to the image object - * @param format Format in which the image will be saved - * @param size Pointer to store the size of the saved buffer - * @return Pointer to the buffer containing the saved image - */ -F3D_EXPORT unsigned char* f3d_image_save_buffer(f3d_image_t* img, int format, unsigned int* size); - -/** - * @brief Convert an image to a string representation for terminal output - * @param img Pointer to the image object - * @return Pointer to the string representation of the image - */ -F3D_EXPORT const char* f3d_image_to_terminal_text(f3d_image_t* img); - -/** - * @brief Set metadata for an image - * @param img Pointer to the image object - * @param key Metadata key - * @param value Metadata value - */ -F3D_EXPORT void f3d_image_set_metadata(f3d_image_t* img, const char* key, const char* value); - -/** - * @brief Get metadata from an image - * @param img Pointer to the image object - * @param key Metadata key - * @return Metadata value - */ -F3D_EXPORT const char* f3d_image_get_metadata(f3d_image_t* img, const char* key); - -/** - * @brief Get all metadata keys from an image - * @param img Pointer to the image object - * @param count Pointer to store the count of metadata keys - * @return Pointer to the array of metadata keys - */ -F3D_EXPORT char** f3d_image_all_metadata(f3d_image_t* img, unsigned int* count); - -/** - * @brief Free metadata keys obtained from an image - * @param keys Pointer to the array of metadata keys - * @param count Count of metadata keys - */ -F3D_EXPORT void f3d_image_free_metadata_keys(char** keys, unsigned int count); - -/** - * @brief Create an image from a file - * @param path Path to the image file - * @return Pointer to the created image object - */ -F3D_EXPORT f3d_image_t* f3d_image_create_from_file(const char* path); - -/** - * @brief Create an image with specified parameters - * @param width Width of the image - * @param height Height of the image - * @param channelCount Number of channels in the image - * @param type Type of channels in the image - * @return Pointer to the created image object - */ -F3D_EXPORT f3d_image_t* f3d_image_create_with_params(unsigned int width, unsigned int height, unsigned int channelCount, unsigned int type); - -/** - * @brief Get the count of supported image formats - * @return Count of supported image formats - */ -F3D_EXPORT unsigned int f3d_image_get_supported_formats_count(); - -/** - * @brief Get the list of supported image formats - * @return Pointer to the array of supported image formats - */ -F3D_EXPORT const char** f3d_image_get_supported_formats(); - -/** - * @brief Get a normalized pixel value from an image - * @param img Pointer to the image object - * @param x X-coordinate of the pixel - * @param y Y-coordinate of the pixel - * @param count Pointer to store the count of pixel values - * @return Pointer to the array of normalized pixel values - */ -F3D_EXPORT double* f3d_image_get_normalized_pixel(f3d_image_t* img, int x, int y, unsigned int* count); - -/** - * @brief Free a normalized pixel value obtained from an image - * @param pixel Pointer to the array of normalized pixel values - */ -F3D_EXPORT void f3d_image_free_normalized_pixel(double* pixel); - -#ifdef __cplusplus -} -#endif - -#endif // F3D_C_API_H +#include "image_c_api.h" +#include "image.h" +#include + +struct f3d_image { + f3d::image img; +}; + +f3d_image_t* f3d_image_new(void) { + return new f3d_image_t(); +} + +void f3d_image_delete(f3d_image_t* img) { + delete img; +} + +void f3d_image_set_resolution(f3d_image_t* img, unsigned int width, unsigned int height) { + img->img.setResolution(width, height); +} + +unsigned int f3d_image_get_width(f3d_image_t* img) { + return img->img.getWidth(); +} + +unsigned int f3d_image_get_height(f3d_image_t* img) { + return img->img.getHeight(); +} + +unsigned int f3d_image_get_channel_count(f3d_image_t* img) { + return img->img.getChannelCount(); +} + +unsigned int f3d_image_get_channel_type(f3d_image_t* img) { + return static_cast(img->img.getChannelType()); +} + +unsigned int f3d_image_get_channel_type_size(f3d_image_t* img) { + return img->img.getChannelTypeSize(); +} + +void f3d_image_set_content(f3d_image_t* img, void* buffer) { + img->img.setContent(buffer); +} + +void* f3d_image_get_content(f3d_image_t* img) { + return img->img.getContent(); +} + +int f3d_image_compare(f3d_image_t* img, f3d_image_t* reference, double threshold, f3d_image_t* diff, double* error) { + return img->img.compare(reference->img, threshold, diff->img, *error); +} + +void f3d_image_save(f3d_image_t* img, const char* path, int format) { + f3d::image::SaveFormat save_format; + switch (format) { + case 0: + save_format = f3d::image::SaveFormat::PNG; + break; + case 1: + save_format = f3d::image::SaveFormat::JPG; + break; + case 2: + save_format = f3d::image::SaveFormat::TIF; + break; + case 3: + save_format = f3d::image::SaveFormat::BMP; + break; + default: + save_format = f3d::image::SaveFormat::PNG; // Default to PNG + break; + } + img->img.save(path, save_format); +} + +unsigned char* f3d_image_save_buffer(f3d_image_t* img, int format, unsigned int* size) { + std::vector buffer = img->img.saveBuffer(static_cast(format)); + unsigned char* c_buffer = new unsigned char[buffer.size()]; + std::copy(buffer.begin(), buffer.end(), c_buffer); + *size = buffer.size(); + return c_buffer; +} + +const char* f3d_image_to_terminal_text(f3d_image_t* img) { + static std::string result; + result = img->img.toTerminalText(); + return result.c_str(); +} + +void f3d_image_set_metadata(f3d_image_t* img, const char* key, const char* value) { + img->img.setMetadata(key, value); +} + +const char* f3d_image_get_metadata(f3d_image_t* img, const char* key) { + static std::string result; + result = img->img.getMetadata(key); + return result.c_str(); +} + +char** f3d_image_all_metadata(f3d_image_t* img, unsigned int* count) { + std::vector metadata_keys = img->img.allMetadata(); + *count = metadata_keys.size(); + char** keys = new char*[metadata_keys.size()]; + for (size_t i = 0; i < metadata_keys.size(); ++i) { + keys[i] = new char[metadata_keys[i].size() + 1]; + strcpy(keys[i], metadata_keys[i].c_str()); + } + return keys; +} + +void f3d_image_free_metadata_keys(char** keys, unsigned int count) { + for (unsigned int i = 0; i < count; ++i) { + delete[] keys[i]; + } + delete[] keys; +} + +// Additional functions to match all functionalities from image.cxx +f3d_image_t* f3d_image_create_from_file(const char* path) { + return new f3d_image_t{ f3d::image(path) }; +} + +f3d_image_t* f3d_image_create_with_params(unsigned int width, unsigned int height, unsigned int channelCount, unsigned int type) { + f3d::image::ChannelType channel_type; + switch (type) { + case 0: + channel_type = f3d::image::ChannelType::BYTE; + break; + case 1: + channel_type = f3d::image::ChannelType::SHORT; + break; + case 2: + channel_type = f3d::image::ChannelType::FLOAT; + break; + default: + channel_type = f3d::image::ChannelType::BYTE; // Default to BYTE + break; + } + return new f3d_image_t{ f3d::image(width, height, channelCount, channel_type) }; +} + +unsigned int f3d_image_get_supported_formats_count() { + std::vector formats = f3d::image::getSupportedFormats(); + return formats.size(); +} + +const char** f3d_image_get_supported_formats() { + static std::vector formats = f3d::image::getSupportedFormats(); + static std::vector c_formats; + c_formats.clear(); + for (const auto& format : formats) { + c_formats.push_back(format.c_str()); + } + return c_formats.data(); +} + +double* f3d_image_get_normalized_pixel(f3d_image_t* img, int x, int y, unsigned int* count) { + std::vector pixel = img->img.getNormalizedPixel({x, y}); + *count = pixel.size(); + double* c_pixel = new double[pixel.size()]; + std::copy(pixel.begin(), pixel.end(), c_pixel); + return c_pixel; +} + +void f3d_image_free_normalized_pixel(double* pixel) { + delete[] pixel; +} From 1b73e8b1eaa1fe0a9915900e830136fe66d2cae2 Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Thu, 6 Jun 2024 19:14:33 -0700 Subject: [PATCH 22/27] Updated comment styling --- library/public/image_c_api.h | 183 ++++++++++++++++++++++++++++------- 1 file changed, 150 insertions(+), 33 deletions(-) diff --git a/library/public/image_c_api.h b/library/public/image_c_api.h index 41a6d434fd..39dcd88574 100644 --- a/library/public/image_c_api.h +++ b/library/public/image_c_api.h @@ -7,93 +7,210 @@ extern "C" { #endif -/* Structure representing a 3D point */ +/** + * @struct f3d_point3_t + * @brief Structure representing a 3D point + */ typedef struct { - float x; - float y; - float z; + float x; /**< X-coordinate */ + float y; /**< Y-coordinate */ + float z; /**< Z-coordinate */ } f3d_point3_t; -/* Structure representing a 3D vector */ +/** + * @struct f3d_vector3_t + * @brief Structure representing a 3D vector + */ typedef struct { - float x; - float y; - float z; + float x; /**< X-coordinate */ + float y; /**< Y-coordinate */ + float z; /**< Z-coordinate */ } f3d_vector3_t; -/* Forward declaration of the f3d_image structure */ +/** + * @struct f3d_image_t + * @brief Forward declaration of the f3d_image structure + */ typedef struct f3d_image f3d_image_t; -/* Function to create a new image object */ +/** + * @brief Create a new image object + * @return Pointer to the newly created image object + */ F3D_EXPORT f3d_image_t* f3d_image_new(void); -/* Function to delete an image object */ +/** + * @brief Delete an image object + * @param img Pointer to the image object to be deleted + */ F3D_EXPORT void f3d_image_delete(f3d_image_t* img); -/* Function to set the resolution of an image */ +/** + * @brief Set the resolution of an image + * @param img Pointer to the image object + * @param width Width of the image + * @param height Height of the image + */ F3D_EXPORT void f3d_image_set_resolution(f3d_image_t* img, unsigned int width, unsigned int height); -/* Function to get the width of an image */ +/** + * @brief Get the width of an image + * @param img Pointer to the image object + * @return Width of the image + */ F3D_EXPORT unsigned int f3d_image_get_width(f3d_image_t* img); -/* Function to get the height of an image */ +/** + * @brief Get the height of an image + * @param img Pointer to the image object + * @return Height of the image + */ F3D_EXPORT unsigned int f3d_image_get_height(f3d_image_t* img); -/* Function to get the number of channels in an image */ +/** + * @brief Get the number of channels in an image + * @param img Pointer to the image object + * @return Number of channels in the image + */ F3D_EXPORT unsigned int f3d_image_get_channel_count(f3d_image_t* img); -/* Function to get the type of channels in an image */ +/** + * @brief Get the type of channels in an image + * @param img Pointer to the image object + * @return Type of channels in the image + */ F3D_EXPORT unsigned int f3d_image_get_channel_type(f3d_image_t* img); -/* Function to get the size of the channel type in an image */ +/** + * @brief Get the size of the channel type in an image + * @param img Pointer to the image object + * @return Size of the channel type in the image + */ F3D_EXPORT unsigned int f3d_image_get_channel_type_size(f3d_image_t* img); -/* Function to set the content of an image from a buffer */ +/** + * @brief Set the content of an image from a buffer + * @param img Pointer to the image object + * @param buffer Pointer to the buffer containing the image content + */ F3D_EXPORT void f3d_image_set_content(f3d_image_t* img, void* buffer); -/* Function to get the content of an image as a buffer */ +/** + * @brief Get the content of an image as a buffer + * @param img Pointer to the image object + * @return Pointer to the buffer containing the image content + */ F3D_EXPORT void* f3d_image_get_content(f3d_image_t* img); -/* Function to compare two images and return the difference */ +/** + * @brief Compare two images and return the difference + * @param img Pointer to the image object + * @param reference Pointer to the reference image object + * @param threshold Comparison threshold + * @param diff Pointer to the image object to store the difference + * @param error Pointer to store the error value + * @return 0 if the images are identical, non-zero otherwise + */ F3D_EXPORT int f3d_image_compare(f3d_image_t* img, f3d_image_t* reference, double threshold, f3d_image_t* diff, double* error); -/* Function to save an image to a file */ +/** + * @brief Save an image to a file + * @param img Pointer to the image object + * @param path Path to the file where the image will be saved + * @param format Format in which the image will be saved + */ F3D_EXPORT void f3d_image_save(f3d_image_t* img, const char* path, int format); -/* Function to save an image to a buffer */ +/** + * @brief Save an image to a buffer + * @param img Pointer to the image object + * @param format Format in which the image will be saved + * @param size Pointer to store the size of the saved buffer + * @return Pointer to the buffer containing the saved image + */ F3D_EXPORT unsigned char* f3d_image_save_buffer(f3d_image_t* img, int format, unsigned int* size); -/* Function to convert an image to a string representation for terminal output */ +/** + * @brief Convert an image to a string representation for terminal output + * @param img Pointer to the image object + * @return Pointer to the string representation of the image + */ F3D_EXPORT const char* f3d_image_to_terminal_text(f3d_image_t* img); -/* Function to set metadata for an image */ +/** + * @brief Set metadata for an image + * @param img Pointer to the image object + * @param key Metadata key + * @param value Metadata value + */ F3D_EXPORT void f3d_image_set_metadata(f3d_image_t* img, const char* key, const char* value); -/* Function to get metadata from an image */ +/** + * @brief Get metadata from an image + * @param img Pointer to the image object + * @param key Metadata key + * @return Metadata value + */ F3D_EXPORT const char* f3d_image_get_metadata(f3d_image_t* img, const char* key); -/* Function to get all metadata keys from an image */ +/** + * @brief Get all metadata keys from an image + * @param img Pointer to the image object + * @param count Pointer to store the count of metadata keys + * @return Pointer to the array of metadata keys + */ F3D_EXPORT char** f3d_image_all_metadata(f3d_image_t* img, unsigned int* count); -/* Function to free metadata keys obtained from an image */ +/** + * @brief Free metadata keys obtained from an image + * @param keys Pointer to the array of metadata keys + * @param count Count of metadata keys + */ F3D_EXPORT void f3d_image_free_metadata_keys(char** keys, unsigned int count); -/* Function to create an image from a file */ +/** + * @brief Create an image from a file + * @param path Path to the image file + * @return Pointer to the created image object + */ F3D_EXPORT f3d_image_t* f3d_image_create_from_file(const char* path); -/* Function to create an image with specified parameters */ +/** + * @brief Create an image with specified parameters + * @param width Width of the image + * @param height Height of the image + * @param channelCount Number of channels in the image + * @param type Type of channels in the image + * @return Pointer to the created image object + */ F3D_EXPORT f3d_image_t* f3d_image_create_with_params(unsigned int width, unsigned int height, unsigned int channelCount, unsigned int type); -/* Function to get the count of supported image formats */ +/** + * @brief Get the count of supported image formats + * @return Count of supported image formats + */ F3D_EXPORT unsigned int f3d_image_get_supported_formats_count(); -/* Function to get the list of supported image formats */ +/** + * @brief Get the list of supported image formats + * @return Pointer to the array of supported image formats + */ F3D_EXPORT const char** f3d_image_get_supported_formats(); -/* Function to get a normalized pixel value from an image */ +/** + * @brief Get a normalized pixel value from an image + * @param img Pointer to the image object + * @param x X-coordinate of the pixel + * @param y Y-coordinate of the pixel + * @param count Pointer to store the count of pixel values + * @return Pointer to the array of normalized pixel values + */ F3D_EXPORT double* f3d_image_get_normalized_pixel(f3d_image_t* img, int x, int y, unsigned int* count); -/* Function to free a normalized pixel value obtained from an image */ +/** + * @brief Free a normalized pixel value obtained from an image + * @param pixel Pointer to the array of normalized pixel values + */ F3D_EXPORT void f3d_image_free_normalized_pixel(double* pixel); #ifdef __cplusplus From c5d5d548a08121f384d192d73b38a0de6bfab48d Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Thu, 6 Jun 2024 19:19:19 -0700 Subject: [PATCH 23/27] Added c to CMake --- library/CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 691d99248b..c732311e4d 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -51,7 +51,7 @@ set(F3D_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/types.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/window_impl.cxx - ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.cxx ) # List of headers that will be installed @@ -70,7 +70,7 @@ set(F3D_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/public/types.h ${CMAKE_CURRENT_SOURCE_DIR}/public/utils.h ${CMAKE_CURRENT_SOURCE_DIR}/public/window.h - ${CMAKE_CURRENT_SOURCE_DIR}/public/image_c_api.h + ${CMAKE_CURRENT_SOURCE_DIR}/public/image_c_api.h ) set(F3D_PLUGIN_HEADERS @@ -195,6 +195,8 @@ endif() # Testing if(BUILD_TESTING) add_subdirectory(testing) + add_executable(test_image_c_api testing/test_image_c_api.c) + target_link_libraries(test_image_c_api PRIVATE libf3d) endif() # Installing From 0be05ad07cd32185b885350f44ce8b9592c303ec Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Thu, 6 Jun 2024 20:01:48 -0700 Subject: [PATCH 24/27] Check test --- library/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index c732311e4d..73b6edf890 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -195,8 +195,6 @@ endif() # Testing if(BUILD_TESTING) add_subdirectory(testing) - add_executable(test_image_c_api testing/test_image_c_api.c) - target_link_libraries(test_image_c_api PRIVATE libf3d) endif() # Installing From 1cd49fd63b4ed6612b0e2ef903194f2318b2e6d6 Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Thu, 6 Jun 2024 20:15:01 -0700 Subject: [PATCH 25/27] Update CMake --- library/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 73b6edf890..3d5c1aac21 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -51,7 +51,7 @@ set(F3D_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/types.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/window_impl.cxx - ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.cxx + # ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.cxx ) # List of headers that will be installed @@ -70,7 +70,7 @@ set(F3D_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/public/types.h ${CMAKE_CURRENT_SOURCE_DIR}/public/utils.h ${CMAKE_CURRENT_SOURCE_DIR}/public/window.h - ${CMAKE_CURRENT_SOURCE_DIR}/public/image_c_api.h + # ${CMAKE_CURRENT_SOURCE_DIR}/public/image_c_api.h ) set(F3D_PLUGIN_HEADERS From 01a8159db85dcc67dffd8c939644a45913e54f41 Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Fri, 7 Jun 2024 18:36:44 -0700 Subject: [PATCH 26/27] Add C to CMake --- library/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 3d5c1aac21..73b6edf890 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -51,7 +51,7 @@ set(F3D_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/types.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/window_impl.cxx - # ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.cxx ) # List of headers that will be installed @@ -70,7 +70,7 @@ set(F3D_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/public/types.h ${CMAKE_CURRENT_SOURCE_DIR}/public/utils.h ${CMAKE_CURRENT_SOURCE_DIR}/public/window.h - # ${CMAKE_CURRENT_SOURCE_DIR}/public/image_c_api.h + ${CMAKE_CURRENT_SOURCE_DIR}/public/image_c_api.h ) set(F3D_PLUGIN_HEADERS From 2d0a8ef64ee1772f47503c045909657014c6b65d Mon Sep 17 00:00:00 2001 From: parker <129785640+parkerstafford@users.noreply.github.com> Date: Fri, 7 Jun 2024 21:11:43 -0700 Subject: [PATCH 27/27] Update image_c_api --- library/CMakeLists.txt | 18 ++++++++++++------ library/src/image_c_api.cxx | 16 +++++++++++++++- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 73b6edf890..c628599f52 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -51,7 +51,7 @@ set(F3D_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/types.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cxx ${CMAKE_CURRENT_SOURCE_DIR}/src/window_impl.cxx - ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/src/image_c_api.cxx ) # List of headers that will be installed @@ -70,7 +70,7 @@ set(F3D_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/public/types.h ${CMAKE_CURRENT_SOURCE_DIR}/public/utils.h ${CMAKE_CURRENT_SOURCE_DIR}/public/window.h - ${CMAKE_CURRENT_SOURCE_DIR}/public/image_c_api.h + ${CMAKE_CURRENT_SOURCE_DIR}/public/image_c_api.h ) set(F3D_PLUGIN_HEADERS @@ -91,7 +91,7 @@ target_include_directories(libf3d $ $ $ - $ + $ ) if (F3D_USE_EXTERNAL_NLOHMANN_JSON) target_link_libraries(libf3d PRIVATE nlohmann_json::nlohmann_json) @@ -112,6 +112,10 @@ set_target_properties(libf3d PROPERTIES PDB_NAME "libf3d" ) +# Disable warnings as errors for image_c_api.cxx +target_compile_options(libf3d PRIVATE + $<$:-Wno-error=deprecated-declarations>) + # It can be useful to disable soversion in case the links are duplicated # It happens with Python wheels for example option(F3D_ENABLE_SOVERSION "Enable libf3d SOVERSION" ON) @@ -195,6 +199,8 @@ endif() # Testing if(BUILD_TESTING) add_subdirectory(testing) + add_executable(test_image_c_api testing/test_image_c_api.c) + target_link_libraries(test_image_c_api PRIVATE libf3d) endif() # Installing @@ -259,13 +265,13 @@ if(BUILD_SHARED_LIBS) DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/f3d" COMPONENT sdk - EXCLUDE_FROM_ALL) + EXCLUDE_FROM ALL) # Install plugin headers install(FILES ${F3D_PLUGIN_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/f3d" COMPONENT plugin_sdk - EXCLUDE_FROM_ALL) + EXCLUDE FROM ALL) # Install pluginsdk cmake and source files install( @@ -279,6 +285,6 @@ if(BUILD_SHARED_LIBS) DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/f3d" COMPONENT plugin_sdk - EXCLUDE_FROM_ALL) + EXCLUDE FROM ALL) endif() diff --git a/library/src/image_c_api.cxx b/library/src/image_c_api.cxx index 3815b360bb..93311549bb 100644 --- a/library/src/image_c_api.cxx +++ b/library/src/image_c_api.cxx @@ -7,17 +7,31 @@ struct f3d_image { }; f3d_image_t* f3d_image_new(void) { - return new f3d_image_t(); + return new f3d_image_t{f3d::image()}; } void f3d_image_delete(f3d_image_t* img) { delete img; } +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4996) // Disable deprecated warnings for MSVC +#elif defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" // Disable deprecated warnings for GCC/Clang +#endif + void f3d_image_set_resolution(f3d_image_t* img, unsigned int width, unsigned int height) { img->img.setResolution(width, height); } +#ifdef _MSC_VER +#pragma warning(pop) +#elif defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic pop +#endif + unsigned int f3d_image_get_width(f3d_image_t* img) { return img->img.getWidth(); }