You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by je...@apache.org on 2007/12/11 14:49:05 UTC
svn commit: r603243 -
/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/GraphicsUtil.java
Author: jeremias
Date: Tue Dec 11 05:49:04 2007
New Revision: 603243
URL: http://svn.apache.org/viewvc?rev=603243&view=rev
Log:
Convenience method to retrieve just the alpha channel from a bitmap.
Modified:
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/GraphicsUtil.java
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/GraphicsUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/GraphicsUtil.java?rev=603243&r1=603242&r2=603243&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/GraphicsUtil.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/GraphicsUtil.java Tue Dec 11 05:49:04 2007
@@ -1084,4 +1084,28 @@
}
*/
+ /**
+ * Extracts an alpha raster from a RenderedImage. The method tries to avoid copying data
+ * unnecessarily by checking if the RenderedImage is a BufferedImage which offers suitable
+ * direct methods.
+ * @param image the image
+ * @return the alpha raster
+ */
+ public static Raster getAlphaRaster(RenderedImage image) {
+ ColorModel cm = image.getColorModel();
+ if (!cm.hasAlpha() || cm.getTransparency() != ColorModel.TRANSLUCENT) {
+ throw new IllegalStateException("Image doesn't have an alpha channel");
+ }
+ Raster alpha;
+ if (image instanceof BufferedImage) {
+ //Optimization possible with BufferedImage (No copying)
+ alpha = ((BufferedImage)image).getAlphaRaster();
+ } else {
+ WritableRaster wraster = GraphicsUtil.makeRasterWritable(image.getData());
+ alpha = image.getColorModel().getAlphaRaster(wraster);
+ }
+ return alpha;
+ }
+
+
}
---------------------------------------------------------------------
Apache XML Graphics Project URL: http://xmlgraphics.apache.org/
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org