@@ -740,11 +740,7 @@ public Image(Device device, String filename) {
740740 if (!NSThread .isMainThread ()) pool = (NSAutoreleasePool ) new NSAutoreleasePool ().alloc ().init ();
741741 try {
742742 if (filename == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
743- initNative (filename );
744- if (this .handle == null ) {
745- initWithSupplier (zoom -> ImageDataLoader .canLoadAtZoom (filename , FileFormat .DEFAULT_ZOOM , zoom ),
746- zoom -> ImageDataLoader .loadByZoom (filename , FileFormat .DEFAULT_ZOOM , zoom ).element ());
747- }
743+ initUsingFileNameProvider (zoom -> zoom == 100 ? filename : null );
748744 init ();
749745 } finally {
750746 if (pool != null ) pool .release ();
@@ -783,34 +779,42 @@ public Image(Device device, String filename) {
783779public Image (Device device , ImageFileNameProvider imageFileNameProvider ) {
784780 super (device );
785781 if (imageFileNameProvider == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
786- this .imageFileNameProvider = imageFileNameProvider ;
787- String filename = imageFileNameProvider .getImagePath (100 );
788- if (filename == null ) SWT .error (SWT .ERROR_INVALID_ARGUMENT );
789782 NSAutoreleasePool pool = null ;
790783 if (!NSThread .isMainThread ()) pool = (NSAutoreleasePool ) new NSAutoreleasePool ().alloc ().init ();
791784 try {
792- initNative (filename );
793- if (this .handle == null ) init (ImageDataLoader .loadByZoom (filename , 100 , 100 ).element (), 100 );
785+ initUsingFileNameProvider (imageFileNameProvider );
794786 init ();
795- String filename2x = imageFileNameProvider .getImagePath (200 );
796- if (filename2x != null ) {
797- alphaInfo_200 = new AlphaInfo ();
798- id id = NSImageRep .imageRepWithContentsOfFile (NSString .stringWith (filename2x ));
799- NSImageRep rep = new NSImageRep (id );
800- handle .addRepresentation (rep );
801- } else if (ImageDataLoader .canLoadAtZoom (filename , 100 , 200 )) {
802- // Try to natively scale up the image (e.g. possible if it's an SVG)
803- ImageData imageData2x = ImageDataLoader .loadByZoom (filename , 100 , 200 ).element ();
804- alphaInfo_200 = new AlphaInfo ();
805- NSBitmapImageRep rep = createRepresentation (imageData2x , alphaInfo_200 );
806- handle .addRepresentation (rep );
807- rep .release ();
808- }
809787 } finally {
810788 if (pool != null ) pool .release ();
811789 }
812790}
813791
792+ private void initUsingFileNameProvider (ImageFileNameProvider imageFileNameProvider ) {
793+ this .imageFileNameProvider = imageFileNameProvider ;
794+ String filename = imageFileNameProvider .getImagePath (100 );
795+ if (filename == null ) {
796+ SWT .error (SWT .ERROR_INVALID_ARGUMENT );
797+ }
798+ initNative (filename );
799+ if (this .handle == null ) {
800+ init (ImageDataLoader .loadByZoom (filename , 100 , 100 ).element (), 100 );
801+ }
802+ String filename2x = imageFileNameProvider .getImagePath (200 );
803+ if (filename2x != null ) {
804+ alphaInfo_200 = new AlphaInfo ();
805+ id id = NSImageRep .imageRepWithContentsOfFile (NSString .stringWith (filename2x ));
806+ NSImageRep rep = new NSImageRep (id );
807+ handle .addRepresentation (rep );
808+ } else if (ImageDataLoader .canLoadAtZoom (filename , 100 , 200 )) {
809+ // Try to natively scale up the image (e.g. possible if it's an SVG)
810+ ImageData imageData2x = ImageDataLoader .loadByZoom (filename , 100 , 200 ).element ();
811+ alphaInfo_200 = new AlphaInfo ();
812+ NSBitmapImageRep rep = createRepresentation (imageData2x , alphaInfo_200 );
813+ handle .addRepresentation (rep );
814+ rep .release ();
815+ }
816+ }
817+
814818/**
815819 * Constructs an instance of this class by loading its representation
816820 * from the ImageData retrieved from the ImageDataProvider. Throws an
0 commit comments