Hi,

Been meaning to do this for a while - this patch simply cleans up the formatting in BufferedImage.

Francis


2007-02-09  Francis Kung  <[EMAIL PROTECTED]>

        * java/awt/image/BufferedImage: Reformatted.
Index: java/awt/image/BufferedImage.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/image/BufferedImage.java,v
retrieving revision 1.23
diff -u -r1.23 BufferedImage.java
--- java/awt/image/BufferedImage.java	10 Dec 2006 20:25:43 -0000	1.23
+++ java/awt/image/BufferedImage.java	9 Feb 2007 16:17:37 -0000
@@ -143,39 +143,39 @@
   {
     SampleModel sm = null;
     ColorModel cm = null;
-    boolean premultiplied = (type == BufferedImage.TYPE_INT_ARGB_PRE || 
-			     type == BufferedImage.TYPE_4BYTE_ABGR_PRE);
+    boolean premultiplied = (type == BufferedImage.TYPE_INT_ARGB_PRE
+                            || type == BufferedImage.TYPE_4BYTE_ABGR_PRE);
 
     switch( type )
       {
       case BufferedImage.TYPE_INT_RGB:
-	sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_INT, 
-					       width, height,
-					       new int[]{ 0x00FF0000, 
-							  0x0000FF00, 
-							  0x000000FF } ) ;
-	cm = new DirectColorModel( 24, 0xff0000, 0xff00, 0xff );
-	break;
+        sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_INT, 
+                                               width, height,
+                                               new int[]{ 0x00FF0000, 
+                                                          0x0000FF00, 
+                                                          0x000000FF } ) ;
+        cm = new DirectColorModel( 24, 0xff0000, 0xff00, 0xff );
+        break;
 	
       case BufferedImage.TYPE_3BYTE_BGR:
-	sm = new PixelInterleavedSampleModel( DataBuffer.TYPE_BYTE,
-					      width, height,
-					      3, width * 3, 
-					      new int[]{ 2, 1, 0 } );
-	cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
-                                  false, false,
-                                  BufferedImage.OPAQUE,
-                                  DataBuffer.TYPE_BYTE);
+        sm = new PixelInterleavedSampleModel( DataBuffer.TYPE_BYTE,
+                                              width, height,
+                                              3, width * 3, 
+                                              new int[]{ 2, 1, 0 } );
+        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:
-	sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_INT, 
-					       width, height,
-					       new int[]{ 0x00FF0000, 
-							  0x0000FF00, 
-							  0x000000FF, 
-							  0xFF000000 } );
+        sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_INT, 
+                                               width, height,
+                                               new int[]{ 0x00FF0000, 
+                                                          0x0000FF00, 
+                                                          0x000000FF, 
+                                                          0xFF000000 } );
         if (premultiplied)
           cm = new DirectColorModel( ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                      32, 0xff0000, 0xff00, 0xff, 0xff000000,
@@ -183,7 +183,8 @@
                                      Buffers.smallestAppropriateTransferType(32));
         else
           cm = new DirectColorModel( 32, 0xff0000, 0xff00, 0xff, 0xff000000 );
-	break;
+        
+        break;
 
       case BufferedImage.TYPE_4BYTE_ABGR:
       case BufferedImage.TYPE_4BYTE_ABGR_PRE:
@@ -195,57 +196,58 @@
                                      true, premultiplied,
                                      BufferedImage.TRANSLUCENT,
                                      DataBuffer.TYPE_BYTE);
-	break;
+        break;
 
       case BufferedImage.TYPE_INT_BGR:
-	sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_INT, 
-					       width, height,
-					       new int[]{ 0x000000FF, 
-							  0x0000FF00, 
-							  0x00FF0000 } ) ;
-	cm = new DirectColorModel( 24, 0xff, 0xff00, 0xff0000 );
+        sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_INT, 
+                                               width, height,
+                                               new int[]{ 0x000000FF, 
+                                                          0x0000FF00, 
+                                                          0x00FF0000 } ) ;
+        cm = new DirectColorModel( 24, 0xff, 0xff00, 0xff0000 );
         break;
 
       case BufferedImage.TYPE_USHORT_565_RGB:
-	sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_USHORT,
-					       width, height,
-					       new int[]{ 0xF800, 
-							  0x7E0, 
-							  0x1F } ) ;
-	cm = new DirectColorModel( 16, 0xF800, 0x7E0, 0x1F );
-	break;
+        sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_USHORT,
+                                               width, height,
+                                               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[]{ 0x7C00, 
-							  0x3E0, 
-							  0x1F } ) ;
-	cm = new DirectColorModel( 15, 0x7C00, 0x3E0, 0x1F );
-	break;
+        sm = new SinglePixelPackedSampleModel( DataBuffer.TYPE_USHORT,
+                                               width, height,
+                                               new int[]{ 0x7C00, 
+                                                          0x3E0, 
+                                                          0x1F } ) ;
+        cm = new DirectColorModel( 15, 0x7C00, 0x3E0, 0x1F );
+        break;
 
       case BufferedImage.TYPE_BYTE_INDEXED:
-	cm = createDefaultIndexedColorModel( false );
+        cm = createDefaultIndexedColorModel( false );
 
       case BufferedImage.TYPE_BYTE_GRAY:
-	sm = new PixelInterleavedSampleModel( DataBuffer.TYPE_BYTE,
-					      width, height,
-					      1, width, new int[]{ 0 } );
-	break;
+        sm = new PixelInterleavedSampleModel( DataBuffer.TYPE_BYTE,
+                                              width, height,
+                                              1, width, new int[]{ 0 } );
+        break;
 
       case BufferedImage.TYPE_USHORT_GRAY:
-	sm = new PixelInterleavedSampleModel( DataBuffer.TYPE_USHORT,
-					      width, height,
-					      1, width, new int[]{ 0 } );
-	break;
+        sm = new PixelInterleavedSampleModel( DataBuffer.TYPE_USHORT,
+                                              width, height,
+                                              1, width, new int[]{ 0 } );
+        break;
 
       case BufferedImage.TYPE_BYTE_BINARY:
-	cm = createDefaultIndexedColorModel( true );
-	sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, 
-					     width, height, 1);
-	break;
+        cm = createDefaultIndexedColorModel( true );
+        sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, 
+                                             width, height, 1);
+        break;
 
       default:
-	sm = null;
+        sm = null;
       }
 
     if( sm == null )
@@ -253,33 +255,32 @@
     
     if( cm == null ) // only for the grayscale types 
       {
-	int buftype;
-	int[] bits = new int[1];
-	if( type == BufferedImage.TYPE_BYTE_GRAY )
-	  {
-	    buftype = DataBuffer.TYPE_BYTE;
-	    bits[0] = 8;
-	  }
-	else
-	  {
-	    buftype = DataBuffer.TYPE_USHORT;
-	    bits[0] = 16;
-	  }
-	ColorSpace graySpace = ColorSpace.getInstance( ColorSpace.CS_GRAY );
-
-	cm = new ComponentColorModel( graySpace, bits, false, false, 
-				      Transparency.OPAQUE, buftype );
+        int buftype;
+        int[] bits = new int[1];
+        if( type == BufferedImage.TYPE_BYTE_GRAY )
+          {
+            buftype = DataBuffer.TYPE_BYTE;
+            bits[0] = 8;
+          }
+        else
+          {
+            buftype = DataBuffer.TYPE_USHORT;
+            bits[0] = 16;
+          }
+        ColorSpace graySpace = ColorSpace.getInstance( ColorSpace.CS_GRAY );
+        
+        cm = new ComponentColorModel( graySpace, bits, false, false, 
+                                      Transparency.OPAQUE, buftype );
       }
 
-    init( cm,
-	  Raster.createWritableRaster(sm, new Point( 0, 0 ) ),
-	  premultiplied,
-	  null, // no properties
-	  type );
+      init( cm,
+            Raster.createWritableRaster(sm, new Point( 0, 0 ) ),
+            premultiplied,
+            null, // no properties
+            type );
   }
 
-  public BufferedImage(int w, int h, int type,
-		       IndexColorModel indexcolormodel)
+  public BufferedImage(int w, int h, int type, IndexColorModel indexcolormodel)
   {
     if ((type != TYPE_BYTE_BINARY) && (type != TYPE_BYTE_INDEXED))
       throw new IllegalArgumentException("Type must be TYPE_BYTE_BINARY or TYPE_BYTE_INDEXED");
@@ -289,27 +290,21 @@
       throw new IllegalArgumentException("Byte type cannot have a larger than 256-color palette.");
 
     init( indexcolormodel,
-	  indexcolormodel.createCompatibleWritableRaster(w, h),
-	  indexcolormodel.isAlphaPremultiplied(),
-	  null, // no properties
-	  type );
+          indexcolormodel.createCompatibleWritableRaster(w, h),
+          indexcolormodel.isAlphaPremultiplied(),
+          null, // no properties
+          type );
   }
 
-  public BufferedImage(ColorModel colormodel, 
-		       WritableRaster writableraster,
-		       boolean premultiplied,
-		       Hashtable<?,?> properties)
+  public BufferedImage(ColorModel colormodel, WritableRaster writableraster,
+		       boolean premultiplied, Hashtable<?,?> properties)
   {
-    init(colormodel, writableraster, premultiplied, properties,
-	 TYPE_CUSTOM);
+    init(colormodel, writableraster, premultiplied, properties, TYPE_CUSTOM);
   }
  
 
-  private void init(ColorModel cm,
-		    WritableRaster writableraster,
-		    boolean premultiplied,
-		    Hashtable properties,
-		    int type)
+  private void init(ColorModel cm, WritableRaster writableraster, 
+                    boolean premultiplied, Hashtable properties, int type)
   {
     raster = writableraster;
     colorModel = cm;
@@ -329,29 +324,32 @@
   {
     if( binary )
       {
-	byte[] t = new byte[]{ 0, (byte)255 };
-	return new IndexColorModel( 1, 2, t, t, t );
+        byte[] t = new byte[]{ 0, (byte)255 };
+        return new IndexColorModel( 1, 2, t, t, t );
       }
 
     byte[] r = new byte[256];
     byte[] g = new byte[256];
     byte[] b = new byte[256];
+    
     int index = 0;
     for( int i = 0; i < 6; i++ )
       for( int j = 0; j < 6; j++ )
-	for( int k = 0; k < 6; k++ )
-	  {
-	    r[ index ] = (byte)(i * 51);
-	    g[ index ] = (byte)(j * 51);
-	    b[ index ] = (byte)(k * 51);
-	    index++;
-	  }
+        for( int k = 0; k < 6; k++ )
+          {
+            r[ index ] = (byte)(i * 51);
+            g[ index ] = (byte)(j * 51);
+            b[ index ] = (byte)(k * 51);
+            index++;
+          }
+    
     while( index < 256 )
       {
-	r[ index ] = g[ index ] = b[ index ] = 
-	  (byte)(18 + (index - 216) * 6);
-	index++;
+        r[ index ] = g[ index ] = b[ index ] = 
+          (byte)(18 + (index - 216) * 6);
+        index++;
       }
+    
     return new IndexColorModel( 8, 256, r, g, b );
   }
   
@@ -375,12 +373,13 @@
     // create a src child that has the right bounds...
     WritableRaster src =
       raster.createWritableChild(x, y, w, h, x, y,
-				 null  // same bands
-				 );
+                                 null);  // same bands
+    
     if (src.getSampleModel () instanceof ComponentSampleModel
         && dest.getSampleModel () instanceof ComponentSampleModel)
       // Refer to ComponentDataBlitOp for optimized data blitting:
       ComponentDataBlitOp.INSTANCE.filter(src, dest);
+    
     else
       {
         // slower path
@@ -397,7 +396,8 @@
     return env.createGraphics (this);
   }
 
-  public void flush() {
+  public void flush()
+  {
   }
   
   public WritableRaster getAlphaRaster()
@@ -512,26 +512,24 @@
 
   public int getRGB(int x, int y)
   {
-    Object rgbElem = raster.getDataElements(x, y,
-					    null // create as needed
-					    );
+    Object rgbElem = raster.getDataElements(x, y, null);
     return colorModel.getRGB(rgbElem);
   }
     
-  public int[] getRGB(int startX, int startY, int w, int h,
-		      int[] rgbArray,
-		      int offset, int scanlineStride)
+  public int[] getRGB(int startX, int startY, int w, int h, int[] rgbArray,
+                      int offset, int scanlineStride)
   {
     if (rgbArray == null)
-    {
-      /*
-	000000000000000000
-	00000[#######-----   [ = start
-	-----########-----   ] = end
-	-----#######]00000
-	000000000000000000  */
-      int size = (h-1)*scanlineStride + w;
-      rgbArray = new int[size];
+      {
+        /*
+	      000000000000000000
+	      00000[#######-----   [ = start
+	      -----########-----   ] = end
+	      -----#######]00000
+	      000000000000000000 
+        */
+        int size = (h-1)*scanlineStride + w;
+        rgbArray = new int[size];
     }
 	
     int endX = startX + w;
@@ -547,15 +545,15 @@
     Object rgbElem = null;
     for (int y=startY; y<endY; y++)
       {
-	int xoffset = offset;
-	for (int x=startX; x<endX; x++)
-	  {
-	    int rgb;
-	    rgbElem = raster.getDataElements(x, y, rgbElem);
-	    rgb = colorModel.getRGB(rgbElem);
-	    rgbArray[xoffset++] = rgb;
-	  }
-	offset += scanlineStride;
+        int xoffset = offset;
+        for (int x=startX; x<endX; x++)
+          {
+            int rgb;
+            rgbElem = raster.getDataElements(x, y, rgbElem);
+            rgb = colorModel.getRGB(rgbElem);
+            rgbArray[xoffset++] = rgb;
+          }
+        offset += scanlineStride;
       }
     return rgbArray;
   }
@@ -572,14 +570,14 @@
     
   public ImageProducer getSource()
   {
-    return new ImageProducer() {
-        
-	Vector consumers = new Vector();
+    return new ImageProducer()
+      {
+        Vector consumers = new Vector();
 
         public void addConsumer(ImageConsumer ic)
         {
-	  if(!consumers.contains(ic))
-	    consumers.add(ic);
+          if(!consumers.contains(ic))
+            consumers.add(ic);
         }
 
         public boolean isConsumer(ImageConsumer ic)
@@ -589,7 +587,7 @@
 
         public void removeConsumer(ImageConsumer ic)
         {
-	  consumers.remove(ic);
+          consumers.remove(ic);
         }
 
         public void startProduction(ImageConsumer ic)
@@ -610,7 +608,7 @@
 
           consumers.add(ic);
 
-	  for(int i=0;i<consumers.size();i++)
+          for(int i=0;i<consumers.size();i++)
             {
               ImageConsumer c = (ImageConsumer) consumers.elementAt(i);
               c.setHints(ImageConsumer.SINGLEPASS);
@@ -638,10 +636,8 @@
     WritableRaster subRaster = 
       getRaster().createWritableChild(x, y, w, h, 0, 0, null);
     
-    return new BufferedImage(getColorModel(),
-			     subRaster,
-			     isPremultiplied,
-			     properties);
+    return new BufferedImage(getColorModel(), subRaster, isPremultiplied,
+                             properties);
   }
 
   public Raster getTile(int tileX, int tileY)
@@ -730,9 +726,7 @@
     
     // create a dest child that has the right bounds...
     WritableRaster dest =
-      raster.createWritableChild(x, y, w, h, x, y,
-				 null  // same bands
-				 );
+      raster.createWritableChild(x, y, w, h, x, y, null);
 
     if (src.getSampleModel () instanceof ComponentSampleModel
         && dest.getSampleModel () instanceof ComponentSampleModel)
@@ -762,14 +756,14 @@
     Object rgbElem = null;
     for (int y=startY; y<endY; y++)
       {
-	int xoffset = offset;
-	for (int x=startX; x<endX; x++)
-	  {
-	    int argb = argbArray[xoffset++];
-	    rgbElem = colorModel.getDataElements(argb, rgbElem);
-	    raster.setDataElements(x, y, rgbElem);
-	  }
-	offset += scanlineStride;    
+        int xoffset = offset;
+        for (int x=startX; x<endX; x++)
+          {
+            int argb = argbArray[xoffset++];
+            rgbElem = colorModel.getDataElements(argb, rgbElem);
+            raster.setDataElements(x, y, rgbElem);
+          }
+        offset += scanlineStride;    
       }
   }
     

Reply via email to