[Pixelle-commit] SF.net SVN: pixelle: [61] trunk/pixelle/src/com/mebigfatguy/pixelle
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-06-23 03:54:10
|
Revision: 61
http://pixelle.svn.sourceforge.net/pixelle/?rev=61&view=rev
Author: dbrosius
Date: 2008-06-22 20:54:13 -0700 (Sun, 22 Jun 2008)
Log Message:
-----------
start hooking up selection processing
Modified Paths:
--------------
trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleEval.java
trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleEvalFactory.java
trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleImage.java
trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java
trunk/pixelle/src/com/mebigfatguy/pixelle/eval/PixelleEval3ByteABGR.java
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleEval.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleEval.java 2008-06-23 01:14:48 UTC (rev 60)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleEval.java 2008-06-23 03:54:13 UTC (rev 61)
@@ -28,6 +28,7 @@
protected int width;
protected int height;
protected OutOfBoundsOption oobOption;
+ private int selectionByte;
public PixelleEval(PixelleImage image, OutOfBoundsOption option) {
srcImage = image;
@@ -111,9 +112,22 @@
}
private double getSelectionValue(int x, int y) {
- return 0.0;
+ return srcImage.getSelectionValue(x, y);
}
- private void setSelectionValue(int x, int y, double value) {
+ protected void setSelectionValue(int x, int y, double value) {
+ if ((x & 0x03) == 0) {
+ selectionByte = 0;
+ }
+
+ int imageWidth = srcImage.getWidth();
+ int bitOffset = 1 << (x & 0x07);
+ if (value == 0.0)
+ selectionByte &= ~bitOffset;
+ else
+ selectionByte |= bitOffset;
+
+ if (((x & 0x07) == 7) || (x == imageWidth))
+ srcImage.setSelectionByte(x >> 3, y, selectionByte);
}
}
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleEvalFactory.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleEvalFactory.java 2008-06-23 01:14:48 UTC (rev 60)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleEvalFactory.java 2008-06-23 03:54:13 UTC (rev 61)
@@ -50,6 +50,9 @@
case BufferedImage.TYPE_BYTE_BINARY:
break;
+ case BufferedImage.TYPE_BYTE_INDEXED:
+ break;
+
case BufferedImage.TYPE_BYTE_GRAY:
return new PixelleEvalByteGray(image, oobOption);
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleImage.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleImage.java 2008-06-23 01:14:48 UTC (rev 60)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleImage.java 2008-06-23 03:54:13 UTC (rev 61)
@@ -18,23 +18,25 @@
*/
package com.mebigfatguy.pixelle;
+import java.awt.AlphaComposite;
import java.awt.Color;
+import java.awt.Composite;
import java.awt.Graphics;
+import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
-import java.awt.image.IndexColorModel;
public class PixelleImage {
private BufferedImage image;
private BufferedImage selection;
+ private Composite composite;
public PixelleImage(BufferedImage img) {
image = img;
- byte[] color = new byte[] {0, -1};
- IndexColorModel bw = new IndexColorModel(1, 2, color, color, color);
- selection = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_BINARY, bw);
+ selection = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_BINARY);
+ composite = AlphaComposite.getInstance(AlphaComposite.XOR, 0.5f);
}
public int getType() {
@@ -52,8 +54,29 @@
public DataBuffer getBuffer() {
return image.getRaster().getDataBuffer();
}
+
public void draw(Graphics g, int left, int top, int width, int height) {
g.drawImage(image, left, top, width, height, Color.WHITE, null);
+ if (g instanceof Graphics2D) {
+ Graphics2D g2d = (Graphics2D)g;
+ Composite saveComposite = g2d.getComposite();
+ try {
+ g2d.setComposite(composite);
+ g.drawImage(selection, left, top, width, height, Color.WHITE, null);
+ } finally {
+ g2d.setComposite(saveComposite);
+ }
+ }
}
-
+
+ public int getSelectionValue(int x, int y) {
+ DataBuffer buffer = selection.getRaster().getDataBuffer();
+ return buffer.getElem(y * image.getWidth() + x);
+ }
+
+ public void setSelectionByte(int xByteOffset, int y, int byteValue) {
+ DataBuffer buffer = selection.getRaster().getDataBuffer();
+ int byteWidth = (getWidth() + 7) / 8;
+ buffer.setElem(y * byteWidth + xByteOffset, byteValue);
+ }
}
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java 2008-06-23 01:14:48 UTC (rev 60)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java 2008-06-23 03:54:13 UTC (rev 61)
@@ -28,6 +28,7 @@
import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.RecognitionException;
import com.mebigfatguy.pixelle.antlr.PixelleLexer;
import com.mebigfatguy.pixelle.antlr.PixelleParser;
@@ -44,6 +45,10 @@
}
public PixelleImage transform() throws PixelleTransformException {
+
+ String currentComponent = "";
+ String currentAlgorithm = "";
+
try {
/** eventually allow for gui to set width/height */
PixelleImage destImage = new PixelleImage(new BufferedImage(srcImage.getWidth(), srcImage.getHeight(), BufferedImage.TYPE_4BYTE_ABGR));
@@ -58,17 +63,21 @@
});
for (Map.Entry<PixelleComponent, String> entry : algorithms.entrySet()) {
- CharStream cs = new ANTLRStringStream(entry.getValue());
+ currentComponent = entry.getKey().name();
+ currentAlgorithm = entry.getValue();
+
+ CharStream cs = new ANTLRStringStream(currentAlgorithm);
PixelleLexer pl = new PixelleLexer(cs);
CommonTokenStream tokens = new CommonTokenStream();
tokens.setTokenSource(pl);
- String clsName = "com.mebigfatguy.pixelle.asm.PixelleExpr" + entry.getKey().name();
+
+ String clsName = "com.mebigfatguy.pixelle.asm.PixelleExpr" + currentComponent;
PixelleParser pp = new PixelleParser(tokens, clsName);
pp.pixelle();
byte[] bytes = pp.getClassBytes();
- dump(bytes, clsName + ".class");
+ dump(bytes, clsName.substring(clsName.lastIndexOf('.') + 1) + ".class");
pcl.addClass(clsName, bytes);
Class<?> cl = pcl.loadClass(clsName);
@@ -81,16 +90,14 @@
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
double value = expr.eval(srcPE, x, y);
-
destPE.setValue(x, y, pixelSpec, value);
}
}
}
return destImage;
-
} catch (Exception e) {
- throw new PixelleTransformException("Failed transforming the image", e);
+ throw new PixelleTransformException("Failed to transform the image: " + currentComponent + ": " + currentAlgorithm, e);
}
}
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/eval/PixelleEval3ByteABGR.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/eval/PixelleEval3ByteABGR.java 2008-06-23 01:14:48 UTC (rev 60)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/eval/PixelleEval3ByteABGR.java 2008-06-23 03:54:13 UTC (rev 61)
@@ -73,6 +73,7 @@
break;
case 's':
+ setSelectionValue(x, y, value);
break;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|