Save This Page
Home » openjdk-7 » java » awt » image » [javadoc | source]
    1   /*
    2    * Portions Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    5    * This code is free software; you can redistribute it and/or modify it
    6    * under the terms of the GNU General Public License version 2 only, as
    7    * published by the Free Software Foundation.  Sun designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Sun in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   22    * CA 95054 USA or visit www.sun.com if you need additional information or
   23    * have any questions.
   24    */
   25   
   26   /* ****************************************************************
   27    ******************************************************************
   28    ******************************************************************
   29    *** COPYRIGHT (c) Eastman Kodak Company, 1997
   30    *** As  an unpublished  work pursuant to Title 17 of the United
   31    *** States Code.  All rights reserved.
   32    ******************************************************************
   33    ******************************************************************
   34    ******************************************************************/
   35   
   36   package java.awt.image;
   37   
   38   /**
   39    *  This abstract class defines an interface for extracting samples of pixels
   40    *  in an image.  All image data is expressed as a collection of pixels.
   41    *  Each pixel consists of a number of samples. A sample is a datum
   42    *  for one band of an image and a band consists of all samples of a
   43    *  particular type in an image.  For example, a pixel might contain
   44    *  three samples representing its red, green and blue components.
   45    *  There are three bands in the image containing this pixel.  One band
   46    *  consists of all the red samples from all pixels in the
   47    *  image.  The second band consists of all the green samples and
   48    *  the remaining band consists of all of the blue samples.  The pixel
   49    *  can be stored in various formats.  For example, all samples from
   50    *  a particular band can be stored contiguously or all samples from a
   51    *  single pixel can be stored contiguously.
   52    *  <p>
   53    *  Subclasses of SampleModel specify the types of samples they can
   54    *  represent (e.g. unsigned 8-bit byte, signed 16-bit short, etc.)
   55    *  and may specify how the samples are organized in memory.
   56    *  In the Java 2D(tm) API, built-in image processing operators may
   57    *  not operate on all possible sample types, but generally will work
   58    *  for unsigned integral samples of 16 bits or less.  Some operators
   59    *  support a wider variety of sample types.
   60    *  <p>
   61    *  A collection of pixels is represented as a Raster, which consists of
   62    *  a DataBuffer and a SampleModel.  The SampleModel allows access to
   63    *  samples in the DataBuffer and may provide low-level information that
   64    *  a programmer can use to directly manipulate samples and pixels in the
   65    *  DataBuffer.
   66    *  <p>
   67    *  This class is generally a fall back method for dealing with
   68    *  images.  More efficient code will cast the SampleModel to the
   69    *  appropriate subclass and extract the information needed to directly
   70    *  manipulate pixels in the DataBuffer.
   71    *
   72    *  @see java.awt.image.DataBuffer
   73    *  @see java.awt.image.Raster
   74    *  @see java.awt.image.ComponentSampleModel
   75    *  @see java.awt.image.PixelInterleavedSampleModel
   76    *  @see java.awt.image.BandedSampleModel
   77    *  @see java.awt.image.MultiPixelPackedSampleModel
   78    *  @see java.awt.image.SinglePixelPackedSampleModel
   79    */
   80   
   81   public abstract class SampleModel
   82   {
   83   
   84       /** Width in pixels of the region of image data that this SampleModel
   85        *  describes.
   86        */
   87       protected int width;
   88   
   89       /** Height in pixels of the region of image data that this SampleModel
   90        *  describes.
   91        */
   92       protected int height;
   93   
   94       /** Number of bands of the image data that this SampleModel describes. */
   95       protected int numBands;
   96   
   97       /** Data type of the DataBuffer storing the pixel data.
   98        *  @see java.awt.image.DataBuffer
   99        */
  100       protected int dataType;
  101   
  102       static private native void initIDs();
  103       static {
  104           ColorModel.loadLibraries();
  105           initIDs();
  106       }
  107   
  108       /**
  109        * Constructs a SampleModel with the specified parameters.
  110        * @param dataType  The data type of the DataBuffer storing the pixel data.
  111        * @param w         The width (in pixels) of the region of image data.
  112        * @param h         The height (in pixels) of the region of image data.
  113        * @param numBands  The number of bands of the image data.
  114        * @throws IllegalArgumentException if <code>w</code> or <code>h</code>
  115        *         is not greater than 0
  116        * @throws IllegalArgumentException if the product of <code>w</code>
  117        *         and <code>h</code> is greater than
  118        *         <code>Integer.MAX_VALUE</code>
  119        * @throws IllegalArgumentException if <code>dataType</code> is not
  120        *         one of the supported data types
  121        */
  122       public SampleModel(int dataType, int w, int h, int numBands)
  123       {
  124           float size = (float)w*h;
  125           if (w <= 0 || h <= 0) {
  126               throw new IllegalArgumentException("Width ("+w+") and height ("+
  127                                                  h+") must be > 0");
  128           }
  129           if (size >= Integer.MAX_VALUE) {
  130               throw new IllegalArgumentException("Dimensions (width="+w+
  131                                                  " height="+h+") are too large");
  132           }
  133   
  134           if (dataType < DataBuffer.TYPE_BYTE ||
  135               (dataType > DataBuffer.TYPE_DOUBLE &&
  136                dataType != DataBuffer.TYPE_UNDEFINED))
  137           {
  138               throw new IllegalArgumentException("Unsupported dataType: "+
  139                                                  dataType);
  140           }
  141   
  142           if (numBands <= 0) {
  143               throw new IllegalArgumentException("Number of bands must be > 0");
  144           }
  145   
  146           this.dataType = dataType;
  147           this.width = w;
  148           this.height = h;
  149           this.numBands = numBands;
  150       }
  151   
  152       /** Returns the width in pixels.
  153        *  @return the width in pixels of the region of image data
  154        *          that this <code>SampleModel</code> describes.
  155        */
  156       final public int getWidth() {
  157            return width;
  158       }
  159   
  160       /** Returns the height in pixels.
  161        *  @return the height in pixels of the region of image data
  162        *          that this <code>SampleModel</code> describes.
  163        */
  164       final public int getHeight() {
  165            return height;
  166       }
  167   
  168       /** Returns the total number of bands of image data.
  169        *  @return the number of bands of image data that this
  170        *          <code>SampleModel</code> describes.
  171        */
  172       final public int getNumBands() {
  173            return numBands;
  174       }
  175   
  176       /** Returns the number of data elements needed to transfer a pixel
  177        *  via the getDataElements and setDataElements methods.  When pixels
  178        *  are transferred via these methods, they may be transferred in a
  179        *  packed or unpacked format, depending on the implementation of the
  180        *  SampleModel.  Using these methods, pixels are transferred as an
  181        *  array of getNumDataElements() elements of a primitive type given
  182        *  by getTransferType().  The TransferType may or may not be the same
  183        *  as the storage DataType.
  184        *  @return the number of data elements.
  185        *  @see #getDataElements(int, int, Object, DataBuffer)
  186        *  @see #getDataElements(int, int, int, int, Object, DataBuffer)
  187        *  @see #setDataElements(int, int, Object, DataBuffer)
  188        *  @see #setDataElements(int, int, int, int, Object, DataBuffer)
  189        *  @see #getTransferType
  190        */
  191       public abstract int getNumDataElements();
  192   
  193       /** Returns the data type of the DataBuffer storing the pixel data.
  194        *  @return the data type.
  195        */
  196       final public int getDataType() {
  197           return dataType;
  198       }
  199   
  200       /** Returns the TransferType used to transfer pixels via the
  201        *  getDataElements and setDataElements methods.  When pixels
  202        *  are transferred via these methods, they may be transferred in a
  203        *  packed or unpacked format, depending on the implementation of the
  204        *  SampleModel.  Using these methods, pixels are transferred as an
  205        *  array of getNumDataElements() elements of a primitive type given
  206        *  by getTransferType().  The TransferType may or may not be the same
  207        *  as the storage DataType.  The TransferType will be one of the types
  208        *  defined in DataBuffer.
  209        *  @return the transfer type.
  210        *  @see #getDataElements(int, int, Object, DataBuffer)
  211        *  @see #getDataElements(int, int, int, int, Object, DataBuffer)
  212        *  @see #setDataElements(int, int, Object, DataBuffer)
  213        *  @see #setDataElements(int, int, int, int, Object, DataBuffer)
  214        *  @see #getNumDataElements
  215        *  @see java.awt.image.DataBuffer
  216        */
  217       public int getTransferType() {
  218           return dataType;
  219       }
  220   
  221       /**
  222        * Returns the samples for a specified pixel in an int array,
  223        * one sample per array element.
  224        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  225        * not in bounds.
  226        * @param x         The X coordinate of the pixel location
  227        * @param y         The Y coordinate of the pixel location
  228        * @param iArray    If non-null, returns the samples in this array
  229        * @param data      The DataBuffer containing the image data
  230        * @return the samples for the specified pixel.
  231        * @see #setPixel(int, int, int[], DataBuffer)
  232        *
  233        * @throws NullPointerException if data is null.
  234        * @throws ArrayIndexOutOfBoundsException if the coordinates are
  235        * not in bounds, or if iArray is too small to hold the output.
  236        */
  237       public int[] getPixel(int x, int y, int iArray[], DataBuffer data) {
  238   
  239           int pixels[];
  240   
  241           if (iArray != null)
  242               pixels = iArray;
  243           else
  244               pixels = new int[numBands];
  245   
  246           for (int i=0; i<numBands; i++) {
  247               pixels[i] = getSample(x, y, i, data);
  248           }
  249   
  250           return pixels;
  251       }
  252   
  253       /**
  254        * Returns data for a single pixel in a primitive array of type
  255        * TransferType.  For image data supported by the Java 2D API, this
  256        * will be one of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT,
  257        * DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT,
  258        * or DataBuffer.TYPE_DOUBLE.  Data may be returned in a packed format,
  259        * thus increasing efficiency for data transfers. Generally, obj
  260        * should be passed in as null, so that the Object will be created
  261        * automatically and will be of the right primitive data type.
  262        * <p>
  263        * The following code illustrates transferring data for one pixel from
  264        * DataBuffer <code>db1</code>, whose storage layout is described by
  265        * SampleModel <code>sm1</code>, to DataBuffer <code>db2</code>, whose
  266        * storage layout is described by SampleModel <code>sm2</code>.
  267        * The transfer will generally be more efficient than using
  268        * getPixel/setPixel.
  269        * <pre>
  270        *       SampleModel sm1, sm2;
  271        *       DataBuffer db1, db2;
  272        *       sm2.setDataElements(x, y, sm1.getDataElements(x, y, null, db1), db2);
  273        * </pre>
  274        * Using getDataElements/setDataElements to transfer between two
  275        * DataBuffer/SampleModel pairs is legitimate if the SampleModels have
  276        * the same number of bands, corresponding bands have the same number of
  277        * bits per sample, and the TransferTypes are the same.
  278        * <p>
  279        * If obj is non-null, it should be a primitive array of type TransferType.
  280        * Otherwise, a ClassCastException is thrown.  An
  281        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  282        * not in bounds, or if obj is non-null and is not large enough to hold
  283        * the pixel data.
  284        * @param x         The X coordinate of the pixel location.
  285        * @param y         The Y coordinate of the pixel location.
  286        * @param obj       If non-null, a primitive array in which to return
  287        *                  the pixel data.
  288        * @param data      The DataBuffer containing the image data.
  289        * @return the data elements for the specified pixel.
  290        * @see #getNumDataElements
  291        * @see #getTransferType
  292        * @see java.awt.image.DataBuffer
  293        * @see #setDataElements(int, int, Object, DataBuffer)
  294        *
  295        * @throws NullPointerException if data is null.
  296        * @throws ArrayIndexOutOfBoundsException if the coordinates are
  297        * not in bounds, or if obj is too small to hold the output.
  298        */
  299       public abstract Object getDataElements(int x, int y,
  300                                              Object obj, DataBuffer data);
  301   
  302       /**
  303        * Returns the pixel data for the specified rectangle of pixels in a
  304        * primitive array of type TransferType.
  305        * For image data supported by the Java 2D API, this
  306        * will be one of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT,
  307        * DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT,
  308        * or DataBuffer.TYPE_DOUBLE.  Data may be returned in a packed format,
  309        * thus increasing efficiency for data transfers. Generally, obj
  310        * should be passed in as null, so that the Object will be created
  311        * automatically and will be of the right primitive data type.
  312        * <p>
  313        * The following code illustrates transferring data for a rectangular
  314        * region of pixels from
  315        * DataBuffer <code>db1</code>, whose storage layout is described by
  316        * SampleModel <code>sm1</code>, to DataBuffer <code>db2</code>, whose
  317        * storage layout is described by SampleModel <code>sm2</code>.
  318        * The transfer will generally be more efficient than using
  319        * getPixels/setPixels.
  320        * <pre>
  321        *       SampleModel sm1, sm2;
  322        *       DataBuffer db1, db2;
  323        *       sm2.setDataElements(x, y, w, h, sm1.getDataElements(x, y, w,
  324        *                           h, null, db1), db2);
  325        * </pre>
  326        * Using getDataElements/setDataElements to transfer between two
  327        * DataBuffer/SampleModel pairs is legitimate if the SampleModels have
  328        * the same number of bands, corresponding bands have the same number of
  329        * bits per sample, and the TransferTypes are the same.
  330        * <p>
  331        * If obj is non-null, it should be a primitive array of type TransferType.
  332        * Otherwise, a ClassCastException is thrown.  An
  333        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  334        * not in bounds, or if obj is non-null and is not large enough to hold
  335        * the pixel data.
  336        * @param x         The minimum X coordinate of the pixel rectangle.
  337        * @param y         The minimum Y coordinate of the pixel rectangle.
  338        * @param w         The width of the pixel rectangle.
  339        * @param h         The height of the pixel rectangle.
  340        * @param obj       If non-null, a primitive array in which to return
  341        *                  the pixel data.
  342        * @param data      The DataBuffer containing the image data.
  343        * @return the data elements for the specified region of pixels.
  344        * @see #getNumDataElements
  345        * @see #getTransferType
  346        * @see #setDataElements(int, int, int, int, Object, DataBuffer)
  347        * @see java.awt.image.DataBuffer
  348        *
  349        * @throws NullPointerException if data is null.
  350        * @throws ArrayIndexOutOfBoundsException if the coordinates are
  351        * not in bounds, or if obj is too small to hold the output.
  352        */
  353       public Object getDataElements(int x, int y, int w, int h,
  354                                     Object obj, DataBuffer data) {
  355   
  356           int type = getTransferType();
  357           int numDataElems = getNumDataElements();
  358           int cnt = 0;
  359           Object o = null;
  360   
  361           switch(type) {
  362   
  363           case DataBuffer.TYPE_BYTE:
  364   
  365               byte[] btemp;
  366               byte[] bdata;
  367   
  368               if (obj == null)
  369                   bdata = new byte[numDataElems*w*h];
  370               else
  371                   bdata = (byte[])obj;
  372   
  373               for (int i=y; i<y+h; i++) {
  374                   for (int j=x; j<x+w; j++) {
  375                       o = getDataElements(j, i, o, data);
  376                       btemp = (byte[])o;
  377                       for (int k=0; k<numDataElems; k++) {
  378                           bdata[cnt++] = btemp[k];
  379                       }
  380                   }
  381               }
  382               obj = (Object)bdata;
  383               break;
  384   
  385           case DataBuffer.TYPE_USHORT:
  386           case DataBuffer.TYPE_SHORT:
  387   
  388               short[] sdata;
  389               short[] stemp;
  390   
  391               if (obj == null)
  392                   sdata = new short[numDataElems*w*h];
  393               else
  394                   sdata = (short[])obj;
  395   
  396               for (int i=y; i<y+h; i++) {
  397                   for (int j=x; j<x+w; j++) {
  398                       o = getDataElements(j, i, o, data);
  399                       stemp = (short[])o;
  400                       for (int k=0; k<numDataElems; k++) {
  401                           sdata[cnt++] = stemp[k];
  402                       }
  403                   }
  404               }
  405   
  406               obj = (Object)sdata;
  407               break;
  408   
  409           case DataBuffer.TYPE_INT:
  410   
  411               int[] idata;
  412               int[] itemp;
  413   
  414               if (obj == null)
  415                   idata = new int[numDataElems*w*h];
  416               else
  417                   idata = (int[])obj;
  418   
  419               for (int i=y; i<y+h; i++) {
  420                   for (int j=x; j<x+w; j++) {
  421                       o = getDataElements(j, i, o, data);
  422                       itemp = (int[])o;
  423                       for (int k=0; k<numDataElems; k++) {
  424                           idata[cnt++] = itemp[k];
  425                       }
  426                   }
  427               }
  428   
  429               obj = (Object)idata;
  430               break;
  431   
  432           case DataBuffer.TYPE_FLOAT:
  433   
  434               float[] fdata;
  435               float[] ftemp;
  436   
  437               if (obj == null)
  438                   fdata = new float[numDataElems*w*h];
  439               else
  440                   fdata = (float[])obj;
  441   
  442               for (int i=y; i<y+h; i++) {
  443                   for (int j=x; j<x+w; j++) {
  444                       o = getDataElements(j, i, o, data);
  445                       ftemp = (float[])o;
  446                       for (int k=0; k<numDataElems; k++) {
  447                           fdata[cnt++] = ftemp[k];
  448                       }
  449                   }
  450               }
  451   
  452               obj = (Object)fdata;
  453               break;
  454   
  455           case DataBuffer.TYPE_DOUBLE:
  456   
  457               double[] ddata;
  458               double[] dtemp;
  459   
  460               if (obj == null)
  461                   ddata = new double[numDataElems*w*h];
  462               else
  463                   ddata = (double[])obj;
  464   
  465               for (int i=y; i<y+h; i++) {
  466                   for (int j=x; j<x+w; j++) {
  467                       o = getDataElements(j, i, o, data);
  468                       dtemp = (double[])o;
  469                       for (int k=0; k<numDataElems; k++) {
  470                           ddata[cnt++] = dtemp[k];
  471                       }
  472                   }
  473               }
  474   
  475               obj = (Object)ddata;
  476               break;
  477           }
  478   
  479           return obj;
  480       }
  481   
  482       /**
  483        * Sets the data for a single pixel in the specified DataBuffer from a
  484        * primitive array of type TransferType.  For image data supported by
  485        * the Java 2D API, this will be one of DataBuffer.TYPE_BYTE,
  486        * DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,
  487        * DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE.  Data in the array
  488        * may be in a packed format, thus increasing efficiency for data
  489        * transfers.
  490        * <p>
  491        * The following code illustrates transferring data for one pixel from
  492        * DataBuffer <code>db1</code>, whose storage layout is described by
  493        * SampleModel <code>sm1</code>, to DataBuffer <code>db2</code>, whose
  494        * storage layout is described by SampleModel <code>sm2</code>.
  495        * The transfer will generally be more efficient than using
  496        * getPixel/setPixel.
  497        * <pre>
  498        *       SampleModel sm1, sm2;
  499        *       DataBuffer db1, db2;
  500        *       sm2.setDataElements(x, y, sm1.getDataElements(x, y, null, db1),
  501        *                           db2);
  502        * </pre>
  503        * Using getDataElements/setDataElements to transfer between two
  504        * DataBuffer/SampleModel pairs is legitimate if the SampleModels have
  505        * the same number of bands, corresponding bands have the same number of
  506        * bits per sample, and the TransferTypes are the same.
  507        * <p>
  508        * obj must be a primitive array of type TransferType.  Otherwise,
  509        * a ClassCastException is thrown.  An
  510        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  511        * not in bounds, or if obj is not large enough to hold the pixel data.
  512        * @param x         The X coordinate of the pixel location.
  513        * @param y         The Y coordinate of the pixel location.
  514        * @param obj       A primitive array containing pixel data.
  515        * @param data      The DataBuffer containing the image data.
  516        * @see #getNumDataElements
  517        * @see #getTransferType
  518        * @see #getDataElements(int, int, Object, DataBuffer)
  519        * @see java.awt.image.DataBuffer
  520        *
  521        * @throws NullPointerException if data is null.
  522        * @throws ArrayIndexOutOfBoundsException if the coordinates are
  523        * not in bounds, or if obj is too small to hold the input.
  524        */
  525       public abstract void setDataElements(int x, int y,
  526                                            Object obj, DataBuffer data);
  527   
  528       /**
  529        * Sets the data for a rectangle of pixels in the specified DataBuffer
  530        * from a primitive array of type TransferType.  For image data supported
  531        * by the Java 2D API, this will be one of DataBuffer.TYPE_BYTE,
  532        * DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,
  533        * DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE.  Data in the array
  534        * may be in a packed format, thus increasing efficiency for data
  535        * transfers.
  536        * <p>
  537        * The following code illustrates transferring data for a rectangular
  538        * region of pixels from
  539        * DataBuffer <code>db1</code>, whose storage layout is described by
  540        * SampleModel <code>sm1</code>, to DataBuffer <code>db2</code>, whose
  541        * storage layout is described by SampleModel <code>sm2</code>.
  542        * The transfer will generally be more efficient than using
  543        * getPixels/setPixels.
  544        * <pre>
  545        *       SampleModel sm1, sm2;
  546        *       DataBuffer db1, db2;
  547        *       sm2.setDataElements(x, y, w, h, sm1.getDataElements(x, y, w, h,
  548        *                           null, db1), db2);
  549        * </pre>
  550        * Using getDataElements/setDataElements to transfer between two
  551        * DataBuffer/SampleModel pairs is legitimate if the SampleModels have
  552        * the same number of bands, corresponding bands have the same number of
  553        * bits per sample, and the TransferTypes are the same.
  554        * <p>
  555        * obj must be a primitive array of type TransferType.  Otherwise,
  556        * a ClassCastException is thrown.  An
  557        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  558        * not in bounds, or if obj is not large enough to hold the pixel data.
  559        * @param x         The minimum X coordinate of the pixel rectangle.
  560        * @param y         The minimum Y coordinate of the pixel rectangle.
  561        * @param w         The width of the pixel rectangle.
  562        * @param h         The height of the pixel rectangle.
  563        * @param obj       A primitive array containing pixel data.
  564        * @param data      The DataBuffer containing the image data.
  565        * @see #getNumDataElements
  566        * @see #getTransferType
  567        * @see #getDataElements(int, int, int, int, Object, DataBuffer)
  568        * @see java.awt.image.DataBuffer
  569        *
  570        * @throws NullPointerException if data is null.
  571        * @throws ArrayIndexOutOfBoundsException if the coordinates are
  572        * not in bounds, or if obj is too small to hold the input.
  573        */
  574       public void setDataElements(int x, int y, int w, int h,
  575                                   Object obj, DataBuffer data) {
  576   
  577           int cnt = 0;
  578           Object o = null;
  579           int type = getTransferType();
  580           int numDataElems = getNumDataElements();
  581   
  582           switch(type) {
  583   
  584           case DataBuffer.TYPE_BYTE:
  585   
  586               byte[] barray = (byte[])obj;
  587               byte[] btemp = new byte[numDataElems];
  588   
  589               for (int i=y; i<y+h; i++) {
  590                   for (int j=x; j<x+w; j++) {
  591                       for (int k=0; k<numDataElems; k++) {
  592                           btemp[k] = barray[cnt++];
  593                       }
  594   
  595                       setDataElements(j, i, btemp, data);
  596                   }
  597               }
  598               break;
  599   
  600           case DataBuffer.TYPE_USHORT:
  601           case DataBuffer.TYPE_SHORT:
  602   
  603               short[] sarray = (short[])obj;
  604               short[] stemp = new short[numDataElems];
  605   
  606               for (int i=y; i<y+h; i++) {
  607                   for (int j=x; j<x+w; j++) {
  608                       for (int k=0; k<numDataElems; k++) {
  609                           stemp[k] = sarray[cnt++];
  610                       }
  611   
  612                       setDataElements(j, i, stemp, data);
  613                   }
  614               }
  615               break;
  616   
  617           case DataBuffer.TYPE_INT:
  618   
  619               int[] iArray = (int[])obj;
  620               int[] itemp = new int[numDataElems];
  621   
  622               for (int i=y; i<y+h; i++) {
  623                   for (int j=x; j<x+w; j++) {
  624                       for (int k=0; k<numDataElems; k++) {
  625                           itemp[k] = iArray[cnt++];
  626                       }
  627   
  628                       setDataElements(j, i, itemp, data);
  629                   }
  630               }
  631               break;
  632   
  633           case DataBuffer.TYPE_FLOAT:
  634   
  635               float[] fArray = (float[])obj;
  636               float[] ftemp = new float[numDataElems];
  637   
  638               for (int i=y; i<y+h; i++) {
  639                   for (int j=x; j<x+w; j++) {
  640                       for (int k=0; k<numDataElems; k++) {
  641                           ftemp[k] = fArray[cnt++];
  642                       }
  643   
  644                       setDataElements(j, i, ftemp, data);
  645                   }
  646               }
  647               break;
  648   
  649           case DataBuffer.TYPE_DOUBLE:
  650   
  651               double[] dArray = (double[])obj;
  652               double[] dtemp = new double[numDataElems];
  653   
  654               for (int i=y; i<y+h; i++) {
  655                   for (int j=x; j<x+w; j++) {
  656                       for (int k=0; k<numDataElems; k++) {
  657                           dtemp[k] = dArray[cnt++];
  658                       }
  659   
  660                       setDataElements(j, i, dtemp, data);
  661                   }
  662               }
  663               break;
  664           }
  665   
  666       }
  667   
  668       /**
  669        * Returns the samples for the specified pixel in an array of float.
  670        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  671        * not in bounds.
  672        * @param x         The X coordinate of the pixel location.
  673        * @param y         The Y coordinate of the pixel location.
  674        * @param fArray    If non-null, returns the samples in this array.
  675        * @param data      The DataBuffer containing the image data.
  676        * @return the samples for the specified pixel.
  677        * @see #setPixel(int, int, float[], DataBuffer)
  678        *
  679        * @throws NullPointerException if data is null.
  680        * @throws ArrayIndexOutOfBoundsException if the coordinates are
  681        * not in bounds, or if fArray is too small to hold the output.
  682        */
  683       public float[] getPixel(int x, int y, float fArray[],
  684                               DataBuffer data) {
  685   
  686           float pixels[];
  687   
  688           if (fArray != null)
  689               pixels = fArray;
  690           else
  691               pixels = new float[numBands];
  692   
  693           for (int i=0; i<numBands; i++)
  694               pixels[i] = getSampleFloat(x, y, i, data);
  695   
  696           return pixels;
  697       }
  698   
  699       /**
  700        * Returns the samples for the specified pixel in an array of double.
  701        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  702        * not in bounds.
  703        * @param x         The X coordinate of the pixel location.
  704        * @param y         The Y coordinate of the pixel location.
  705        * @param dArray    If non-null, returns the samples in this array.
  706        * @param data      The DataBuffer containing the image data.
  707        * @return the samples for the specified pixel.
  708        * @see #setPixel(int, int, double[], DataBuffer)
  709        *
  710        * @throws NullPointerException if data is null.
  711        * @throws ArrayIndexOutOfBoundsException if the coordinates are
  712        * not in bounds, or if dArray is too small to hold the output.
  713        */
  714       public double[] getPixel(int x, int y, double dArray[],
  715                                DataBuffer data) {
  716   
  717           double pixels[];
  718   
  719           if(dArray != null)
  720               pixels = dArray;
  721           else
  722               pixels = new double[numBands];
  723   
  724           for (int i=0; i<numBands; i++)
  725               pixels[i] = getSampleDouble(x, y, i, data);
  726   
  727           return pixels;
  728       }
  729   
  730       /**
  731        * Returns all samples for a rectangle of pixels in an
  732        * int array, one sample per array element.
  733        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  734        * not in bounds.
  735        * @param x         The X coordinate of the upper left pixel location.
  736        * @param y         The Y coordinate of the upper left pixel location.
  737        * @param w         The width of the pixel rectangle.
  738        * @param h         The height of the pixel rectangle.
  739        * @param iArray    If non-null, returns the samples in this array.
  740        * @param data      The DataBuffer containing the image data.
  741        * @return the samples for the specified region of pixels.
  742        * @see #setPixels(int, int, int, int, int[], DataBuffer)
  743        *
  744        * @throws NullPointerException if data is null.
  745        * @throws ArrayIndexOutOfBoundsException if the coordinates are
  746        * not in bounds, or if iArray is too small to hold the output.
  747        */
  748       public int[] getPixels(int x, int y, int w, int h,
  749                              int iArray[], DataBuffer data) {
  750   
  751           int pixels[];
  752           int Offset=0;
  753   
  754           if (iArray != null)
  755               pixels = iArray;
  756           else
  757               pixels = new int[numBands * w * h];
  758   
  759           for (int i=y; i<(h+y); i++) {
  760               for (int j=x; j<(w+x); j++) {
  761                   for(int k=0; k<numBands; k++) {
  762                       pixels[Offset++] = getSample(j, i, k, data);
  763                   }
  764               }
  765           }
  766   
  767           return pixels;
  768       }
  769   
  770       /**
  771        * Returns all samples for a rectangle of pixels in a float
  772        * array, one sample per array element.
  773        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  774        * not in bounds.
  775        * @param x         The X coordinate of the upper left pixel location.
  776        * @param y         The Y coordinate of the upper left pixel location.
  777        * @param w         The width of the pixel rectangle.
  778        * @param h         The height of the pixel rectangle.
  779        * @param fArray    If non-null, returns the samples in this array.
  780        * @param data      The DataBuffer containing the image data.
  781        * @return the samples for the specified region of pixels.
  782        * @see #setPixels(int, int, int, int, float[], DataBuffer)
  783        *
  784        * @throws NullPointerException if data is null.
  785        * @throws ArrayIndexOutOfBoundsException if the coordinates are
  786        * not in bounds, or if fArray is too small to hold the output.
  787        */
  788       public float[] getPixels(int x, int y, int w, int h,
  789                                float fArray[], DataBuffer data) {
  790   
  791           float pixels[];
  792           int Offset = 0;
  793   
  794           if (fArray != null)
  795               pixels = fArray;
  796           else
  797               pixels = new float[numBands * w * h];
  798   
  799           for (int i=y; i<(h+y); i++) {
  800               for(int j=x; j<(w+x); j++) {
  801                   for(int k=0; k<numBands; k++) {
  802                       pixels[Offset++] = getSampleFloat(j, i, k, data);
  803                   }
  804               }
  805           }
  806   
  807           return pixels;
  808       }
  809   
  810       /**
  811        * Returns all samples for a rectangle of pixels in a double
  812        * array, one sample per array element.
  813        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  814        * not in bounds.
  815        * @param x         The X coordinate of the upper left pixel location.
  816        * @param y         The Y coordinate of the upper left pixel location.
  817        * @param w         The width of the pixel rectangle.
  818        * @param h         The height of the pixel rectangle.
  819        * @param dArray    If non-null, returns the samples in this array.
  820        * @param data      The DataBuffer containing the image data.
  821        * @return the samples for the specified region of pixels.
  822        * @see #setPixels(int, int, int, int, double[], DataBuffer)
  823        *
  824        * @throws NullPointerException if data is null.
  825        * @throws ArrayIndexOutOfBoundsException if the coordinates are
  826        * not in bounds, or if dArray is too small to hold the output.
  827        */
  828       public double[] getPixels(int x, int y, int w, int h,
  829                                 double dArray[], DataBuffer data) {
  830           double pixels[];
  831           int    Offset = 0;
  832   
  833           if (dArray != null)
  834               pixels = dArray;
  835           else
  836               pixels = new double[numBands * w * h];
  837   
  838           // Fix 4217412
  839           for (int i=y; i<(h+y); i++) {
  840               for (int j=x; j<(w+x); j++) {
  841                   for (int k=0; k<numBands; k++) {
  842                       pixels[Offset++] = getSampleDouble(j, i, k, data);
  843                   }
  844               }
  845           }
  846   
  847           return pixels;
  848       }
  849   
  850   
  851       /**
  852        * Returns the sample in a specified band for the pixel located
  853        * at (x,y) as an int.
  854        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  855        * not in bounds.
  856        * @param x         The X coordinate of the pixel location.
  857        * @param y         The Y coordinate of the pixel location.
  858        * @param b         The band to return.
  859        * @param data      The DataBuffer containing the image data.
  860        * @return the sample in a specified band for the specified pixel.
  861        * @see #setSample(int, int, int, int, DataBuffer)
  862        *
  863        * @throws NullPointerException if data is null.
  864        * @throws ArrayIndexOutOfBoundsException if the coordinates or
  865        * the band index are not in bounds.
  866        */
  867       public abstract int getSample(int x, int y, int b, DataBuffer data);
  868   
  869   
  870       /**
  871        * Returns the sample in a specified band
  872        * for the pixel located at (x,y) as a float.
  873        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  874        * not in bounds.
  875        * @param x         The X coordinate of the pixel location.
  876        * @param y         The Y coordinate of the pixel location.
  877        * @param b         The band to return.
  878        * @param data      The DataBuffer containing the image data.
  879        * @return the sample in a specified band for the specified pixel.
  880        *
  881        * @throws NullPointerException if data is null.
  882        * @throws ArrayIndexOutOfBoundsException if the coordinates or
  883        * the band index are not in bounds.
  884        */
  885       public float getSampleFloat(int x, int y, int b, DataBuffer data) {
  886   
  887           float sample;
  888           sample = (float) getSample(x, y, b, data);
  889           return sample;
  890       }
  891   
  892       /**
  893        * Returns the sample in a specified band
  894        * for a pixel located at (x,y) as a double.
  895        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  896        * not in bounds.
  897        * @param x         The X coordinate of the pixel location.
  898        * @param y         The Y coordinate of the pixel location.
  899        * @param b         The band to return.
  900        * @param data      The DataBuffer containing the image data.
  901        * @return the sample in a specified band for the specified pixel.
  902        *
  903        * @throws NullPointerException if data is null.
  904        * @throws ArrayIndexOutOfBoundsException if the coordinates or
  905        * the band index are not in bounds.
  906        */
  907       public double getSampleDouble(int x, int y, int b, DataBuffer data) {
  908   
  909           double sample;
  910   
  911           sample = (double) getSample(x, y, b, data);
  912           return sample;
  913       }
  914   
  915       /**
  916        * Returns the samples for a specified band for the specified rectangle
  917        * of pixels in an int array, one sample per array element.
  918        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  919        * not in bounds.
  920        * @param x         The X coordinate of the upper left pixel location.
  921        * @param y         The Y coordinate of the upper left pixel location.
  922        * @param w         The width of the pixel rectangle.
  923        * @param h         The height of the pixel rectangle.
  924        * @param b         The band to return.
  925        * @param iArray    If non-null, returns the samples in this array.
  926        * @param data      The DataBuffer containing the image data.
  927        * @return the samples for the specified band for the specified region
  928        *         of pixels.
  929        * @see #setSamples(int, int, int, int, int, int[], DataBuffer)
  930        *
  931        * @throws NullPointerException if data is null.
  932        * @throws ArrayIndexOutOfBoundsException if the coordinates or
  933        * the band index are not in bounds, or if iArray is too small to
  934        * hold the output.
  935        */
  936       public int[] getSamples(int x, int y, int w, int h, int b,
  937                               int iArray[], DataBuffer data) {
  938           int pixels[];
  939           int Offset=0;
  940   
  941           if (iArray != null)
  942               pixels = iArray;
  943           else
  944               pixels = new int[w * h];
  945   
  946           for(int i=y; i<(h+y); i++) {
  947               for (int j=x; j<(w+x); j++) {
  948                   pixels[Offset++] = getSample(j, i, b, data);
  949               }
  950           }
  951   
  952           return pixels;
  953       }
  954   
  955       /**
  956        * Returns the samples for a specified band for the specified rectangle
  957        * of pixels in a float array, one sample per array element.
  958        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  959        * not in bounds.
  960        * @param x         The X coordinate of the upper left pixel location.
  961        * @param y         The Y coordinate of the upper left pixel location.
  962        * @param w         The width of the pixel rectangle.
  963        * @param h         The height of the pixel rectangle.
  964        * @param b         The band to return.
  965        * @param fArray    If non-null, returns the samples in this array.
  966        * @param data      The DataBuffer containing the image data.
  967        * @return the samples for the specified band for the specified region
  968        *         of pixels.
  969        * @see #setSamples(int, int, int, int, int, float[], DataBuffer)
  970        *
  971        * @throws NullPointerException if data is null.
  972        * @throws ArrayIndexOutOfBoundsException if the coordinates or
  973        * the band index are not in bounds, or if fArray is too small to
  974        * hold the output.
  975        */
  976       public float[] getSamples(int x, int y, int w, int h,
  977                                 int b, float fArray[],
  978                                 DataBuffer data) {
  979           float pixels[];
  980           int   Offset=0;
  981   
  982           if (fArray != null)
  983               pixels = fArray;
  984           else
  985               pixels = new float[w * h];
  986   
  987           for (int i=y; i<(h+y); i++) {
  988               for (int j=x; j<(w+x); j++) {
  989                   pixels[Offset++] = getSampleFloat(j, i, b, data);
  990               }
  991           }
  992   
  993           return pixels;
  994       }
  995   
  996       /**
  997        * Returns the samples for a specified band for a specified rectangle
  998        * of pixels in a double array, one sample per array element.
  999        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
 1000        * not in bounds.
 1001        * @param x         The X coordinate of the upper left pixel location.
 1002        * @param y         The Y coordinate of the upper left pixel location.
 1003        * @param w         The width of the pixel rectangle.
 1004        * @param h         The height of the pixel rectangle.
 1005        * @param b         The band to return.
 1006        * @param dArray    If non-null, returns the samples in this array.
 1007        * @param data      The DataBuffer containing the image data.
 1008        * @return the samples for the specified band for the specified region
 1009        *         of pixels.
 1010        * @see #setSamples(int, int, int, int, int, double[], DataBuffer)
 1011        *
 1012        * @throws NullPointerException if data is null.
 1013        * @throws ArrayIndexOutOfBoundsException if the coordinates or
 1014        * the band index are not in bounds, or if dArray is too small to
 1015        * hold the output.
 1016        */
 1017       public double[] getSamples(int x, int y, int w, int h,
 1018                                  int b, double dArray[],
 1019                                  DataBuffer data) {
 1020           double pixels[];
 1021           int    Offset=0;
 1022   
 1023           if (dArray != null)
 1024               pixels = dArray;
 1025           else
 1026               pixels = new double[w * h];
 1027   
 1028           for (int i=y; i<(y+h); i++) {
 1029               for (int j=x; j<(x+w); j++) {
 1030                   pixels[Offset++] = getSampleDouble(j, i, b, data);
 1031               }
 1032           }
 1033   
 1034           return pixels;
 1035       }
 1036   
 1037       /**
 1038        * Sets a pixel in  the DataBuffer using an int array of samples for input.
 1039        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
 1040        * not in bounds.
 1041        * @param x         The X coordinate of the pixel location.
 1042        * @param y         The Y coordinate of the pixel location.
 1043        * @param iArray    The input samples in an int array.
 1044        * @param data      The DataBuffer containing the image data.
 1045        * @see #getPixel(int, int, int[], DataBuffer)
 1046        *
 1047        * @throws NullPointerException if iArray or data is null.
 1048        * @throws ArrayIndexOutOfBoundsException if the coordinates are
 1049        * not in bounds, or if iArray is too small to hold the input.
 1050        */
 1051       public void setPixel(int x, int y, int iArray[], DataBuffer data) {
 1052   
 1053           for (int i=0; i<numBands; i++)
 1054               setSample(x, y, i, iArray[i], data);
 1055       }
 1056   
 1057       /**
 1058        * Sets a pixel in the DataBuffer using a float array of samples for input.
 1059        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
 1060        * not in bounds.
 1061        * @param x         The X coordinate of the pixel location.
 1062        * @param y         The Y coordinate of the pixel location.
 1063        * @param fArray    The input samples in a float array.
 1064        * @param data      The DataBuffer containing the image data.
 1065        * @see #getPixel(int, int, float[], DataBuffer)
 1066        *
 1067        * @throws NullPointerException if fArray or data is null.
 1068        * @throws ArrayIndexOutOfBoundsException if the coordinates are
 1069        * not in bounds, or if fArray is too small to hold the input.
 1070        */
 1071       public void setPixel(int x, int y, float fArray[], DataBuffer data) {
 1072   
 1073           for (int i=0; i<numBands; i++)
 1074               setSample(x, y, i, fArray[i], data);
 1075       }
 1076   
 1077       /**
 1078        * Sets a pixel in the DataBuffer using a double array of samples
 1079        * for input.
 1080        * @param x         The X coordinate of the pixel location.
 1081        * @param y         The Y coordinate of the pixel location.
 1082        * @param dArray    The input samples in a double array.
 1083        * @param data      The DataBuffer containing the image data.
 1084        * @see #getPixel(int, int, double[], DataBuffer)
 1085        *
 1086        * @throws NullPointerException if dArray or data is null.
 1087        * @throws ArrayIndexOutOfBoundsException if the coordinates are
 1088        * not in bounds, or if fArray is too small to hold the input.
 1089        */
 1090       public void setPixel(int x, int y, double dArray[], DataBuffer data) {
 1091   
 1092           for (int i=0; i<numBands; i++)
 1093               setSample(x, y, i, dArray[i], data);
 1094       }
 1095   
 1096       /**
 1097        * Sets all samples for a rectangle of pixels from an int array containing
 1098        * one sample per array element.
 1099        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
 1100        * not in bounds.
 1101        * @param x         The X coordinate of the upper left pixel location.
 1102        * @param y         The Y coordinate of the upper left pixel location.
 1103        * @param w         The width of the pixel rectangle.
 1104        * @param h         The height of the pixel rectangle.
 1105        * @param iArray    The input samples in an int array.
 1106        * @param data      The DataBuffer containing the image data.
 1107        * @see #getPixels(int, int, int, int, int[], DataBuffer)
 1108        *
 1109        * @throws NullPointerException if iArray or data is null.
 1110        * @throws ArrayIndexOutOfBoundsException if the coordinates are
 1111        * not in bounds, or if iArray is too small to hold the input.
 1112        */
 1113       public void setPixels(int x, int y, int w, int h,
 1114                             int iArray[], DataBuffer data) {
 1115           int Offset=0;
 1116   
 1117           for (int i=y; i<(y+h); i++) {
 1118               for (int j=x; j<(x+w); j++) {
 1119                   for (int k=0; k<numBands; k++) {
 1120                       setSample(j, i, k, iArray[Offset++], data);
 1121                   }
 1122               }
 1123           }
 1124       }
 1125   
 1126       /**
 1127        * Sets all samples for a rectangle of pixels from a float array containing
 1128        * one sample per array element.
 1129        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
 1130        * not in bounds.
 1131        * @param x         The X coordinate of the upper left pixel location.
 1132        * @param y         The Y coordinate of the upper left pixel location.
 1133        * @param w         The width of the pixel rectangle.
 1134        * @param h         The height of the pixel rectangle.
 1135        * @param fArray    The input samples in a float array.
 1136        * @param data      The DataBuffer containing the image data.
 1137        * @see #getPixels(int, int, int, int, float[], DataBuffer)
 1138        *
 1139        * @throws NullPointerException if fArray or data is null.
 1140        * @throws ArrayIndexOutOfBoundsException if the coordinates are
 1141        * not in bounds, or if fArray is too small to hold the input.
 1142        */
 1143       public void setPixels(int x, int y, int w, int h,
 1144                             float fArray[], DataBuffer data) {
 1145           int Offset=0;
 1146   
 1147           for (int i=y; i<(y+h); i++) {
 1148               for (int j=x; j<(x+w); j++) {
 1149                   for(int k=0; k<numBands; k++) {
 1150                       setSample(j, i, k, fArray[Offset++], data);
 1151                   }
 1152               }
 1153           }
 1154       }
 1155   
 1156       /**
 1157        * Sets all samples for a rectangle of pixels from a double array
 1158        * containing one sample per array element.
 1159        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
 1160        * not in bounds.
 1161        * @param x         The X coordinate of the upper left pixel location.
 1162        * @param y         The Y coordinate of the upper left pixel location.
 1163        * @param w         The width of the pixel rectangle.
 1164        * @param h         The height of the pixel rectangle.
 1165        * @param dArray    The input samples in a double array.
 1166        * @param data      The DataBuffer containing the image data.
 1167        * @see #getPixels(int, int, int, int, double[], DataBuffer)
 1168        *
 1169        * @throws NullPointerException if dArray or data is null.
 1170        * @throws ArrayIndexOutOfBoundsException if the coordinates are
 1171        * not in bounds, or if dArray is too small to hold the input.
 1172        */
 1173       public void setPixels(int x, int y, int w, int h,
 1174                             double dArray[], DataBuffer data) {
 1175           int Offset=0;
 1176   
 1177           for (int i=y; i<(y+h); i++) {
 1178               for (int j=x; j<(x+w); j++) {
 1179                   for (int k=0; k<numBands; k++) {
 1180                       setSample(j, i, k, dArray[Offset++], data);
 1181                   }
 1182               }
 1183           }
 1184       }
 1185   
 1186       /**
 1187        * Sets a sample in the specified band for the pixel located at (x,y)
 1188        * in the DataBuffer using an int for input.
 1189        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
 1190        * not in bounds.
 1191        * @param x         The X coordinate of the pixel location.
 1192        * @param y         The Y coordinate of the pixel location.
 1193        * @param b         The band to set.
 1194        * @param s         The input sample as an int.
 1195        * @param data      The DataBuffer containing the image data.
 1196        * @see #getSample(int, int, int,  DataBuffer)
 1197        *
 1198        * @throws NullPointerException if data is null.
 1199        * @throws ArrayIndexOutOfBoundsException if the coordinates or
 1200        * the band index are not in bounds.
 1201        */
 1202       public abstract void setSample(int x, int y, int b,
 1203                                      int s,
 1204                                      DataBuffer data);
 1205   
 1206       /**
 1207        * Sets a sample in the specified band for the pixel located at (x,y)
 1208        * in the DataBuffer using a float for input.
 1209        * The default implementation of this method casts the input
 1210        * float sample to an int and then calls the
 1211        * <code>setSample(int, int, int, DataBuffer)</code> method using
 1212        * that int value.
 1213        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
 1214        * not in bounds.
 1215        * @param x         The X coordinate of the pixel location.
 1216        * @param y         The Y coordinate of the pixel location.
 1217        * @param b         The band to set.
 1218        * @param s         The input sample as a float.
 1219        * @param data      The DataBuffer containing the image data.
 1220        * @see #getSample(int, int, int, DataBuffer)
 1221        *
 1222        * @throws NullPointerException if data is null.
 1223        * @throws ArrayIndexOutOfBoundsException if the coordinates or
 1224        * the band index are not in bounds.
 1225        */
 1226       public void setSample(int x, int y, int b,
 1227                             float s ,
 1228                             DataBuffer data) {
 1229           int sample = (int)s;
 1230   
 1231           setSample(x, y, b, sample, data);
 1232       }
 1233   
 1234       /**
 1235        * Sets a sample in the specified band for the pixel located at (x,y)
 1236        * in the DataBuffer using a double for input.
 1237        * The default implementation of this method casts the input
 1238        * double sample to an int and then calls the
 1239        * <code>setSample(int, int, int, DataBuffer)</code> method using
 1240        * that int value.
 1241        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
 1242        * not in bounds.
 1243        * @param x         The X coordinate of the pixel location.
 1244        * @param y         The Y coordinate of the pixel location.
 1245        * @param b         The band to set.
 1246        * @param s         The input sample as a double.
 1247        * @param data      The DataBuffer containing the image data.
 1248        * @see #getSample(int, int, int, DataBuffer)
 1249        *
 1250        * @throws NullPointerException if data is null.
 1251        * @throws ArrayIndexOutOfBoundsException if the coordinates or
 1252        * the band index are not in bounds.
 1253        */
 1254       public void setSample(int x, int y, int b,
 1255                             double s,
 1256                             DataBuffer data) {
 1257           int sample = (int)s;
 1258   
 1259           setSample(x, y, b, sample, data);
 1260       }
 1261   
 1262       /**
 1263        * Sets the samples in the specified band for the specified rectangle
 1264        * of pixels from an int array containing one sample per array element.
 1265        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
 1266        * not in bounds.
 1267        * @param x         The X coordinate of the upper left pixel location.
 1268        * @param y         The Y coordinate of the upper left pixel location.
 1269        * @param w         The width of the pixel rectangle.
 1270        * @param h         The height of the pixel rectangle.
 1271        * @param b         The band to set.
 1272        * @param iArray    The input samples in an int array.
 1273        * @param data      The DataBuffer containing the image data.
 1274        * @see #getSamples(int, int, int, int, int, int[], DataBuffer)
 1275        *
 1276        * @throws NullPointerException if iArray or data is null.
 1277        * @throws ArrayIndexOutOfBoundsException if the coordinates or
 1278        * the band index are not in bounds, or if iArray is too small to
 1279        * hold the input.
 1280        */
 1281       public void setSamples(int x, int y, int w, int h, int b,
 1282                              int iArray[], DataBuffer data) {
 1283   
 1284           int Offset=0;
 1285   
 1286           for (int i=y; i<(y+h); i++) {
 1287               for (int j=x; j<(x+w); j++) {
 1288                   setSample(j, i, b, iArray[Offset++], data);
 1289               }
 1290           }
 1291       }
 1292   
 1293       /**
 1294        * Sets the samples in the specified band for the specified rectangle
 1295        * of pixels from a float array containing one sample per array element.
 1296        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
 1297        * not in bounds.
 1298        * @param x         The X coordinate of the upper left pixel location.
 1299        * @param y         The Y coordinate of the upper left pixel location.
 1300        * @param w         The width of the pixel rectangle.
 1301        * @param h         The height of the pixel rectangle.
 1302        * @param b         The band to set.
 1303        * @param fArray    The input samples in a float array.
 1304        * @param data      The DataBuffer containing the image data.
 1305        * @see #getSamples(int, int, int, int, int, float[], DataBuffer)
 1306        *
 1307        * @throws NullPointerException if fArray or data is null.
 1308        * @throws ArrayIndexOutOfBoundsException if the coordinates or
 1309        * the band index are not in bounds, or if fArray is too small to
 1310        * hold the input.
 1311        */
 1312       public void setSamples(int x, int y, int w, int h, int b,
 1313                              float fArray[], DataBuffer data) {
 1314           int Offset=0;
 1315   
 1316           for (int i=y; i<(y+h); i++) {
 1317               for (int j=x; j<(x+w); j++) {
 1318                   setSample(j, i, b, fArray[Offset++], data);
 1319               }
 1320           }
 1321       }
 1322   
 1323       /**
 1324        * Sets the samples in the specified band for the specified rectangle
 1325        * of pixels from a double array containing one sample per array element.
 1326        * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
 1327        * not in bounds.
 1328        * @param x         The X coordinate of the upper left pixel location.
 1329        * @param y         The Y coordinate of the upper left pixel location.
 1330        * @param w         The width of the pixel rectangle.
 1331        * @param h         The height of the pixel rectangle.
 1332        * @param b         The band to set.
 1333        * @param dArray    The input samples in a double array.
 1334        * @param data      The DataBuffer containing the image data.
 1335        * @see #getSamples(int, int, int, int, int, double[], DataBuffer)
 1336        *
 1337        * @throws NullPointerException if dArray or data is null.
 1338        * @throws ArrayIndexOutOfBoundsException if the coordinates or
 1339        * the band index are not in bounds, or if dArray is too small to
 1340        * hold the input.
 1341        */
 1342       public void setSamples(int x, int y, int w, int h, int b,
 1343                              double dArray[], DataBuffer data) {
 1344           int Offset=0;
 1345   
 1346           for (int i=y; i<(y+h); i++) {
 1347               for (int j=x; j<(x+w); j++) {
 1348                   setSample(j, i, b, dArray[Offset++], data);
 1349               }
 1350           }
 1351       }
 1352   
 1353       /**
 1354        *  Creates a SampleModel which describes data in this SampleModel's
 1355        *  format, but with a different width and height.
 1356        *  @param w the width of the image data
 1357        *  @param h the height of the image data
 1358        *  @return a <code>SampleModel</code> describing the same image
 1359        *          data as this <code>SampleModel</code>, but with a
 1360        *          different size.
 1361        */
 1362       public abstract SampleModel createCompatibleSampleModel(int w, int h);
 1363   
 1364       /**
 1365        * Creates a new SampleModel
 1366        * with a subset of the bands of this
 1367        * SampleModel.
 1368        * @param bands the subset of bands of this <code>SampleModel</code>
 1369        * @return a <code>SampleModel</code> with a subset of bands of this
 1370        *         <code>SampleModel</code>.
 1371        */
 1372       public abstract SampleModel createSubsetSampleModel(int bands[]);
 1373   
 1374       /**
 1375        * Creates a DataBuffer that corresponds to this SampleModel.
 1376        * The DataBuffer's width and height will match this SampleModel's.
 1377        * @return a <code>DataBuffer</code> corresponding to this
 1378        *         <code>SampleModel</code>.
 1379        */
 1380       public abstract DataBuffer createDataBuffer();
 1381   
 1382       /** Returns the size in bits of samples for all bands.
 1383        *  @return the size of samples for all bands.
 1384        */
 1385       public abstract int[] getSampleSize();
 1386   
 1387       /** Returns the size in bits of samples for the specified band.
 1388        *  @param band the specified band
 1389        *  @return the size of the samples of the specified band.
 1390        */
 1391       public abstract int getSampleSize(int band);
 1392   
 1393   }

Save This Page
Home » openjdk-7 » java » awt » image » [javadoc | source]