This patch (committed) fixes a couple of bugs in the BufferedImage constructor - the wrong ColorSpace was being used for the TYPE_BYTE_GRAY and TYPE_USHORT_GRAY image types:

2006-07-11  David Gilbert  <[EMAIL PROTECTED]>

        * java/awt/image/BufferedImage.java
        (BufferedImage(int, int, int)): Use correct color space for
        TYPE_BYTE_GRAY and TYPE_USHORT_GRAY, and throw an
        IllegalArgumentException for an unrecognised type.

Mauve tests to follow.  This also fixes some errors in the Intel test suite.

Regards,

Dave
Index: java/awt/image/BufferedImage.java
===================================================================
RCS file: /sources/classpath/classpath/java/awt/image/BufferedImage.java,v
retrieving revision 1.16
diff -u -r1.16 BufferedImage.java
--- java/awt/image/BufferedImage.java   27 Jun 2006 14:51:36 -0000      1.16
+++ java/awt/image/BufferedImage.java   11 Jul 2006 09:18:33 -0000
@@ -100,11 +100,33 @@
   Vector observers;
   
   /**
-   * Creates a new buffered image.
+   * Creates a new <code>BufferedImage</code> with the specified width, height
+   * and type.  Valid <code>type</code> values are:
    * 
-   * @param w  the width.
-   * @param h  the height.
-   * @param type  the image type (see the constants defined by this class).
+   * <ul>
+   *   <li>[EMAIL PROTECTED] #TYPE_INT_RGB}</li>
+   *   <li>[EMAIL PROTECTED] #TYPE_INT_ARGB}</li>
+   *   <li>[EMAIL PROTECTED] #TYPE_INT_ARGB_PRE}</li>
+   *   <li>[EMAIL PROTECTED] #TYPE_INT_BGR}</li>
+   *   <li>[EMAIL PROTECTED] #TYPE_3BYTE_BGR}</li>
+   *   <li>[EMAIL PROTECTED] #TYPE_4BYTE_ABGR}</li>
+   *   <li>[EMAIL PROTECTED] #TYPE_4BYTE_ABGR_PRE}</li>
+   *   <li>[EMAIL PROTECTED] #TYPE_USHORT_565_RGB}</li>
+   *   <li>[EMAIL PROTECTED] #TYPE_USHORT_555_RGB}</li>
+   *   <li>[EMAIL PROTECTED] #TYPE_BYTE_GRAY}</li>
+   *   <li>[EMAIL PROTECTED] #TYPE_USHORT_GRAY}</li>
+   *   <li>[EMAIL PROTECTED] #TYPE_BYTE_BINARY}</li>
+   *   <li>[EMAIL PROTECTED] #TYPE_BYTE_INDEXED}</li>
+   * </ul>
+   * 
+   * @param w  the width (must be > 0).
+   * @param h  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>type</code> is not one of the
+   *     specified values.
    */
   public BufferedImage(int w, int h, int type)
   {
@@ -181,13 +203,15 @@
        case TYPE_4BYTE_ABGR_PRE:
          bits = bits4;
          break;
-       case TYPE_BYTE_GRAY:
-         bits = bits1byte;
-         break;
-       case TYPE_USHORT_GRAY:
-         bits = bits1ushort;
-         dataType = DataBuffer.TYPE_USHORT;
-         break;
+        case TYPE_BYTE_GRAY:
+          bits = bits1byte;
+          cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
+          break;
+        case TYPE_USHORT_GRAY:
+          bits = bits1ushort;
+          cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
+          dataType = DataBuffer.TYPE_USHORT;
+          break;
        }
        cm = new ComponentColorModel(cs, bits, alpha, premultiplied,
                                     alpha ?
@@ -203,6 +227,8 @@
        String msg2 = "type not implemented yet";
        throw new UnsupportedOperationException(msg2);
        // FIXME: build color-cube and create color model
+      default:
+        throw new IllegalArgumentException("Unknown image type " + type);
       }
     
     init(cm,

Reply via email to