SeadragonExporter crashes when run through Toolkit

Bug #877788 reported by Bertrand Fan
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Gephi
Fix Committed
High
Bertrand Fan

Bug Description

I am using the Toolkit to try to export via the SeadragonExporter. I extracted the org-gephi-plugins-seadragon.jar and imgscalr-lib-3.1.jar from the seadragon NPM.

My code looks like this:

SeadragonExporter exporter = new SeadragonExporter();

exporter.setPath(new File("/tmp/test"));

Workspace currentWorkspace = Lookup.getDefault().lookup(ProjectController.class).getCurrentWorkspace();
exporter.setWorkspace(currentWorkspace);

exporter.setTileSize(256);
exporter.setWidth(8000);
exporter.setHeight(8000);
exporter.setMargin(20);
exporter.execute();

which throws this error:

Exception in thread "main" java.lang.RuntimeException: java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
 at org.gephi.plugins.seadragon.SeadragonExporter.execute(SeadragonExporter.java:96)
 at org.gephi.toolkit.demos.HeadlessSimple.script(HeadlessSimple.java:180)
 at org.gephi.toolkit.demos.Main.main(Main.java:41)
Caused by: java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
 at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:999)
 at java.awt.image.BufferedImage.<init>(BufferedImage.java:324)
 at com.thebuzzmedia.imgscalr.Scalr.scaleImage(Scalr.java:1785)
 at com.thebuzzmedia.imgscalr.Scalr.scaleImageIncrementally(Scalr.java:1868)
 at com.thebuzzmedia.imgscalr.Scalr.resize(Scalr.java:1502)
 at com.thebuzzmedia.imgscalr.Scalr.resize(Scalr.java:1022)
 at org.gephi.plugins.seadragon.TileRenderer.writeLevel(TileRenderer.java:40)
 at org.gephi.plugins.seadragon.SeadragonExporter.export(SeadragonExporter.java:134)
 at org.gephi.plugins.seadragon.SeadragonExporter.execute(SeadragonExporter.java:94)
 ... 2 more

I ran it through the debugger and it looks like what's happening is SeadragonExporter.export loops through all the levels, in my case, 12 levels, calculating a levelScale for each and sending this to TileRenderer.writeLevel

writeLevel then creates an image with this code:

BufferedImage scaledImage = Scalr.resize(image, Scalr.Method.QUALITY, (int) (scale * image.getWidth()), (int) (scale * image.getHeight()), Scalr.OP_ANTIALIAS);

But as you can see, when we get down to the final level, 0:

main[1] print level
 level = 3
main[1] print levelScale
 levelScale = 0.001953125
main[1] cont
>
Breakpoint hit: "thread=main", org.gephi.plugins.seadragon.SeadragonExporter.export(), line=134 bci=261

main[1] print level
 level = 2
main[1] print levelScale
 levelScale = 9.765625E-4
main[1] cont
>
Breakpoint hit: "thread=main", org.gephi.plugins.seadragon.SeadragonExporter.export(), line=134 bci=261

main[1] print level
 level = 1
main[1] print levelScale
 levelScale = 4.8828125E-4
main[1] cont
>
Breakpoint hit: "thread=main", org.gephi.plugins.seadragon.SeadragonExporter.export(), line=134 bci=261

main[1] print level
 level = 0
main[1] print levelScale
 levelScale = 2.4414062E-4

The levelScale is so small that levelScale * image.getWidth() approximates to 0, which throws the exception because we can't create an image with a width or a height of 0. I've tried running deepZoom on my exported image normally and it looks like at the 0 level it is a 1x1 pixel image anyway.

Can we patch the code to return 1 instead of 0 for the calculation if it calculates to 0?

Revision history for this message
Mathieu Bastian (mathieu.bastian) wrote :

Thank you for the report, having 1 as a min seems the right thing to do. Can you provide a patch? I'll apply it asap and release a new version.

Changed in gephi:
status: New → Confirmed
importance: Undecided → High
Revision history for this message
Bertrand Fan (bertrandom) wrote :

Awesome, here's my patch.

Revision history for this message
Mathieu Bastian (mathieu.bastian) wrote :

Thanks! I applied the patch and uploaded a new version. Check for updates in Gephi, the new version should be there.

Changed in gephi:
status: Confirmed → Fix Committed
assignee: nobody → Bertrand Fan (bertrandom)
Revision history for this message
Bertrand Fan (bertrandom) wrote :

Thanks for applying that, I tested with the new org-gephi-plugins-seadragon.jar and it doesn't crash anymore. Success!

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.