You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by lb...@apache.org on 2013/07/12 23:17:11 UTC
svn commit: r1502693 - in /xmlgraphics/commons/trunk:
src/java/org/apache/xmlgraphics/ps/ImageEncodingHelper.java
src/java/org/apache/xmlgraphics/ps/PSImageUtils.java
test/java/org/apache/xmlgraphics/ps/ImageEncodingHelperTestCase.java
Author: lbernardo
Date: Fri Jul 12 21:17:10 2013
New Revision: 1502693
URL: http://svn.apache.org/r1502693
Log:
FOP-2259: 1 bit TIFF error; patch submitted by Simon Steiner
Modified:
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/ImageEncodingHelper.java
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSImageUtils.java
xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/ImageEncodingHelperTestCase.java
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/ImageEncodingHelper.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/ImageEncodingHelper.java?rev=1502693&r1=1502692&r2=1502693&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/ImageEncodingHelper.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/ImageEncodingHelper.java Fri Jul 12 21:17:10 2013
@@ -51,6 +51,8 @@ public class ImageEncodingHelper {
private boolean firstTileDump;
private boolean enableCMYK;
private boolean isBGR;
+ private boolean outputbw;
+ private boolean bwinvert;
/**
* Main constructor
@@ -58,6 +60,7 @@ public class ImageEncodingHelper {
*/
public ImageEncodingHelper(RenderedImage image) {
this(image, false);
+ outputbw = true;
}
/**
@@ -118,7 +121,12 @@ public class ImageEncodingHelper {
if (encoded) {
return;
}
- encodeRenderedImageAsRGB(image, out);
+ encodeRenderedImageAsRGB(image, out, outputbw, bwinvert);
+ }
+
+ public static void encodeRenderedImageAsRGB(RenderedImage image, OutputStream out)
+ throws IOException {
+ encodeRenderedImageAsRGB(image, out, false, false);
}
/**
@@ -127,7 +135,7 @@ public class ImageEncodingHelper {
* @param out the OutputStream to write the pixels to
* @throws IOException if an I/O error occurs
*/
- public static void encodeRenderedImageAsRGB(RenderedImage image, OutputStream out)
+ public static void encodeRenderedImageAsRGB(RenderedImage image, OutputStream out, boolean outputbw, boolean bwinvert)
throws IOException {
Raster raster = getRaster(image);
Object data;
@@ -138,7 +146,7 @@ public class ImageEncodingHelper {
data = new byte[nbands];
break;
case DataBuffer.TYPE_USHORT:
- data = new short[nbands];
+ data = null;
break;
case DataBuffer.TYPE_INT:
data = new int[nbands];
@@ -157,13 +165,23 @@ public class ImageEncodingHelper {
int w = image.getWidth();
int h = image.getHeight();
- byte[] buf = new byte[w * 3];
+ int numDataElements = raster.getNumDataElements();
+ if (numDataElements > 1 || !outputbw) {
+ numDataElements = 3;
+ }
+
+ byte[] buf = new byte[w * numDataElements];
+
for (int y = 0; y < h; y++) {
int idx = -1;
for (int x = 0; x < w; x++) {
int rgb = colorModel.getRGB(raster.getDataElements(x, y, data));
- buf[++idx] = (byte)(rgb >> 16);
- buf[++idx] = (byte)(rgb >> 8);
+ if (numDataElements > 1) {
+ buf[++idx] = (byte)(rgb >> 16);
+ buf[++idx] = (byte)(rgb >> 8);
+ } else if (bwinvert && rgb == -1) {
+ rgb = 1;
+ }
buf[++idx] = (byte)(rgb);
}
out.write(buf);
@@ -438,7 +456,7 @@ public class ImageEncodingHelper {
*/
public static void encodePackedColorComponents(RenderedImage image, OutputStream out)
throws IOException {
- ImageEncodingHelper helper = new ImageEncodingHelper(image, true);
+ ImageEncodingHelper helper = new ImageEncodingHelper(image);
helper.encode(out);
}
@@ -469,7 +487,9 @@ public class ImageEncodingHelper {
public String getImplicitFilter() {
return null; //No implicit filters with RenderedImage instances
}
-
}
+ public void setBWInvert(boolean v) {
+ bwinvert = v;
+ }
}
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSImageUtils.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSImageUtils.java?rev=1502693&r1=1502692&r2=1502693&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSImageUtils.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/ps/PSImageUtils.java Fri Jul 12 21:17:10 2013
@@ -25,6 +25,7 @@ import java.awt.geom.Dimension2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.ColorModel;
import java.awt.image.DataBuffer;
+import java.awt.image.DataBufferByte;
import java.awt.image.IndexColorModel;
import java.awt.image.Raster;
import java.awt.image.RenderedImage;
@@ -141,6 +142,11 @@ public class PSImageUtils {
gen.restoreGraphicsState();
}
+ public static void writeImage(ImageEncoder encoder, Dimension imgDim, String imgDescription,
+ Rectangle2D targetRect, ColorModel colorModel, PSGenerator gen) throws IOException {
+ writeImage(encoder, imgDim, imgDescription, targetRect, colorModel, gen, null);
+ }
+
/**
* Writes a bitmap image to the PostScript stream.
* @param encoder the image encoder
@@ -152,7 +158,7 @@ public class PSImageUtils {
* @throws IOException In case of an I/O exception
*/
public static void writeImage(ImageEncoder encoder, Dimension imgDim, String imgDescription,
- Rectangle2D targetRect, ColorModel colorModel, PSGenerator gen)
+ Rectangle2D targetRect, ColorModel colorModel, PSGenerator gen, RenderedImage ri)
throws IOException {
gen.saveGraphicsState();
@@ -178,6 +184,13 @@ public class PSImageUtils {
imageDict.put("/DataSource", "Data");
populateImageDictionary(imgDim, colorModel, imageDict);
+
+ if (ri != null) {
+ DataBuffer buffer = ri.getData().getDataBuffer();
+ if (!(buffer instanceof DataBufferByte)) {
+ imageDict.put("/BitsPerComponent", 8);
+ }
+ }
writeImageCommand(imageDict, colorModel, gen);
/*
@@ -351,7 +364,7 @@ public class PSImageUtils {
ImageEncodingHelper helper = new ImageEncodingHelper(img);
ColorModel cm = helper.getEncodedColorModel();
- writeImage(encoder, imgDim, imgDescription, targetRect, cm, gen);
+ writeImage(encoder, imgDim, imgDescription, targetRect, cm, gen, img);
}
/**
Modified: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/ImageEncodingHelperTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/ImageEncodingHelperTestCase.java?rev=1502693&r1=1502692&r2=1502693&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/ImageEncodingHelperTestCase.java (original)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/ps/ImageEncodingHelperTestCase.java Fri Jul 12 21:17:10 2013
@@ -97,8 +97,8 @@ public class ImageEncodingHelperTestCase
BufferedImage imageRGB = new BufferedImage(100, 75, BufferedImage.TYPE_INT_BGR);
imageRGB = prepareImage(imageRGB);
- ImageEncodingHelper imageEncodingHelperBGR = new ImageEncodingHelper(imageBGR);
- ImageEncodingHelper imageEncodingHelperRGB = new ImageEncodingHelper(imageRGB);
+ ImageEncodingHelper imageEncodingHelperBGR = new ImageEncodingHelper(imageBGR, false);
+ ImageEncodingHelper imageEncodingHelperRGB = new ImageEncodingHelper(imageRGB, false);
ByteArrayOutputStream baosBGR = new ByteArrayOutputStream();
imageEncodingHelperBGR.encode(baosBGR);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org