[Pixelle-commit] SF.net SVN: pixelle:[290] trunk/pixelle/src/com/mebigfatguy/pixelle
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2009-07-20 07:39:23
|
Revision: 290
http://pixelle.svn.sourceforge.net/pixelle/?rev=290&view=rev
Author: dbrosius
Date: 2009-07-20 07:39:22 +0000 (Mon, 20 Jul 2009)
Log Message:
-----------
stub in selection outliner
Modified Paths:
--------------
trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleEval.java
trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleImage.java
trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleEval.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleEval.java 2009-07-20 07:36:47 UTC (rev 289)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleEval.java 2009-07-20 07:39:22 UTC (rev 290)
@@ -21,12 +21,12 @@
import java.awt.Color;
import java.awt.image.DataBuffer;
-/**
+/**
* an abstract class for evaluation pixels in arbitrary images by enforcing a
* template pattern that derived classes implement per image format.
*/
public abstract class PixelleEval {
-
+
protected PixelleImage srcImage;
protected DataBuffer buffer;
protected int width;
@@ -34,7 +34,7 @@
protected IndexOutOfBoundsOption ioobOption;
protected ColorOutOfBoundsOption coobOption;
private int selectionByte;
-
+
/**
* create an evaluator for a specific image and options
*
@@ -50,7 +50,7 @@
ioobOption = iOption;
coobOption = cOption;
}
-
+
/**
* template method to get the red value at a specific x and y
*
@@ -95,65 +95,67 @@
* @return the pixel value at the given coordinate for the pixel specification
*/
public double getValue(int x, int y, char pixelSpec) {
-
+
/* in the future, allow customization of out of bounds indices */
if (((x < 0) || (x >= width)) || ((y < 0) || (y >= height))) {
switch (ioobOption) {
- case SpecifiedColor:
- Color c = ioobOption.getColor();
- switch (pixelSpec) {
- case 'r':
- return c.getRed();
- case 'g':
- return c.getGreen();
- case 'b':
- return c.getBlue();
- case 't':
- return 1.0;
- case 's':
- default:
- return 0.0;
- }
-
- case BorderColor:
- if (x < 0)
- x = 0;
- else if (x >= width)
- x = width - 1;
- if (y < 0)
- y = 0;
- else if (y >= height)
- y = height - 1;
+ case SpecifiedColor:
+ Color c = ioobOption.getColor();
+ switch (pixelSpec) {
+ case 'r':
+ return c.getRed();
+ case 'g':
+ return c.getGreen();
+ case 'b':
+ return c.getBlue();
+ case 't':
+ return 1.0;
+ case 's':
+ default:
+ return 0.0;
+ }
+
+ case BorderColor:
+ if (x < 0) {
+ x = 0;
+ } else if (x >= width) {
+ x = width - 1;
+ }
+ if (y < 0) {
+ y = 0;
+ } else if (y >= height) {
+ y = height - 1;
+ }
break;
-
- case WrapColor:
- x %= width;
- y %= height;
+
+ case WrapColor:
+ x %= width;
+ y %= height;
break;
}
}
-
+
switch (pixelSpec) {
- case 'r':
- return getRedValue(x, y);
-
- case 'g':
- return getGreenValue(x, y);
-
- case 'b':
- return getBlueValue(x, y);
-
- case 't':
- return getTransparencyValue(x, y);
-
- case 's':
- return getSelectionValue(x, y);
-
- default:
- return 0.0;
+ case 'r':
+ return getRedValue(x, y);
+
+ case 'g':
+ return getGreenValue(x, y);
+
+ case 'b':
+ return getBlueValue(x, y);
+
+ case 't':
+ return getTransparencyValue(x, y);
+
+ case 's':
+ return getSelectionValue(x, y);
+
+ default:
+ return 0.0;
}
}
-
+
/**
* sets the pixel value at the specified x, y
* @param x the x coordinate
@@ -164,7 +166,7 @@
public void setValue(int x, int y, char pixelSpec, double value) {
//Overridden in classes that are uses for output images
}
-
+
/**
* gets the width of the source image
*
@@ -173,7 +175,7 @@
public int getWidth() {
return width;
}
-
+
/**
* gets the height of the source image
*
@@ -182,7 +184,7 @@
public int getHeight() {
return height;
}
-
+
/**
* gets the selection value at specific index
*
@@ -194,11 +196,11 @@
if ((x & 0x07) == 0) {
selectionByte = srcImage.getSelectionByte(x >> 3, y);
}
-
+
int bitOffset = 1 << (x & 0x07);
return ((selectionByte & bitOffset) == 0) ? 0 : 1;
}
-
+
/**
* sets the selection value at a specific index
* @param x the x coordinate
@@ -207,59 +209,65 @@
*/
protected void setSelectionValue(int x, int y, double value) {
int bit = x & 0x07;
- if (bit == 0)
+ if (bit == 0) {
selectionByte = 0;
-
+ }
+
if (value != 0.0) {
int bitOffset = 1 << (7 - bit);
selectionByte |= bitOffset;
}
-
- if ((bit == 7) || (x == width))
+
+ if ((bit == 7) || (x == width)) {
srcImage.setSelectionByte(x >> 3, y, selectionByte);
+ }
}
-
+
/**
* adjust out of bounds colors by applying rules of ColorOutOfBoundsOption
* @param value the input color value
* @return the output color value
*/
protected double adjustColor(double value) {
- if ((value >= 0.0) && (value <= 255.0))
+ if ((value >= 0.0) && (value <= 255.0)) {
return value;
-
+ }
+
switch (coobOption) {
-
- case Roll: {
- int ival = (int)(value + 0.49) % 256;
- return ival;
- }
- case Wave: {
- int ival = (int)(value + 0.49);
- int period = ival / 256;
- if ((period & 0x01) != 0) {
- if (ival > 0)
- ival = 255 - (ival+1) & 0x00FF;
- else
- ival = ival & 0x00FF;
+ case Roll: {
+ int ival = (int)(value + 0.49) % 256;
+ return ival;
+ }
+
+ case Wave: {
+ int ival = (int)(value + 0.49);
+ int period = ival / 256;
+ if ((period & 0x01) != 0) {
+ if (ival > 0) {
+ ival = 255 - (ival+1) & 0x00FF;
+ } else {
+ ival = ival & 0x00FF;
}
- else {
- if (ival > 0)
- ival = ival & 0x00FF;
- else
- ival = 256 - ival & 0x00FF;
+ }
+ else {
+ if (ival > 0) {
+ ival = ival & 0x00FF;
+ } else {
+ ival = 256 - ival & 0x00FF;
}
- return ival;
}
+ return ival;
+ }
- case Clip:
- default: {
- if (value < 0.0)
- return 0.0;
- else
- return 255.0;
+ case Clip:
+ default: {
+ if (value < 0.0) {
+ return 0.0;
+ } else {
+ return 255.0;
}
}
+ }
}
}
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleImage.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleImage.java 2009-07-20 07:36:47 UTC (rev 289)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleImage.java 2009-07-20 07:39:22 UTC (rev 290)
@@ -32,18 +32,18 @@
* to represent the real image, and the second to represent selection.
*/
public class PixelleImage {
-
- private BufferedImage image;
+
+ private final BufferedImage image;
private BufferedImage selection;
- private Composite composite;
-
+ private final Composite composite;
+
public PixelleImage() {
this(new BufferedImage(400, 400, BufferedImage.TYPE_3BYTE_BGR));
}
-
+
public PixelleImage(BufferedImage img) {
image = img;
-
+
byte[] wb = new byte[] {-1, 0};
byte[] alpha = new byte[] {0, -1};
IndexColorModel model = new IndexColorModel(1, 2, wb, wb, wb, alpha);
@@ -53,27 +53,27 @@
g.setColor(Color.WHITE);
g.fillRect(0, 0, getWidth(), getHeight());
}
-
+
public BufferedImage getSaveImage() {
return image;
}
-
+
public int getType() {
return image.getType();
}
-
+
public final int getWidth() {
return image.getWidth();
}
-
+
public final int getHeight() {
return image.getHeight();
}
-
+
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, null);
if (g instanceof Graphics2D) {
@@ -87,16 +87,21 @@
}
}
}
-
+
public int getSelectionByte(int xByteOffset, int y) {
DataBuffer buffer = selection.getRaster().getDataBuffer();
int byteWidth = (getWidth() + 7) >> 3;
return buffer.getElem(y * byteWidth + xByteOffset);
}
-
+
public void setSelectionByte(int xByteOffset, int y, int byteValue) {
DataBuffer buffer = selection.getRaster().getDataBuffer();
int byteWidth = (getWidth() + 7) >> 3;
buffer.setElem(y * byteWidth + xByteOffset, byteValue);
}
+
+ public void finishImage() {
+ SelectionOutliner so = new SelectionOutliner();
+ selection = so.createOutline(selection);
+ }
}
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java 2009-07-20 07:36:47 UTC (rev 289)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java 2009-07-20 07:39:22 UTC (rev 290)
@@ -41,12 +41,12 @@
* transforms one bitmap into another based on the algorithms defined by the user.
*/
public class PixelleTransformer {
-
+
private final PixelleImage[] srcImages;
private Map<PixelleComponent, String> algorithms = null;
private final ImageType outputImageType;
private final Point dimension;
-
+
/**
* constructions a transformer given a source bitmap and algorithms
* @param images the source images
@@ -59,7 +59,7 @@
outputImageType = imageType;
dimension = newDimension;
}
-
+
/**
* builds a sample set of algorithms that creates a 'pleasing' image
*
@@ -76,7 +76,7 @@
}
/**
* transforms the image into a destination image based on the algorithms supplied.
- * It does this by generating classes that implement the PixelleExpr interface, and
+ * It does this by generating classes that implement the PixelleExpr interface, and
* dynamically loads them to create the new pixel values.
*
* @return the destination bitmap
@@ -84,14 +84,14 @@
* a bitmap
*/
public PixelleImage transform() throws PixelleTransformException {
-
+
String currentComponent = "";
String currentAlgorithm = "";
try {
PixelleImage destImage;
PixelleEval destPE;
-
+
if (outputImageType == ImageType.RGB) {
destImage = new PixelleImage(new BufferedImage(dimension.x, dimension.y, BufferedImage.TYPE_4BYTE_ABGR));
destPE = new PixelleEval4ByteABGR(destImage, PixelleEvalFactory.getIndexOutOfBoundsOption(), PixelleEvalFactory.getColorOutOfBoundsOption());
@@ -99,17 +99,17 @@
destImage = new PixelleImage(new BufferedImage(dimension.x, dimension.y, BufferedImage.TYPE_BYTE_GRAY));
destPE = new PixelleEvalByteGray(destImage, PixelleEvalFactory.getIndexOutOfBoundsOption(), PixelleEvalFactory.getColorOutOfBoundsOption());
}
-
+
PixelleEval[] sourceEvals = new PixelleEval[srcImages.length];
for (int i = 0; i < srcImages.length; i++) {
PixelleEval srcPE = PixelleEvalFactory.create(srcImages[i]);
sourceEvals[i] = srcPE;
}
-
+
PixelleClassLoader pcl = AccessController.doPrivileged(new PrivilegedAction<PixelleClassLoader>() {
- public PixelleClassLoader run() {
- return new PixelleClassLoader(Thread.currentThread().getContextClassLoader());
- }
+ public PixelleClassLoader run() {
+ return new PixelleClassLoader(Thread.currentThread().getContextClassLoader());
+ }
});
for (Map.Entry<PixelleComponent, String> entry : algorithms.entrySet()) {
@@ -120,24 +120,24 @@
PixelleLexer pl = new PixelleLexer(cs);
CommonTokenStream tokens = new CommonTokenStream();
tokens.setTokenSource(pl);
-
-
+
+
String clsName = "com.mebigfatguy.pixelle.asm.PixelleExpr" + currentComponent;
PixelleParser pp = new PixelleParser(tokens, clsName);
pp.pixelle();
-
+
byte[] bytes = pp.getClassBytes();
//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();
+
+ 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(sourceEvals, x, y);
@@ -145,36 +145,39 @@
}
}
}
-
+
+ destImage.finishImage();
+
return destImage;
} catch (Exception e) {
throw new PixelleTransformException("Failed to transform the image: " + currentComponent + ": " + currentAlgorithm, e);
}
}
-
- /** for debugging */
- private static void dump(byte[] byteCode, String name)
- {
- FileOutputStream fos = null;
- try
- {
- File clsFile = new File(System.getProperty("java.io.tmpdir"), name);
- fos = new FileOutputStream(clsFile);
- fos.write(byteCode);
- fos.flush();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- finally
- {
- try {
- if (fos != null)
- fos.close();
- } catch (IOException ioe) {
- }
- }
- }
+ /** for debugging */
+ private static void dump(byte[] byteCode, String name)
+ {
+ FileOutputStream fos = null;
+ try
+ {
+ File clsFile = new File(System.getProperty("java.io.tmpdir"), name);
+ fos = new FileOutputStream(clsFile);
+ fos.write(byteCode);
+ fos.flush();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try {
+ if (fos != null) {
+ fos.close();
+ }
+ } catch (IOException ioe) {
+ }
+ }
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|