Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
shell: bash
run: |
sudo yum install --setopt=tsflags=nodocs -y eigen3-devel ceres-solver-devel json-devel
sudo python -m pip install nanobind

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
Expand Down Expand Up @@ -152,6 +153,7 @@ jobs:
shell: bash
run: |
sudo yum install --setopt=tsflags=nodocs -y eigen3-devel ceres-solver-devel json-devel
sudo python -m pip install nanobind

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
Expand Down
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX /EHsc")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX")
add_compile_definitions( NOMINMAX )
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
elseif (
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang"
)
# GCC/Clang strict flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -pedantic")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wall -Wextra -pedantic")
Expand Down Expand Up @@ -69,6 +73,7 @@ endforeach()

option( ENABLE_SHARED "Enable Shared Libraries" ON )
option( RTA_CENTOS7_CERES_HACK "Work around broken config in ceres-solver 1.12" OFF )
option( RTA_BUILD_PYTHON_BINDINGS "Build python bindings" ON )
option( ENABLE_COVERAGE "Enable code coverage reporting" OFF )

if ( ENABLE_SHARED )
Expand All @@ -93,6 +98,10 @@ add_subdirectory("src/${RAWTOACES_CORE_LIB}")
add_subdirectory("src/${RAWTOACES_UTIL_LIB}")
add_subdirectory("src/rawtoaces")

if ( RTA_BUILD_PYTHON_BINDINGS )
add_subdirectory(src/bindings)
endif ( RTA_BUILD_PYTHON_BINDINGS )

enable_testing()
add_subdirectory(tests)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ To build `rawtoaces` you would need to satisfy these dependencies:
| `ceres` | `1.12.0` | Ceres Solver is an open source library for solving Non-linear Least Squares problems with bounds constraints and unconstrained optimization problems. It processes non-linear regression for rawtoaces. | [Ceres Solver installation](http://ceres-solver.org/installation.html)|
| `boost` | `1.76.0` | Boost has multiple C++ libraries that support tasks related to linear algebra, multithreading, image processing, unit testing, etc. It unit testing for rawtoaces. | [Boost download](http://www.boost.org/) |
| `OpenImageIO` | `3.0` | OpenImageIO is an open source library providing vast functionality for image processing. rawtoaces relies on OpenImageIO for reading raw files, saving AcesContainer files, and also all pixel operations. | [OpenImageIO installation](https://github.com/AcademySoftwareFoundation/OpenImageIO/blob/main/INSTALL.md) |
| `nanobind` | `1.9` | nanobind is a small binding library that exposes C++ types in Python and vice versa. | [nanobind installation](https://nanobind.readthedocs.io/en/latest/installing.html) |


### MacOS
Expand Down
3 changes: 2 additions & 1 deletion build_scripts/install_deps_linux.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ time sudo apt-get -q -f install -y \
libceres-dev \
nlohmann-json3-dev \
libopencv-dev \
openimageio-tools libopenimageio-dev
openimageio-tools libopenimageio-dev \
nanobind-dev
2 changes: 1 addition & 1 deletion build_scripts/install_deps_mac.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -ex

brew install ceres-solver nlohmann-json openimageio
brew install ceres-solver nlohmann-json openimageio nanobind robin-map
3 changes: 2 additions & 1 deletion build_scripts/install_deps_windows.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ set -ex
vcpkg install \
ceres:x64-windows \
nlohmann-json:x64-windows \
openimageio:x64-windows
openimageio:x64-windows \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this builds and installs the OIIO python bindings by default. You may need some kind of modifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. Will check. We don't need OIIO on the python side that right now.

nanobind:x64-windows
16 changes: 16 additions & 0 deletions configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,19 @@ if (RTA_CENTOS7_CERES_HACK)
else ()
find_package ( Ceres CONFIG REQUIRED )
endif ()

if (RTA_BUILD_PYTHON_BINDINGS)

if ( CMAKE_VERSION VERSION_LESS 3.18 )
set( DEV_MODULE Development )
else ()
set( DEV_MODULE Development.Module )
endif ()

find_package ( Python 3.8 COMPONENTS Interpreter ${DEV_MODULE} REQUIRED )

execute_process (
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT)
find_package ( nanobind CONFIG REQUIRED )
endif ()
40 changes: 40 additions & 0 deletions src/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
cmake_minimum_required ( VERSION 3.12 )
include_directories ( "${CMAKE_CURRENT_SOURCE_DIR}" )

nanobind_add_module( rawtoaces_bindings
py_util.cpp py_util.h
py_core.cpp py_core.h
py_module.cpp
)

target_link_libraries( rawtoaces_bindings
PUBLIC
${RAWTOACES_UTIL_LIB}
)

if ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" )
target_compile_options ( nanobind-static PRIVATE -Wno-pedantic )
target_compile_options ( rawtoaces_bindings PRIVATE -Wno-pedantic )
if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 10.0 )
target_compile_options ( nanobind-static PRIVATE -Wno-error=zero-length-bounds )
target_compile_options ( rawtoaces_bindings PRIVATE -Wno-error=zero-length-bounds )
endif ()
elseif ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" )
target_compile_options ( nanobind-static PRIVATE -Wno-error=zero-length-array )
target_compile_options ( rawtoaces_bindings PRIVATE -Wno-error=zero-length-array )
endif()

set_target_properties( rawtoaces_bindings PROPERTIES
OUTPUT_NAME "rawtoaces"
#EXPORT_NAME "rawtoaces"
#SOVERSION ${RAWTOACES_MAJOR_VERSION}.${RAWTOACES_MINOR_VERSION}.${RAWTOACES_PATCH_VERSION}
#VERSION ${RAWTOACES_VERSION}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments. needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. I think the binary should be versioned, but uncommenting that makes configure fail.

Also I don't know if this whole 'export' thing is needed, I use it to change the library name, as the 'rawtoaces' target name is already taken. This also makes the library install with the rest of targets, I don't know if the destination should be different. This is good enough for now. We'll need somebody more familiar with python tools deployment to finalise this, I suppose.

)

install(
TARGETS rawtoaces_bindings
EXPORT RAWTOACESTargets
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PUBLIC_HEADER DESTINATION include/rawtoaces
)
9 changes: 9 additions & 0 deletions src/bindings/py_core.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the rawtoaces Project.

#include "py_core.h"

void core_bindings( nanobind::module_ & /*m - unused*/ )
{
// TODO: add the core lib bindings here
}
6 changes: 6 additions & 0 deletions src/bindings/py_core.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the rawtoaces Project.

#include <nanobind/nanobind.h>

void core_bindings( nanobind::module_ &m );
11 changes: 11 additions & 0 deletions src/bindings/py_module.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the rawtoaces Project.

#include "py_core.h"
#include "py_util.h"

NB_MODULE( rawtoaces, m )
{
core_bindings( m );
util_bindings( m );
}
39 changes: 39 additions & 0 deletions src/bindings/py_util.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the rawtoaces Project.

#include "py_util.h"
#include <nanobind/stl/string.h>
#include <rawtoaces/image_converter.h>

using namespace rta::util;

void util_bindings( nanobind::module_ &m )
{
nanobind::class_<ImageConverter> image_converter( m, "ImageConverter" );

image_converter.def( nanobind::init<>() );

// TODO: add the rest of the ImageConverter methods and properties
image_converter
.def_rw(
"settings",
&ImageConverter::settings ) // The Settings class is described below
.def( "process_image", &ImageConverter::process_image );

nanobind::class_<ImageConverter::Settings> settings(
image_converter, "Settings" );

// TODO: add the rest of the Settings' properties
settings.def( nanobind::init<>() )
.def_rw(
"WB_Method",
&ImageConverter::Settings::
WB_method ) // The WBMethod enum is described below
.def_rw( "illuminant", &ImageConverter::Settings::illuminant );

// TODO: add the rest of WBMethod values, add other enums following this example
nanobind::enum_<ImageConverter::Settings::WBMethod>( settings, "WBMethod" )
.value( "Metadata", ImageConverter::Settings::WBMethod::Metadata )
.value( "Illuminant", ImageConverter::Settings::WBMethod::Illuminant )
.export_values();
}
6 changes: 6 additions & 0 deletions src/bindings/py_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the rawtoaces Project.

#include <nanobind/nanobind.h>

void util_bindings( nanobind::module_ &m );
2 changes: 1 addition & 1 deletion src/rawtoaces_util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ install( TARGETS ${RAWTOACES_UTIL_LIB}
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PUBLIC_HEADER DESTINATION include/rawtoaces
)
)
Loading