You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by de...@apache.org on 2006/04/22 22:29:56 UTC

svn commit: r396160 - in /xmlgraphics/batik/trunk: sources/org/apache/batik/ext/awt/image/rendered/Any2sRGBRed.java test-references/samples/mapSpain.png

Author: deweese
Date: Sat Apr 22 13:29:55 2006
New Revision: 396160

URL: http://svn.apache.org/viewcvs?rev=396160&view=rev
Log:
1) Greyscale sources are now treated as if they have sRGB Gamma
    (bug 22260)

Modified:
    xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/image/rendered/Any2sRGBRed.java
    xmlgraphics/batik/trunk/test-references/samples/mapSpain.png

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/image/rendered/Any2sRGBRed.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/image/rendered/Any2sRGBRed.java?rev=396160&r1=396159&r2=396160&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/image/rendered/Any2sRGBRed.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/image/rendered/Any2sRGBRed.java Sat Apr 22 13:29:55 2006
@@ -174,17 +174,17 @@
             float [][] matrix = null;
             switch (srcSM.getNumBands()) {
             case 1:
-                matrix = new float[1][3];
+                matrix = new float[3][1];
                 matrix[0][0] = 1; // Red
-                matrix[0][1] = 1; // Grn
-                matrix[0][2] = 1; // Blu
+                matrix[1][0] = 1; // Grn
+                matrix[2][0] = 1; // Blu
                 break;
             case 2:
-                matrix = new float[2][4];
+                matrix = new float[4][2];
                 matrix[0][0] = 1; // Red
-                matrix[0][1] = 1; // Grn
-                matrix[0][2] = 1; // Blu
-                matrix[1][3] = 1; // Alpha
+                matrix[1][0] = 1; // Grn
+                matrix[3][0] = 1; // Blu
+                matrix[3][1] = 1; // Alpha
                 break;
             case 3:
                 matrix = new float[3][3];
@@ -193,7 +193,7 @@
                 matrix[2][2] = 1; // Blu
                 break;
             default:
-                matrix = new float[srcSM.getNumBands()][4];
+                matrix = new float[4][srcSM.getNumBands()];
                 matrix[0][0] = 1; // Red
                 matrix[1][1] = 1; // Grn
                 matrix[2][2] = 1; // Blu
@@ -203,53 +203,88 @@
             Raster srcRas = src.getData(wr.getBounds());
             BandCombineOp op = new BandCombineOp(matrix, null);
             op.filter(srcRas, wr);
-        } else {
-            ColorModel dstCM = getColorModel();
-            if (srcCM.getColorSpace() == dstCM.getColorSpace()) {
-                // No transform needed, just reformat data...
-                // System.out.println("Bypassing");
+            return wr;
+        }
 
-                if (is_INT_PACK_COMP(srcSM))
-                    src.copyData(wr);
-                else
-                    GraphicsUtil.copyData(src.getData(wr.getBounds()), wr);
+        if (srcCM.getColorSpace() == 
+            ColorSpace.getInstance(ColorSpace.CS_GRAY)) {
 
-                return wr;
+            // This is a little bit of a hack.  There is only
+            // a linear grayscale ICC profile in the JDK so
+            // many things use this when the data _really_
+            // has sRGB gamma applied.
+            try {
+            float [][] matrix = null;
+            switch (srcSM.getNumBands()) {
+            case 1:
+                matrix = new float[3][1];
+                matrix[0][0] = 1; // Red
+                matrix[1][0] = 1; // Grn
+                matrix[2][0] = 1; // Blu
+                break;
+            case 2:
+            default:
+                matrix = new float[4][2];
+                matrix[0][0] = 1; // Red
+                matrix[1][0] = 1; // Grn
+                matrix[3][0] = 1; // Blu
+                matrix[4][1] = 1; // Alpha
+                break;
             }
-
             Raster srcRas = src.getData(wr.getBounds());
-            WritableRaster srcWr  = (WritableRaster)srcRas;
-
-            // Divide out alpha if we have it.  We need to do this since
-            // the color convert may not be a linear operation which may 
-            // lead to out of range values.
-            ColorModel srcBICM = srcCM;
-            if (srcCM.hasAlpha())
-                srcBICM = GraphicsUtil.coerceData(srcWr, srcCM, false);
-
-            BufferedImage srcBI, dstBI;
-            srcBI = new BufferedImage(srcBICM, 
-                                      srcWr.createWritableTranslatedChild(0,0),
-                                      false, 
-                                      null);
-
-            // System.out.println("src: " + srcBI.getWidth() + "x" + 
-            //                    srcBI.getHeight());
-
-            ColorConvertOp op = new ColorConvertOp(dstCM.getColorSpace(), 
-                                                   null);
-            dstBI = op.filter(srcBI, null);
+            BandCombineOp op = new BandCombineOp(matrix, null);
+            op.filter(srcRas, wr);
+            } catch (Throwable t) {
+                t.printStackTrace();
+            }
+            return wr;
+        }
 
-            // System.out.println("After filter:");
+        ColorModel dstCM = getColorModel();
+        if (srcCM.getColorSpace() == dstCM.getColorSpace()) {
+            // No transform needed, just reformat data...
+            // System.out.println("Bypassing");
             
-            WritableRaster wr00 = wr.createWritableTranslatedChild(0,0);
-            for (int i=0; i<dstCM.getColorSpace().getNumComponents(); i++)
-                copyBand(dstBI.getRaster(), i, wr00,    i);
-
-            if (dstCM.hasAlpha())
-                copyBand(srcWr, srcSM.getNumBands()-1,
-                         wr,    getSampleModel().getNumBands()-1);
+            if (is_INT_PACK_COMP(srcSM))
+                src.copyData(wr);
+            else
+                GraphicsUtil.copyData(src.getData(wr.getBounds()), wr);
+            
+            return wr;
         }
+        
+        Raster srcRas = src.getData(wr.getBounds());
+        WritableRaster srcWr  = (WritableRaster)srcRas;
+        
+        // Divide out alpha if we have it.  We need to do this since
+        // the color convert may not be a linear operation which may 
+        // lead to out of range values.
+        ColorModel srcBICM = srcCM;
+        if (srcCM.hasAlpha())
+            srcBICM = GraphicsUtil.coerceData(srcWr, srcCM, false);
+        
+        BufferedImage srcBI, dstBI;
+        srcBI = new BufferedImage(srcBICM, 
+                                  srcWr.createWritableTranslatedChild(0,0),
+                                  false, 
+                                  null);
+        
+        // System.out.println("src: " + srcBI.getWidth() + "x" + 
+        //                    srcBI.getHeight());
+        
+        ColorConvertOp op = new ColorConvertOp(dstCM.getColorSpace(), 
+                                               null);
+        dstBI = op.filter(srcBI, null);
+        
+        // System.out.println("After filter:");
+        
+        WritableRaster wr00 = wr.createWritableTranslatedChild(0,0);
+        for (int i=0; i<dstCM.getColorSpace().getNumComponents(); i++)
+            copyBand(dstBI.getRaster(), i, wr00,    i);
+        
+        if (dstCM.hasAlpha())
+            copyBand(srcWr, srcSM.getNumBands()-1,
+                     wr,    getSampleModel().getNumBands()-1);
         return wr;
     }
 

Modified: xmlgraphics/batik/trunk/test-references/samples/mapSpain.png
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/trunk/test-references/samples/mapSpain.png?rev=396160&r1=396159&r2=396160&view=diff
==============================================================================
Binary files - no diff available.