Skip to content

Commit 3f4cd78

Browse files
lgritzssh4net
authored andcommitted
api(ImageBuf): IB::localpixels_as_[writable_]byte_image_span (AcademySoftwareFoundation#5011)
Utilities to ask the IB for the local pixels as an untyped span of bytes. This is a "safe" alternative to `localpixels()`, which just returned a single pointer, instead returning an image_span that understands the sizes and strides of the buffer. --------- Signed-off-by: Larry Gritz <lg@larrygritz.com> Signed-off-by: Vlad <shaamaan@gmail.com>
1 parent c976397 commit 3f4cd78

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/include/OpenImageIO/imagebuf.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,16 @@ class OIIO_API ImageBuf {
13691369
void* localpixels();
13701370
const void* localpixels() const;
13711371

1372+
/// Return an `image_span<const std::byte>` giving the extent and layout
1373+
/// of "local" pixel memory, if they are fully in RAM and not backed by an
1374+
/// ImageCache, or an empty span otherwise.
1375+
image_span<const std::byte> localpixels_as_byte_image_span() const;
1376+
1377+
/// Return an `image_span<std::byte>` giving the extent and layout of
1378+
/// "local" pixel memory, if they are fully in RAM and not backed by an
1379+
/// ImageCache, and it is a writable IB, or an empty span otherwise.
1380+
image_span<std::byte> localpixels_as_writable_byte_image_span();
1381+
13721382
/// Pixel-to-pixel stride within the localpixels memory.
13731383
stride_t pixel_stride() const;
13741384
/// Scanline-to-scanline stride within the localpixels memory.

src/libOpenImageIO/imagebuf.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,6 +2140,22 @@ ImageBuf::localpixels()
21402140

21412141

21422142

2143+
image_span<const std::byte>
2144+
ImageBuf::localpixels_as_byte_image_span() const
2145+
{
2146+
return m_impl->m_bufspan;
2147+
}
2148+
2149+
2150+
2151+
image_span<std::byte>
2152+
ImageBuf::localpixels_as_writable_byte_image_span()
2153+
{
2154+
return m_impl->m_readonly ? image_span<std::byte>() : m_impl->m_bufspan;
2155+
}
2156+
2157+
2158+
21432159
const void*
21442160
ImageBuf::localpixels() const
21452161
{

0 commit comments

Comments
 (0)