[Patchanim-commit] SF.net SVN: patchanim: [226] trunk/patchanim/src/com/mebigfatguy/patchanim
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-02-24 02:49:04
|
Revision: 226
http://patchanim.svn.sourceforge.net/patchanim/?rev=226&view=rev
Author: dbrosius
Date: 2008-02-23 18:49:10 -0800 (Sat, 23 Feb 2008)
Log Message:
-----------
transparency seems to be mostly working
Modified Paths:
--------------
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java
trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchAnimator.java
trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchGenerator.java
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-02-24 02:28:36 UTC (rev 225)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-02-24 02:49:10 UTC (rev 226)
@@ -95,7 +95,7 @@
}
private void initComponents() {
- image = PatchGenerator.buildImage(rgb, SAMPLE_SIZE, SAMPLE_SIZE);
+ image = PatchGenerator.buildImage(rgb, false, SAMPLE_SIZE, SAMPLE_SIZE);
setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
Dimension d = new Dimension(SAMPLE_SIZE, SAMPLE_SIZE);
setMinimumSize(d);
@@ -146,6 +146,7 @@
mediator.addDocumentChangedListener(new DocumentChangedListener() {
public void documentChanged(DocumentChangedEvent dce) {
PatchAnimDocument doc = dce.getDocument();
+ image = PatchGenerator.buildImage(rgb, doc.useAlpha(), SAMPLE_SIZE, SAMPLE_SIZE);
oob = doc.getOutOfBoundsColor();
PatchPanelMediator mediator = PatchPanelMediator.getMediator();
if ((color != PatchColor.Alpha) || mediator.getDocument().useAlpha())
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchAnimator.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchAnimator.java 2008-02-24 02:28:36 UTC (rev 225)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchAnimator.java 2008-02-24 02:49:10 UTC (rev 226)
@@ -43,7 +43,7 @@
}
public void animatePatches() throws InterruptedException {
- BufferedImage image = PatchGenerator.buildImage(null, document.getWidth(), document.getHeight());
+ BufferedImage image = PatchGenerator.buildImage(null, document.useAlpha(), document.getWidth(), document.getHeight());
List<CombinedPatch> patches = document.getPatches();
int lastPatch = patches.size() - 1;
int tweenCount = document.getTweenCount();
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchGenerator.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchGenerator.java 2008-02-24 02:28:36 UTC (rev 225)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/surface/PatchGenerator.java 2008-02-24 02:49:10 UTC (rev 226)
@@ -37,23 +37,27 @@
if (patch == null)
return;
+ int numComponents = image.getColorModel().getNumComponents();
+ boolean useAlpha = numComponents == 4;
+
WritableRaster wr = image.getRaster();
DataBuffer db = wr.getDataBuffer();
int pixel = 0;
- PatchCoords[] coords = new PatchCoords[3];
+ PatchCoords[] coords = new PatchCoords[4];
coords[0] = patch.getPatch(PatchColor.Red);
coords[1] = patch.getPatch(PatchColor.Green);
coords[2] = patch.getPatch(PatchColor.Blue);
+ coords[3] = patch.getPatch(PatchColor.Alpha);
int order = coords[0].getOrder();
double u;
double v;
double[] uCoeffs = new double[order];
double[] vCoeffs = new double[order];
- double[] value = new double[3];
- int[] iValue = new int[3];
+ double[] value = new double[4];
+ int[] iValue = new int[4];
int sampleSizeX = image.getWidth();
int sampleSizeY = image.getHeight();
@@ -66,21 +70,23 @@
u = (double)iu / (double)sampleSizeX;
buildCoefficients(u, uCoeffs);
- value[0] = value[1] = value[2] = 0.0;
+ value[0] = value[1] = value[2] = value[3] = 0.0;
for (int j = 0; j < order; j++) {
for (int i = 0; i < order; i++) {
double coeff = uCoeffs[i] * vCoeffs[j];
- value[0] += coords[0].getCoordinate(i, j).getColor() * coeff;
- value[1] += coords[1].getCoordinate(i, j).getColor() * coeff;
- value[2] += coords[2].getCoordinate(i, j).getColor() * coeff;
+ for (int k = 0; k < numComponents; k++) {
+ value[k] += coords[k].getCoordinate(i, j).getColor() * coeff;
+ }
}
}
- for (int k = 0; k < 3; k++) {
+ for (int k = 0; k < numComponents; k++) {
iValue[k] = adjustColor(value[k], oob);
}
+ if (useAlpha)
+ db.setElem(pixel++, iValue[3]);
db.setElem(pixel++, iValue[2]);
db.setElem(pixel++, iValue[1]);
db.setElem(pixel++, iValue[0]);
@@ -167,11 +173,11 @@
return value;
}
- public static BufferedImage buildImage(Color color, int sampleSizeX, int sampleSizeY) {
+ public static BufferedImage buildImage(Color color, boolean useAlpha, int sampleSizeX, int sampleSizeY) {
BufferedImage image = null;
if (color == null) {
- image = new BufferedImage(sampleSizeX, sampleSizeY, BufferedImage.TYPE_3BYTE_BGR);
+ image = new BufferedImage(sampleSizeX, sampleSizeY, useAlpha ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_3BYTE_BGR);
} else {
byte[] r = new byte[256];
byte[] g = new byte[256];
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|