Skip to content

Commit

Permalink
fix(ImageBuf): IB::pixeltype() did not always return the right value (#…
Browse files Browse the repository at this point in the history
…4614)

The implementation of IB::pixeltype() was:

- Make sure at least the spec had been read (lazy read).
- If there are "local pixels", return the pixel type from the spec,
otherwise return the cache pixel type.

But there is a flaw in this logic: If only the metadata has been read
but not the pixels, the local pixels might not be allocated yet, but
also there is not a cache and no cached pixel type, so pixeltype() will
return UNKNOWN even though we do already know what type of pixels will
be stored when they are eventually read.

The correct logic is:

- Make sure at least the spec had been read (lazy read).
- If it's a cached image, return the cache pixel type, otherwise return
the pixel type from the spec (which will be correct because we
definitely have read the spec at this point).

Also, for legit cached images, ensure that cachedpixeltype is set upon
read_spec() and doesn't have to wait for a full read().

Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz authored Feb 2, 2025
1 parent 38824fc commit c4873d5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/libOpenImageIO/imagebuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class ImageBufImpl {
TypeDesc pixeltype() const
{
validate_spec();
return m_localpixels ? m_spec.format : m_cachedpixeltype;
return cachedpixels() ? m_cachedpixeltype : m_spec.format;
}

DeepData* deepdata()
Expand Down Expand Up @@ -1128,6 +1128,7 @@ ImageBufImpl::init_spec(string_view filename, int subimage, int miplevel,
if (peltype != TypeDesc::UNKNOWN) {
m_spec.format = (TypeDesc::BASETYPE)peltype;
m_spec.channelformats.clear();
m_cachedpixeltype = m_spec.format;
}

if (m_nsubimages) {
Expand Down

0 comments on commit c4873d5

Please sign in to comment.