Skip to content

Commit

Permalink
Spritesheet Deep Copy Splicing
Browse files Browse the repository at this point in the history
Changes the spritesheet dialog splicing to create deep copies of the
subimages so the original (usually much larger) spritesheet image is not
retained and becomes eligible for garbage collection. The technique used
was benchmarked to be quite fast using source composition which is
basically the same as a bitblt. This fixes the out of bounds errors in
the dialog because the subimage rectangle is intersected by the graphics
clip. The behavior is now the same as GM except for subimage rectangles
that lay on the edge or outside the spritesheet which will not contain
parts of the previous subimage (arguably a bug in GM). Later if the
editor were changed to use texture paging this would be needed anyway
to copy directly into the texture.
  • Loading branch information
RobertBColton committed Aug 20, 2020
1 parent a243645 commit 73f0bdf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion org/lateralgm/components/impl/SpriteStripDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

package org.lateralgm.components.impl;

import java.awt.AlphaComposite;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Expand Down Expand Up @@ -159,7 +161,17 @@ public BufferedImage[] getStrip()

int i = 0;
for (Rectangle r : this)
ret[i++] = img.getSubimage(r.x,r.y,r.width,r.height);
{
// deep copy the subimage so the original (likely much larger) spritesheet
// isn't retained and can be eligible for garbage collection
BufferedImage subimage = new BufferedImage(r.width,r.height,img.getType());
Graphics2D g2d = (Graphics2D)subimage.createGraphics();
// Src is fastest copy method, essentially a bitblt
g2d.setComposite(AlphaComposite.Src);
g2d.drawImage(img,-r.x,-r.y,null);
g2d.dispose(); // << cleanup
ret[i++] = subimage;
}

return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion org/lateralgm/main/LGM.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@

public final class LGM
{
public static final String version = "1.8.185"; //$NON-NLS-1$
public static final String version = "1.8.186"; //$NON-NLS-1$

// TODO: This list holds the class loader for any loaded plugins which should be
// cleaned up and closed when the application closes.
Expand Down

0 comments on commit 73f0bdf

Please sign in to comment.