Skip to content

Commit

Permalink
Reworked image buffer. Reusable images are now wiped clean instead of
Browse files Browse the repository at this point in the history
being replaced, and the OMScalingRaster/OMScalingIcons just use the
source image and modify that image at rendertime through the Graphics
object.
  • Loading branch information
dfdietrick committed Jul 25, 2014
1 parent 585804c commit c8afba5
Show file tree
Hide file tree
Showing 14 changed files with 559 additions and 438 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<!-- ############################
Cleanup targets
############################ -->
<target name="clean_all" depends="clean, clean_docs" description="Delete jar files, class files, and generated documentation.">
<target name="clean_all" depends="clean" description="Delete jar files, class files, and generated documentation.">
<delete dir="${mac.app}" />
<delete dir="${openmap_package.dir}" />
</target>
Expand Down
46 changes: 32 additions & 14 deletions src/openmap/com/bbn/openmap/BufferedMapBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package com.bbn.openmap;

import java.awt.AlphaComposite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
Expand Down Expand Up @@ -51,7 +52,7 @@ public class BufferedMapBean extends MapBean {

private static Logger logger = Logger.getLogger(BufferedMapBean.class.getName());
protected boolean bufferDirty = true;
protected Image drawingBuffer = null;
protected BufferedImage drawingBuffer = null;

PanHelper panningTransform = null;

Expand All @@ -76,17 +77,36 @@ public void componentResized(ComponentEvent e) {
}

/**
* Create the drawing buffer for the layers based on the projection
* parameters.
* Provide a drawing buffer for the layers based on the projection
* parameters. If the currentImageBuffer is the right size, the pixels will
* be cleared.
*
* @param proj
* @return BufferedImage used for reusable image buffer.
* @param currentImageBuffer the buffer to reuse and return, if the size is
* appropriate. Flushed if another BufferedImage is returned.
* @param proj the current projection of the map
* @return BufferedImage to be used for image buffer.
*/
protected BufferedImage resetDrawingBuffer(Projection proj) {
protected BufferedImage resetDrawingBuffer(BufferedImage currentImageBuffer, Projection proj) {
try {

int w = proj.getWidth();
int h = proj.getHeight();

if (currentImageBuffer != null) {
int cibWidth = currentImageBuffer.getWidth();
int cibHeight = currentImageBuffer.getHeight();

if (cibWidth == w && cibHeight == h) {
Graphics2D graphics = (Graphics2D) currentImageBuffer.getGraphics();
graphics.setComposite(AlphaComposite.Clear);
graphics.fillRect(0, 0, w, h);
graphics.setComposite(AlphaComposite.SrcOver);
return currentImageBuffer;
} else {
currentImageBuffer.flush();
}
}

return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

} catch (java.lang.NegativeArraySizeException nae) {
Expand All @@ -106,15 +126,14 @@ public void paintChildren(Graphics g, Rectangle clip) {

// if a layer has requested a render, then we render all of
// them into a drawing buffer
Image localDrawingBuffer = drawingBuffer;
BufferedImage localDrawingBuffer = drawingBuffer;

if (panningTransform == null && bufferDirty) {
bufferDirty = false;

if (localDrawingBuffer == null) {
localDrawingBuffer = resetDrawingBuffer(getProjection());
drawingBuffer = localDrawingBuffer;
}
localDrawingBuffer = resetDrawingBuffer(localDrawingBuffer, getProjection());
// In case it's been resized
drawingBuffer = localDrawingBuffer;

// draw the old image
Graphics gr = getMapBeanRepaintPolicy().modifyGraphicsForPainting(localDrawingBuffer.getGraphics());
Expand Down Expand Up @@ -174,7 +193,6 @@ public boolean isBuffered() {
*/
public void setBufferDirty(boolean value) {
bufferDirty = value;
disposeDrawingBuffer();
}

/**
Expand All @@ -196,7 +214,7 @@ protected void disposeDrawingBuffer() {
localDrawingBuffer.flush();
}
}

public void dispose() {
disposeDrawingBuffer();
super.dispose();
Expand Down
5 changes: 1 addition & 4 deletions src/openmap/com/bbn/openmap/dataAccess/image/ImageTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,13 @@ protected boolean updateImageForProjection(Projection proj) {

if (imageDecoder != null) {
if (!isOnMap(proj)) {
bitmap = null;
sourceImage = null;
setNeedToRegenerate(true);
return false;
}

// Check the scale against the cache to see if we should do
// anything.
if (shouldFetchForProjection(proj)) {
bitmap = null;

if (realSelection == null) {
if (getFillPaint() == com.bbn.openmap.omGraphics.OMColor.clear) {
Expand All @@ -189,7 +186,7 @@ protected boolean updateImageForProjection(Projection proj) {
realSelection = null;
}

if (sourceImage == null) {
if (bitmap == null) {
if (cache != null) {
setImage((Image) cache.get(imageDecoder));
} else {
Expand Down
14 changes: 5 additions & 9 deletions src/openmap/com/bbn/openmap/layer/BufferedLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -544,17 +544,13 @@ public void repaint(Layer layer) {
* image if the buffer is dirty.
*/
public void paintChildren(Graphics g, Rectangle clip) {
Image localDrawingBuffer = drawingBuffer;
BufferedImage localDrawingBuffer = drawingBuffer;
if (bufferDirty) {

// bufferDirty will be reset, drawingBuffer re-allocated in
// superclass method.
disposeDrawingBuffer();

// We need to reallocate, since the drawingBuffer is transparent
// for this MapBean. It's the fastest way to erase a transparent
// image.
localDrawingBuffer = resetDrawingBuffer(getProjection());
// Reset will clear out the pixels if the size of the buffer is
// appropriate for the projection
localDrawingBuffer = resetDrawingBuffer(localDrawingBuffer, getProjection());
// Reassign the drawingBuffer if a new buffer was allocated.
drawingBuffer = localDrawingBuffer;

paintLayers(localDrawingBuffer.getGraphics());
Expand Down
14 changes: 14 additions & 0 deletions src/openmap/com/bbn/openmap/layer/DemoLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,20 @@ public OMGraphicList init() {
if (sp != null) {
omsi.putAttribute(OMGraphic.TOOLTIP, sp.getDescription());
}

omsi = new OMScalingIcon(43f, -70f, ii);
omsi.setBaseScale(500000);
omsi.setMinScale(500000);
omsi.setMaxScale(500000);
omsi.setRotationAngle(-Math.PI / 4);
omsi.putAttribute(OMGraphicConstants.LABEL, new OMTextLabeler("SFPPV-----*****", OMText.JUSTIFY_LEFT, OMTextLabeler.ANCHOR_RIGHT));
omsi.putAttribute(OMGraphicConstants.NO_ROTATE, Boolean.TRUE);
omList.add(omsi);

if (sp != null) {
omsi.putAttribute(OMGraphic.TOOLTIP, sp.getDescription());
}

} else {
Debug.output("DemoLayer: couldn't create symbol from SymbolReferenceLibrary");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ public OMGraphicList construct() {
logger.fine(msg);
e.printStackTrace();
} else {
logger.fine(getName() + " layer ran out of memory, attempting to recover...");
logger.info(getName() + " layer ran out of memory, attempting to recover...");
}
} catch (Throwable e) {
msg = getName() + "|LayerWorker.construct(): " + e.getClass().getName() + ", "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class SimpleAnimationLayer extends OMGraphicHandlerLayer {
/**
* A movement factor for the points.
*/
double movementFactor = 1.0;
double movementFactor = 4.0;
/**
* Timer used to drive the animation for the layer.
*/
Expand Down Expand Up @@ -375,6 +375,7 @@ public void run() {
*
* @param point the OMPoint to move.
* @param factor a movement factor, in pixels.
* @param proj the current map projection
*/
protected void moveRandomly(OMPoint point, double factor, Projection proj) {
double hor = Math.random() - .5;
Expand All @@ -394,6 +395,7 @@ protected void moveRandomly(OMPoint point, double factor, Projection proj) {
*
* @param point the OMPoint to move.
* @param factor a movement factor, in pixels.
* @param proj the current map projection
*/
protected void moveRandomly(OMScalingIcon point, double factor, Projection proj) {
double hor = Math.random() - .5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void workerComplete(OMGraphicList aList) {
layer.setList(aList);

// Don't call repaint if the layer list was null, and still is.
if (repaintIt && aList != null) {
if (repaintIt || aList != null) {
layer.repaint();
} else {
getLogger().fine("Not painting cause of nothin'");
Expand Down
Loading

0 comments on commit c8afba5

Please sign in to comment.