| 209 | |
| 210 | private: |
| 211 | static py::array_t<typename pixel_traits<pixel_type>::basic_pixel_type, py::array::c_style> convert_to_numpy(matrix<pixel_type>&& img) |
| 212 | { |
| 213 | using basic_pixel_type = typename pixel_traits<pixel_type>::basic_pixel_type; |
| 214 | const size_t dtype_size = sizeof(basic_pixel_type); |
| 215 | const auto rows = static_cast<const size_t>(num_rows(img)); |
| 216 | const auto cols = static_cast<const size_t>(num_columns(img)); |
| 217 | const size_t channels = pixel_traits<pixel_type>::num; |
| 218 | const size_t image_size = dtype_size * rows * cols * channels; |
| 219 | |
| 220 | std::unique_ptr<pixel_type[]> arr_ptr = img.steal_memory(); |
| 221 | basic_pixel_type* arr = (basic_pixel_type *) arr_ptr.release(); |
| 222 | |
| 223 | if (channels == 1) |
| 224 | { |
| 225 | return pybind11::template array_t<basic_pixel_type, py::array::c_style>( |
| 226 | {rows, cols}, // shape |
| 227 | {dtype_size*cols, dtype_size}, // strides |
| 228 | arr, // pointer |
| 229 | pybind11::capsule{ arr, [](void *arr_p) { delete[] reinterpret_cast<basic_pixel_type*>(arr_p); } } |
| 230 | ); |
| 231 | } |
| 232 | else |
| 233 | { |
| 234 | return pybind11::template array_t<basic_pixel_type, py::array::c_style>( |
| 235 | {rows, cols, channels}, // shape |
| 236 | {dtype_size * cols * channels, dtype_size * channels, dtype_size}, // strides |
| 237 | arr, // pointer |
| 238 | pybind11::capsule{ arr, [](void *arr_p) { delete[] reinterpret_cast<basic_pixel_type*>(arr_p); } } |
| 239 | ); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | }; |
| 244 |
nothing calls this directly
no test coverage detected