Skip to content

Commit

Permalink
feat(IB): Add ImageBuf::wrapmode_name, inverse of wrapmode_from_string (
Browse files Browse the repository at this point in the history
#4340)

Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz authored Jul 16, 2024
1 parent e9d3656 commit be110f6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/include/OpenImageIO/imagebuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,8 @@ class OIIO_API ImageBuf {
/// name, this will return `WrapDefault`.
static WrapMode WrapMode_from_string(string_view name);

/// Return the name corresponding to the wrap mode.
static ustring wrapmode_name(WrapMode wrap);

friend class IteratorBase;

Expand Down
22 changes: 18 additions & 4 deletions src/libOpenImageIO/imagebuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2904,18 +2904,32 @@ ImageBuf::do_wrap(int& x, int& y, int& z, WrapMode wrap) const



static const ustring wrapnames[] = { ustring("default"), ustring("black"),
ustring("clamp"), ustring("periodic"),
ustring("mirror") };


ImageBuf::WrapMode
ImageBuf::WrapMode_from_string(string_view name)
{
static const char* names[] = { "default", "black", "clamp",
"periodic", "mirror", nullptr };
for (int i = 0; names[i]; ++i)
if (name == names[i])
int i = 0;
for (auto w : wrapnames) {
if (name == w)
return WrapMode(i);
++i;
}
return WrapDefault; // name not found
}


ustring
ImageBuf::wrapmode_name(WrapMode wrap)
{
unsigned int w(wrap);
return w <= 4 ? wrapnames[w] : wrapnames[0];
}



void
ImageBuf::IteratorBase::release_tile()
Expand Down
9 changes: 9 additions & 0 deletions src/libOpenImageIO/imagebuf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ test_wrap(wrap_impl wrap, int coord, int origin, int width)
void
test_wrapmodes()
{
OIIO_CHECK_EQUAL(ImageBuf::WrapMode_from_string("black"),
ImageBuf::WrapBlack);
OIIO_CHECK_EQUAL(ImageBuf::WrapMode_from_string("mirror"),
ImageBuf::WrapMirror);
OIIO_CHECK_EQUAL(ImageBuf::WrapMode_from_string("unknown"),
ImageBuf::WrapDefault);
OIIO_CHECK_EQUAL("black", ImageBuf::wrapmode_name(ImageBuf::WrapBlack));
OIIO_CHECK_EQUAL("mirror", ImageBuf::wrapmode_name(ImageBuf::WrapMirror));

const int ori = 0;
const int w = 4;
static int val[] = { -7, -6, -5, -4, -3, -2, -1, 0, 1,
Expand Down

0 comments on commit be110f6

Please sign in to comment.