diff --git a/extras/src/main/java/edu/umd/cs/piccolox/nodes/PCacheCamera.java b/extras/src/main/java/edu/umd/cs/piccolox/nodes/PCacheCamera.java index dadeac5..d753762 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/nodes/PCacheCamera.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/nodes/PCacheCamera.java @@ -56,7 +56,7 @@ * */ private static final long serialVersionUID = 1L; - private BufferedImage paintBuffer; + private transient BufferedImage paintBuffer; private boolean imageAnimate; private PBounds imageAnimateBounds; @@ -65,16 +65,29 @@ */ protected BufferedImage getPaintBuffer() { final PBounds fRef = getFullBoundsReference(); - // TODO eclipse formatting made this ugly - if (paintBuffer == null || paintBuffer.getWidth() < fRef.getWidth() - || paintBuffer.getHeight() < fRef.getHeight()) { - paintBuffer = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() - .getDefaultConfiguration().createCompatibleImage((int) Math.ceil(fRef.getWidth()), - (int) Math.ceil(fRef.getHeight())); + if (paintBuffer == null || isBufferSmallerThanBounds(fRef)) { + paintBuffer = buildPaintBuffer(fRef); } return paintBuffer; } + private boolean isBufferSmallerThanBounds(final PBounds bounds) { + return paintBuffer.getWidth() < bounds.getWidth() || paintBuffer.getHeight() < bounds.getHeight(); + } + + private BufferedImage buildPaintBuffer(final PBounds fRef) { + final int newBufferWidth = (int) Math.ceil(fRef.getWidth()); + final int newBufferHeight = (int) Math.ceil(fRef.getHeight()); + + if (GraphicsEnvironment.isHeadless()) { + return new BufferedImage(newBufferWidth, newBufferHeight, BufferedImage.TYPE_4BYTE_ABGR); + } + else { + return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration() + .createCompatibleImage(newBufferWidth, newBufferHeight); + } + } + /** * Caches the information necessary to animate from the current view bounds * to the specified centerBounds