Skip to content

Commit a9466c1

Browse files
authored
Merge pull request #5721 from johnhaddon/srgbFiasco
Image/ImageGadget : Avoid `IECoreImage.ImageReader`
2 parents a515001 + f91d847 commit a9466c1

File tree

14 files changed

+183
-164
lines changed

14 files changed

+183
-164
lines changed

Changes.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,23 @@ Fixes
99
- Fixed hangs and crashes when using non-default session modes such as SVM shading.
1010
- Fixed failure to render background light in batch renders (#5234).
1111
- Fixed failure to update when reverting a background shader to previous values.
12+
- GafferUI :
13+
- Fixed `Color space 'sRGB' could not be found` errors when running with certain custom OCIO configs (#5695).
14+
- Fixed icon colours when running with an ACES OCIO config.
1215

1316
Breaking Changes
1417
----------------
1518

1619
- CyclesOptions : Changed `hairShape` default value to "ribbon", to match Cycles' and Blender's own defaults.
20+
- Pointer :
21+
- Removed `Pointer( const ImagePrimitive * )` constructor.
22+
- Removed `image()` method.
23+
24+
API
25+
---
26+
27+
- ImageGadget : Removed `textureLoader()` method.
28+
- Pointer : Added `fileName()` method.
1729

1830
[^1]: To be omitted from final release notes for 1.4.0.0.
1931

SConstruct

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ libraries = {
10581058
"GafferUI" : {
10591059
"envAppends" : {
10601060
## \todo Stop linking against `Iex`. It is only necessary on Windows Imath 2 builds.
1061-
"LIBS" : [ "Gaffer", "Iex$IMATH_LIB_SUFFIX", "IECoreGL$CORTEX_LIB_SUFFIX", "IECoreImage$CORTEX_LIB_SUFFIX", "IECoreScene$CORTEX_LIB_SUFFIX" ],
1061+
"LIBS" : [ "Gaffer", "Iex$IMATH_LIB_SUFFIX", "IECoreGL$CORTEX_LIB_SUFFIX", "IECoreImage$CORTEX_LIB_SUFFIX", "IECoreScene$CORTEX_LIB_SUFFIX", "OpenImageIO$OIIO_LIB_SUFFIX", "OpenImageIO_Util$OIIO_LIB_SUFFIX" ],
10621062
},
10631063
"pythonEnvAppends" : {
10641064
"LIBS" : [ "IECoreImage$CORTEX_LIB_SUFFIX", "IECoreScene$CORTEX_LIB_SUFFIX", "IECoreGL$CORTEX_LIB_SUFFIX", "GafferUI", "GafferBindings" ],

include/GafferUI/ImageGadget.h

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ IE_CORE_FORWARDDECLARE( Texture )
5353
namespace GafferUI
5454
{
5555

56+
/// Gadget suitable for displaying icons and the like. For
57+
/// high-performance display of images generated by ImageNode,
58+
/// see `GafferImageUI::ImageGadget`.
5659
class GAFFERUI_API ImageGadget : public Gadget
5760
{
5861

@@ -62,22 +65,29 @@ class GAFFERUI_API ImageGadget : public Gadget
6265
/// the GAFFERUI_IMAGE_PATHS environment variable.
6366
/// Throws if the file cannot be loaded.
6467
explicit ImageGadget( const std::string &fileName );
65-
/// A copy of the image is taken.
68+
/// \deprecated
6669
ImageGadget( const IECoreImage::ConstImagePrimitivePtr image );
6770
~ImageGadget() override;
6871

6972
GAFFER_GRAPHCOMPONENT_DECLARE_TYPE( GafferUI::ImageGadget, ImageGadgetTypeId, Gadget );
7073

7174
Imath::Box3f bound() const override;
7275

73-
/// Returns the texture loader used for converting images
74-
/// on disk into textures for rendering. This is exposed
75-
/// publicly so that other code can share the same texture
76-
/// cache.
77-
static IECoreGL::TextureLoader *textureLoader();
78-
/// Loads a texture using the `textureLoader()` and applies
79-
/// the default ImageGadget texture parameters.
80-
static IECoreGL::ConstTexturePtr loadTexture( const std::string &fileName );
76+
struct GAFFERUI_API TextureParameters
77+
{
78+
GLint minFilter = GL_LINEAR_MIPMAP_LINEAR;
79+
GLint magFilter = GL_LINEAR;
80+
float lodBias = -1.0;
81+
GLint wrapS = GL_CLAMP_TO_BORDER;
82+
GLint wrapT = GL_CLAMP_TO_BORDER;
83+
static TextureParameters defaultParameters() { return {}; }
84+
};
85+
86+
/// Loads a texture suitable for rendering with `StandardStyle::renderImage()`,
87+
/// searching for it on the paths defined by the `GAFFERUI_IMAGE_PATHS` environment
88+
/// variable. Throws if the file cannot be loaded. Uses an internal cache, so the
89+
/// returned texture may be shared with other code, and is therefore const.
90+
static IECoreGL::ConstTexturePtr loadTexture( const std::string &fileName, const TextureParameters &parameters = TextureParameters::defaultParameters() );
8191

8292
protected :
8393

include/GafferUI/Pointer.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ class GAFFERUI_API Pointer : public IECore::RefCounted
5656

5757
IE_CORE_DECLAREMEMBERPTR( Pointer )
5858

59-
/// A copy of the image is taken.
60-
explicit Pointer( const IECoreImage::ImagePrimitive *image, const Imath::V2i &hotspot = Imath::V2i( -1 ) );
6159
/// Images are loaded from the paths specified by the
6260
/// GAFFERUI_IMAGE_PATHS environment variable.
6361
Pointer( const std::string &fileName, const Imath::V2i &hotspot = Imath::V2i( -1 ) );
6462

65-
const IECoreImage::ImagePrimitive *image() const;
63+
const std::string &fileName() const;
6664
const Imath::V2i &hotspot() const;
6765

6866
/// Sets the current pointer. Passing null resets the
@@ -83,7 +81,7 @@ class GAFFERUI_API Pointer : public IECore::RefCounted
8381

8482
private :
8583

86-
IECoreImage::ConstImagePrimitivePtr m_image;
84+
std::string m_fileName;
8785
Imath::V2i m_hotspot;
8886

8987
};

python/GafferUI/Image.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ def _qtIcon( self, highlighted = False ) :
171171
icon.addPixmap( self._qtPixmapDisabled(), QtGui.QIcon.Disabled )
172172
return icon
173173

174+
## \todo Deprecate and remove - we want to phase out ImagePrimitive.
175+
# Although we don't use this function or the `Image( ImagePrimitive )`
176+
# constructor in Gaffer itself, we can't do this immediately because some
177+
# external code currently depends on it.
174178
@staticmethod
175179
def _qtPixmapFromImagePrimitive( image ) :
176180

@@ -238,14 +242,7 @@ def __cacheGetter( cls, fileName ) :
238242
if not resolvedFileName :
239243
raise Exception( "Unable to find file \"%s\"" % fileName )
240244

241-
reader = IECore.Reader.create( resolvedFileName )
242-
243-
image = reader.read()
244-
if not isinstance( image, IECoreImage.ImagePrimitive ) :
245-
raise Exception( "File \"%s\" is not an image file" % resolvedFileName )
246-
247-
result = cls._qtPixmapFromImagePrimitive( image )
248-
245+
result = QtGui.QPixmap( resolvedFileName )
249246
cost = result.width() * result.height() * ( 4 if result.hasAlpha() else 3 )
250247

251248
return ( result, cost )

python/GafferUI/_Pointer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __pointerChanged() :
5555
application.restoreOverrideCursor()
5656
__cursorOverridden = False
5757
else :
58-
pixmap = GafferUI.Image._qtPixmapFromImagePrimitive( pointer.image() )
58+
pixmap = GafferUI.Image._qtPixmapFromFile( pointer.fileName() )
5959
cursor = QtGui.QCursor( pixmap, pointer.hotspot().x, pointer.hotspot().y )
6060
if __cursorOverridden :
6161
application.changeOverrideCursor( cursor )

python/GafferUITest/ImageGadgetTest.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
##########################################################################
3636

3737
import os
38+
import pathlib
3839
import unittest
3940
import imath
4041

@@ -64,16 +65,19 @@ def testMissingFiles( self ) :
6465

6566
self.assertRaises( Exception, GafferUI.ImageGadget, "iDonNotExist" )
6667

67-
def testTextureLoader( self ) :
68+
def testAllImages( self ) :
6869

69-
# must access an attribute from IECoreGL to force import
70-
# before calling textureLoader(), because it is imported
71-
# lazily by GafferUI.
72-
import IECoreGL
73-
IECoreGL.TextureLoader
70+
with GafferUI.Window() as window :
71+
gadgetWidget = GafferUI.GadgetWidget()
7472

75-
l = GafferUI.ImageGadget.textureLoader()
76-
self.assertTrue( isinstance( l, IECoreGL.TextureLoader ) )
73+
window.setVisible( True )
74+
75+
for path in IECore.SearchPath( os.environ["GAFFERUI_IMAGE_PATHS"] ).paths :
76+
for image in pathlib.Path( path ).glob( "*.png" ) :
77+
imageGadget = GafferUI.ImageGadget( str( image ) )
78+
gadgetWidget.getViewportGadget().setPrimaryChild( imageGadget )
79+
gadgetWidget.getViewportGadget().frame( imageGadget.bound() )
80+
self.waitForIdle( 100 )
7781

7882
if __name__ == "__main__":
7983
unittest.main()

src/GafferUI/AnnotationsGadget.cpp

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -74,37 +74,15 @@ Box2f nodeFrame( const NodeGadget *nodeGadget )
7474
}
7575

7676

77-
IECoreGL::Texture *bookmarkTexture()
77+
const IECoreGL::Texture *bookmarkTexture()
7878
{
79-
static IECoreGL::TexturePtr bookmarkTexture;
80-
81-
if( !bookmarkTexture )
82-
{
83-
bookmarkTexture = ImageGadget::textureLoader()->load( "bookmarkStar2.png" );
84-
85-
IECoreGL::Texture::ScopedBinding binding( *bookmarkTexture );
86-
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
87-
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
88-
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER );
89-
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER );
90-
}
79+
static IECoreGL::ConstTexturePtr bookmarkTexture = ImageGadget::loadTexture( "bookmarkStar2.png" );
9180
return bookmarkTexture.get();
9281
}
9382

94-
IECoreGL::Texture *numericBookmarkTexture()
83+
const IECoreGL::Texture *numericBookmarkTexture()
9584
{
96-
static IECoreGL::TexturePtr numericBookmarkTexture;
97-
98-
if( !numericBookmarkTexture )
99-
{
100-
numericBookmarkTexture = ImageGadget::textureLoader()->load( "bookmarkStar.png" );
101-
102-
IECoreGL::Texture::ScopedBinding binding( *numericBookmarkTexture );
103-
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
104-
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
105-
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER );
106-
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER );
107-
}
85+
static IECoreGL::ConstTexturePtr numericBookmarkTexture = ImageGadget::loadTexture( "bookmarkStar.png" );
10886
return numericBookmarkTexture.get();
10987
}
11088

0 commit comments

Comments
 (0)