OSDN Git Service

Merged gcj-eclipse branch to trunk.
[pf3gnuchains/gcc-fork.git] / libjava / classpath / java / awt / image / WritableRaster.java
index 473c6fe..bf8db14 100644 (file)
@@ -136,8 +136,9 @@ public class WritableRaster extends Raster
   {
     // This mirrors the code from the super class
     
-    // FIXME: Throw RasterFormatException if child bounds extends
-    // beyond the bounds of this raster.
+    if (parentX < minX || parentX + w > minX + width
+        || parentY < minY || parentY + h > minY + height)
+      throw new RasterFormatException("Child raster extends beyond parent");
     
     SampleModel sm = (bandList == null) ?
       sampleModel :
@@ -149,6 +150,25 @@ public class WritableRaster extends Raster
                   sampleModelTranslateY + childMinY - parentY),
         this);
   }
+  
+  public Raster createChild(int parentX, int parentY, int width,
+                            int height, int childMinX, int childMinY,
+                            int[] bandList)
+  {
+    if (parentX < minX || parentX + width > minX + this.width
+        || parentY < minY || parentY + height > minY + this.height)
+      throw new RasterFormatException("Child raster extends beyond parent");
+    
+    SampleModel sm = (bandList == null) ?
+      sampleModel :
+      sampleModel.createSubsetSampleModel(bandList);
+
+    return new WritableRaster(sm, dataBuffer,
+        new Rectangle(childMinX, childMinY, width, height),
+        new Point(sampleModelTranslateX + childMinX - parentX,
+                  sampleModelTranslateY + childMinY - parentY),
+        this);
+  }
 
   public void setDataElements(int x, int y, Object inData)
   {