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

Add ImageBuf::setpixel() methods that use cspan instead of ptr/len. #2443

Merged
merged 1 commit into from
Dec 30, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/include/OpenImageIO/imagebuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,31 @@ class OIIO_API ImageBuf {
WrapMode wrap = WrapBlack) const;


/// Set the pixel with coordinates (x,y,0) to have the values in span
/// `pixel[]`. The number of channels copied is the minimum of the span
/// length and the actual number of channels in the image.
void setpixel(int x, int y, cspan<float> pixel)
{
setpixel(x, y, 0, pixel);
}

/// Set the pixel with coordinates (x,y,z) to have the values in span
/// `pixel[]`. The number of channels copied is the minimum of the span
/// length and the actual number of channels in the image.
void setpixel(int x, int y, int z, cspan<float> pixel)
{
setpixel(x, y, z, pixel.data(), int(pixel.size()));
}

/// Set the `i`-th pixel value of the image (out of width*height*depth),
/// from floating-point values in span `pixel[]`. The number of
/// channels copied is the minimum of the span length and the actual
/// number of channels in the image.
void setpixel(int i, cspan<float> pixel)
{
setpixel(i, pixel.data(), int(pixel.size()));
}

/// Set the pixel with coordinates (x,y,0) to have the values in
/// pixel[0..n-1]. The number of channels copied, n, is the minimum
/// of maxchannels and the actual number of channels in the image.
Expand Down
4 changes: 2 additions & 2 deletions src/python/py_imagebuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ImageBuf_setpixel(ImageBuf& buf, int x, int y, int z, py::object p)
std::vector<float> pixel;
py_to_stdvector(pixel, p);
if (pixel.size())
buf.setpixel(x, y, z, &pixel[0], pixel.size());
buf.setpixel(x, y, z, pixel);
}

void
Expand All @@ -100,7 +100,7 @@ ImageBuf_setpixel1(ImageBuf& buf, int i, py::object p)
std::vector<float> pixel;
py_to_stdvector(pixel, p);
if (pixel.size())
buf.setpixel(i, &pixel[0], pixel.size());
buf.setpixel(i, pixel);
}


Expand Down