Less garbage
@@ -23,6 +23,7 @@ import java.io.*;
/** Records and saves GIFs. */
public class GifRecorder{
private static final float defaultSize = 300;
+ private static BufferedImage outImage;
private KeyCode resizeKey = KeyCode.CONTROL_LEFT,
openKey = KeyCode.E,
@@ -330,7 +331,10 @@ public class GifRecorder{
}
private BufferedImage toImage(byte[] frames, int width, int height){
- BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+ if(outImage == null || outImage.getWidth() != width || outImage.getHeight() != height){
+ outImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+ }
+ BufferedImage image = outImage;
for(int i = 0; i < width*height*4; i += 4){
int r = frames[i];
@@ -347,19 +351,6 @@ public class GifRecorder{
return image;
}
- private BufferedImage toImage(Pixmap pixmap){
- Color color = new Color();
- BufferedImage image = new BufferedImage(pixmap.getWidth(), pixmap.getHeight(), BufferedImage.TYPE_INT_ARGB);
- for(int x = 0; x < image.getWidth(); x++){
- for(int y = 0; y < image.getHeight(); y++){
- color.set(pixmap.getPixel(x, y));
- color.a = 1f;
- image.setRGB(x, y, Color.argb8888(color));
- }
- }
- return image;
- }
-
/** Default controller implementation, uses the provided keys */
class DefaultController implements RecorderController{
