Skip to content

Commit

Permalink
Add ImageBuf::setpixel() methods that use cspan instead of ptr/len.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgritz committed Dec 29, 2019
1 parent adfa94d commit ce7804d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
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

0 comments on commit ce7804d

Please sign in to comment.