Sorry, sent the last mail prematurely by accident, Here is a patch for the bug:
--- PNGImageEncoder.java 2003-11-11 08:37:21.000000000 +0100 +++ org/apache/batik/ext/awt/image/codec/PNGImageEncoder.java 2003-11-11 15:21:52.000000000 +0100 @@ -296,6 +296,7 @@ private int colorType; private int bpp; // bytes per pixel, rounded up + private int upShift[]; // channel left-shifts private boolean skipAlpha = false; private boolean compressGray = false; @@ -421,7 +422,8 @@ for (int s = xOffset; s < numSamples; s += xSkip) { for (int b = 0; b < numBands; b++) { currRow[count++] = - (byte)clamp(samples[s + b] >> bitShift, maxValue); + (byte)clamp((samples[s + b] << upShift[b]) >> bitShift, + maxValue); } } break; @@ -429,7 +431,7 @@ case 16: for (int s = xOffset; s < numSamples; s += xSkip) { for (int b = 0; b < numBands; b++) { - int val = clamp(samples[s + b] >> bitShift, maxValue); + int val = clamp((samples[s + b] << upShift[b]) >> bitShift, maxValue); currRow[count++] = (byte)(val >> 8); currRow[count++] = (byte)(val & 0xff); } @@ -850,6 +852,7 @@ SampleModel sampleModel = image.getSampleModel(); int[] sampleSize = sampleModel.getSampleSize(); + this.upShift = new int[sampleSize.length]; // Set bitDepth to a sentinel value this.bitDepth = -1; @@ -872,12 +875,6 @@ // Get bit depth from channel 0 of the image this.bitDepth = sampleSize[0]; - // Ensure all channels have the same bit depth - for (int i = 1; i < sampleSize.length; i++) { - if (sampleSize[i] != bitDepth) { - throw new RuntimeException(); - } - } // Round bit depth up to a power of 2 if (bitDepth > 2 && bitDepth < 4) { @@ -889,6 +886,17 @@ } else if (bitDepth > 16) { throw new RuntimeException(); } + + // Ensure all channels have the same bit depth if 1,2,4 bits, + // set the left-shifts corresponding to the rounded-up bit depths + for (int i = 0; i < sampleSize.length; i++) { + if(sampleSize[i] != sampleSize[0] && bitDepth < 8) + throw new RuntimeException(); + else if (bitDepth-sampleSize[i] < 0) + throw new RuntimeException(); + else upShift[i] = (bitDepth-sampleSize[i]); + } + } this.numBands = sampleModel.getNumBands(); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]