Skip to content

Commit c4873d5

Browse files
authored
fix(ImageBuf): IB::pixeltype() did not always return the right value (#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 <lg@larrygritz.com>
1 parent 38824fc commit c4873d5

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/libOpenImageIO/imagebuf.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class ImageBufImpl {
189189
TypeDesc pixeltype() const
190190
{
191191
validate_spec();
192-
return m_localpixels ? m_spec.format : m_cachedpixeltype;
192+
return cachedpixels() ? m_cachedpixeltype : m_spec.format;
193193
}
194194

195195
DeepData* deepdata()
@@ -1128,6 +1128,7 @@ ImageBufImpl::init_spec(string_view filename, int subimage, int miplevel,
11281128
if (peltype != TypeDesc::UNKNOWN) {
11291129
m_spec.format = (TypeDesc::BASETYPE)peltype;
11301130
m_spec.channelformats.clear();
1131+
m_cachedpixeltype = m_spec.format;
11311132
}
11321133

11331134
if (m_nsubimages) {

0 commit comments

Comments
 (0)