Skip to content

Commit

Permalink
speed up raster engrave preview
Browse files Browse the repository at this point in the history
Java profiler for the win :-)
  • Loading branch information
mgmax authored and t-oster committed Aug 22, 2018
1 parent c2227a5 commit 0beb401
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/com/t_oster/visicut/gui/beans/PreviewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public void run()
catch (OutOfMemoryError e)
{
logger.log(Level.FINE, "Out of memory during rendering. Staring garbage collection");
buffer = null;
System.gc();
try
{
Expand Down
12 changes: 7 additions & 5 deletions src/com/t_oster/visicut/model/RasterProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.util.List;

/**
Expand Down Expand Up @@ -157,7 +158,11 @@ public BufferedImage getRenderedPreview(GraphicSet objects, MaterialProfile mate
if (bb != null && bb.width > 0 && bb.height > 0)
{
final BufferedImage scaledImg = renderObjects(objects, mm2px, bb, BufferedImage.TYPE_INT_ARGB);

final WritableRaster alphaRaster = scaledImg.getAlphaRaster(); // caching this yields significant speedup
final int[] zeros = new int[]
{
0, 0, 0
};
BufferedImageAdapter ad = new BufferedImageAdapter(scaledImg, invertColors)
{
//TODO: Gefahr, dass man das Dithering ergebnis verändert, falls
Expand All @@ -167,10 +172,7 @@ public void setGreyScale(int x, int y, int greyscale)
{
if (greyscale == 255)
{
scaledImg.getAlphaRaster().setPixel(x, y, new int[]
{
0, 0, 0
});
alphaRaster.setPixel(x, y, zeros);
}
else if (greyscale == 0)
{
Expand Down

0 comments on commit 0beb401

Please sign in to comment.