deweese 2005/02/13 03:32:26 Modified: sources/org/apache/batik/ext/awt/image GraphicsUtil.java sources/org/apache/batik/ext/awt/image/rendered Any2LumRed.java Log: Fix for masks when using Alpha Premultiplied (Mac OS X). Revision Changes Path 1.35 +61 -51 xml-batik/sources/org/apache/batik/ext/awt/image/GraphicsUtil.java Index: GraphicsUtil.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/GraphicsUtil.java,v retrieving revision 1.34 retrieving revision 1.35 diff -u -r1.34 -r1.35 --- GraphicsUtil.java 6 Sep 2004 00:01:58 -0000 1.34 +++ GraphicsUtil.java 13 Feb 2005 11:32:26 -0000 1.35 @@ -1010,63 +1010,73 @@ // System.out.println("CoerceData: " + wr.getSampleModel()); - int [] pixel = null; - int bands = wr.getNumBands(); - float norm; if (newAlphaPreMult) { - if (is_BYTE_COMP_Data(wr.getSampleModel())) - mult_BYTE_COMP_Data(wr); - else if (is_INT_PACK_Data(wr.getSampleModel(), true)) - mult_INT_PACK_Data(wr); - else { - norm = 1f/255f; - int x0, x1, y0, y1, a, b; - float alpha; - x0 = wr.getMinX(); - x1 = x0+wr.getWidth(); - y0 = wr.getMinY(); - y1 = y0+wr.getHeight(); - for (int y=y0; y<y1; y++) - for (int x=x0; x<x1; x++) { - pixel = wr.getPixel(x,y,pixel); - a = pixel[bands-1]; - if ((a >= 0) && (a < 255)) { - alpha = a*norm; - for (b=0; b<bands-1; b++) - pixel[b] = (int)(pixel[b]*alpha+0.5f); - wr.setPixel(x,y,pixel); - } - } - } + multiplyAlpha(wr); } else { - if (is_BYTE_COMP_Data(wr.getSampleModel())) - divide_BYTE_COMP_Data(wr); - else if (is_INT_PACK_Data(wr.getSampleModel(), true)) - divide_INT_PACK_Data(wr); - else { - int x0, x1, y0, y1, a, b; - float ialpha; - x0 = wr.getMinX(); - x1 = x0+wr.getWidth(); - y0 = wr.getMinY(); - y1 = y0+wr.getHeight(); - for (int y=y0; y<y1; y++) - for (int x=x0; x<x1; x++) { - pixel = wr.getPixel(x,y,pixel); - a = pixel[bands-1]; - if ((a > 0) && (a < 255)) { - ialpha = 255/(float)a; - for (b=0; b<bands-1; b++) - pixel[b] = (int)(pixel[b]*ialpha+0.5f); - wr.setPixel(x,y,pixel); - } - } - } + divideAlpha(wr); } return coerceColorModel(cm, newAlphaPreMult); } + public static void multiplyAlpha(WritableRaster wr) { + if (is_BYTE_COMP_Data(wr.getSampleModel())) + mult_BYTE_COMP_Data(wr); + else if (is_INT_PACK_Data(wr.getSampleModel(), true)) + mult_INT_PACK_Data(wr); + else { + int [] pixel = null; + int bands = wr.getNumBands(); + float norm = 1f/255f; + int x0, x1, y0, y1, a, b; + float alpha; + x0 = wr.getMinX(); + x1 = x0+wr.getWidth(); + y0 = wr.getMinY(); + y1 = y0+wr.getHeight(); + for (int y=y0; y<y1; y++) + for (int x=x0; x<x1; x++) { + pixel = wr.getPixel(x,y,pixel); + a = pixel[bands-1]; + if ((a >= 0) && (a < 255)) { + alpha = a*norm; + for (b=0; b<bands-1; b++) + pixel[b] = (int)(pixel[b]*alpha+0.5f); + wr.setPixel(x,y,pixel); + } + } + } + } + + public static void divideAlpha(WritableRaster wr) { + if (is_BYTE_COMP_Data(wr.getSampleModel())) + divide_BYTE_COMP_Data(wr); + else if (is_INT_PACK_Data(wr.getSampleModel(), true)) + divide_INT_PACK_Data(wr); + else { + int x0, x1, y0, y1, a, b; + float ialpha; + int bands = wr.getNumBands(); + int [] pixel = null; + + x0 = wr.getMinX(); + x1 = x0+wr.getWidth(); + y0 = wr.getMinY(); + y1 = y0+wr.getHeight(); + for (int y=y0; y<y1; y++) + for (int x=x0; x<x1; x++) { + pixel = wr.getPixel(x,y,pixel); + a = pixel[bands-1]; + if ((a > 0) && (a < 255)) { + ialpha = 255/(float)a; + for (b=0; b<bands-1; b++) + pixel[b] = (int)(pixel[b]*ialpha+0.5f); + wr.setPixel(x,y,pixel); + } + } + } + } + /** * Copies data from one bufferedImage to another paying attention * to the state of AlphaPreMultiplied. 1.8 +9 -8 xml-batik/sources/org/apache/batik/ext/awt/image/rendered/Any2LumRed.java Index: Any2LumRed.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/rendered/Any2LumRed.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- Any2LumRed.java 18 Aug 2004 07:14:07 -0000 1.7 +++ Any2LumRed.java 13 Feb 2005 11:32:26 -0000 1.8 @@ -65,8 +65,9 @@ // Get my source. CachableRed src = (CachableRed)getSources().get(0); - SampleModel sm = src.getSampleModel(); - ColorModel srcCM = src.getColorModel(); + SampleModel sm = src.getSampleModel(); + ColorModel srcCM = src.getColorModel(); + Raster srcRas = src.getData(wr.getBounds()); if (srcCM == null) { // We don't really know much about this source. @@ -80,11 +81,9 @@ matrix[0][0] = 1; } - Raster srcRas = src.getData(wr.getBounds()); BandCombineOp op = new BandCombineOp(matrix, null); op.filter(srcRas, wr); } else { - Raster srcRas = src.getData(wr.getBounds()); WritableRaster srcWr = (WritableRaster)srcRas; // Divide out alpha if we have it. We need to do this since @@ -139,11 +138,13 @@ ColorConvertOp op = new ColorConvertOp(null); op.filter(srcBI, dstBI); - // I never have to 'fix' alpha premult since I take - // it's value from my source.... - if (dstCM.hasAlpha()) + // Have to 'fix' alpha premult + if (dstCM.hasAlpha()) { copyBand(srcWr, sm.getNumBands()-1, wr, getSampleModel().getNumBands()-1); + if (dstCM.isAlphaPremultiplied()) + GraphicsUtil.multiplyAlpha(wr); + } } return wr; }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]