Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C Bindings #1444

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -89,6 +91,7 @@ target_include_directories(libf3d
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/private>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/plugin>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/plugin>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)
if (F3D_USE_EXTERNAL_NLOHMANN_JSON)
target_link_libraries(libf3d PRIVATE nlohmann_json::nlohmann_json)
Expand All @@ -109,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
$<$<COMPILE_LANGUAGE:CXX>:-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)
Expand Down Expand Up @@ -192,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
Expand Down Expand Up @@ -256,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(
Expand All @@ -276,6 +285,6 @@ if(BUILD_SHARED_LIBS)
DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/f3d"
COMPONENT plugin_sdk
EXCLUDE_FROM_ALL)
EXCLUDE FROM ALL)

endif()
220 changes: 220 additions & 0 deletions library/public/image_c_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
#ifndef F3D_C_API_H
#define F3D_C_API_H

#include "export.h" // Ensure F3D_EXPORT is defined
Meakk marked this conversation as resolved.
Show resolved Hide resolved

#ifdef __cplusplus
extern "C" {
#endif

/**
* @struct f3d_point3_t
* @brief Structure representing a 3D point
*/
typedef struct {
float x; /**< X-coordinate */
float y; /**< Y-coordinate */
float z; /**< Z-coordinate */
} f3d_point3_t;

/**
* @struct f3d_vector3_t
* @brief Structure representing a 3D vector
*/
typedef struct {
float x; /**< X-coordinate */
float y; /**< Y-coordinate */
float z; /**< Z-coordinate */
} 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);
Meakk marked this conversation as resolved.
Show resolved Hide resolved

/**
* @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
Loading
Loading