deweese 01/10/11 05:31:23
Modified: sources/org/apache/batik/ext/awt/image/codec
PNGImageEncoder.java
Log:
1) Encoding a subimage of a BufferedImage now works properly.
The problem was a bug in the JDK's implementation of subimage or
getData (probably subimage). See code for details.
Revision Changes Path
1.4 +31 -10
xml-batik/sources/org/apache/batik/ext/awt/image/codec/PNGImageEncoder.java
Index: PNGImageEncoder.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/codec/PNGImageEncoder.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PNGImageEncoder.java 2001/07/04 16:49:59 1.3
+++ PNGImageEncoder.java 2001/10/11 12:31:23 1.4
@@ -13,6 +13,8 @@
import java.awt.image.Raster;
import java.awt.image.RenderedImage;
import java.awt.image.SampleModel;
+import java.awt.Rectangle;
+
import java.io.ByteArrayOutputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
@@ -303,17 +305,17 @@
return (val > maxValue) ? maxValue : val;
}
- private void encodePass(OutputStream os,
- Raster ras,
- int xOffset, int yOffset,
- int xSkip, int ySkip) throws IOException {
- int minX = ras.getMinX();
- int minY = ras.getMinY();
- int width = ras.getWidth();
+ private void encodePass(OutputStream os, Raster ras,
+ int xOffset, int yOffset,
+ int xSkip, int ySkip)
+ throws IOException {
+ int minX = ras.getMinX();
+ int minY = ras.getMinY();
+ int width = ras.getWidth();
int height = ras.getHeight();
xOffset *= numBands;
- xSkip *= numBands;
+ xSkip *= numBands;
int samplesPerByte = 8/bitDepth;
@@ -415,8 +417,27 @@
DeflaterOutputStream dos =
new DeflaterOutputStream(ios, new Deflater(9));
- // Future work - don't convert entire image to a Raster
- Raster ras = image.getData();
+ // Future work - don't convert entire image to a Raster It
+ // might seem that you could just call image.getData() but
+ // 'BufferedImage.subImage' doesn't appear to set the Width
+ // and height properly of the Child Raster, so the Raster
+ // you get back here appears larger than it should.
+ // This solves that problem by bounding the raster to the
+ // image's bounds...
+ Raster ras = image.getData(new Rectangle(image.getMinX(),
+ image.getMinY(),
+ image.getWidth(),
+ image.getHeight()));
+ // System.out.println("Image: [" +
+ // image.getMinY() + ", " +
+ // image.getMinX() + ", " +
+ // image.getWidth() + ", " +
+ // image.getHeight() + "]");
+ // System.out.println("Ras: [" +
+ // ras.getMinX() + ", " +
+ // ras.getMinY() + ", " +
+ // ras.getWidth() + ", " +
+ // ras.getHeight() + "]");
if (skipAlpha) {
int numBands = ras.getNumBands() - 1;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]