aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render/pcl/PCLGenerator.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/fop/render/pcl/PCLGenerator.java')
-rw-r--r--src/java/org/apache/fop/render/pcl/PCLGenerator.java46
1 files changed, 7 insertions, 39 deletions
diff --git a/src/java/org/apache/fop/render/pcl/PCLGenerator.java b/src/java/org/apache/fop/render/pcl/PCLGenerator.java
index fbb9c6ad0..50cf622c7 100644
--- a/src/java/org/apache/fop/render/pcl/PCLGenerator.java
+++ b/src/java/org/apache/fop/render/pcl/PCLGenerator.java
@@ -47,6 +47,8 @@ import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.xmlgraphics.image.GraphicsUtil;
import org.apache.xmlgraphics.util.UnitConv;
+import org.apache.fop.util.BitmapImageUtil;
+
/**
* This class provides methods for generating PCL print files.
*/
@@ -522,7 +524,7 @@ public class PCLGenerator {
* @return the gray value
*/
public final int convertToGray(int r, int g, int b) {
- return (r * 30 + g * 59 + b * 11) / 100;
+ return BitmapImageUtil.convertToGray(r, g, b);
}
/**
@@ -574,13 +576,7 @@ public class PCLGenerator {
* @return true if it's a monochrome image
*/
public static boolean isMonochromeImage(RenderedImage img) {
- ColorModel cm = img.getColorModel();
- if (cm instanceof IndexColorModel) {
- IndexColorModel icm = (IndexColorModel)cm;
- return icm.getMapSize() == 2;
- } else {
- return false;
- }
+ return BitmapImageUtil.isMonochromeImage(img);
}
/**
@@ -589,7 +585,7 @@ public class PCLGenerator {
* @return true if it's a grayscale image
*/
public static boolean isGrayscaleImage(RenderedImage img) {
- return (img.getColorModel().getColorSpace().getNumComponents() == 1);
+ return BitmapImageUtil.isGrayscaleImage(img);
}
private MonochromeBitmapConverter createMonochromeBitmapConverter() {
@@ -766,22 +762,7 @@ public class PCLGenerator {
}
}
if (src == null) {
- src = new BufferedImage(effDim.width, effDim.height,
- BufferedImage.TYPE_BYTE_GRAY);
- Graphics2D g2d = src.createGraphics();
- try {
- g2d.setBackground(Color.white);
- g2d.setColor(Color.black);
- g2d.clearRect(0, 0, effDim.width, effDim.height);
-
- AffineTransform at = new AffineTransform();
- double sx = effDim.getWidth() / orgDim.getWidth();
- double sy = effDim.getHeight() / orgDim.getHeight();
- at.scale(sx, sy);
- g2d.drawRenderedImage(img, at);
- } finally {
- g2d.dispose();
- }
+ src = BitmapImageUtil.convertToGrayscale(img, effDim);
}
MonochromeBitmapConverter converter = createMonochromeBitmapConverter();
converter.setHint("quality", "false");
@@ -793,22 +774,9 @@ public class PCLGenerator {
setTransparencyMode(sourceTransparency || mask != null, true);
paintMonochromeBitmap(red, effResolution);
} else {
- //TODO untested!
RenderedImage effImg = img;
if (scaled) {
- BufferedImage buf = new BufferedImage(effDim.width, effDim.height,
- BufferedImage.TYPE_BYTE_BINARY);
- Graphics2D g2d = buf.createGraphics();
- try {
- AffineTransform at = new AffineTransform();
- double sx = effDim.getWidth() / orgDim.getWidth();
- double sy = effDim.getHeight() / orgDim.getHeight();
- at.scale(sx, sy);
- g2d.drawRenderedImage(img, at);
- } finally {
- g2d.dispose();
- }
- effImg = buf;
+ effImg = BitmapImageUtil.convertToMonochrome(img, effDim);
}
setSourceTransparencyMode(sourceTransparency);
selectCurrentPattern(0, 0); //Solid black