[wosaic commit] r336 - in trunk/src/wosaic: . utilities

1 view
Skip to first unread message

codesite...@google.com

unread,
Sep 17, 2008, 2:21:03 PM9/17/08
to wosaic...@googlegroups.com
Author: swegner2
Date: Wed Sep 17 11:20:15 2008
New Revision: 336

Modified:
trunk/src/wosaic/JAIProcessor.java
trunk/src/wosaic/WosaicUI.java
trunk/src/wosaic/utilities/Mosaic.java
trunk/src/wosaic/utilities/Parameters.java
trunk/src/wosaic/utilities/Pixel.java

Log:
Revert changes back to 332


Modified: trunk/src/wosaic/JAIProcessor.java
==============================================================================
--- trunk/src/wosaic/JAIProcessor.java (original)
+++ trunk/src/wosaic/JAIProcessor.java Wed Sep 17 11:20:15 2008
@@ -19,6 +19,8 @@
*/
public class JAIProcessor implements Runnable {

+ private int[][][] colorMap;
+
/**
* This is the Pixel object for the master image.
*/
@@ -66,7 +68,31 @@
statusObject = stat;
}

+ /**
+ * Split an image up into segments, and calculate its average color.
+ *
+ * @param numRows Number of rows in the mosaic
+ * @param numCols Number of columns in the mosaic
+ * @param width the width of a segment
+ * @param height the height of a segment
+ * @param mPixel the source image
+ * @return the average colors of each segment
+ */
+ public int[][][] analyzeSegments(final int numRows, final int numCols,
+ final int width, final int height, final Pixel mPixel) {
+
+ final int[][][] avgColors = new int[numRows][numCols][3];
+
+ for (int r = 0; r < numRows; r++)
+ for (int c = 0; c < numCols; c++) {
+ final int startY = r * height;
+ final int startX = c * width;
+ mPixel.getAvgColor(startX, startY, width, height,
+ avgColors[r][c]);
+ }

+ return avgColors;
+ }

/**
* Creates a mosaic by analyzing the master image, and then getting images
@@ -77,8 +103,7 @@
// System.out.println("Running MosaicThrd...");

// Calculate average colors of the segments of the master
- //colorMap = analyzeSegments(params.resRows, params.resCols, master.width
- mosaic.analyzeSegments(params.resRows, params.resCols, master.width
+ colorMap = analyzeSegments(params.resRows, params.resCols, master.width
/ params.resCols, master.height / params.resRows, master);

BufferedImage newImg = null;
@@ -91,7 +116,7 @@
}
final Pixel newPixel = new Pixel(newImg);

- mosaic.updateMosaic(newPixel);
+ mosaic.updateMosaic(newPixel, colorMap);
Thread.yield();
}


Modified: trunk/src/wosaic/WosaicUI.java
==============================================================================
--- trunk/src/wosaic/WosaicUI.java (original)
+++ trunk/src/wosaic/WosaicUI.java Wed Sep 17 11:20:15 2008
@@ -930,9 +930,6 @@

// Setup the parameters
final Parameters params = GenParams(SourceImage);
-
- // Choose algorithm type
- params.alg = Parameters.Algorithm.NoRepeats;

// Create the grid elements in our mosaic panel
MosaicDisplay.setGrid(params.resRows, params.resCols);

Modified: trunk/src/wosaic/utilities/Mosaic.java
==============================================================================
--- trunk/src/wosaic/utilities/Mosaic.java (original)
+++ trunk/src/wosaic/utilities/Mosaic.java Wed Sep 17 11:20:15 2008
@@ -3,14 +3,8 @@
*/
package wosaic.utilities;

-import java.awt.Graphics2D;
import java.awt.Point;
-import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
-import java.awt.image.ByteLookupTable;
-import java.awt.image.LookupOp;
-import java.awt.image.RescaleOp;
-import java.awt.image.ShortLookupTable;
import java.awt.image.WritableRaster;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -37,9 +31,6 @@
private Parameters params;

private int[][] scoreGrid;
-
- int[][][] colorMap;
-

/**
* Constructor for a mosaic object called by the Controller.
@@ -221,10 +212,6 @@

public void save(final BufferedImage img, final String file,
final String type) throws IOException {
-
- // DEBUG Apply tinting...
- tint(1f);
-
final FileOutputStream os = new FileOutputStream(file);
final JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
encoder.encode(img);
@@ -250,7 +237,8 @@
* @param colorMap the 3D array containing color information about the
* master image
*/
- public synchronized void updateMosaic(final Pixel srcPixel) {
+ public synchronized void updateMosaic(final Pixel srcPixel,
+ final int[][][] colorMap) {
// Check all the segments to see where this might fit
final ArrayList<Point> updatedCoords = new ArrayList<Point>();

@@ -267,17 +255,11 @@
// Like in golf, a lower score is better. This is simply
// made up of the total difference in each channel, added
// together. Other weights can be added in the future.
- int matchScore = rmDiff + gmDiff + bmDiff;
-
- // Decrease the score if this has been used before...
- if(params.alg == Parameters.Algorithm.NoRepeats) {
- matchScore += srcPixel.used * 10;
- }
+ final int matchScore = rmDiff + gmDiff + bmDiff;

if (imageGrid[r][c] != null) {

if (matchScore < scoreGrid[r][c]) {
- srcPixel.used++;
imageGrid[r][c] = srcPixel;
scoreGrid[r][c] = matchScore;
updatedCoords.add(new Point(r, c));
@@ -285,7 +267,6 @@

} else {
// Just assign this Pixel to this spot
- srcPixel.used++;
imageGrid[r][c] = srcPixel;
scoreGrid[r][c] = matchScore;

@@ -298,103 +279,6 @@
notifyAll();
}

-
- /**
- * Split an image up into segments, and calculate its average color.
- *
- * @param numRows
- * @param numCols
- * @param width
- * the width of a segment
- * @param height
- * the height of a segment
- * @param mPixel
- * the source image
- * @return the average colors of each segment
- */
- public void analyzeSegments(final int numRows, final int numCols,
- final int width, final int height, final Pixel mPixel) {
-
- final int[][][] avgColors = new int[numRows][numCols][3];
-
- for (int r = 0; r < numRows; r++)
- for (int c = 0; c < numCols; c++) {
- final int startY = r * height;
- final int startX = c * width;
- mPixel.getAvgColor(startX, startY, width, height,
- avgColors[r][c]);
- }
-
- colorMap = avgColors;
- }
-
- /**
- *
- * @param correction - Amount of tinting to apply
- *
- * Tints the tiles in the mosaic to more closely
- * match the master image.
- */
- public void tint(float correction) {
-
- // Construct rendering hints
- RenderingHints hints = new
RenderingHints(RenderingHints.KEY_ALPHA_INTERPOLATION,
RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
- hints.put(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
- hints.put(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
- hints.put(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
- hints.put(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
-
- int i, j, width, height;
-
- width = imageGrid.length;
- height = imageGrid[0].length;
-
- short[][] lookupData = new short[3][256];
- ShortLookupTable lookuptable;
- LookupOp op;
-
- for(i = 0; i < width; i++) {
- for (j=0; j < height; j++) {
- System.out.println("Processing img " + i + ", " + j);
- // Grab Image
- BufferedImage img = imageGrid[i][j].getImage();
-
-
- for (int k = 0; k < 3; k++) {
- // System.out.println("\tProcessing channel " + k);
- int sourceColor = (int)colorMap[i][j][k];
-
- for(int actualColor = 0; actualColor < 256; actualColor++) {
- //System.out.println("\t\tProcessing color " + actualColor);
- short newColor = (short)(.5f*actualColor + .5f*sourceColor);
- System.out.println("Lookup for channel " + k + ", value " +
actualColor + ": " + newColor);
- lookupData[k][actualColor] = newColor;
- }
- }
-
- lookuptable = new ShortLookupTable(0, lookupData);
- //
-
- /*
-
- System.out.print("r: " + offset[0]);
- System.out.print(" g: " + offset[1]);
- System.out.print(" b: " + offset[2] + "\n");
-
- */
-
- op = new LookupOp(lookuptable, hints);
- op.filter(img, img);
-
- /* Draw the image, applying the filter */
- // Graphics2D g2d = (Graphics2D) img.getGraphics();
- // g2d.drawImage(img, rop, 0, 0);
- }
- }
-
- }
-
-
/**
* Update the Pixel in a given coordinate with a new one.
*
@@ -407,8 +291,5 @@
final Pixel newPixel, int score) {
imageGrid[row][col] = newPixel;
scoreGrid[row][col] = score;
-
- // FIXME: The Mosaic should signal something to paint
}
-
}

Modified: trunk/src/wosaic/utilities/Parameters.java
==============================================================================
--- trunk/src/wosaic/utilities/Parameters.java (original)
+++ trunk/src/wosaic/utilities/Parameters.java Wed Sep 17 11:20:15 2008
@@ -37,13 +37,6 @@
* Physical width of each segment
*/
public int sWidth;
-
- public static enum Algorithm {
- BestFit,
- NoRepeats
- }
-
- public Algorithm alg;

/**
* Creates a fully initialized parameter set.

Modified: trunk/src/wosaic/utilities/Pixel.java
==============================================================================
--- trunk/src/wosaic/utilities/Pixel.java (original)
+++ trunk/src/wosaic/utilities/Pixel.java Wed Sep 17 11:20:15 2008
@@ -43,8 +43,6 @@
* The image's current width.
*/
public int width;
-
- public int used = 0;

/**
* Creates a Pixel object from a BufferedImage
@@ -187,14 +185,6 @@
public Raster getImageRaster() {
if (cachedRaster == null) cachedRaster = image.getData();
return cachedRaster;
- }
-
- /**
- *
- * @return the buffered image for this pixel
- */
- public BufferedImage getImage() {
- return image;
}

/**

Reply all
Reply to author
Forward
0 new messages