[Pixelle-commit] SF.net SVN: pixelle:[214] trunk/pixelle/src/com/mebigfatguy/pixelle
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-11-21 06:16:32
|
Revision: 214
http://pixelle.svn.sourceforge.net/pixelle/?rev=214&view=rev
Author: dbrosius
Date: 2008-11-21 06:16:27 +0000 (Fri, 21 Nov 2008)
Log Message:
-----------
support transforming to grayscale
Modified Paths:
--------------
trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleComponent.java
trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleEval.java
trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java
trunk/pixelle/src/com/mebigfatguy/pixelle/eval/PixelleEval4ByteABGR.java
trunk/pixelle/src/com/mebigfatguy/pixelle/eval/PixelleEvalByteGray.java
trunk/pixelle/src/com/mebigfatguy/pixelle/resources/algorithms.xml
trunk/pixelle/src/com/mebigfatguy/pixelle/resources/algorithms.xsd
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleComponent.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleComponent.java 2008-11-21 05:44:09 UTC (rev 213)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleComponent.java 2008-11-21 06:16:27 UTC (rev 214)
@@ -55,10 +55,9 @@
}
public static Set<PixelleComponent> gsValues() {
- Set<PixelleComponent> components = EnumSet.<PixelleComponent>allOf(PixelleComponent.class);
- components.remove(PixelleComponent.RED);
- components.remove(PixelleComponent.GREEN);
- components.remove(PixelleComponent.BLUE);
+ Set<PixelleComponent> components = EnumSet.<PixelleComponent>noneOf(PixelleComponent.class);
+ components.add(PixelleComponent.BLACK);
+ components.add(PixelleComponent.SELECTION);
return components;
}
}
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleEval.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleEval.java 2008-11-21 05:44:09 UTC (rev 213)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleEval.java 2008-11-21 06:16:27 UTC (rev 214)
@@ -153,6 +153,17 @@
return 0.0;
}
}
+
+ /**
+ * sets the pixel value at the specified x, y
+ * @param x the x coordinate
+ * @param y the y coordinate
+ * @param pixelSpec the component to set
+ * @param value the value to set
+ */
+ 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
@@ -221,7 +232,7 @@
case Roll: {
int ival = (int)(value + 0.49) % 256;
- return (double)ival;
+ return ival;
}
case Wave: {
@@ -239,7 +250,7 @@
else
ival = 256 - ival & 0x00FF;
}
- return (double)ival;
+ return ival;
}
case Clip:
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java 2008-11-21 05:44:09 UTC (rev 213)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java 2008-11-21 06:16:27 UTC (rev 214)
@@ -34,6 +34,7 @@
import com.mebigfatguy.pixelle.antlr.PixelleLexer;
import com.mebigfatguy.pixelle.antlr.PixelleParser;
import com.mebigfatguy.pixelle.eval.PixelleEval4ByteABGR;
+import com.mebigfatguy.pixelle.eval.PixelleEvalByteGray;
/**
* transforms one bitmap into another based on the algorithms defined by the user.
@@ -80,19 +81,22 @@
*/
public PixelleImage transform() throws PixelleTransformException {
- if (outputImageType == ImageType.Grayscale) {
- throw new PixelleTransformException("Transforming to Grayscale not implemented yet");
- }
-
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));
+ PixelleImage destImage;
+ PixelleEval destPE;
+ if (outputImageType == ImageType.RGB) {
+ destImage = new PixelleImage(new BufferedImage(srcImage.getWidth(), srcImage.getHeight(), BufferedImage.TYPE_4BYTE_ABGR));
+ destPE = new PixelleEval4ByteABGR(destImage, PixelleEvalFactory.getIndexOutOfBoundsOption(), PixelleEvalFactory.getColorOutOfBoundsOption());
+ } else {
+ destImage = new PixelleImage(new BufferedImage(srcImage.getWidth(), srcImage.getHeight(), BufferedImage.TYPE_BYTE_GRAY));
+ destPE = new PixelleEvalByteGray(destImage, PixelleEvalFactory.getIndexOutOfBoundsOption(), PixelleEvalFactory.getColorOutOfBoundsOption());
+ }
PixelleEval srcPE = PixelleEvalFactory.create(srcImage);
- PixelleEval4ByteABGR destPE = new PixelleEval4ByteABGR(destImage, PixelleEvalFactory.getIndexOutOfBoundsOption(), PixelleEvalFactory.getColorOutOfBoundsOption());
PixelleClassLoader pcl = AccessController.doPrivileged(new PrivilegedAction<PixelleClassLoader>() {
public PixelleClassLoader run() {
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/eval/PixelleEval4ByteABGR.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/eval/PixelleEval4ByteABGR.java 2008-11-21 05:44:09 UTC (rev 213)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/eval/PixelleEval4ByteABGR.java 2008-11-21 06:16:27 UTC (rev 214)
@@ -31,24 +31,25 @@
@Override
public double getTransparencyValue(int x, int y) {
- return (double)buffer.getElem(y * width * 4 + x * 4);
+ return buffer.getElem(y * width * 4 + x * 4);
}
@Override
public double getBlueValue(int x, int y) {
- return (double)buffer.getElem(y * width * 4 + x * 4 + 1);
+ return buffer.getElem(y * width * 4 + x * 4 + 1);
}
@Override
public double getGreenValue(int x, int y) {
- return (double)buffer.getElem(y * width * 4 + x * 4 + 2);
+ return buffer.getElem(y * width * 4 + x * 4 + 2);
}
@Override
public double getRedValue(int x, int y) {
- return (double)buffer.getElem(y * width * 4 + x * 4 + 3);
+ return buffer.getElem(y * width * 4 + x * 4 + 3);
}
+ @Override
public void setValue(int x, int y, char pixelSpec, double value) {
value = adjustColor(value);
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/eval/PixelleEvalByteGray.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/eval/PixelleEvalByteGray.java 2008-11-21 05:44:09 UTC (rev 213)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/eval/PixelleEvalByteGray.java 2008-11-21 06:16:27 UTC (rev 214)
@@ -50,7 +50,23 @@
}
private double getValue(int x, int y) {
- return (double)buffer.getElem(y * width + x);
+ return buffer.getElem(y * width + x);
}
+
+ @Override
+ public void setValue(int x, int y, char pixelSpec, double value) {
+
+ value = adjustColor(value);
+
+ switch (pixelSpec) {
+ case 'k':
+ buffer.setElem(y * width + x, (int)(value + 0.49));
+ break;
+
+ case 's':
+ setSelectionValue(x, y, value);
+ break;
+ }
+ }
}
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/resources/algorithms.xml
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/resources/algorithms.xml 2008-11-21 05:44:09 UTC (rev 213)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/resources/algorithms.xml 2008-11-21 06:16:27 UTC (rev 214)
@@ -48,9 +48,6 @@
<component name="black">
(255 - p[x,y].r) - min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
</component>
- <component name="transparency">
- 255
- </component>
<component name="selection">
0
</component>
@@ -59,9 +56,6 @@
<component name="black">
(255 - p[x,y].g) - min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
</component>
- <component name="transparency">
- 255
- </component>
<component name="selection">
0
</component>
@@ -70,9 +64,6 @@
<component name="black">
(255 - p[x,y].b) - min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
</component>
- <component name="transparency">
- 255
- </component>
<component name="selection">
0
</component>
@@ -81,9 +72,6 @@
<component name="black">
min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
</component>
- <component name="transparency">
- 255
- </component>
<component name="selection">
0
</component>
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/resources/algorithms.xsd
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/resources/algorithms.xsd 2008-11-21 05:44:09 UTC (rev 213)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/resources/algorithms.xsd 2008-11-21 06:16:27 UTC (rev 214)
@@ -42,6 +42,7 @@
<xsd:enumeration value="blue"/>
<xsd:enumeration value="selection"/>
<xsd:enumeration value="green"/>
+ <xsd:enumeration value="black"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="algorithms" type="AlgorithmsClass"/>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|