[Patchanim-commit] SF.net SVN: patchanim: [14] trunk/patchanim/src/com/mebigfatguy/patchanim
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-01-26 05:12:34
|
Revision: 14
http://patchanim.svn.sourceforge.net/patchanim/?rev=14&view=rev
Author: dbrosius
Date: 2008-01-25 21:12:25 -0800 (Fri, 25 Jan 2008)
Log Message:
-----------
R,G,B Sample patch drawing starting to work.
Modified Paths:
--------------
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java
trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java
trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java 2008-01-25 13:06:04 UTC (rev 13)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java 2008-01-26 05:12:25 UTC (rev 14)
@@ -23,6 +23,7 @@
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
+import java.awt.image.BufferedImage;
import java.util.ResourceBundle;
import javax.swing.Box;
@@ -91,15 +92,11 @@
mediator.addActivePatchChangedListener(new ActivePatchChangedListener() {
public void activePatchChanged(ActivePatchChangedEvent apce) {
CombinedPatch currentPatch = apce.getActivePatch();
- if (color == PatchColor.Red)
- coords = currentPatch.getRedPatch();
- else if (color == PatchColor.Green)
- coords = currentPatch.getGreenPatch();
- else if (color == PatchColor.Blue)
- coords = currentPatch.getBluePatch();
- else
- return;
- setColorField();
+ coords = currentPatch.getPatch(color);
+ if (coords != null) {
+ setColorField();
+ sample.recalcImage(color, currentPatch);
+ }
}
});
}
@@ -113,7 +110,7 @@
}
});
}
-
+
public void drawDecoration(Graphics2D g, Rectangle bounds) {
if (coords == null)
return;
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-01-25 13:06:04 UTC (rev 13)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-01-26 05:12:25 UTC (rev 14)
@@ -31,11 +31,15 @@
import javax.swing.BorderFactory;
import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
import com.mebigfatguy.patchanim.PatchColor;
+import com.mebigfatguy.patchanim.surface.CombinedPatch;
+import com.mebigfatguy.patchanim.surface.PatchCoords;
public class JPatchSamplePanel extends JPanel {
private static final int SAMPLE_SIZE = 200;
+ private static final int ORDER = 4;
private PatchColor color;
private Color rgb;
private BufferedImage image;
@@ -82,6 +86,80 @@
});
}
+ public void recalcImage(final PatchColor color, final CombinedPatch patch) {
+ Thread t = new Thread(new Runnable() {
+ public void run() {
+ if (color == PatchColor.Combined) {
+
+ } else {
+ PatchCoords coords = patch.getPatch(color);
+
+ double u, u2, u3, oneMinusU, oneMinusU2, oneMinusU3;
+ double v, v2, v3, oneMinusV, oneMinusV2, oneMinusV3;
+ double[] uCoeffs = new double[ORDER];
+ double[] vCoeffs = new double[ORDER];
+
+ for (int iu = 0; iu < SAMPLE_SIZE; iu++) {
+ u = (double)iu / (double)SAMPLE_SIZE;
+ u2 = u * u;
+ u3 = u2 * u;
+ oneMinusU = 1.0 - u;
+ oneMinusU2 = oneMinusU * oneMinusU;
+ oneMinusU3 = oneMinusU2 * oneMinusU;
+
+ uCoeffs[0] = oneMinusU3;
+ uCoeffs[1] = 3.0 * u * oneMinusU2;
+ uCoeffs[2] = 3.0 * u2 * oneMinusU;
+ uCoeffs[3] = u3;
+
+ for (int iv = 0; iv < SAMPLE_SIZE; iv++) {
+ v = (double)iv / (double)SAMPLE_SIZE;
+ v2 = v * v;
+ v3 = v2 * v;
+ oneMinusV = 1.0 - v;
+ oneMinusV2 = oneMinusV * oneMinusV;
+ oneMinusV3 = oneMinusV2 * oneMinusV;
+
+ vCoeffs[0] = oneMinusV3;
+ vCoeffs[1] = 3.0 * v * oneMinusV2;
+ vCoeffs[2] = 3.0 * v2 * oneMinusV;
+ vCoeffs[3] = v3;
+
+ double value = 0.0;
+ for (int i = 0; i < ORDER; i++) {
+ for (int j = 0; j < ORDER; j++) {
+ value += coords.getCoordinate(i, j).getColor() * uCoeffs[i] * vCoeffs[j];
+ }
+ }
+
+ int iValue = (int)value;
+ if (iValue > 255)
+ iValue = 255;
+ else if (iValue < 0)
+ iValue = 0;
+ if (color == PatchColor.Red)
+ iValue <<= 16;
+ else if (color == PatchColor.Green)
+ iValue <<= 8;
+ iValue |= 0xFF000000;
+
+ image.setRGB(iu, iv, iValue);
+ }
+ }
+ }
+
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ invalidate();
+ revalidate();
+ repaint();
+ }
+ });
+ }
+ });
+ t.start();
+ }
+
private void buildImage() {
if (rgb == null) {
image = new BufferedImage(SAMPLE_SIZE, SAMPLE_SIZE, BufferedImage.TYPE_3BYTE_BGR);
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java 2008-01-25 13:06:04 UTC (rev 13)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/CombinedPatch.java 2008-01-26 05:12:25 UTC (rev 14)
@@ -19,25 +19,26 @@
package com.mebigfatguy.patchanim.surface;
import java.io.Serializable;
+import java.util.EnumMap;
import java.util.Random;
+import com.mebigfatguy.patchanim.PatchColor;
+
public class CombinedPatch implements Serializable {
+ private static final long serialVersionUID = 8732763987020552187L;
+
+ private EnumMap<PatchColor, PatchCoords> patches = new EnumMap<PatchColor, PatchCoords>(PatchColor.class);
- private PatchCoords red;
- private PatchCoords green;
- private PatchCoords blue;
-
public CombinedPatch() {
-
- red = buildRandomPatch();
- green = buildRandomPatch();
- blue = buildRandomPatch();
+ patches.put(PatchColor.Red, buildRandomPatch());
+ patches.put(PatchColor.Green, buildRandomPatch());
+ patches.put(PatchColor.Blue, buildRandomPatch());
}
public CombinedPatch(PatchCoords redPatch, PatchCoords greenPatch, PatchCoords bluePatch) {
- red = redPatch;
- green = greenPatch;
- blue = bluePatch;
+ patches.put(PatchColor.Red, redPatch);
+ patches.put(PatchColor.Green, greenPatch);
+ patches.put(PatchColor.Blue, bluePatch);
}
private PatchCoords buildRandomPatch() {
@@ -51,30 +52,14 @@
return new PatchCoords(coords);
}
- public PatchCoords getRedPatch() {
- return red;
+ public PatchCoords getPatch(PatchColor color) {
+ return patches.get(color);
}
- public void setRedPatch(PatchCoords coords) {
- red = coords;
+ public void setPatch(PatchColor color, PatchCoords coords) {
+ patches.put(color, coords);
}
- public PatchCoords getGreenPatch() {
- return green;
- }
-
- public void setGreenPatch(PatchCoords coords) {
- green = coords;
- }
-
- public PatchCoords getBluePatch() {
- return blue;
- }
-
- public void setBluePatch(PatchCoords coords) {
- blue = coords;
- }
-
@Override
public String toString() {
return "Patch Coordinates";
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java 2008-01-25 13:06:04 UTC (rev 13)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchCoords.java 2008-01-26 05:12:25 UTC (rev 14)
@@ -30,12 +30,12 @@
coords = coordinates;
}
- public Coordinate getCoordinate(int u, int v) {
- return coords[u][v];
+ public Coordinate getCoordinate(int i, int j) {
+ return coords[i][j];
}
- public void setCoordinate(int u, int v, Coordinate coordinate) {
- coords[u][v] = coordinate;
+ public void setCoordinate(int i, int j, Coordinate coordinate) {
+ coords[i][j] = coordinate;
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|