Skip to content

Commit

Permalink
Merge pull request #5743 from johnhaddon/twoChannelImageGadget
Browse files Browse the repository at this point in the history
ImageGadget : Support 2-channel images
  • Loading branch information
johnhaddon authored Mar 21, 2024
2 parents 48e53f3 + 3038ce4 commit c02ce07
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Fixes
- Fixed bugs caused by reordering images using `GraphComponent::reorderChildren()`.
- InteractiveRender : Fixed context used to evaluate scene globals when renderer is set to "Default" [^1].
- Instancer : Fixed handling of unindexed primvars in RootPerVertex mode [^1].
- ImageGadget :
- Fixed loading of 2 channel images [^1].
- Fixed error message to include filename [^1].

API
---
Expand Down
8 changes: 6 additions & 2 deletions src/GafferUI/ImageGadget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ using TextureCache = IECorePreview::LRUCache<TextureCacheKey, ConstTexturePtr>;
IECoreGL::ConstTexturePtr textureGetter( const TextureCacheKey &key, size_t &cost, const IECore::Canceller *canceller )
{
const OIIO::ImageSpec config( OIIO::TypeDesc::UCHAR );
OIIO::ImageBuf imageBuf( resolvedFileName( key.fileName ), /* subimage = */ 0, /* miplevel = */ 0, /* imagecache = */ nullptr, &config );
const std::string fileName = resolvedFileName( key.fileName );
OIIO::ImageBuf imageBuf( fileName, /* subimage = */ 0, /* miplevel = */ 0, /* imagecache = */ nullptr, &config );
imageBuf = OIIO::ImageBufAlgo::flip( imageBuf );
if( imageBuf.has_error() )
{
Expand All @@ -159,14 +160,17 @@ IECoreGL::ConstTexturePtr textureGetter( const TextureCacheKey &key, size_t &cos
case 1 :
pixelFormat = GL_RED;
break;
case 2 :
pixelFormat = GL_LUMINANCE_ALPHA;
break;
case 3 :
pixelFormat = GL_RGB;
break;
case 4 :
pixelFormat = GL_RGBA;
break;
default :
throw IECore::Exception( fmt::format( "Unsupported number of channels ({}) in \"{}\"", imageBuf.nchannels(), imageBuf.name() ) );
throw IECore::Exception( fmt::format( "Unsupported number of channels ({}) in \"{}\"", imageBuf.nchannels(), fileName ) );
}

GLuint id;
Expand Down

0 comments on commit c02ce07

Please sign in to comment.