Hi,

This patch corrects some of the default image types in BufferedImage, so
that they use the right ColorModels and SampleModels.

A supporting Mauve test has been committed.

Also included is a tiny fix to BufferedImageGraphics with huge results;
it now recognises the INT_RGB image type and optimizes it properly,
resulting in a huge speedup (see PR 29510).

Cheers,
Francis


2006-10-19  Francis Kung  <[EMAIL PROTECTED]>

        PR 29510
        * java/awt/image/BufferedImage.java
        (constructor): Updated some properties of default image types.
        * gnu/java/awt/peer/gtk/BufferedImageGraphics.java
        (argb32): Updated field to match default in BufferedImage.

### Eclipse Workspace Patch 1.0
#P classpath
Index: gnu/java/awt/peer/gtk/BufferedImageGraphics.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/BufferedImageGraphics.java,v
retrieving revision 1.14
diff -u -r1.14 BufferedImageGraphics.java
--- gnu/java/awt/peer/gtk/BufferedImageGraphics.java	17 Oct 2006 18:59:19 -0000	1.14
+++ gnu/java/awt/peer/gtk/BufferedImageGraphics.java	19 Oct 2006 20:27:22 -0000
@@ -103,7 +103,7 @@
   /**
    * Colormodels we recognize for fast copying.
    */  
-  static ColorModel rgb32 = new DirectColorModel(32, 0xFF0000, 0xFF00, 0xFF);
+  static ColorModel rgb32 = new DirectColorModel(24, 0xFF0000, 0xFF00, 0xFF);
   static ColorModel argb32 = new DirectColorModel(32, 0xFF0000, 0xFF00, 0xFF,
 						  0xFF000000);
   private boolean hasFastCM;
Index: java/awt/image/BufferedImage.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/image/BufferedImage.java,v
retrieving revision 1.21
diff -u -r1.21 BufferedImage.java
--- java/awt/image/BufferedImage.java	11 Oct 2006 20:14:59 -0000	1.21
+++ java/awt/image/BufferedImage.java	19 Oct 2006 20:27:22 -0000
@@ -130,12 +130,12 @@
    *   <li>[EMAIL PROTECTED] #TYPE_BYTE_INDEXED}</li>
    * </ul>
    * 
-   * @param w  the width (must be > 0).
-   * @param h  the height (must be > 0).
+   * @param width the width (must be > 0).
+   * @param height the height (must be > 0).
    * @param type  the image type (see the list of valid types above).
    * 
-   * @throws IllegalArgumentException if <code>w</code> or <code>h</code> is
-   *     less than or equal to zero.
+   * @throws IllegalArgumentException if <code>width</code> or
+   *     <code>height</code> is less than or equal to zero.
    * @throws IllegalArgumentException if <code>type</code> is not one of the
    *     specified values.
    */
@@ -162,8 +162,11 @@
 					      width, height,
 					      3, width * 3, 
 					      new int[]{ 2, 1, 0 } );
-	cm = new DirectColorModel( 24, 0xff, 0xff00, 0xff0000 );
-	break;
+	cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
+                                  false, false,
+                                  BufferedImage.OPAQUE,
+                                  DataBuffer.TYPE_BYTE);
+        break;
 
       case BufferedImage.TYPE_INT_ARGB:
       case BufferedImage.TYPE_INT_ARGB_PRE:
@@ -184,19 +187,14 @@
 
       case BufferedImage.TYPE_4BYTE_ABGR:
       case BufferedImage.TYPE_4BYTE_ABGR_PRE:
-	sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_INT, 
-					       width, height,
-					       new int[]{ 0x000000FF, 
-							  0xFF000000, 
-							  0x00FF0000, 
-							  0x0000FF00 } );
-        if (premultiplied)
-          cm = new DirectColorModel( ColorSpace.getInstance(ColorSpace.CS_sRGB),
-                                     32, 0xff0000, 0xff00, 0xff, 0xff000000,
-                                     true,
-                                     Buffers.smallestAppropriateTransferType(32));
-        else
-          cm = new DirectColorModel( 32, 0xff0000, 0xff00, 0xff, 0xff000000 );
+        sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, 
+                                             width, height,
+                                             4, 4*width,
+                                             new int[]{3, 2, 1, 0});
+        cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
+                                     true, premultiplied,
+                                     BufferedImage.TRANSLUCENT,
+                                     DataBuffer.TYPE_BYTE);
 	break;
 
       case BufferedImage.TYPE_INT_BGR:
@@ -205,24 +203,24 @@
 					       new int[]{ 0x000000FF, 
 							  0x0000FF00, 
 							  0x00FF0000 } ) ;
-	cm = new DirectColorModel( 32, 0xff, 0xff00, 0xff0000 );
-	break;
+	cm = new DirectColorModel( 24, 0xff, 0xff00, 0xff0000 );
+        break;
 
       case BufferedImage.TYPE_USHORT_565_RGB:
 	sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_USHORT,
 					       width, height,
-					       new int[]{ 0x0000001F, 
-							  0x000007E0, 
-							  0x0000F800 } ) ;
-	cm = new DirectColorModel( 16, 0x1F, 0x7E0, 0xf800 );
+					       new int[]{ 0xF800, 
+							  0x7E0, 
+							  0x1F } ) ;
+	cm = new DirectColorModel( 16, 0xF800, 0x7E0, 0x1F );
 	break;
       case BufferedImage.TYPE_USHORT_555_RGB:
 	sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_USHORT,
 					       width, height,
-					       new int[]{ 0x0000001F, 
-							  0x000003E0, 
-							  0x00007C00 } ) ;
-	cm = new DirectColorModel( 15, 0x1F, 0x3E0, 0x7c00 );
+					       new int[]{ 0x7C00, 
+							  0x3E0, 
+							  0x1F } ) ;
+	cm = new DirectColorModel( 15, 0x7C00, 0x3E0, 0x1F );
 	break;
 
       case BufferedImage.TYPE_BYTE_INDEXED:

Reply via email to