[Pixelle-commit] SF.net SVN: pixelle:[233] trunk/pixelle
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2009-02-16 08:09:51
|
Revision: 233
http://pixelle.svn.sourceforge.net/pixelle/?rev=233&view=rev
Author: dbrosius
Date: 2009-02-16 08:09:42 +0000 (Mon, 16 Feb 2009)
Log Message:
-----------
start changing over to use multiple input sources - not working yet
Modified Paths:
--------------
trunk/pixelle/etc/Pixelle.g
trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleExpr.java
trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java
Modified: trunk/pixelle/etc/Pixelle.g
===================================================================
--- trunk/pixelle/etc/Pixelle.g 2009-01-02 02:05:36 UTC (rev 232)
+++ trunk/pixelle/etc/Pixelle.g 2009-02-16 08:09:42 UTC (rev 233)
@@ -33,19 +33,38 @@
@members {
ClassWriter cw;
MethodVisitor mv;
+ String clz;
public PixelleParser(CommonTokenStream tokens, String clsName) {
super(tokens, new RecognizerSharedState());
- clsName = clsName.replace('.', '/');
+ clz = clsName.replace('.', '/');
cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
- cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, clsName, null, "java/lang/Object", new String[] {"com/mebigfatguy/pixelle/PixelleExpr"});
+ cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, clz, null, "java/lang/Object", new String[] {"com/mebigfatguy/pixelle/PixelleExpr"});
+
+ cw.visitField(Opcodes.ACC_PRIVATE, "width", "I", null, Integer.valueOf(0));
+ cw.visitField(Opcodes.ACC_PRIVATE, "height", "I", null, Integer.valueOf(0));
+
mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, new String[0]);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(0,0);
- mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "eval", "(Lcom/mebigfatguy/pixelle/PixelleEval;II)D", null, new String[0]);
+
+ mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "setOutputSize", "(II)V", null, new String[0]);
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
+ mv.visitInsn(Opcodes.DUP);
+ mv.visitVarInsn(Opcodes.ILOAD, 1);
+ mv.visitFieldInsn(Opcodes.PUTFIELD, clz, "width", "I");
+ mv.visitVarInsn(Opcodes.ILOAD, 2);
+ mv.visitFieldInsn(Opcodes.PUTFIELD, clz, "height", "I");
+ mv.visitInsn(Opcodes.RETURN);
+ mv.visitMaxs(0,0);
+
+ mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "eval", "([Lcom/mebigfatguy/pixelle/PixelleEval;II)D", null, new String[0]);
+ mv.visitVarInsn(Opcodes.ALOAD, 1);
+ mv.visitInsn(Opcodes.ARRAYLENGTH);
+ mv.visitVarInsn(Opcodes.ISTORE, 4);
}
public byte[] getClassBytes() {
@@ -277,6 +296,10 @@
| factor ;
factor
+ @init
+ {
+ int sourceSelector = 0;
+ }
: NUMBER
{
mv.visitLdcInsn(Double.valueOf($NUMBER.text));
@@ -285,6 +308,13 @@
| 'p'
{
mv.visitVarInsn(Opcodes.ALOAD, 1);
+ }
+ // Put in source selector code, for now use 0
+ {
+ mv.visitLdcInsn(Integer.valueOf(sourceSelector));
+ mv.visitVarInsn(Opcodes.ILOAD, 4);
+ mv.visitInsn(Opcodes.IREM);
+ mv.visitInsn(Opcodes.AALOAD);
}
'[' expr
{
@@ -312,14 +342,14 @@
}
| 'width'
{
- mv.visitVarInsn(Opcodes.ALOAD, 1);
- mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/mebigfatguy/pixelle/PixelleEval", "getWidth", "()I" );
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
+ mv.visitFieldInsn(Opcodes.GETFIELD, clz, "width", "I");
mv.visitInsn(Opcodes.I2D);
}
| 'height'
{
- mv.visitVarInsn(Opcodes.ALOAD, 1);
- mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/mebigfatguy/pixelle/PixelleEval", "getHeight", "()I" );
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
+ mv.visitFieldInsn(Opcodes.GETFIELD, clz, "height", "I");
mv.visitInsn(Opcodes.I2D);
}
| 'abs' '(' expr ')'
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleExpr.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleExpr.java 2009-01-02 02:05:36 UTC (rev 232)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleExpr.java 2009-02-16 08:09:42 UTC (rev 233)
@@ -23,5 +23,6 @@
* pixel component values.
*/
public interface PixelleExpr {
- double eval(PixelleEval e, int x, int y);
+ void setOutputSize(int width, int height);
+ double eval(PixelleEval[] exprs, int x, int y);
}
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java 2009-01-02 02:05:36 UTC (rev 232)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java 2009-02-16 08:09:42 UTC (rev 233)
@@ -101,6 +101,9 @@
}
PixelleEval srcPE = PixelleEvalFactory.create(srcImage);
+ PixelleEval[] sources = new PixelleEval[1];
+ sources[0] = srcPE;
+
PixelleClassLoader pcl = AccessController.doPrivileged(new PrivilegedAction<PixelleClassLoader>() {
public PixelleClassLoader run() {
return new PixelleClassLoader(Thread.currentThread().getContextClassLoader());
@@ -122,19 +125,20 @@
pp.pixelle();
byte[] bytes = pp.getClassBytes();
- //dump(bytes, clsName.substring(clsName.lastIndexOf('.') + 1) + ".class");
+ dump(bytes, clsName.substring(clsName.lastIndexOf('.') + 1) + ".class");
pcl.addClass(clsName, bytes);
Class<?> cl = pcl.loadClass(clsName);
PixelleExpr expr = (PixelleExpr)cl.newInstance();
-
int width = destImage.getWidth();
int height = destImage.getHeight();
+ expr.setOutputSize(width, height);
+
char pixelSpec = entry.getKey().getPixelSpec();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
- double value = expr.eval(srcPE, x, y);
+ double value = expr.eval(sources, x, y);
destPE.setValue(x, y, pixelSpec, value);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|