deweese 02/02/25 11:23:20 Modified: sources/org/apache/batik/ext/awt/image/rendered ProfileRed.java Log: Fixed an Alpha Premult problem when source was not unpremultiplied. Revision Changes Path 1.5 +30 -27 xml-batik/sources/org/apache/batik/ext/awt/image/rendered/ProfileRed.java Index: ProfileRed.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/rendered/ProfileRed.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ProfileRed.java 22 Feb 2002 12:08:05 -0000 1.4 +++ ProfileRed.java 25 Feb 2002 19:23:20 -0000 1.5 @@ -37,7 +37,7 @@ * on its source * * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a> - * @version $Id: ProfileRed.java,v 1.4 2002/02/22 12:08:05 vhardy Exp $ + * @version $Id: ProfileRed.java,v 1.5 2002/02/25 19:23:20 deweese Exp $ */ public class ProfileRed extends AbstractRed { private static final ColorSpace sRGBCS @@ -140,23 +140,24 @@ * BandedSampleModel, do the conversion now. */ if(!(imgCM instanceof ComponentColorModel) || - !(img.getSampleModel() instanceof BandedSampleModel)){ + !(img.getSampleModel() instanceof BandedSampleModel) || + (imgCM.hasAlpha() && + imgCM.isAlphaPremultiplied() == true)) { ComponentColorModel imgCompCM = new ComponentColorModel (imgCS, // Same ColorSpace as img imgCM.getComponentSize(), // Number of bits/comp imgCM.hasAlpha(), // Same alpha as img - imgCM.isAlphaPremultiplied(), // Same premult as img + false, // unpremult alpha (so we can remove it next). imgCM.getTransparency(), // Same trans as img DataBuffer.TYPE_BYTE); // 8 bit/component. - WritableRaster wr - = Raster.createBandedRaster + WritableRaster wr = Raster.createBandedRaster (DataBuffer.TYPE_BYTE, argbWR.getWidth(), argbWR.getHeight(), imgCompCM.getNumComponents(), new Point(0, 0)); - + BufferedImage imgComp = new BufferedImage (imgCompCM, wr, imgCompCM.isAlphaPremultiplied(), null); @@ -179,19 +180,19 @@ * profile, using a ComponentColorModel as well, because * we know the number of components match (this was * checked at the begining of this routine). */ - ComponentColorModel newCM - = new ComponentColorModel(colorSpace, // ****** New ColorSpace ******** - imgCM.getComponentSize(), // Array of number of bits per components - false, // No alpa - false, // Not premultiplied - Transparency.OPAQUE, // No transparency - DataBuffer.TYPE_BYTE); // 8 Bits + ComponentColorModel newCM = new ComponentColorModel + (colorSpace, // **** New ColorSpace **** + imgCM.getComponentSize(), // Array of number of bits per components + false, // No alpa + false, // Not premultiplied + Transparency.OPAQUE, // No transparency + DataBuffer.TYPE_BYTE); // 8 Bits // Build a raster with bands 0, 1 and 2 of img's raster DataBufferByte data = (DataBufferByte)srcWR.getDataBuffer(); srcWR = Raster.createBandedRaster - (data, img.getWidth(), img.getHeight(), - img.getWidth(), new int[]{0, 1, 2}, + (data, argbWR.getWidth(), argbWR.getHeight(), + argbWR.getWidth(), new int[]{0, 1, 2}, new int[]{0, 0, 0}, new Point(0, 0)); BufferedImage newImg = new BufferedImage (newCM, srcWR, newCM.isAlphaPremultiplied(), null); @@ -208,7 +209,7 @@ DataBuffer.TYPE_BYTE); WritableRaster wr = Raster.createBandedRaster - (DataBuffer.TYPE_BYTE, img.getWidth(), img.getHeight(), + (DataBuffer.TYPE_BYTE, argbWR.getWidth(), argbWR.getHeight(), sRGBCompCM.getNumComponents(), new Point(0, 0)); BufferedImage sRGBImage = new BufferedImage @@ -227,16 +228,17 @@ byte[][] argbBanks = {rgbBanks[0], rgbBanks[1], rgbBanks[2], imgBanks[3]}; DataBufferByte argbData = new DataBufferByte(argbBanks, imgBanks[0].length); - srcWR = Raster.createBandedRaster(argbData, img.getWidth(), img.getHeight(), - img.getWidth(), new int[]{0, 1, 2, 3}, - new int[]{0, 0, 0, 0}, new Point(0, 0)); - sRGBCompCM = - new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), - new int[]{8, 8, 8, 8}, - true, - false, - Transparency.TRANSLUCENT, - DataBuffer.TYPE_BYTE); + srcWR = Raster.createBandedRaster + (argbData, argbWR.getWidth(), argbWR.getHeight(), + argbWR.getWidth(), new int[]{0, 1, 2, 3}, + new int[]{0, 0, 0, 0}, new Point(0, 0)); + sRGBCompCM = new ComponentColorModel + (ColorSpace.getInstance(ColorSpace.CS_sRGB), + new int[]{8, 8, 8, 8}, + true, + false, + Transparency.TRANSLUCENT, + DataBuffer.TYPE_BYTE); sRGBImage = new BufferedImage(sRGBCompCM, srcWR, false, @@ -251,6 +253,8 @@ argbWR.createWritableTranslatedChild(0, 0), false, null); + + /////////////////////////////////////////////// // BUG IN ColorConvertOp: The following breaks: // colorConvertOp.filter(sRGBImage, result); @@ -262,7 +266,6 @@ RenderingHints.VALUE_COLOR_RENDER_QUALITY); g.drawImage(sRGBImage, 0, 0, null); g.dispose(); - return argbWR; }catch(Exception e){
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]