[Polycasso-commit] SF.net SVN: polycasso:[49] trunk/polycasso/src/com/mebigfatguy/polycasso/ ImageG
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2009-11-25 04:18:41
|
Revision: 49
http://polycasso.svn.sourceforge.net/polycasso/?rev=49&view=rev
Author: dbrosius
Date: 2009-11-25 04:18:33 +0000 (Wed, 25 Nov 2009)
Log Message:
-----------
pull stuff out of sync block that doesn't need to be synchronized
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java 2009-11-25 03:58:52 UTC (rev 48)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java 2009-11-25 04:18:33 UTC (rev 49)
@@ -47,6 +47,7 @@
private Feedback feedback;
private Thread[] t = null;
private Object lock = new Object();
+ private Object startStopLock = new Object();
/**
* creates an ImageGenerator for the given target image, and size
@@ -99,7 +100,7 @@
* starts up threads to start looking for images that are closest to the target
*/
public void startGenerating() {
- synchronized(lock) {
+ synchronized(startStopLock) {
if (t == null) {
t = new Thread[NUM_THREADS];
for (int i = 0; i < NUM_THREADS; i++) {
@@ -114,7 +115,7 @@
* shuts down threads that were looking for images
*/
public void stopGenerating() {
- synchronized(lock) {
+ synchronized(startStopLock) {
if (t != null) {
try {
for (int i = 0; i < NUM_THREADS; i++) {
@@ -162,6 +163,7 @@
double delta = feedback.calculateDelta(image);
String message = null;
+ boolean newBest = false;
synchronized(lock) {
attempt++;
if (delta < bestScore) {
@@ -169,15 +171,20 @@
bestScore = delta;
if (Polycasso.DEBUG)
message = "Attempt: " + attempt + " BestScore: " + bestScore + " type: " + type.name();
- fireImageGenerated(image);
- image = new BufferedImage(imageSize.width, imageSize.height, BufferedImage.TYPE_4BYTE_ABGR);
- g2d = (Graphics2D)image.getGraphics();
+ newBest = true;
}
}
+
if (Polycasso.DEBUG) {
if (message != null)
System.out.println(message);
}
+
+ if (newBest) {
+ fireImageGenerated(image);
+ image = new BufferedImage(imageSize.width, imageSize.height, BufferedImage.TYPE_4BYTE_ABGR);
+ g2d = (Graphics2D)image.getGraphics();
+ }
}
} catch (Exception e) {
e.printStackTrace();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|