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 2008/11/04 14:40:55 UTC
svn commit: r711251 - in
/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader:
ImageProcessingHints.java impl/ImageConverterG2D2Bitmap.java
Author: jeremias
Date: Tue Nov 4 05:40:55 2008
New Revision: 711251
URL: http://svn.apache.org/viewvc?rev=711251&view=rev
Log:
Additional hint for generating a monochrome (1-bit) bitmap. Useful for "high-speed" PCL output.
Modified:
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageProcessingHints.java
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2Bitmap.java
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageProcessingHints.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageProcessingHints.java?rev=711251&r1=711250&r2=711251&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageProcessingHints.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/ImageProcessingHints.java Tue Nov 4 05:40:55 2008
@@ -43,6 +43,12 @@
String BITMAP_TYPE_INTENT_GRAY = "gray";
/**
+ * Used with BITMAP_TYPE_INTENT to indicate that the generated bitmap should be a
+ * 1 bit black and white image.
+ */
+ String BITMAP_TYPE_INTENT_MONO = "mono";
+
+ /**
* Used to indicate how existing transparency information (for example, an alpha channel)
* shall be treated. */
Object TRANSPARENCY_INTENT = "TRANSPARENCY_INTENT";
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2Bitmap.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2Bitmap.java?rev=711251&r1=711250&r2=711251&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2Bitmap.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2Bitmap.java Tue Nov 4 05:40:55 2008
@@ -51,9 +51,11 @@
ImageGraphics2D g2dImage = (ImageGraphics2D)src;
Object formatIntent = hints.get(ImageProcessingHints.BITMAP_TYPE_INTENT);
- boolean gray = false;
+ int bitsPerPixel = 24;
if (ImageProcessingHints.BITMAP_TYPE_INTENT_GRAY.equals(formatIntent)) {
- gray = true;
+ bitsPerPixel = 8;
+ } else if (ImageProcessingHints.BITMAP_TYPE_INTENT_MONO.equals(formatIntent)) {
+ bitsPerPixel = 1;
}
Object transparencyIntent = hints.get(ImageProcessingHints.TRANSPARENCY_INTENT);
@@ -68,7 +70,7 @@
resolution = res.intValue();
}
- BufferedImage bi = paintToBufferedImage(g2dImage, gray, withAlpha, resolution);
+ BufferedImage bi = paintToBufferedImage(g2dImage, bitsPerPixel, withAlpha, resolution);
ImageBuffered bufImage = new ImageBuffered(src.getInfo(), bi, null);
return bufImage;
@@ -77,36 +79,52 @@
/**
* Paints a Graphics2D image on a BufferedImage and returns this bitmap.
* @param g2dImage the Graphics2D image
- * @param gray true if the generated image should be in grayscales
+ * @param bitsPerPixel the desired number of bits per pixel (supported: 1, 8, 24)
* @param withAlpha true if the generated image should have an alpha channel
* @param resolution the requested bitmap resolution
* @return the newly created BufferedImage
*/
protected BufferedImage paintToBufferedImage(ImageGraphics2D g2dImage,
- boolean gray, boolean withAlpha, int resolution) {
+ int bitsPerPixel, boolean withAlpha, int resolution) {
ImageSize size = g2dImage.getSize();
+ RenderingHints additionalHints = null;
int bmw = (int)Math.ceil(UnitConv.mpt2px(size.getWidthMpt(), resolution));
int bmh = (int)Math.ceil(UnitConv.mpt2px(size.getHeightMpt(), resolution));
BufferedImage bi;
- if (gray) {
+ switch (bitsPerPixel) {
+ case 1:
+ bi = new BufferedImage(bmw, bmh, BufferedImage.TYPE_BYTE_BINARY);
+ withAlpha = false;
+ //withAlpha is ignored in this case
+ additionalHints = new RenderingHints(null);
+ //The following usually has no effect but some class libraries might support it
+ additionalHints.put(RenderingHints.KEY_DITHERING,
+ RenderingHints.VALUE_DITHER_ENABLE);
+ break;
+ case 8:
if (withAlpha) {
bi = createGrayBufferedImageWithAlpha(bmw, bmh);
} else {
bi = new BufferedImage(bmw, bmh, BufferedImage.TYPE_BYTE_GRAY);
}
- } else {
+ break;
+ default:
if (withAlpha) {
bi = new BufferedImage(bmw, bmh, BufferedImage.TYPE_INT_ARGB);
} else {
bi = new BufferedImage(bmw, bmh, BufferedImage.TYPE_INT_RGB);
}
}
+
Graphics2D g2d = bi.createGraphics();
try {
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
setRenderingHintsForBufferedImage(g2d);
+ if (additionalHints != null) {
+ g2d.addRenderingHints(additionalHints);
+ }
g2d.setBackground(Color.white);
g2d.setColor(Color.black);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org