Home | History | Annotate | Download | only in image
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 /**
     18  * @author Igor V. Stolyarov
     19  * @version $Revision$
     20  */
     21 
     22 package java.awt.image;
     23 
     24 import java.awt.Point;
     25 import java.awt.Rectangle;
     26 
     27 import org.apache.harmony.awt.gl.image.OrdinaryWritableRaster;
     28 import org.apache.harmony.awt.internal.nls.Messages;
     29 
     30 /**
     31  * The Raster class represents a rectangular area of pixels. This class is
     32  * defined by DataBuffer and SampleModel objects. The DataBuffer object stores
     33  * sample values and DSampleModel defines the location of sample in this
     34  * DataBuffer.
     35  *
     36  * @since Android 1.0
     37  */
     38 public class Raster {
     39 
     40     /**
     41      * The DataBuffer of this Raster.
     42      */
     43     protected DataBuffer dataBuffer;
     44 
     45     /**
     46      * The height of this Raster.
     47      */
     48     protected int height;
     49 
     50     /**
     51      * The X coordinate of the upper left pixel in this Raster.
     52      */
     53     protected int minX;
     54 
     55     /**
     56      * The Y coordinate of the upper left pixel in this Raster.
     57      */
     58     protected int minY;
     59 
     60     /**
     61      * The number of bands in this Raster.
     62      */
     63     protected int numBands;
     64 
     65     /**
     66      * The number of data elements.
     67      */
     68     protected int numDataElements;
     69 
     70     /**
     71      * The parent of this Raster.
     72      */
     73     protected Raster parent;
     74 
     75     /**
     76      * The SampleModel of this Raster.
     77      */
     78     protected SampleModel sampleModel;
     79 
     80     /**
     81      * The X translation from the coordinate space of the SampleModel of this
     82      * Raster.
     83      */
     84     protected int sampleModelTranslateX;
     85 
     86     /**
     87      * The Y translation from the coordinate space of the SampleModel of this
     88      * Raster.
     89      */
     90     protected int sampleModelTranslateY;
     91 
     92     /**
     93      * The width of this Raster.
     94      */
     95     protected int width;
     96 
     97     /**
     98      * Creates a Raster object with a BandedSampleModel and the specified
     99      * DataBuffer. The number of bands is defined by the length of bandOffsets
    100      * or bankIndices arrays.
    101      *
    102      * @param dataBuffer
    103      *            the specified DataBuffer.
    104      * @param w
    105      *            the width of the image data.
    106      * @param h
    107      *            the height of the image data.
    108      * @param scanlineStride
    109      *            the scanline stride of the image data.
    110      * @param bankIndices
    111      *            the bank indices of bands.
    112      * @param bandOffsets
    113      *            the band offsets of bands.
    114      * @param location
    115      *            the location which defines the upper left corner of Raster.
    116      * @return the WritableRaster object.
    117      */
    118     public static WritableRaster createBandedRaster(DataBuffer dataBuffer, int w, int h,
    119             int scanlineStride, int bankIndices[], int bandOffsets[], Point location) {
    120 
    121         if (w <= 0 || h <= 0) {
    122             // awt.22E=w or h is less than or equal to zero
    123             throw new RasterFormatException(Messages.getString("awt.22E")); //$NON-NLS-1$
    124         }
    125 
    126         if (location == null) {
    127             location = new Point(0, 0);
    128         }
    129 
    130         if ((long)location.x + w > Integer.MAX_VALUE || (long)location.y + h > Integer.MAX_VALUE) {
    131             // awt.276=location.x + w or location.y + h results in integer
    132             // overflow
    133             throw new RasterFormatException(Messages.getString("awt.276")); //$NON-NLS-1$
    134         }
    135 
    136         if (bankIndices == null || bandOffsets == null) {
    137             // awt.277=bankIndices or bandOffsets is null
    138             throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.277")); //$NON-NLS-1$
    139         }
    140 
    141         if (dataBuffer == null) {
    142             // awt.278=dataBuffer is null
    143             throw new NullPointerException(Messages.getString("awt.278")); //$NON-NLS-1$
    144         }
    145 
    146         int dataType = dataBuffer.getDataType();
    147 
    148         if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_USHORT
    149                 && dataType != DataBuffer.TYPE_INT) {
    150             // awt.230=dataType is not one of the supported data types
    151             throw new IllegalArgumentException(Messages.getString("awt.230")); //$NON-NLS-1$
    152         }
    153 
    154         BandedSampleModel sampleModel = new BandedSampleModel(dataType, w, h, scanlineStride,
    155                 bankIndices, bandOffsets);
    156 
    157         return new OrdinaryWritableRaster(sampleModel, dataBuffer, location);
    158     }
    159 
    160     /**
    161      * Creates a Raster object with a BandedSampleModel and the specified data
    162      * type. The Data type can be one of the following values: TYPE_BYTE,
    163      * TYPE_USHORT, or TYPE_INT.
    164      *
    165      * @param dataType
    166      *            the data type of the samples: TYPE_BYTE, TYPE_USHORT, or
    167      *            TYPE_INT.
    168      * @param w
    169      *            the width of the image data.
    170      * @param h
    171      *            the height of the image data.
    172      * @param scanlineStride
    173      *            the scanline stride of the image data.
    174      * @param bankIndices
    175      *            the bank indices of bands.
    176      * @param bandOffsets
    177      *            the band offsets of bands.
    178      * @param location
    179      *            the location which defines the upper left corner of the
    180      *            Raster.
    181      * @return the WritableRaster object.
    182      */
    183     public static WritableRaster createBandedRaster(int dataType, int w, int h, int scanlineStride,
    184             int bankIndices[], int bandOffsets[], Point location) {
    185 
    186         if (w <= 0 || h <= 0) {
    187             // awt.22E=w or h is less than or equal to zero
    188             throw new RasterFormatException(Messages.getString("awt.22E")); //$NON-NLS-1$
    189         }
    190 
    191         if (location == null) {
    192             location = new Point(0, 0);
    193         }
    194 
    195         if ((long)location.x + w > Integer.MAX_VALUE || (long)location.y + h > Integer.MAX_VALUE) {
    196             // awt.276=location.x + w or location.y + h results in integer
    197             // overflow
    198             throw new RasterFormatException(Messages.getString("awt.276")); //$NON-NLS-1$
    199         }
    200 
    201         if (bankIndices == null || bandOffsets == null) {
    202             // awt.277=bankIndices or bandOffsets is null
    203             throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.277")); //$NON-NLS-1$
    204         }
    205 
    206         if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_USHORT
    207                 && dataType != DataBuffer.TYPE_INT) {
    208             // awt.230=dataType is not one of the supported data types
    209             throw new IllegalArgumentException(Messages.getString("awt.230")); //$NON-NLS-1$
    210         }
    211 
    212         int maxOffset = bandOffsets[0];
    213         int maxBank = bankIndices[0];
    214 
    215         for (int i = 0; i < bankIndices.length; i++) {
    216             if (bandOffsets[i] > maxOffset) {
    217                 maxOffset = bandOffsets[i];
    218             }
    219             if (bankIndices[i] > maxBank) {
    220                 maxBank = bankIndices[i];
    221             }
    222         }
    223 
    224         int numBanks = maxBank + 1;
    225         int dataSize = scanlineStride * (h - 1) + w + maxOffset;
    226 
    227         DataBuffer data = null;
    228 
    229         switch (dataType) {
    230             case DataBuffer.TYPE_BYTE:
    231                 data = new DataBufferByte(dataSize, numBanks);
    232                 break;
    233             case DataBuffer.TYPE_USHORT:
    234                 data = new DataBufferUShort(dataSize, numBanks);
    235                 break;
    236             case DataBuffer.TYPE_INT:
    237                 data = new DataBufferInt(dataSize, numBanks);
    238                 break;
    239         }
    240         return createBandedRaster(data, w, h, scanlineStride, bankIndices, bandOffsets, location);
    241     }
    242 
    243     /**
    244      * Creates a Raster object with a BandedSampleModel and the specified data
    245      * type. The Data type can be one of the following values: TYPE_BYTE,
    246      * TYPE_USHORT, or TYPE_INT.
    247      *
    248      * @param dataType
    249      *            the data type of the samples: TYPE_BYTE, TYPE_USHORT, or
    250      *            TYPE_INT.
    251      * @param w
    252      *            the width of the image data.
    253      * @param h
    254      *            the height of the image data.
    255      * @param bands
    256      *            the number of bands.
    257      * @param location
    258      *            the location which defines the upper left corner of the
    259      *            Raster.
    260      * @return the WritableRaster object.
    261      */
    262     public static WritableRaster createBandedRaster(int dataType, int w, int h, int bands,
    263             Point location) {
    264 
    265         if (w <= 0 || h <= 0) {
    266             // awt.22E=w or h is less than or equal to zero
    267             throw new RasterFormatException(Messages.getString("awt.22E")); //$NON-NLS-1$
    268         }
    269 
    270         if (location == null) {
    271             location = new Point(0, 0);
    272         }
    273 
    274         if ((long)location.x + w > Integer.MAX_VALUE || (long)location.y + h > Integer.MAX_VALUE) {
    275             // awt.276=location.x + w or location.y + h results in integer
    276             // overflow
    277             throw new RasterFormatException(Messages.getString("awt.276")); //$NON-NLS-1$
    278         }
    279 
    280         if (bands < 1) {
    281             // awt.279=bands is less than 1
    282             throw new ArrayIndexOutOfBoundsException(Messages.getString("awt.279")); //$NON-NLS-1$
    283         }
    284 
    285         int bandOffsets[] = new int[bands];
    286         int bankIndices[] = new int[bands];
    287 
    288         for (int i = 0; i < bands; i++) {
    289             bandOffsets[i] = 0;
    290             bankIndices[i] = i;
    291         }
    292         return createBandedRaster(dataType, w, h, w, bankIndices, bandOffsets, location);
    293     }
    294 
    295     /**
    296      * Creates a Raster object with a PixelInterleavedSampleModel and the
    297      * specified DataBuffer.
    298      *
    299      * @param dataBuffer
    300      *            the DataBuffer.
    301      * @param w
    302      *            the width of image data.
    303      * @param h
    304      *            the height of image data.
    305      * @param scanlineStride
    306      *            the scanline stride of the image data.
    307      * @param pixelStride
    308      *            the pixel stride of image data.
    309      * @param bandOffsets
    310      *            the band offsets of bands.
    311      * @param location
    312      *            the location which defines the upper left corner of the
    313      *            Raster.
    314      * @return the WritableRaster object.
    315      */
    316     public static WritableRaster createInterleavedRaster(DataBuffer dataBuffer, int w, int h,
    317             int scanlineStride, int pixelStride, int bandOffsets[], Point location) {
    318 
    319         if (w <= 0 || h <= 0) {
    320             // awt.22E=w or h is less than or equal to zero
    321             throw new RasterFormatException(Messages.getString("awt.22E")); //$NON-NLS-1$
    322         }
    323 
    324         if (location == null) {
    325             location = new Point(0, 0);
    326         }
    327 
    328         if ((long)location.x + w > Integer.MAX_VALUE || (long)location.y + h > Integer.MAX_VALUE) {
    329             // awt.276=location.x + w or location.y + h results in integer
    330             // overflow
    331             throw new RasterFormatException(Messages.getString("awt.276")); //$NON-NLS-1$
    332         }
    333 
    334         if (dataBuffer == null) {
    335             // awt.278=dataBuffer is null
    336             throw new NullPointerException(Messages.getString("awt.278")); //$NON-NLS-1$
    337         }
    338 
    339         int dataType = dataBuffer.getDataType();
    340         if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_USHORT) {
    341             // awt.230=dataType is not one of the supported data types
    342             throw new IllegalArgumentException(Messages.getString("awt.230")); //$NON-NLS-1$
    343         }
    344 
    345         if (dataBuffer.getNumBanks() > 1) {
    346             // awt.27A=dataBuffer has more than one bank
    347             throw new RasterFormatException(Messages.getString("awt.27A")); //$NON-NLS-1$
    348         }
    349 
    350         if (bandOffsets == null) {
    351             // awt.27B=bandOffsets is null
    352             throw new NullPointerException(Messages.getString("awt.27B")); //$NON-NLS-1$
    353         }
    354 
    355         PixelInterleavedSampleModel sampleModel = new PixelInterleavedSampleModel(dataType, w, h,
    356                 pixelStride, scanlineStride, bandOffsets);
    357 
    358         return new OrdinaryWritableRaster(sampleModel, dataBuffer, location);
    359 
    360     }
    361 
    362     /**
    363      * Creates a Raster object with a PixelInterleavedSampleModel and the
    364      * specified data type. The Data type can be one of the following values:
    365      * TYPE_BYTE, TYPE_USHORT, or TYPE_INT.
    366      *
    367      * @param dataType
    368      *            the data type of the samples: TYPE_BYTE, TYPE_USHORT, or
    369      *            TYPE_INT.
    370      * @param w
    371      *            the width of image data.
    372      * @param h
    373      *            the height of image data.
    374      * @param scanlineStride
    375      *            the scanline stride of the image data.
    376      * @param pixelStride
    377      *            the pixel stride of image data.
    378      * @param bandOffsets
    379      *            the band offsets of bands.
    380      * @param location
    381      *            the location which defines the upper left corner of the
    382      *            Raster.
    383      * @return the WritableRaster object.
    384      */
    385     public static WritableRaster createInterleavedRaster(int dataType, int w, int h,
    386             int scanlineStride, int pixelStride, int bandOffsets[], Point location) {
    387 
    388         if (w <= 0 || h <= 0) {
    389             // awt.22E=w or h is less than or equal to zero
    390             throw new RasterFormatException(Messages.getString("awt.22E")); //$NON-NLS-1$
    391         }
    392 
    393         if (location == null) {
    394             location = new Point(0, 0);
    395         }
    396 
    397         if ((long)location.x + w > Integer.MAX_VALUE || (long)location.y + h > Integer.MAX_VALUE) {
    398             // awt.276=location.x + w or location.y + h results in integer
    399             // overflow
    400             throw new RasterFormatException(Messages.getString("awt.276")); //$NON-NLS-1$
    401         }
    402 
    403         if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_USHORT) {
    404             // awt.230=dataType is not one of the supported data types
    405             throw new IllegalArgumentException(Messages.getString("awt.230")); //$NON-NLS-1$
    406         }
    407 
    408         if (bandOffsets == null) {
    409             // awt.27B=bandOffsets is null
    410             throw new NullPointerException(Messages.getString("awt.27B")); //$NON-NLS-1$
    411         }
    412 
    413         int minOffset = bandOffsets[0];
    414         for (int i = 1; i < bandOffsets.length; i++) {
    415             if (bandOffsets[i] < minOffset) {
    416                 minOffset = bandOffsets[i];
    417             }
    418         }
    419         int size = (h - 1) * scanlineStride + w * pixelStride + minOffset;
    420         DataBuffer data = null;
    421 
    422         switch (dataType) {
    423             case DataBuffer.TYPE_BYTE:
    424                 data = new DataBufferByte(size);
    425                 break;
    426             case DataBuffer.TYPE_USHORT:
    427                 data = new DataBufferUShort(size);
    428                 break;
    429         }
    430 
    431         return createInterleavedRaster(data, w, h, scanlineStride, pixelStride, bandOffsets,
    432                 location);
    433     }
    434 
    435     /**
    436      * Creates a Raster object with a PixelInterleavedSampleModel and the
    437      * specified data type. The Data type can be one of the following values:
    438      * TYPE_BYTE, TYPE_USHORT, or TYPE_INT.
    439      *
    440      * @param dataType
    441      *            the data type of samples: TYPE_BYTE, TYPE_USHORT, or TYPE_INT.
    442      * @param w
    443      *            the width of image data.
    444      * @param h
    445      *            the height of image data.
    446      * @param bands
    447      *            the number of bands.
    448      * @param location
    449      *            the location which defines the upper left corner of the
    450      *            Raster.
    451      * @return the WritableRaster.
    452      */
    453     public static WritableRaster createInterleavedRaster(int dataType, int w, int h, int bands,
    454             Point location) {
    455 
    456         if (w <= 0 || h <= 0) {
    457             // awt.22E=w or h is less than or equal to zero
    458             throw new RasterFormatException(Messages.getString("awt.22E")); //$NON-NLS-1$
    459         }
    460 
    461         if (location == null) {
    462             location = new Point(0, 0);
    463         }
    464 
    465         if ((long)location.x + w > Integer.MAX_VALUE || (long)location.y + h > Integer.MAX_VALUE) {
    466             // awt.276=location.x + w or location.y + h results in integer
    467             // overflow
    468             throw new RasterFormatException(Messages.getString("awt.276")); //$NON-NLS-1$
    469         }
    470 
    471         if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_USHORT) {
    472             // awt.230=dataType is not one of the supported data types
    473             throw new IllegalArgumentException(Messages.getString("awt.230")); //$NON-NLS-1$
    474         }
    475 
    476         int bandOffsets[] = new int[bands];
    477         for (int i = 0; i < bands; i++) {
    478             bandOffsets[i] = i;
    479         }
    480 
    481         return createInterleavedRaster(dataType, w, h, w * bands, bands, bandOffsets, location);
    482     }
    483 
    484     /**
    485      * Creates a Raster object with a SinglePixelPackedSampleModel and the
    486      * specified DataBuffer.
    487      *
    488      * @param dataBuffer
    489      *            the DataBuffer.
    490      * @param w
    491      *            the width of the image data.
    492      * @param h
    493      *            the height of the image data.
    494      * @param scanlineStride
    495      *            the scanline stride of the image data.
    496      * @param bandMasks
    497      *            the band masks.
    498      * @param location
    499      *            the location which defines the upper left corner of the
    500      *            Raster.
    501      * @return the WritableRaster.
    502      */
    503     public static WritableRaster createPackedRaster(DataBuffer dataBuffer, int w, int h,
    504             int scanlineStride, int bandMasks[], Point location) {
    505         if (dataBuffer == null) {
    506             // awt.278=dataBuffer is null
    507             throw new NullPointerException(Messages.getString("awt.278")); //$NON-NLS-1$
    508         }
    509 
    510         if (w <= 0 || h <= 0) {
    511             // awt.22E=w or h is less than or equal to zero
    512             throw new RasterFormatException(Messages.getString("awt.22E")); //$NON-NLS-1$
    513         }
    514 
    515         if (location == null) {
    516             location = new Point(0, 0);
    517         }
    518 
    519         if ((long)location.x + w > Integer.MAX_VALUE || (long)location.y + h > Integer.MAX_VALUE) {
    520             // awt.276=location.x + w or location.y + h results in integer
    521             // overflow
    522             throw new RasterFormatException(Messages.getString("awt.276")); //$NON-NLS-1$
    523         }
    524 
    525         if (bandMasks == null) {
    526             // awt.27C=bandMasks is null
    527             throw new RasterFormatException(Messages.getString("awt.27C")); //$NON-NLS-1$
    528         }
    529 
    530         if (dataBuffer.getNumBanks() > 1) {
    531             // awt.27A=dataBuffer has more than one bank
    532             throw new RasterFormatException(Messages.getString("awt.27A")); //$NON-NLS-1$
    533         }
    534 
    535         int dataType = dataBuffer.getDataType();
    536         if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_USHORT
    537                 && dataType != DataBuffer.TYPE_INT) {
    538             // awt.230=dataType is not one of the supported data types
    539             throw new IllegalArgumentException(Messages.getString("awt.230")); //$NON-NLS-1$
    540         }
    541 
    542         SinglePixelPackedSampleModel sampleModel = new SinglePixelPackedSampleModel(dataType, w, h,
    543                 scanlineStride, bandMasks);
    544 
    545         return new OrdinaryWritableRaster(sampleModel, dataBuffer, location);
    546     }
    547 
    548     /**
    549      * Creates a Raster object with a MultiPixelPackedSampleModel and the
    550      * specified DataBuffer.
    551      *
    552      * @param dataBuffer
    553      *            the DataBuffer.
    554      * @param w
    555      *            the width of the image data.
    556      * @param h
    557      *            the height of the image data.
    558      * @param bitsPerPixel
    559      *            the number of bits per pixel.
    560      * @param location
    561      *            the location which defines the upper left corner of the
    562      *            Raster.
    563      * @return the WritableRaster.
    564      */
    565     public static WritableRaster createPackedRaster(DataBuffer dataBuffer, int w, int h,
    566             int bitsPerPixel, Point location) {
    567 
    568         if (w <= 0 || h <= 0) {
    569             // awt.22E=w or h is less than or equal to zero
    570             throw new RasterFormatException(Messages.getString("awt.22E")); //$NON-NLS-1$
    571         }
    572 
    573         if (location == null) {
    574             location = new Point(0, 0);
    575         }
    576 
    577         if ((long)location.x + w > Integer.MAX_VALUE || (long)location.y + h > Integer.MAX_VALUE) {
    578             // awt.276=location.x + w or location.y + h results in integer
    579             // overflow
    580             throw new RasterFormatException(Messages.getString("awt.276")); //$NON-NLS-1$
    581         }
    582 
    583         if (dataBuffer == null) {
    584             // awt.278=dataBuffer is null
    585             throw new NullPointerException(Messages.getString("awt.278")); //$NON-NLS-1$
    586         }
    587 
    588         if (dataBuffer.getNumBanks() > 1) {
    589             // awt.27A=dataBuffer has more than one bank
    590             throw new RasterFormatException(Messages.getString("awt.27A")); //$NON-NLS-1$
    591         }
    592 
    593         int dataType = dataBuffer.getDataType();
    594         if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_USHORT
    595                 && dataType != DataBuffer.TYPE_INT) {
    596             // awt.230=dataType is not one of the supported data types
    597             throw new IllegalArgumentException(Messages.getString("awt.230")); //$NON-NLS-1$
    598         }
    599 
    600         MultiPixelPackedSampleModel sampleModel = new MultiPixelPackedSampleModel(dataType, w, h,
    601                 bitsPerPixel);
    602 
    603         return new OrdinaryWritableRaster(sampleModel, dataBuffer, location);
    604 
    605     }
    606 
    607     /**
    608      * Creates a Raster object with a MultiPixelPackedSampleModel and the
    609      * specified DataBuffer.
    610      *
    611      * @param dataType
    612      *            the data type of samples: TYPE_BYTE, TYPE_USHORT, or TYPE_INT.
    613      * @param w
    614      *            the width of the image data.
    615      * @param h
    616      *            the height of the image data.
    617      * @param bands
    618      *            the number of bands.
    619      * @param bitsPerBand
    620      *            the number of bits per band.
    621      * @param location
    622      *            the location which defines the upper left corner of the
    623      *            Raster.
    624      * @return the WritableRaster.
    625      */
    626     public static WritableRaster createPackedRaster(int dataType, int w, int h, int bands,
    627             int bitsPerBand, Point location) {
    628 
    629         if (w <= 0 || h <= 0) {
    630             // awt.22E=w or h is less than or equal to zero
    631             throw new RasterFormatException(Messages.getString("awt.22E")); //$NON-NLS-1$
    632         }
    633 
    634         if (location == null) {
    635             location = new Point(0, 0);
    636         }
    637 
    638         if ((long)location.x + w > Integer.MAX_VALUE || (long)location.y + h > Integer.MAX_VALUE) {
    639             // awt.276=location.x + w or location.y + h results in integer
    640             // overflow
    641             throw new RasterFormatException(Messages.getString("awt.276")); //$NON-NLS-1$
    642         }
    643 
    644         if (bands < 1 || bitsPerBand < 1) {
    645             // awt.27D=bitsPerBand or bands is not greater than zero
    646             throw new IllegalArgumentException(Messages.getString("awt.27D")); //$NON-NLS-1$
    647         }
    648 
    649         if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_USHORT
    650                 && dataType != DataBuffer.TYPE_INT) {
    651             // awt.230=dataType is not one of the supported data types
    652             throw new IllegalArgumentException(Messages.getString("awt.230")); //$NON-NLS-1$
    653         }
    654 
    655         if (bitsPerBand * bands > DataBuffer.getDataTypeSize(dataType)) {
    656             // awt.27E=The product of bitsPerBand and bands is greater than the
    657             // number of bits held by dataType
    658             throw new IllegalArgumentException(Messages.getString("awt.27E")); //$NON-NLS-1$
    659         }
    660 
    661         if (bands > 1) {
    662 
    663             int bandMasks[] = new int[bands];
    664             int mask = (1 << bitsPerBand) - 1;
    665 
    666             for (int i = 0; i < bands; i++) {
    667                 bandMasks[i] = mask << (bitsPerBand * (bands - 1 - i));
    668             }
    669 
    670             return createPackedRaster(dataType, w, h, bandMasks, location);
    671         }
    672         DataBuffer data = null;
    673         int size = ((bitsPerBand * w + DataBuffer.getDataTypeSize(dataType) - 1) / DataBuffer
    674                 .getDataTypeSize(dataType))
    675                 * h;
    676 
    677         switch (dataType) {
    678             case DataBuffer.TYPE_BYTE:
    679                 data = new DataBufferByte(size);
    680                 break;
    681             case DataBuffer.TYPE_USHORT:
    682                 data = new DataBufferUShort(size);
    683                 break;
    684             case DataBuffer.TYPE_INT:
    685                 data = new DataBufferInt(size);
    686                 break;
    687         }
    688         return createPackedRaster(data, w, h, bitsPerBand, location);
    689     }
    690 
    691     /**
    692      * Creates a Raster object with a SinglePixelPackedSampleModel and the
    693      * specified DataBuffer.
    694      *
    695      * @param dataType
    696      *            the data type of samples: TYPE_BYTE, TYPE_USHORT, or TYPE_INT.
    697      * @param w
    698      *            the width of the image data.
    699      * @param h
    700      *            the height of the image data.
    701      * @param bandMasks
    702      *            the band masks.
    703      * @param location
    704      *            the location which defines the upper left corner of the
    705      *            Raster.
    706      * @return the WritableRaster.
    707      */
    708     public static WritableRaster createPackedRaster(int dataType, int w, int h, int bandMasks[],
    709             Point location) {
    710 
    711         if (dataType != DataBuffer.TYPE_BYTE && dataType != DataBuffer.TYPE_USHORT
    712                 && dataType != DataBuffer.TYPE_INT) {
    713             // awt.230=dataType is not one of the supported data types
    714             throw new IllegalArgumentException(Messages.getString("awt.230")); //$NON-NLS-1$
    715         }
    716 
    717         if (w <= 0 || h <= 0) {
    718             // awt.22E=w or h is less than or equal to zero
    719             throw new RasterFormatException(Messages.getString("awt.22E")); //$NON-NLS-1$
    720         }
    721 
    722         if (location == null) {
    723             location = new Point(0, 0);
    724         }
    725 
    726         if ((long)location.x + w > Integer.MAX_VALUE || (long)location.y + h > Integer.MAX_VALUE) {
    727             // awt.276=location.x + w or location.y + h results in integer
    728             // overflow
    729             throw new RasterFormatException(Messages.getString("awt.276")); //$NON-NLS-1$
    730         }
    731 
    732         if (bandMasks == null) {
    733             // awt.27C=bandMasks is null
    734             throw new NullPointerException(Messages.getString("awt.27C")); //$NON-NLS-1$
    735         }
    736 
    737         DataBuffer data = null;
    738 
    739         switch (dataType) {
    740             case DataBuffer.TYPE_BYTE:
    741                 data = new DataBufferByte(w * h);
    742                 break;
    743             case DataBuffer.TYPE_USHORT:
    744                 data = new DataBufferUShort(w * h);
    745                 break;
    746             case DataBuffer.TYPE_INT:
    747                 data = new DataBufferInt(w * h);
    748                 break;
    749         }
    750 
    751         return createPackedRaster(data, w, h, w, bandMasks, location);
    752     }
    753 
    754     /**
    755      * Creates a Raster object with the specified DataBuffer and SampleModel.
    756      *
    757      * @param sm
    758      *            the specified SampleModel.
    759      * @param db
    760      *            the specified DataBuffer.
    761      * @param location
    762      *            the location which defines the upper left corner of the
    763      *            Raster.
    764      * @return the Raster.
    765      */
    766     public static Raster createRaster(SampleModel sm, DataBuffer db, Point location) {
    767 
    768         if (sm == null || db == null) {
    769             // awt.27F=SampleModel or DataBuffer is null
    770             throw new NullPointerException(Messages.getString("awt.27F")); //$NON-NLS-1$
    771         }
    772 
    773         if (location == null) {
    774             location = new Point(0, 0);
    775         }
    776 
    777         return new Raster(sm, db, location);
    778     }
    779 
    780     /**
    781      * Creates a WritableRaster with the specified SampleModel and DataBuffer.
    782      *
    783      * @param sm
    784      *            the specified SampleModel.
    785      * @param db
    786      *            the specified DataBuffer.
    787      * @param location
    788      *            the location which defines the upper left corner of the
    789      *            Raster.
    790      * @return the WritableRaster.
    791      */
    792     public static WritableRaster createWritableRaster(SampleModel sm, DataBuffer db, Point location) {
    793 
    794         if (sm == null || db == null) {
    795             // awt.27F=SampleModel or DataBuffer is null
    796             throw new NullPointerException(Messages.getString("awt.27F")); //$NON-NLS-1$
    797         }
    798 
    799         if (location == null) {
    800             location = new Point(0, 0);
    801         }
    802 
    803         return new OrdinaryWritableRaster(sm, db, location);
    804     }
    805 
    806     /**
    807      * Creates a WritableRaster with the specified SampleModel.
    808      *
    809      * @param sm
    810      *            the specified SampleModel.
    811      * @param location
    812      *            the location which defines the upper left corner of the
    813      *            Raster.
    814      * @return the WritableRaster.
    815      */
    816     public static WritableRaster createWritableRaster(SampleModel sm, Point location) {
    817 
    818         if (sm == null) {
    819             // awt.280=SampleModel is null
    820             throw new NullPointerException(Messages.getString("awt.280")); //$NON-NLS-1$
    821         }
    822 
    823         if (location == null) {
    824             location = new Point(0, 0);
    825         }
    826 
    827         return createWritableRaster(sm, sm.createDataBuffer(), location);
    828     }
    829 
    830     /**
    831      * Instantiates a new Raster object with the specified SampleModel and
    832      * DataBuffer.
    833      *
    834      * @param sampleModel
    835      *            the specified SampleModel.
    836      * @param dataBuffer
    837      *            the specified DataBuffer.
    838      * @param origin
    839      *            the specified origin.
    840      */
    841     protected Raster(SampleModel sampleModel, DataBuffer dataBuffer, Point origin) {
    842 
    843         this(sampleModel, dataBuffer, new Rectangle(origin.x, origin.y, sampleModel.getWidth(),
    844                 sampleModel.getHeight()), origin, null);
    845     }
    846 
    847     /**
    848      * Instantiates a new Raster object with the specified SampleModel,
    849      * DataBuffer, rectangular region and parent Raster.
    850      *
    851      * @param sampleModel
    852      *            the specified SampleModel.
    853      * @param dataBuffer
    854      *            the specified DataBuffer.
    855      * @param aRegion
    856      *            the a rectangular region which defines the new image bounds.
    857      * @param sampleModelTranslate
    858      *            this point defines the translation point from the SampleModel
    859      *            coordinates to the new Raster coordinates.
    860      * @param parent
    861      *            the parent of this Raster.
    862      */
    863     protected Raster(SampleModel sampleModel, DataBuffer dataBuffer, Rectangle aRegion,
    864             Point sampleModelTranslate, Raster parent) {
    865 
    866         if (sampleModel == null || dataBuffer == null || aRegion == null
    867                 || sampleModelTranslate == null) {
    868             // awt.281=sampleModel, dataBuffer, aRegion or sampleModelTranslate
    869             // is null
    870             throw new NullPointerException(Messages.getString("awt.281")); //$NON-NLS-1$
    871         }
    872 
    873         if (aRegion.width <= 0 || aRegion.height <= 0) {
    874             // awt.282=aRegion has width or height less than or equal to zero
    875             throw new RasterFormatException(Messages.getString("awt.282")); //$NON-NLS-1$
    876         }
    877 
    878         if ((long)aRegion.x + (long)aRegion.width > Integer.MAX_VALUE) {
    879             // awt.283=Overflow X coordinate of Raster
    880             throw new RasterFormatException(Messages.getString("awt.283")); //$NON-NLS-1$
    881         }
    882 
    883         if ((long)aRegion.y + (long)aRegion.height > Integer.MAX_VALUE) {
    884             // awt.284=Overflow Y coordinate of Raster
    885             throw new RasterFormatException(Messages.getString("awt.284")); //$NON-NLS-1$
    886         }
    887 
    888         if (sampleModel instanceof ComponentSampleModel) {
    889             validateDataBuffer(dataBuffer, aRegion.width, aRegion.height,
    890                     ((ComponentSampleModel)sampleModel).getScanlineStride());
    891         } else if (sampleModel instanceof MultiPixelPackedSampleModel) {
    892             validateDataBuffer(dataBuffer, aRegion.width, aRegion.height,
    893                     ((MultiPixelPackedSampleModel)sampleModel).getScanlineStride());
    894         } else if (sampleModel instanceof SinglePixelPackedSampleModel) {
    895             validateDataBuffer(dataBuffer, aRegion.width, aRegion.height,
    896                     ((SinglePixelPackedSampleModel)sampleModel).getScanlineStride());
    897         }
    898 
    899         this.sampleModel = sampleModel;
    900         this.dataBuffer = dataBuffer;
    901         this.minX = aRegion.x;
    902         this.minY = aRegion.y;
    903         this.width = aRegion.width;
    904         this.height = aRegion.height;
    905         this.sampleModelTranslateX = sampleModelTranslate.x;
    906         this.sampleModelTranslateY = sampleModelTranslate.y;
    907         this.parent = parent;
    908         this.numBands = sampleModel.getNumBands();
    909         this.numDataElements = sampleModel.getNumDataElements();
    910 
    911     }
    912 
    913     /**
    914      * Instantiates a new Raster with the specified SampleModel.
    915      *
    916      * @param sampleModel
    917      *            the specified SampleModel.
    918      * @param origin
    919      *            the origin.
    920      */
    921     protected Raster(SampleModel sampleModel, Point origin) {
    922         this(sampleModel, sampleModel.createDataBuffer(), new Rectangle(origin.x, origin.y,
    923                 sampleModel.getWidth(), sampleModel.getHeight()), origin, null);
    924     }
    925 
    926     /**
    927      * Creates the child of this Raster by sharing the specified rectangular
    928      * area in this raster. The parentX, parentY, width and height parameters
    929      * specify the rectangular area to be shared.
    930      *
    931      * @param parentX
    932      *            the X coordinate of the upper left corner of this Raster.
    933      * @param parentY
    934      *            the Y coordinate of the upper left corner of this Raster.
    935      * @param width
    936      *            the width of the child area.
    937      * @param height
    938      *            the height of the child area.
    939      * @param childMinX
    940      *            the X coordinate of child area mapped to the parentX
    941      *            coordinate.
    942      * @param childMinY
    943      *            the Y coordinate of child area mapped to the parentY
    944      *            coordinate.
    945      * @param bandList
    946      *            the array of band indices.
    947      * @return the Raster.
    948      */
    949     public Raster createChild(int parentX, int parentY, int width, int height, int childMinX,
    950             int childMinY, int bandList[]) {
    951         if (width <= 0 || height <= 0) {
    952             // awt.285=Width or Height of child Raster is less than or equal to
    953             // zero
    954             throw new RasterFormatException(Messages.getString("awt.285")); //$NON-NLS-1$
    955         }
    956 
    957         if (parentX < this.minX || parentX + width > this.minX + this.width) {
    958             // awt.286=parentX disposes outside Raster
    959             throw new RasterFormatException(Messages.getString("awt.286")); //$NON-NLS-1$
    960         }
    961 
    962         if (parentY < this.minY || parentY + height > this.minY + this.height) {
    963             // awt.287=parentY disposes outside Raster
    964             throw new RasterFormatException(Messages.getString("awt.287")); //$NON-NLS-1$
    965         }
    966 
    967         if ((long)parentX + width > Integer.MAX_VALUE) {
    968             // awt.288=parentX + width results in integer overflow
    969             throw new RasterFormatException(Messages.getString("awt.288")); //$NON-NLS-1$
    970         }
    971 
    972         if ((long)parentY + height > Integer.MAX_VALUE) {
    973             // awt.289=parentY + height results in integer overflow
    974             throw new RasterFormatException(Messages.getString("awt.289")); //$NON-NLS-1$
    975         }
    976 
    977         if ((long)childMinX + width > Integer.MAX_VALUE) {
    978             // awt.28A=childMinX + width results in integer overflow
    979             throw new RasterFormatException(Messages.getString("awt.28A")); //$NON-NLS-1$
    980         }
    981 
    982         if ((long)childMinY + height > Integer.MAX_VALUE) {
    983             // awt.28B=childMinY + height results in integer overflow
    984             throw new RasterFormatException(Messages.getString("awt.28B")); //$NON-NLS-1$
    985         }
    986 
    987         SampleModel childModel;
    988 
    989         if (bandList == null) {
    990             childModel = sampleModel;
    991         } else {
    992             childModel = sampleModel.createSubsetSampleModel(bandList);
    993         }
    994 
    995         int childTranslateX = childMinX - parentX;
    996         int childTranslateY = childMinY - parentY;
    997 
    998         return new Raster(childModel, dataBuffer,
    999                 new Rectangle(childMinX, childMinY, width, height), new Point(childTranslateX
   1000                         + sampleModelTranslateX, childTranslateY + sampleModelTranslateY), this);
   1001     }
   1002 
   1003     /**
   1004      * Create a compatible WritableRaster with the same parameters as this
   1005      * Raster.
   1006      *
   1007      * @return the WritableRaster.
   1008      */
   1009     public WritableRaster createCompatibleWritableRaster() {
   1010         return new OrdinaryWritableRaster(sampleModel, new Point(0, 0));
   1011     }
   1012 
   1013     /**
   1014      * Create a compatible WritableRaster with the same parameters as this
   1015      * Raster and the specified size.
   1016      *
   1017      * @param w
   1018      *            the width of the new WritableRaster.
   1019      * @param h
   1020      *            the height of the new WritableRaster.
   1021      * @return the WritableRaster.
   1022      */
   1023     public WritableRaster createCompatibleWritableRaster(int w, int h) {
   1024         if (w <= 0 || h <= 0) {
   1025             // awt.22E=w or h is less than or equal to zero
   1026             throw new RasterFormatException(Messages.getString("awt.22E")); //$NON-NLS-1$
   1027         }
   1028 
   1029         SampleModel sm = sampleModel.createCompatibleSampleModel(w, h);
   1030 
   1031         return new OrdinaryWritableRaster(sm, new Point(0, 0));
   1032     }
   1033 
   1034     /**
   1035      * Create a compatible WritableRaster with the same parameters as this
   1036      * Raster and the specified size and location.
   1037      *
   1038      * @param x
   1039      *            the X coordinate of the new WritableRaster.
   1040      * @param y
   1041      *            the Y coordinate of the new WritableRaster.
   1042      * @param w
   1043      *            the width of the new WritableRaster.
   1044      * @param h
   1045      *            the height of the new WritableRaster.
   1046      * @return the WritableRaster.
   1047      */
   1048     public WritableRaster createCompatibleWritableRaster(int x, int y, int w, int h) {
   1049 
   1050         WritableRaster raster = createCompatibleWritableRaster(w, h);
   1051 
   1052         return raster.createWritableChild(0, 0, w, h, x, y, null);
   1053     }
   1054 
   1055     /**
   1056      * Create a compatible WritableRaster with the same parameters as this
   1057      * Raster and the specified rectangle which determines new WritableRaster's
   1058      * location and size.
   1059      *
   1060      * @param rect
   1061      *            the specified Rectangle.
   1062      * @return the WritableRaster.
   1063      */
   1064     public WritableRaster createCompatibleWritableRaster(Rectangle rect) {
   1065         if (rect == null) {
   1066             // awt.28C=Rect is null
   1067             throw new NullPointerException(Messages.getString("awt.28C")); //$NON-NLS-1$
   1068         }
   1069 
   1070         return createCompatibleWritableRaster(rect.x, rect.y, rect.width, rect.height);
   1071     }
   1072 
   1073     /**
   1074      * Creates the translated child of this Raster. The New Raster object is a
   1075      * reference to the this Raster with a different location.
   1076      *
   1077      * @param childMinX
   1078      *            the X coordinate of the new Raster.
   1079      * @param childMinY
   1080      *            the Y coordinate of the new Raster.
   1081      * @return the Raster.
   1082      */
   1083     public Raster createTranslatedChild(int childMinX, int childMinY) {
   1084         return createChild(minX, minY, width, height, childMinX, childMinY, null);
   1085     }
   1086 
   1087     /**
   1088      * Gets the bounds of this Raster as a rectangle.
   1089      *
   1090      * @return the bounds of this Raster.
   1091      */
   1092     public Rectangle getBounds() {
   1093         return new Rectangle(minX, minY, width, height);
   1094     }
   1095 
   1096     /**
   1097      * Gets the DataBuffer associated with this Raster.
   1098      *
   1099      * @return the DataBuffer associated with this Raster.
   1100      */
   1101     public DataBuffer getDataBuffer() {
   1102         return dataBuffer;
   1103     }
   1104 
   1105     /**
   1106      * Gets the data elements which represent the pixel data of the specified
   1107      * rectangle area as a primitive array. The following image data types are
   1108      * supported: DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT,
   1109      * DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT, or
   1110      * DataBuffer.TYPE_DOUBLE.
   1111      *
   1112      * @param x
   1113      *            the X coordinate of the area of pixels.
   1114      * @param y
   1115      *            the Y coordinate of the area of pixels.
   1116      * @param w
   1117      *            the width of the area of pixels.
   1118      * @param h
   1119      *            the height of the area of pixels.
   1120      * @param outData
   1121      *            the resulting array.
   1122      * @return the data elements of the specified area of this Raster.
   1123      */
   1124     public Object getDataElements(int x, int y, int w, int h, Object outData) {
   1125         return sampleModel.getDataElements(x - sampleModelTranslateX, y - sampleModelTranslateY, w,
   1126                 h, outData, dataBuffer);
   1127     }
   1128 
   1129     /**
   1130      * Gets the data elements which represent the specified pixel of this Raster
   1131      * as a primitive array. The following image data types are supported:
   1132      * DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT,
   1133      * DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE.
   1134      *
   1135      * @param x
   1136      *            the X coordinate of the pixel.
   1137      * @param y
   1138      *            the Y coordinate of the pixel.
   1139      * @param outData
   1140      *            the resulting data.
   1141      * @return the data elements of the specified pixel of this Raster.
   1142      */
   1143     public Object getDataElements(int x, int y, Object outData) {
   1144         return sampleModel.getDataElements(x - sampleModelTranslateX, y - sampleModelTranslateY,
   1145                 outData, dataBuffer);
   1146     }
   1147 
   1148     /**
   1149      * Gets the height of this Raster.
   1150      *
   1151      * @return the height of this Raster.
   1152      */
   1153     public final int getHeight() {
   1154         return height;
   1155     }
   1156 
   1157     /**
   1158      * Gets the minimum X coordinate of this Raster.
   1159      *
   1160      * @return the minimum X coordinate of this Raster.
   1161      */
   1162     public final int getMinX() {
   1163         return minX;
   1164     }
   1165 
   1166     /**
   1167      * Gets the minimum Y coordinate of this Raster.
   1168      *
   1169      * @return the minimum Y coordinate of this Raster.
   1170      */
   1171     public final int getMinY() {
   1172         return minY;
   1173     }
   1174 
   1175     /**
   1176      * Gets the number of bands in this Raster.
   1177      *
   1178      * @return the number of bands in this Raster.
   1179      */
   1180     public final int getNumBands() {
   1181         return numBands;
   1182     }
   1183 
   1184     /**
   1185      * Gets the number of data elements for one pixel.
   1186      *
   1187      * @return the number of data elements for one pixel.
   1188      */
   1189     public final int getNumDataElements() {
   1190         return numDataElements;
   1191     }
   1192 
   1193     /**
   1194      * Gets the parent Raster for this Raster object.
   1195      *
   1196      * @return the parent Raster for this Raster object.
   1197      */
   1198     public Raster getParent() {
   1199         return parent;
   1200     }
   1201 
   1202     /**
   1203      * Gets a double array of samples for the specified pixel in this Raster.
   1204      *
   1205      * @param x
   1206      *            the pixel's X coordinate.
   1207      * @param y
   1208      *            the pixel's Y coordinate.
   1209      * @param dArray
   1210      *            the double array where result array will be stored.
   1211      * @return the double array of samples for the specified pixel in this
   1212      *         Raster.
   1213      */
   1214     public double[] getPixel(int x, int y, double dArray[]) {
   1215         return sampleModel.getPixel(x - sampleModelTranslateX, y - sampleModelTranslateY, dArray,
   1216                 dataBuffer);
   1217     }
   1218 
   1219     /**
   1220      * Gets a float array of samples for the specified pixel in this Raster.
   1221      *
   1222      * @param x
   1223      *            the pixel's X coordinate.
   1224      * @param y
   1225      *            the pixel's Y coordinate.
   1226      * @param fArray
   1227      *            the float array where the result array will be stored.
   1228      * @return the float array of samples for the specified pixel in this
   1229      *         Raster.
   1230      */
   1231     public float[] getPixel(int x, int y, float fArray[]) {
   1232         return sampleModel.getPixel(x - sampleModelTranslateX, y - sampleModelTranslateY, fArray,
   1233                 dataBuffer);
   1234     }
   1235 
   1236     /**
   1237      * Gets an integer array of samples for the specified pixel in this Raster.
   1238      *
   1239      * @param x
   1240      *            the pixel's X coordinate.
   1241      * @param y
   1242      *            the pixel's Y coordinate.
   1243      * @param iArray
   1244      *            the integer array where the result array will be stored.
   1245      * @return the integer array of samples for the specified pixel in this
   1246      *         Raster.
   1247      */
   1248     public int[] getPixel(int x, int y, int iArray[]) {
   1249         return sampleModel.getPixel(x - sampleModelTranslateX, y - sampleModelTranslateY, iArray,
   1250                 dataBuffer);
   1251     }
   1252 
   1253     /**
   1254      * Gets an double array of samples for the specified rectangular area of
   1255      * pixels in this Raster.
   1256      *
   1257      * @param x
   1258      *            the X coordinate of the area of pixels.
   1259      * @param y
   1260      *            the Y coordinate of the area of pixels.
   1261      * @param w
   1262      *            the width of the area of pixels.
   1263      * @param h
   1264      *            the height of the area of pixels.
   1265      * @param dArray
   1266      *            the resulting array.
   1267      * @return the double array of samples for the specified rectangular area of
   1268      *         pixels in this Raster.
   1269      */
   1270     public double[] getPixels(int x, int y, int w, int h, double dArray[]) {
   1271         return sampleModel.getPixels(x - sampleModelTranslateX, y - sampleModelTranslateY, w, h,
   1272                 dArray, dataBuffer);
   1273     }
   1274 
   1275     /**
   1276      * Gets an float array of samples for the specified rectangular area of
   1277      * pixels in this Raster.
   1278      *
   1279      * @param x
   1280      *            the X coordinate of the area of pixels.
   1281      * @param y
   1282      *            the Y coordinate of the area of pixels.
   1283      * @param w
   1284      *            the width of the area of pixels.
   1285      * @param h
   1286      *            the height of the area of pixels.
   1287      * @param fArray
   1288      *            the resulting array.
   1289      * @return the float array of samples for the specified rectangular area of
   1290      *         pixels in this Raster.
   1291      */
   1292     public float[] getPixels(int x, int y, int w, int h, float fArray[]) {
   1293         return sampleModel.getPixels(x - sampleModelTranslateX, y - sampleModelTranslateY, w, h,
   1294                 fArray, dataBuffer);
   1295     }
   1296 
   1297     /**
   1298      * Gets an integer array of samples for the specified rectangular area of
   1299      * pixels in this raster.
   1300      *
   1301      * @param x
   1302      *            the X coordinate of the area of pixels.
   1303      * @param y
   1304      *            the Y coordinate of the area of pixels.
   1305      * @param w
   1306      *            the width of pixel's the area of pixels.
   1307      * @param h
   1308      *            the height of pixel's the area of pixels.
   1309      * @param iArray
   1310      *            the resulting array.
   1311      * @return the integer array of samples for the specified rectangular area
   1312      *         of pixels in this Raster.
   1313      */
   1314     public int[] getPixels(int x, int y, int w, int h, int iArray[]) {
   1315         return sampleModel.getPixels(x - sampleModelTranslateX, y - sampleModelTranslateY, w, h,
   1316                 iArray, dataBuffer);
   1317     }
   1318 
   1319     /**
   1320      * Gets the sample for the specified band of the specified pixel as an
   1321      * integer.
   1322      *
   1323      * @param x
   1324      *            the X coordinate of the pixel.
   1325      * @param y
   1326      *            the Y coordinate of the pixel.
   1327      * @param b
   1328      *            the band.
   1329      * @return the sample for the specified band of the specified pixel as an
   1330      *         integer.
   1331      */
   1332     public int getSample(int x, int y, int b) {
   1333         return sampleModel.getSample(x - sampleModelTranslateX, y - sampleModelTranslateY, b,
   1334                 dataBuffer);
   1335     }
   1336 
   1337     /**
   1338      * Gets the sample for the specified band of the specified pixel as a
   1339      * double.
   1340      *
   1341      * @param x
   1342      *            the X coordinate of the pixel.
   1343      * @param y
   1344      *            the Y coordinate of the pixel.
   1345      * @param b
   1346      *            the band.
   1347      * @return the sample for the specified band of the specified pixel as a
   1348      *         double.
   1349      */
   1350     public double getSampleDouble(int x, int y, int b) {
   1351         return sampleModel.getSampleDouble(x - sampleModelTranslateX, y - sampleModelTranslateY, b,
   1352                 dataBuffer);
   1353     }
   1354 
   1355     /**
   1356      * Gets the sample for the specified band of the specified pixel as a float.
   1357      *
   1358      * @param x
   1359      *            the X coordinate of the pixel.
   1360      * @param y
   1361      *            the Y coordinate of the pixel.
   1362      * @param b
   1363      *            the band.
   1364      * @return the sample for the specified band of the specified pixel as a
   1365      *         float.
   1366      */
   1367     public float getSampleFloat(int x, int y, int b) {
   1368         return sampleModel.getSampleFloat(x - sampleModelTranslateX, y - sampleModelTranslateY, b,
   1369                 dataBuffer);
   1370     }
   1371 
   1372     /**
   1373      * Gets the SampleModel associated with this Raster.
   1374      *
   1375      * @return the SampleModel associated with this Raster.
   1376      */
   1377     public SampleModel getSampleModel() {
   1378         return sampleModel;
   1379     }
   1380 
   1381     /**
   1382      * Gets the translation of the X coordinate from the SampleModel coordinate
   1383      * system to the Rasters's coordinate system.
   1384      *
   1385      * @return the value of the translation of the X coordinate from the
   1386      *         SampleModel coordinate system to the Rasters's coordinate system.
   1387      */
   1388     public final int getSampleModelTranslateX() {
   1389         return sampleModelTranslateX;
   1390     }
   1391 
   1392     /**
   1393      * Gets the translation of the Y coordinate from the SampleModel coordinate
   1394      * system to the Rasters's coordinate system.
   1395      *
   1396      * @return the value of the translation of the Y coordinate from the
   1397      *         SampleModel coordinate system to the Rasters's coordinate system.
   1398      */
   1399     public final int getSampleModelTranslateY() {
   1400         return sampleModelTranslateY;
   1401     }
   1402 
   1403     /**
   1404      * Gets the double array of samples for the specified band of the specified
   1405      * rectangular area of pixels in this Raster as a double array.
   1406      *
   1407      * @param x
   1408      *            the X coordinate of the rectangular area of pixels.
   1409      * @param y
   1410      *            the Y coordinate of the rectangular area of pixels.
   1411      * @param w
   1412      *            the width of the rectangular area of pixels.
   1413      * @param h
   1414      *            the height of the rectangular area of pixels.
   1415      * @param b
   1416      *            the band.
   1417      * @param dArray
   1418      *            the resulting double array.
   1419      * @return the double array of samples for the specified band of the
   1420      *         specified rectangular area of pixels.
   1421      */
   1422     public double[] getSamples(int x, int y, int w, int h, int b, double dArray[]) {
   1423 
   1424         return sampleModel.getSamples(x - sampleModelTranslateX, y - sampleModelTranslateY, w, h,
   1425                 b, dArray, dataBuffer);
   1426     }
   1427 
   1428     /**
   1429      * Gets the float array of samples for the specified band of the specified
   1430      * rectangular area of pixels in this Raster as a float array.
   1431      *
   1432      * @param x
   1433      *            the X coordinate of the rectangular area of pixels.
   1434      * @param y
   1435      *            the Y coordinate of the rectangular area of pixels.
   1436      * @param w
   1437      *            the width of the rectangular area of pixels.
   1438      * @param h
   1439      *            the height of the rectangular area of pixels.
   1440      * @param b
   1441      *            the band.
   1442      * @param fArray
   1443      *            the resulting float array.
   1444      * @return the float array of samples for the specified band of the
   1445      *         specified rectangular area of pixels.
   1446      */
   1447     public float[] getSamples(int x, int y, int w, int h, int b, float fArray[]) {
   1448 
   1449         return sampleModel.getSamples(x - sampleModelTranslateX, y - sampleModelTranslateY, w, h,
   1450                 b, fArray, dataBuffer);
   1451     }
   1452 
   1453     /**
   1454      * Gets the integer array of samples for the specified band of the specified
   1455      * rectangular area of pixels in this Raster as a integer array.
   1456      *
   1457      * @param x
   1458      *            the X coordinate of the rectangular area of pixels.
   1459      * @param y
   1460      *            the Y coordinate of the rectangular area of pixels.
   1461      * @param w
   1462      *            the width of the rectangular area of pixels.
   1463      * @param h
   1464      *            the height of the rectangular area of pixels.
   1465      * @param b
   1466      *            the band.
   1467      * @param iArray
   1468      *            the resulting integer array.
   1469      * @return the integer array of samples for the specified band of the
   1470      *         specified rectangular area of pixels.
   1471      */
   1472     public int[] getSamples(int x, int y, int w, int h, int b, int iArray[]) {
   1473         return sampleModel.getSamples(x - sampleModelTranslateX, y - sampleModelTranslateY, w, h,
   1474                 b, iArray, dataBuffer);
   1475     }
   1476 
   1477     /**
   1478      * Gets the transfer type for pixels of this Raster.
   1479      *
   1480      * @see SampleModel#getTransferType()
   1481      * @return the transfer type for pixels of this Raster.
   1482      */
   1483     public final int getTransferType() {
   1484         return sampleModel.getTransferType();
   1485     }
   1486 
   1487     /**
   1488      * Gets the width of this Raster.
   1489      *
   1490      * @return the width of this Raster.
   1491      */
   1492     public final int getWidth() {
   1493         return width;
   1494     }
   1495 
   1496     /**
   1497      * Validate data buffer.
   1498      *
   1499      * @param dataBuffer
   1500      *            the data buffer.
   1501      * @param w
   1502      *            the w.
   1503      * @param h
   1504      *            the h.
   1505      * @param scanlineStride
   1506      *            the scanline stride.
   1507      */
   1508     private static void validateDataBuffer(final DataBuffer dataBuffer, final int w, final int h,
   1509             final int scanlineStride) {
   1510         if (dataBuffer.getSize() < (scanlineStride * (h - 1) + w - 1)) {
   1511             // awt.298=dataBuffer is too small
   1512             throw new RasterFormatException(Messages.getString("awt.298")); //$NON-NLS-1$
   1513         }
   1514     }
   1515 }
   1516