Skip to content

Commit

Permalink
Throw error on non-contiguous Python buffer provided to Image ctor.
Browse files Browse the repository at this point in the history
  • Loading branch information
ssheorey committed Oct 4, 2023
1 parent ea2001f commit 7758739
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cpp/pybind/geometry/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ void pybind_image(py::module &m) {
}
height = (int)info.shape[0];
width = (int)info.shape[1];
if (info.strides[1] != num_of_channels * bytes_per_channel ||
info.strides[0] !=
width * num_of_channels * bytes_per_channel) {
throw std::runtime_error(
"Image can only be initialized from a contiguous "
"buffer.");
}
auto img = new Image();
img->Prepare(width, height, num_of_channels, bytes_per_channel);
memcpy(img->data_.data(), info.ptr, img->data_.size());
Expand Down

0 comments on commit 7758739

Please sign in to comment.