Skip to content

Commit

Permalink
Update image_c_api
Browse files Browse the repository at this point in the history
  • Loading branch information
parkerstafford committed Jun 8, 2024
1 parent 01a8159 commit 2d0a8ef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
18 changes: 12 additions & 6 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -91,7 +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}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)
if (F3D_USE_EXTERNAL_NLOHMANN_JSON)
target_link_libraries(libf3d PRIVATE nlohmann_json::nlohmann_json)
Expand All @@ -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
$<$<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 @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -279,6 +285,6 @@ if(BUILD_SHARED_LIBS)
DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/f3d"
COMPONENT plugin_sdk
EXCLUDE_FROM_ALL)
EXCLUDE FROM ALL)

endif()
16 changes: 15 additions & 1 deletion library/src/image_c_api.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 2d0a8ef

Please sign in to comment.