< prev index next >

src/java.desktop/share/classes/java/awt/image/Raster.java

Print this page




 960      *         than one bank and {@code sm} is a
 961      *         PixelInterleavedSampleModel, SinglePixelPackedSampleModel,
 962      *         or MultiPixelPackedSampleModel.
 963      * @throws NullPointerException if either SampleModel or DataBuffer is null
 964      */
 965     public static WritableRaster createWritableRaster(SampleModel sm,
 966                                                       DataBuffer db,
 967                                                       Point location) {
 968         if ((sm == null) || (db == null)) {
 969             throw new NullPointerException("SampleModel and DataBuffer cannot be null");
 970         }
 971         if (location == null) {
 972            location = new Point(0,0);
 973         }
 974 
 975         int dataType = sm.getDataType();
 976 
 977         if (sm instanceof PixelInterleavedSampleModel) {
 978             switch(dataType) {
 979                 case DataBuffer.TYPE_BYTE:

 980                     return new ByteInterleavedRaster(sm, db, location);


 981 
 982                 case DataBuffer.TYPE_USHORT:

 983                     return new ShortInterleavedRaster(sm, db, location);
 984             }


 985         } else if (sm instanceof SinglePixelPackedSampleModel) {
 986             switch(dataType) {
 987                 case DataBuffer.TYPE_BYTE:

 988                     return new ByteInterleavedRaster(sm, db, location);


 989 
 990                 case DataBuffer.TYPE_USHORT:

 991                     return new ShortInterleavedRaster(sm, db, location);


 992 
 993                 case DataBuffer.TYPE_INT:

 994                     return new IntegerInterleavedRaster(sm, db, location);
 995             }


 996         } else if (sm instanceof MultiPixelPackedSampleModel &&
 997                    dataType == DataBuffer.TYPE_BYTE &&

 998                    sm.getSampleSize(0) < 8) {
 999             return new BytePackedRaster(sm, db, location);
1000         }
1001 
1002         // we couldn't do anything special - do the generic thing
1003 
1004         return new SunWritableRaster(sm,db,location);
1005     }
1006 
1007     /**
1008      *  Constructs a Raster with the given SampleModel.  The Raster's
1009      *  upper left corner is origin and it is the same size as the
1010      *  SampleModel.  A DataBuffer large enough to describe the
1011      *  Raster is automatically created.
1012      *  @param sampleModel     The SampleModel that specifies the layout
1013      *  @param origin          The Point that specified the origin
1014      *  @throws RasterFormatException if computing either
1015      *          {@code origin.x + sampleModel.getWidth()} or
1016      *          {@code origin.y + sampleModel.getHeight()} results in
1017      *          integer overflow
1018      *  @throws NullPointerException either {@code sampleModel} or
1019      *          {@code origin} is null
1020      */
1021     protected Raster(SampleModel sampleModel,
1022                      Point origin) {
1023         this(sampleModel,




 960      *         than one bank and {@code sm} is a
 961      *         PixelInterleavedSampleModel, SinglePixelPackedSampleModel,
 962      *         or MultiPixelPackedSampleModel.
 963      * @throws NullPointerException if either SampleModel or DataBuffer is null
 964      */
 965     public static WritableRaster createWritableRaster(SampleModel sm,
 966                                                       DataBuffer db,
 967                                                       Point location) {
 968         if ((sm == null) || (db == null)) {
 969             throw new NullPointerException("SampleModel and DataBuffer cannot be null");
 970         }
 971         if (location == null) {
 972            location = new Point(0,0);
 973         }
 974 
 975         int dataType = sm.getDataType();
 976 
 977         if (sm instanceof PixelInterleavedSampleModel) {
 978             switch(dataType) {
 979                 case DataBuffer.TYPE_BYTE:
 980                     if (db instanceof DataBufferByte) {
 981                         return new ByteInterleavedRaster(sm, db, location);
 982                     }
 983                     break;
 984 
 985                 case DataBuffer.TYPE_USHORT:
 986                     if (db instanceof DataBufferUShort) {
 987                         return new ShortInterleavedRaster(sm, db, location);
 988                     }
 989                     break;
 990             }
 991         } else if (sm instanceof SinglePixelPackedSampleModel) {
 992             switch(dataType) {
 993                 case DataBuffer.TYPE_BYTE:
 994                     if (db instanceof DataBufferByte) {
 995                         return new ByteInterleavedRaster(sm, db, location);
 996                     }
 997                     break;
 998 
 999                 case DataBuffer.TYPE_USHORT:
1000                     if (db instanceof DataBufferUShort) {
1001                         return new ShortInterleavedRaster(sm, db, location);
1002                     }
1003                     break;
1004 
1005                 case DataBuffer.TYPE_INT:
1006                     if (db instanceof DataBufferInt) {
1007                         return new IntegerInterleavedRaster(sm, db, location);
1008                     }
1009                     break;
1010             }
1011         } else if (sm instanceof MultiPixelPackedSampleModel &&
1012                    dataType == DataBuffer.TYPE_BYTE &&
1013                    db instanceof DataBufferByte &&
1014                    sm.getSampleSize(0) < 8) {
1015             return new BytePackedRaster(sm, db, location);
1016         }
1017 
1018         // we couldn't do anything special - do the generic thing

1019         return new SunWritableRaster(sm,db,location);
1020     }
1021 
1022     /**
1023      *  Constructs a Raster with the given SampleModel.  The Raster's
1024      *  upper left corner is origin and it is the same size as the
1025      *  SampleModel.  A DataBuffer large enough to describe the
1026      *  Raster is automatically created.
1027      *  @param sampleModel     The SampleModel that specifies the layout
1028      *  @param origin          The Point that specified the origin
1029      *  @throws RasterFormatException if computing either
1030      *          {@code origin.x + sampleModel.getWidth()} or
1031      *          {@code origin.y + sampleModel.getHeight()} results in
1032      *          integer overflow
1033      *  @throws NullPointerException either {@code sampleModel} or
1034      *          {@code origin} is null
1035      */
1036     protected Raster(SampleModel sampleModel,
1037                      Point origin) {
1038         this(sampleModel,


< prev index next >