2004-04-20 Ingo Proetel <proetel@aicas.com>
authormkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 20 Apr 2004 11:13:09 +0000 (11:13 +0000)
committermkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 20 Apr 2004 11:13:09 +0000 (11:13 +0000)
* java/awt/FontMetrics.java:
(charsWidth): fixed accumulation of total_width
(getWidth): simple default implementation
* java/awt/Polygon.java (getBoundingBox): Use correct y-coordinate
in Rectangle constructor.
* java/awt/image/Raster.java (toString): Added method.
* java/awt/image/SampleModel.java (<init>): Added error cause
information to thrown exception.
* java/awt/image/SinglePixelPackedSampleModel.java (getDataElements):
New method.
(setDataElements): New method.
(setPixels): New method.
(toString): New method.

2004-04-20  Sascha Brawer  <brawer@dandelis.ch>

* java/awt/image/ComponentColorModel.java
(createCompatibleSampleModel): Return PixelInterleavedSampleModel
for TYPE_BYTE and TYPE_USHORT transferTypes, in order to pass the
Mauve tests on this method. Improved documentation.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@80894 138bc75d-0d04-0410-961f-82ee72b054a4

libjava/ChangeLog
libjava/java/awt/FontMetrics.java
libjava/java/awt/Polygon.java
libjava/java/awt/image/ComponentColorModel.java
libjava/java/awt/image/Raster.java
libjava/java/awt/image/SampleModel.java
libjava/java/awt/image/SinglePixelPackedSampleModel.java

index 2388b08..17017de 100644 (file)
@@ -1,3 +1,26 @@
+2004-04-20  Ingo Proetel  <proetel@aicas.com>
+
+       * java/awt/FontMetrics.java:
+       (charsWidth): fixed accumulation of total_width
+       (getWidth): simple default implementation
+       * java/awt/Polygon.java (getBoundingBox): Use correct y-coordinate
+       in Rectangle constructor.
+       * java/awt/image/Raster.java (toString): Added method. 
+       * java/awt/image/SampleModel.java (<init>): Added error cause
+       information to thrown exception.
+       * java/awt/image/SinglePixelPackedSampleModel.java (getDataElements):
+       New method.
+       (setDataElements): New method.
+       (setPixels): New method.
+       (toString): New method.
+
+2004-04-20  Sascha Brawer  <brawer@dandelis.ch>
+
+       * java/awt/image/ComponentColorModel.java
+       (createCompatibleSampleModel): Return PixelInterleavedSampleModel
+       for TYPE_BYTE and TYPE_USHORT transferTypes, in order to pass the
+       Mauve tests on this method. Improved documentation.
+
 2004-04-20  Michael Koch  <konqueror@gmx.de>
 
        * javax/swing/JLayeredPane.java,
index 6a1a1c0..cb76f50 100644 (file)
@@ -292,8 +292,7 @@ charsWidth(char buf[], int offset, int len)
 {
   int total_width = 0;
   for (int i = offset; i < len; i++)
-    total_width = charWidth(buf[i]);
-
+    total_width += charWidth(buf[i]);
   return(total_width);
 }
 
@@ -328,7 +327,12 @@ bytesWidth(byte buf[], int offset, int len)
 public int[]
 getWidths()
 {
-  return(new int[256]);
+  int [] result = new int[256];
+  for(char i = 0; i < 256; i++)
+  {
+    result[i]= charWidth(i);
+  }
+  return(result);
 }
 
 /*************************************************************************/
@@ -347,3 +351,4 @@ toString()
 
 } // class FontMetrics 
 
+
index e91144c..96c370a 100644 (file)
@@ -294,7 +294,7 @@ public class Polygon implements Shape, Serializable
             else if (y > maxy)
               maxy = y;
           }
-        bounds = new Rectangle (minx, maxy, maxx - minx, maxy - miny);
+        bounds = new Rectangle (minx, miny, maxx - minx, maxy - miny);
       }
     return bounds;
   }
index cc96ab1..24d8b8e 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000, 2002  Free Software Foundation
+/* Copyright (C) 2000, 2002, 2004  Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -292,19 +292,56 @@ public class ComponentColorModel extends ColorModel
     return Raster.createWritableRaster(sm, origin);
   }
 
+
+  /**
+   * Creates a <code>SampleModel</code> whose arrangement of pixel
+   * data is compatible to this <code>ColorModel</code>.
+   *
+   * @param w the number of pixels in the horizontal direction.
+   * @param h the number of pixels in the vertical direction.
+   */
   public SampleModel createCompatibleSampleModel(int w, int h)
   {
-    int pixelStride = getNumComponents();
-    
-    /* TODO: Maybe we don't need to create a new offset array each
-       time, but rather use the same array every time. */
-    int[] bandOffsets = new int[pixelStride];
-    for (int i=0; i<pixelStride; i++) bandOffsets[i] = i;
-    return new ComponentSampleModel(transferType, w, h,
-                                   pixelStride, pixelStride*w,
-                                   bandOffsets);
+    int pixelStride, scanlineStride;
+    int[] bandOffsets;
+
+    pixelStride = getNumComponents();
+    scanlineStride = pixelStride * w;
+
+    /* We might be able to re-use the same bandOffsets array among
+     * multiple calls to this method. However, this optimization does
+     * not seem worthwile because setting up descriptive data
+     * structures (such as SampleModels) is neglectible in comparision
+     * to shuffling around masses of pixel data.
+     */
+    bandOffsets = new int[pixelStride];
+    for (int i = 0; i < pixelStride; i++)
+      bandOffsets[i] = i;
+
+    /* FIXME: Think about whether it would make sense to return the
+     * possibly more efficient PixelInterleavedSampleModel for other
+     * transferTypes as well. It seems unlikely that this would break
+     * any user applications, so the Mauve tests on this method
+     * might be too restrictive.
+     */
+    switch (transferType)
+      {
+      case DataBuffer.TYPE_BYTE:
+      case DataBuffer.TYPE_USHORT:
+        return new PixelInterleavedSampleModel(transferType, w, h,
+                                               pixelStride,
+                                               scanlineStride,
+                                               bandOffsets);
+
+      default:
+        return new ComponentSampleModel(transferType, w, h,
+                                        pixelStride,
+                                        scanlineStride,
+                                        bandOffsets);
+      }
   }
 
+
   public boolean isCompatibleSampleModel(SampleModel sm)
   {
     return 
index ff6033a..4fd194e 100644 (file)
@@ -452,4 +452,25 @@ public class Raster
                                  y-sampleModelTranslateY,
                                  w, h, b, dArray, dataBuffer);
   }
+  
+  /**
+   * Create a String representing the stat of this Raster.
+   * @return A String representing the stat of this Raster.
+   * @see java.lang.Object#toString()
+   */
+  public String toString()
+  {
+    StringBuffer result = new StringBuffer();
+    
+    result.append(getClass().getName());
+    result.append("[(");
+    result.append(minX).append(",").append(minY).append("), ");
+    result.append(width).append(" x ").append(height).append(",");
+    result.append(sampleModel).append(",");
+    result.append(dataBuffer);
+    result.append("]");
+    
+    return result.toString();
+  }
+  
 }
index 219a871..a5d65ff 100644 (file)
@@ -58,7 +58,9 @@ public abstract class SampleModel
 
   public SampleModel(int dataType, int w, int h, int numBands)
   {
-    if ((w<=0) || (h<=0)) throw new IllegalArgumentException();
+    if ((w <= 0) || (h <= 0)) 
+      throw new IllegalArgumentException((w <= 0 ? " width<=0" : " width is ok")
+                                         +(h <= 0 ? " height<=0" : " height is ok"));
        
     // FIXME: How can an int be greater than Integer.MAX_VALUE?
     // FIXME: How do we identify an unsupported data type?
@@ -68,7 +70,7 @@ public abstract class SampleModel
     this.height = h;
     this.numBands = numBands;  
   }
-
+  
   public final int getWidth()
   {
     return width;
index 3affe05..578500d 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000, 2002, 2003  Free Software Foundation
+/* Copyright (C) 2000, 2002, 2003, 2004  Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -162,6 +162,63 @@ public class SinglePixelPackedSampleModel extends SampleModel
                           1  // length
                           );
   }
+  
+  /**
+   * This is a more efficient implementation of the default implementation in the super
+   * class. 
+   * @param x The x-coordinate of the pixel rectangle to store in <code>obj</code>.
+   * @param y The y-coordinate of the pixel rectangle to store in <code>obj</code>.
+   * @param w The width of the pixel rectangle to store in <code>obj</code>.
+   * @param h The height of the pixel rectangle to store in <code>obj</code>.
+   * @param obj The primitive array to store the pixels into or null to force creation.
+   * @param data The DataBuffer that is the source of the pixel data.
+   * @return The primitive array containing the pixel data.
+   * @see java.awt.image.SampleModel#getDataElements(int, int, int, int, java.lang.Object, java.awt.image.DataBuffer)
+   */
+  public Object getDataElements(int x, int y, int w, int h, Object obj,
+                                                       DataBuffer data)
+  {
+    int size = w*h;
+    int dataSize = size;
+    Object pixelData = null;
+    switch (getTransferType())
+    {
+      case DataBuffer.TYPE_BYTE:
+        pixelData = ((DataBufferByte) data).getData();
+        if (obj == null) obj = new byte[dataSize];
+        break;
+       case DataBuffer.TYPE_USHORT:
+         pixelData = ((DataBufferUShort) data).getData();
+         if (obj == null) obj = new short[dataSize];
+         break;
+        case DataBuffer.TYPE_INT:
+          pixelData = ((DataBufferInt) data).getData();
+          if (obj == null) obj = new int[dataSize];
+          break;
+         default:
+             // Seems like the only sensible thing to do.
+           throw new ClassCastException();
+      }
+      if(x==0 && scanlineStride == w)
+      { 
+        // The full width need to be copied therefore we can copy in one shot.
+        System.arraycopy(pixelData, scanlineStride*y + data.getOffset(), obj, 0, size);
+      }
+      else
+      {  
+        // Since we do not need the full width we need to copy line by line.
+        int outOffset = 0;
+        int dataOffset = scanlineStride*y + x + data.getOffset();
+        for (int yy = y; yy<(y+h); yy++)
+        {
+          System.arraycopy(pixelData, dataOffset, obj, outOffset, w);
+          dataOffset += scanlineStride;
+          outOffset += w;
+        }
+      }
+    return obj;
+  }
+  
 
   public int[] getPixel(int x, int y, int[] iArray, DataBuffer data)
   {
@@ -201,7 +258,51 @@ public class SinglePixelPackedSampleModel extends SampleModel
     int samples = data.getElem(offset);
     return (samples & bitMasks[b]) >>> bitOffsets[b];
   }
-
+  
+  /**
+   * This method implements a more efficient way to set data elements than the default
+   * implementation of the super class. It sets the data elements line by line instead 
+   * of pixel by pixel.
+   * @param x The x-coordinate of the data elements in <code>obj</code>.
+   * @param y The y-coordinate of the data elements in <code>obj</code>.
+   * @param w The width of the data elements in <code>obj</code>.
+   * @param h The height of the data elements in <code>obj</code>.
+   * @param obj The primitive array containing the data elements to set.
+   * @param data The DataBuffer to store the data elements into.
+   * @see java.awt.image.SampleModel#setDataElements(int, int, int, int, java.lang.Object, java.awt.image.DataBuffer)
+   */
+  public void setDataElements(int x, int y, int w, int h,
+                               Object obj, DataBuffer data)
+  {
+    
+    Object pixelData;
+    switch (getTransferType())
+    {
+      case DataBuffer.TYPE_BYTE:
+        pixelData = ((DataBufferByte) data).getData();
+        break;
+       case DataBuffer.TYPE_USHORT:
+         pixelData = ((DataBufferUShort) data).getData();
+         break;
+       case DataBuffer.TYPE_INT:
+         pixelData = ((DataBufferInt) data).getData();
+         break;
+       default:
+          // Seems like the only sensible thing to do.
+          throw new ClassCastException();
+    }
+    
+    int inOffset = 0;
+    int dataOffset = scanlineStride*y + x + data.getOffset();
+    for (int yy=y; yy<(y+h); yy++)
+    {
+      System.arraycopy(obj,inOffset,pixelData,dataOffset,w);
+      dataOffset += scanlineStride;
+      inOffset += w;
+    }
+  }
+  
+  
   public void setDataElements(int x, int y, Object obj, DataBuffer data)
   {
     int offset = scanlineStride*y + x + data.getOffset();
@@ -273,6 +374,39 @@ public class SinglePixelPackedSampleModel extends SampleModel
     data.setElem(offset, samples);
   }
 
+  /**
+   * This method implements a more efficient way to set pixels than the default
+   * implementation of the super class. It copies the pixel components directly
+   * from the input array instead of creating a intermediate buffer.
+   * @param x The x-coordinate of the pixel rectangle in <code>obj</code>.
+   * @param y The y-coordinate of the pixel rectangle in <code>obj</code>.
+   * @param w The width of the pixel rectangle in <code>obj</code>.
+   * @param h The height of the pixel rectangle in <code>obj</code>.
+   * @param obj The primitive array containing the pixels to set.
+   * @param data The DataBuffer to store the pixels into.
+   * @see java.awt.image.SampleModel#setPixels(int, int, int, int, int[], java.awt.image.DataBuffer)
+   */
+  public void setPixels(int x, int y, int w, int h, int[] iArray,
+                                               DataBuffer data)
+  {
+    int inOffset = 0;
+    int[] pixel = new int[numBands];
+    for (int yy=y; yy<(y+h); yy++)
+     {
+      int offset = scanlineStride*yy + x;
+      for (int xx=x; xx<(x+w); xx++)
+       { 
+        int samples = 0;
+        for (int b=0; b<numBands; b++)
+          samples |= (iArray[inOffset+b] << bitOffsets[b]) & bitMasks[b];
+        data.setElem(0, offset, samples);
+        inOffset += numBands;
+        offset += 1;
+      }
+    }
+  }
+  
+  
   public void setSample(int x, int y, int b, int s, DataBuffer data)
   {
     int offset = scanlineStride*y + x;
@@ -282,4 +416,24 @@ public class SinglePixelPackedSampleModel extends SampleModel
     samples |= (s << bitOffsets[b]) & bitMask;
     data.setElem(offset, samples);
   }
+  
+  /**
+   * Creates a String with some information about this SampleModel.
+   * @return A String describing this SampleModel.
+   * @see java.lang.Object#toString()
+   */
+  public String toString()
+  {
+    StringBuffer result = new StringBuffer();
+    result.append(getClass().getName());
+    result.append("[");
+    result.append("scanlineStride=").append(scanlineStride);
+    for(int i=0; i < bitMasks.length; i+=1)
+    {
+      result.append(", mask[").append(i).append("]=0x").append(Integer.toHexString(bitMasks[i]));
+    }
+    
+    result.append("]");
+    return result.toString();
+  }
 }