AcademySoftwareFoundation / AcademySoftwareFoundation/OpenImageIO

[BUG] ImageBufImpl::pixeladdr method fails on buffers with per channel formats

Open
#2,910 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.4k
Forks
698
Avg merge
3d 9h
Merged PRs (30d)
48

Description

**Describe the bug**
It seems like a lot of the methods on the ImageBuf object don't work nicely with native pixels / per channel formats.
I first had issues with the ImageBuf allocating its own pixel storage, and thought I'd worked around it by providing my own buffer, only for many other methods to not work.

```
OIIO::ImageSpec spec(10, 10, 3, OIIO::TypeDesc::UNKNOWN);
spec.channelformats.clear();
spec.channelnames.clear();
spec.channelnames.push_back("R");
spec.channelformats.push_back(OIIO::TypeDesc::FLOAT);
spec.channelnames.push_back("G");
spec.channelformats.push_back(OIIO::TypeDesc::FLOAT);
spec.channelnames.push_back("B");
spec.channelformats.push_back(OIIO::TypeDesc::FLOAT);

// Does not work, will not allocate :(
//OIIO::ImageBuf buf(spec, OIIO::InitializePixels::No);
// Manually allocate buffer
auto pixels = std::make_unique(spec.image_bytes(true));
OIIO::ImageBuf buf(spec, (void*)pixels.get());

// Try to get pointer to G channel
auto dst = buf.pixeladdr(0, 0, 0, 1); // should return pixels + sizeof(float), but instead returns pixels :(
```

https://github.com/OpenImageIO/oiio/blob/1e488aedc231853570f9e8c7886ab80546d3510a/src/libOpenImageIO/imagebuf.cpp#L371 The issue is that here, we are storing spec->format.size() which will be 0 for UNKNOWN, when instead anyone asking for m_channel_stride should instead be calling something like spec.channel_bytes(n, true);

Additionally, all these calls should probably be calling the "native" modes for things like spec.pixel_bytes() spec.scanline_bytes() no? Unless I missed a huge disclaimer that you cannot use ImageBuf objects with native channels.

Contributor guide

Open the contributing guide

Research direction

Start in src/libOpenImageIO/imagebuf.cpp at the referenced pixeladdr implementation, then inspect the ImageSpec byte-size helpers used for per-channel formats. Verify that pixeladdr returns the correct offset for the requested channel and that native-channel allocation and byte calculations remain consistent; no test file is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.