home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / image / SampleModel.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  28.5 KB  |  928 lines

  1. /*
  2.  * @(#)SampleModel.java    1.13 98/03/18
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. /* ****************************************************************
  16.  ******************************************************************
  17.  ******************************************************************
  18.  *** COPYRIGHT (c) Eastman Kodak Company, 1997
  19.  *** As  an unpublished  work pursuant to Title 17 of the United
  20.  *** States Code.  All rights reserved.
  21.  ******************************************************************
  22.  ******************************************************************
  23.  ******************************************************************/
  24.  
  25. package java.awt.image;
  26.  
  27. /**
  28.  *  This abstract class defines an interface for extracting samples of
  29.  *  an image without knowing how the underlying data is stored in a
  30.  *  DataBuffer.  All image data is expressed as a collection of pixels.
  31.  *  Each pixel consists of a number of samples. A sample is a collection
  32.  *  of data for one band of an image. 
  33.  *  
  34.  *  This class is generally a fall back method for dealing with
  35.  *  images.  More efficient code will cast the SampleModel to the
  36.  *  appropriate subclass and extract the information needed to directly
  37.  *  manipulate pixels in the DataBuffer.
  38.  *
  39.  *  @see DataBuffer
  40.  *  @see ComponentSampleModel
  41.  *  @see BandedSampleModel
  42.  *  @see MultiPixelPackedSampleModel
  43.  *  @see SinglePixelPackedSampleModel
  44.  */
  45.  
  46. public abstract class SampleModel
  47. {
  48.  
  49.     /** Width of the region of image data that this SampleModel describes. */
  50.     protected int width;
  51.  
  52.     /** Height of the region of image data that this SampleModel describes. */
  53.     protected int height;
  54.  
  55.     /** number of bands of the inage data that this SampleModel describes. */
  56.     protected int numBands;
  57.  
  58.     /** Data type of the underlying pixel data. */
  59.     protected int dataType; 
  60.  
  61.     /** minimum sample value for all bands. */
  62.     private float minMinSampleValue;
  63.  
  64.     /** maximum sample value for all bands. */
  65.     private float maxMaxSampleValue;
  66.  
  67.     /** minimum sample values for various bands. */
  68.     private float minSampleValue[];
  69.  
  70.     /** maximum sample values for various bands. */
  71.     private float maxSampleValue[];
  72.       
  73.     static private native void initIDs();
  74.     static {
  75.         ColorModel.loadLibraries();
  76.         initIDs();
  77.     }
  78.  
  79.     /**
  80.      * Constructs a SampleModel with the specified parameters.
  81.      * @param dataType the data type of the underlying pixel data.
  82.      * @param w     The width (in pixels) of the region of image data.
  83.      * @param h         The height (in pixels) of the region of image data.
  84.      * @param numBands  The number of bands of the image data.
  85.      */
  86.     public SampleModel(int dataType, int w, int h, int numBands) 
  87.     {
  88.         float size = (float)w*h;
  89.         if (w <= 0 || h <= 0) {
  90.             throw new IllegalArgumentException("Width ("+w+") and height ("+
  91.                                                height+") must be > 0");
  92.         }
  93.         if (size >= Integer.MAX_VALUE) {
  94.             throw new IllegalArgumentException("Dimensions (width="+w+
  95.                                                " height="+h+") are too large");
  96.         }
  97.     this.dataType = dataType;
  98.     this.width = w;
  99.     this.height = h;
  100.     this.numBands = numBands;
  101.     }
  102.  
  103.     /** Returns the width in pixels. */
  104.     final public int getWidth() {
  105.      return width;
  106.     }
  107.       
  108.     /** Returns the height in pixels. */
  109.     final public int getHeight() {
  110.      return height;
  111.     }
  112.       
  113.     /** Returns the total number of bands of image data. */
  114.     final public int getNumBands() {
  115.      return numBands;
  116.     }
  117.  
  118.     /** Returns the number of data elements needed to store a pixel. */
  119.     public abstract int getNumDataElements();
  120.     
  121.     /** Returns the data type. */
  122.     final public int getDataType() {
  123.     return dataType;
  124.     }
  125.  
  126.     /** Returns the transfer type of the data. */
  127.     public abstract int getTransferType();
  128.  
  129.     /** 
  130.      * Returns the samples for a specified pixel in an array of int.
  131.      * @param x     The X coordinate of the pixel location.
  132.      * @param y     The Y coordinate of the pixel location.
  133.      * @param iArray    If non-null, returns the samples in this array.
  134.      * @param data      The DataBuffer containing the image data.
  135.      */
  136.     public int[] getPixel(int x, int y, int iArray[], DataBuffer data) {
  137.  
  138.     int pixels[];
  139.     
  140.     if (iArray != null)
  141.         pixels = iArray;
  142.     else
  143.         pixels = new int[numBands];
  144.  
  145.     for (int i=0; i<numBands; i++) {
  146.         pixels[i] = getSample(x, y, i, data); 
  147.     }
  148.  
  149.     return pixels;
  150.     }
  151.  
  152.     /** 
  153.      * Returns the pixel data in an array of primitives that can be byte,
  154.      * short or int. Which primitive type is returned depends on
  155.      * the transfer type. Data is returned in the packed format,
  156.      * thus increasing efficiency for data transfers. Generally, obj
  157.      * should be passed in as null, so that the Object will be created
  158.      * automatically and will be of the right primitive data type.
  159.      * <pre>
  160.      *          SampleModel sm1, sm2;
  161.      *         DataBuffer db1, db2;
  162.      *          sm2.setPixelData(x, y, sm1.getPixelData(x, y, null, db1), db2);
  163.      * </pre>
  164.      * @param x     The X coordinate of the pixel location.
  165.      * @param y     The Y coordinate of the pixel location.
  166.      * @param obj       If non-null, returns the primitive array in this object.
  167.      * @param data      The DataBuffer containing the image data.
  168.      */
  169.     public abstract Object getPixelData(int x, int y,
  170.                     Object obj, DataBuffer data);
  171.  
  172.     /** 
  173.      * Returns the pixel data for the specified rectangle in an
  174.      * array of primitives that can be byte,
  175.      * short or int. Which primitive type is returned depends on
  176.      * the transfer type. Data is returned in the packed format,
  177.      * thus increasing efficiency for data transfers. Generally, obj
  178.      * should be passed in as null, so that the Object will be created
  179.      * automatically and will be of the right primitive data type.
  180.      * <pre>
  181.      *          SampleModel sm1, sm2;
  182.      *         DataBuffer db1, db2;
  183.      *          sm2.setPixelData(x, y, w, h, sm1.getPixelData(x, y, w,
  184.      * h, null, db1), db2);
  185.      * </pre>
  186.      * @param x     The X coordinate of the pixel location.
  187.      * @param y     The Y coordinate of the pixel location.
  188.      * @param w         The width of the pixel rectangle.
  189.      * @param h         The height of the pixel rectangle.
  190.      * @param obj       If non-null, returns the primitive array in this object.
  191.      * @param data      The DataBuffer containing the image data.
  192.      */
  193.     public Object getPixelData(int x, int y, int w, int h,
  194.               Object obj, DataBuffer data) {
  195.  
  196.     int type = getTransferType();
  197.     int numDataElems = getNumDataElements();
  198.     int cnt = 0;
  199.     Object o = null;
  200.         
  201.     switch(type) {
  202.         
  203.     case DataBuffer.BYTE_DATA:
  204.  
  205.         byte[] btemp;
  206.         byte[] bdata;
  207.  
  208.         if (obj == null)
  209.         bdata = new byte[numDataElems*w*h];
  210.         else
  211.         bdata = (byte[])obj;
  212.                 
  213.         for (int i=y; i<y+h; i++) {
  214.         for (int j=x; j<x+w; j++) {
  215.             o = getPixelData(j, i, o, data);
  216.             btemp = (byte[])o;
  217.             for (int k=0; k<numDataElems; k++) {
  218.             bdata[cnt++] = btemp[k];
  219.             }
  220.         }
  221.         }
  222.         obj = (Object)bdata;
  223.         break;
  224.         
  225.     case DataBuffer.SHORT_DATA:
  226.  
  227.         short[] sdata;
  228.         short[] stemp;
  229.  
  230.         if (obj == null)
  231.         sdata = new short[numDataElems*w*h];
  232.         else
  233.         sdata = (short[])obj;
  234.         
  235.         for (int i=y; i<y+h; i++) {
  236.         for (int j=x; j<x+w; j++) {
  237.             o = getPixelData(j, i, o, data);
  238.             stemp = (short[])o;
  239.             for (int k=0; k<numDataElems; k++) {
  240.             sdata[cnt++] = stemp[k];
  241.             }
  242.         }
  243.         }
  244.         
  245.         obj = (Object)sdata;
  246.         break;
  247.  
  248.     case DataBuffer.INT_DATA:
  249.  
  250.         int[] idata;
  251.         int[] itemp;
  252.  
  253.         if (obj == null)
  254.         idata = new int[numDataElems*w*h];
  255.         else
  256.         idata = (int[])obj;
  257.         
  258.         for (int i=y; i<y+h; i++) {
  259.         for (int j=x; j<x+w; j++) {
  260.             o = getPixelData(j, i, o, data);
  261.             itemp = (int[])o;
  262.             for (int k=0; k<numDataElems; k++) {
  263.             idata[cnt++] = itemp[k];
  264.             }
  265.         }
  266.         }
  267.  
  268.         obj = (Object)idata;
  269.         break;
  270.     }
  271.     
  272.     return obj;
  273.     }
  274.  
  275.     /** 
  276.      * Puts the pixel data from an Object that contains an
  277.      * array of primitives that can be byte,
  278.      * short or int. Which primitive type it contains depends on
  279.      * the transfer type. Data in the Object is in the packed format,
  280.      * thus increasing efficiency for data transfers.
  281.      * <pre>
  282.      *          SampleModel sm1, sm2;
  283.      *         DataBuffer db1, db2;
  284.      *          sm2.setPixelData(x, y, sm1.getPixelData(x, y, null, db1), db2);
  285.      * </pre>
  286.      * @param x     The X coordinate of the pixel location.
  287.      * @param y     The Y coordinate of the pixel location.
  288.      * @param obj       If non-null, returns the primitive array in this object.
  289.      * @param data      The DataBuffer containing the image data.
  290.      */
  291.     public abstract void setPixelData(int x, int y,
  292.                       Object obj, DataBuffer data);
  293.  
  294.     /** 
  295.      * Puts the rectangle of pixel data from an Object that contains an
  296.      * array of primitives that can be byte,
  297.      * short or int. Which primitive type it contains depends on
  298.      * the transfer type. Data in the Object is in the packed format,
  299.      * thus increasing efficiency for data transfers.
  300.      * <pre>
  301.      *          SampleModel sm1, sm2;
  302.      *         DataBuffer db1, db2;
  303.      *          sm2.setPixelData(x, y, w, h, sm1.getPixelData(x, y, w, h, null,
  304.      * db1), db2);
  305.      * </pre>
  306.      * @param x     The X coordinate of the pixel location.
  307.      * @param y     The Y coordinate of the pixel location.
  308.      * @param w         The width of the pixel rectangle.
  309.      * @param h         The height of the pixel rectangle.
  310.      * @param obj       If non-null, returns the primitive array in this object.
  311.      * @param data      The DataBuffer containing the image data.
  312.      */    
  313.     void setPixelData(int x, int y, int w, int h, Object obj, DataBuffer data) {
  314.  
  315.     int cnt = 0;
  316.     Object o = null;
  317.     int type = getTransferType();
  318.     int numDataElems = getNumDataElements();
  319.         
  320.     switch(type) {
  321.         
  322.     case DataBuffer.BYTE_DATA:
  323.  
  324.         byte[] barray = (byte[])obj;
  325.         byte[] btemp = new byte[numDataElems];
  326.         
  327.         for (int i=y; i<y+h; i++) {
  328.         for (int j=x; j<x+w; j++) {
  329.             for (int k=0; k<numDataElems; k++) {
  330.             btemp[k] = barray[cnt++];
  331.             }
  332.             
  333.             setPixelData(j, i, btemp, data);
  334.         }
  335.         }
  336.         break;
  337.     
  338.     case DataBuffer.SHORT_DATA:
  339.  
  340.         short[] sarray = (short[])obj;
  341.         short[] stemp = new short[numDataElems];
  342.         
  343.         for (int i=y; i<y+h; i++) {
  344.         for (int j=x; j<x+w; j++) {
  345.             for (int k=0; k<numDataElems; k++) {
  346.             stemp[k] = sarray[cnt++];
  347.             }
  348.  
  349.             setPixelData(j, i, stemp, data);
  350.         }
  351.         }
  352.         break;
  353.  
  354.     case DataBuffer.INT_DATA:
  355.            
  356.         int[] iarray = (int[])obj;
  357.         int[] itemp = new int[numDataElems];
  358.         
  359.         for (int i=y; i<y+h; i++) {
  360.         for (int j=x; j<x+w; j++) {
  361.             for (int k=0; k<numDataElems; k++) {
  362.             itemp[k] = iarray[cnt++];
  363.             }
  364.  
  365.             setPixelData(j, i, itemp, data);
  366.         }
  367.         }
  368.         break;
  369.     }
  370.     
  371.     }
  372.     
  373.     /**
  374.      * Returns the samples for the specified pixel in an array of float.
  375.      * @param x     The X coordinate of the pixel location.
  376.      * @param y     The Y coordinate of the pixel location.
  377.      * @param fArray    If non-null, returns the samples in this array.
  378.      * @param data      The DataBuffer containing the image data.
  379.      */
  380.     public float[] getPixel(int x, int y, float fArray[],
  381.                 DataBuffer data) {
  382.  
  383.     float pixels[];
  384.  
  385.     if (fArray != null)
  386.         pixels = fArray;
  387.     else
  388.         pixels = new float[numBands];
  389.  
  390.     for (int i=0; i<numBands; i++)
  391.         pixels[i] = getSampleFloat(x, y, i, data);
  392.     
  393.     return pixels;
  394.     }
  395.  
  396.     /**
  397.      * Returns the samples for the specified pixle in an array of double.
  398.      * @param x     The X coordinate of the pixel location.
  399.      * @param y     The Y coordinate of the pixel location.
  400.      * @param dArray     If non-null, returns the samples in this array.
  401.      * @param data     The DataBuffer containing the image data.
  402.      */
  403.     public double[] getPixel(int x, int y, double dArray[],
  404.                  DataBuffer data) {
  405.  
  406.     double pixels[];
  407.  
  408.     if(dArray != null)
  409.         pixels = dArray;
  410.     else
  411.         pixels = new double[numBands];
  412.  
  413.     for (int i=0; i<numBands; i++)
  414.         pixels[i] = getSampleDouble(x, y, i, data);
  415.  
  416.     return pixels;
  417.     }
  418.  
  419.     /**
  420.      * Returns all samples for a rectangle of pixels in an 
  421.      * int array, one sample per array element.
  422.      * @param x     The X coordinate of the upper left pixel location.
  423.      * @param y     The Y coordinate of the upper left pixel location.
  424.      * @param w     The width of the pixel rectangle.
  425.      * @param h     The height of the pixel rectangle.
  426.      * @param iArray     If non-null, returns the samples in this array.
  427.      * @param data     The DataBuffer containing the image data.
  428.      */
  429.     public int[] getPixel(int x, int y, int w, int h,
  430.               int iArray[], DataBuffer data) {
  431.     
  432.     int pixels[];
  433.     int Offset=0;
  434.  
  435.     if (iArray != null)
  436.         pixels = iArray;
  437.     else
  438.         pixels = new int[numBands * w * h];
  439.  
  440.     for (int i=y; i<(h+y); i++) {
  441.         for (int j=x; j<(w+x); j++) {
  442.         for(int k=0; k<numBands; k++) {
  443.             pixels[Offset++] = getSample(j, i, k, data);
  444.         }
  445.         }
  446.     }
  447.  
  448.     return pixels;
  449.     }
  450.  
  451.     /**
  452.      * Returns all samples for a rectangle of pixels in a float
  453.      * array, one sample per array element.
  454.      * @param x     The X coordinate of the upper left pixel location.
  455.      * @param y     The Y coordinate of the upper left pixel location.
  456.      * @param w     The width of the pixel rectangle.
  457.      * @param h     The height of the pixel rectangle.
  458.      * @param fArray     If non-null, returns the samples in this array.
  459.      * @param data     The DataBuffer containing the image data.
  460.      */
  461.     public float[] getPixel(int x, int y, int w, int h,
  462.                 float fArray[], DataBuffer data) {
  463.     
  464.     float pixels[];
  465.     int Offset = 0;
  466.  
  467.     if (fArray != null)
  468.         pixels = fArray;
  469.     else
  470.         pixels = new float[numBands * w * h];
  471.  
  472.     for (int i=y; i<(h+y); i++) {
  473.         for(int j=x; j<(w+x); j++) {
  474.         for(int k=0; k<numBands; k++) {
  475.             pixels[Offset++] = getSampleFloat(j, i, k, data);
  476.         }            
  477.         }
  478.     }
  479.  
  480.     return pixels;
  481.     }
  482.  
  483.     /**
  484.      * Returns all samples for a rectangle of pixels in a double
  485.      * array, one sample per array element.
  486.      * @param x     The X coordinate of the upper left pixel location.
  487.      * @param y     The Y coordinate of the upper left pixel location.
  488.      * @param w     The width of the pixel rectangle.
  489.      * @param h     The height of the pixel rectangle.
  490.      * @param dArray     If non-null, returns the samples in this array.
  491.      * @param data     The DataBuffer containing the image data.
  492.      */
  493.     public double[] getPixel(int x, int y, int w, int h,
  494.                  double dArray[], DataBuffer data) {
  495.     double pixels[];
  496.     int    Offset = 0;
  497.  
  498.     if (dArray != null)
  499.         pixels = dArray;
  500.     else
  501.         pixels = new double[numBands * w * h];
  502.  
  503.     for (int i=0; i<(h+y); i++) {
  504.         for (int j=0; j<(w+x); j++) {
  505.         for (int k=0; k<numBands; k++) {
  506.             pixels[Offset++] = getSampleDouble(j, i, k, data);
  507.         }
  508.         }
  509.     }
  510.  
  511.     return pixels;
  512.     }
  513.  
  514.  
  515.     /** 
  516.      * Returns the sample in a specified band for the pixel located
  517.      * at (x,y) as an int.
  518.      * @param x     The X coordinate of the pixel location.
  519.      * @param y     The Y coordinate of the pixel location.
  520.      * @param b     The band to return.
  521.      * @param data     The DataBuffer containing the image data.
  522.      */
  523.     public abstract int getSample(int x, int y, int b, DataBuffer data);
  524.  
  525.  
  526.     /** 
  527.      * Returns the sample in a specified band
  528.      * for the pixel located at (x,y) as a float.
  529.      * @param x     The X coordinate of the pixel location.
  530.      * @param y     The Y coordinate of the pixel location.
  531.      * @param b     The band to return.
  532.      * @param data     The DataBuffer containing the image data.
  533.      */
  534.     public float getSampleFloat(int x, int y, int b, DataBuffer data) {
  535.     
  536.     float sample;
  537.     sample = (float) getSample(x, y, b, data);
  538.     return sample;
  539.     }
  540.     
  541.     /** 
  542.      * Returns the sample in a specified band
  543.      * for a pixel located at (x,y) as a double.
  544.      * @param x     The X coordinate of the pixel location.
  545.      * @param y     The Y coordinate of the pixel location.
  546.      * @param b     The band to return.
  547.      * @param data     The DataBuffer containing the image data.
  548.      */
  549.     public double getSampleDouble(int x, int y, int b, DataBuffer data) {
  550.     
  551.     double sample;
  552.     
  553.     sample = (double) getSample(x, y, b, data);
  554.     return sample;
  555.     }
  556.  
  557.     /**
  558.      * Returns the samples for a specified band for the specified rectangle
  559.      * of pixels in an int array, one sample per array element.
  560.      * @param x     The X coordinate of the upper left pixel location.
  561.      * @param y     The Y coordinate of the upper left pixel location.
  562.      * @param w     The width of the pixel rectangle.
  563.      * @param h     The height of the pixel rectangle.
  564.      * @param b     The band to return.
  565.      * @param iArray     If non-null, returns the samples in this array.
  566.      * @param data     The DataBuffer containing the image data.
  567.      */
  568.     public int[] getSample(int x, int y, int w, int h, int b,
  569.                int iArray[], DataBuffer data) {
  570.     int pixels[];
  571.     int Offset=0;
  572.  
  573.     if (iArray != null)
  574.         pixels = iArray;
  575.     else
  576.         pixels = new int[w * h];
  577.  
  578.     for(int i=y; i<(h+y); i++) {
  579.         for (int j=x; j<(w+x); j++) {
  580.         pixels[Offset++] = getSample(j, i, b, data);
  581.         }
  582.     }
  583.  
  584.     return pixels;
  585.     }
  586.  
  587.     /**
  588.      * Returns the samples for a specified band for the specified rectangle
  589.      * of pixels in a float array, one sample per array element.
  590.      * @param x     The X coordinate of the upper left pixel location.
  591.      * @param y     The Y coordinate of the upper left pixel location.
  592.      * @param w     The width of the pixel rectangle.
  593.      * @param h     The height of the pixel rectangle.
  594.      * @param b     The band to return.
  595.      * @param fArray     If non-null, returns the samples in this array.
  596.      * @param data     The DataBuffer containing the image data.
  597.      */
  598.     public float[] getSample(int x, int y, int w, int h,
  599.                  int b, float fArray[],
  600.                  DataBuffer data) {
  601.     float pixels[];
  602.     int   Offset=0;
  603.  
  604.     if (fArray != null)
  605.         pixels = fArray;
  606.     else
  607.         pixels = new float[w * h];
  608.  
  609.     for (int i=y; i<(h+y); i++) {
  610.         for (int j=x; j<(w+x); j++) {
  611.         pixels[Offset++] = getSampleFloat(j, i, b, data);
  612.         }
  613.     }
  614.  
  615.     return pixels;
  616.     }
  617.  
  618.     /**
  619.      * Returns the samples for a specified band for a specified rectangle
  620.      * of pixels in a double array, one sample per array element.
  621.      * @param x     The X coordinate of the upper left pixel location.
  622.      * @param y     The Y coordinate of the upper left pixel location.
  623.      * @param w     The width of the pixel rectangle.
  624.      * @param h     The height of the pixel rectangle.
  625.      * @param b     The band to return.
  626.      * @param dArray     If non-null, returns the samples in this array.
  627.      * @param data     The DataBuffer containing the image data.
  628.      */
  629.     public double[] getSample(int x, int y, int w, int h,
  630.                   int b, double dArray[],
  631.                   DataBuffer data) {
  632.     double pixels[];
  633.     int    Offset=0;
  634.  
  635.     if (dArray != null)
  636.         pixels = dArray;
  637.     else
  638.         pixels = new double[w * h];
  639.  
  640.     for (int i=y; i<(y+h); i++) {
  641.         for (int j=x; j<(x+w); j++) {
  642.         pixels[Offset++] = getSampleDouble(j, i, b, data);
  643.         }
  644.     }
  645.  
  646.     return pixels;
  647.     }
  648.  
  649.     /** 
  650.      * Sets a pixel in     the DataBuffer using an int array of samples for input.
  651.      * @param x     The X coordinate of the pixel location.
  652.      * @param y     The Y coordinate of the pixel location.
  653.      * @param iArray     The input samples in an int array.
  654.      * @param data     The DataBuffer containing the image data.
  655.      */
  656.     public void setPixel(int x, int y, int iArray[], DataBuffer data) {
  657.  
  658.     for (int i=0; i<numBands; i++)
  659.         setSample(x, y, i, iArray[i], data);
  660.     }
  661.   
  662.     /**
  663.      * Sets a pixel in the DataBuffer using a float array of samples for input.
  664.      * @param x     The X coordinate of the pixel location.
  665.      * @param y     The Y coordinate of the pixel location.
  666.      * @param fArray     The input samples in a float array.
  667.      * @param data     The DataBuffer containing the image data.
  668.      */
  669.     public void setPixel(int x, int y, float fArray[], DataBuffer data) {
  670.  
  671.     for (int i=0; i<numBands; i++)
  672.         setSample(x, y, i, fArray[i], data);
  673.     }
  674.  
  675.     /**
  676.      * Sets a pixel in the DataBuffer using a double array of samples for input.
  677.      * @param x     The X coordinate of the pixel location.
  678.      * @param y     The Y coordinate of the pixel location.
  679.      * @param dArray     The input samples in a double array.
  680.      * @param data     The DataBuffer containing the image data.
  681.      */
  682.     public void setPixel(int x, int y, double dArray[], DataBuffer data) {
  683.  
  684.     for (int i=0; i<numBands; i++)
  685.         setSample(x, y, i, dArray[i], data);
  686.     }
  687.   
  688.     /**
  689.      * Sets all samples for a rectangle of pixels from an int array containing
  690.      * one sample per array element.
  691.      * @param x     The X coordinate of the upper left pixel location.
  692.      * @param y     The Y coordinate of the upper left pixel location.
  693.      * @param w     The width of the pixel rectangle.
  694.      * @param h     The height of the pixel rectangle.
  695.      * @param iArray     The input samples in an int array.
  696.      * @param data     The DataBuffer containing the image data.
  697.      */
  698.     public void setPixel(int x, int y, int w, int h,
  699.              int iArray[], DataBuffer data) {
  700.     int Offset=0;
  701.     
  702.     for (int i=y; i<(y+h); i++) {
  703.         for (int j=x; j<(x+w); j++) {
  704.         for (int k=0; k<numBands; k++) {
  705.             setSample(j, i, k, iArray[Offset++], data);
  706.         }
  707.         }
  708.     }
  709.     }
  710.       
  711.     /**
  712.      * Sets all samples for a rectangle of pixels from a float array containing
  713.      * one sample per array element.
  714.      * @param x     The X coordinate of the upper left pixel location.
  715.      * @param y     The Y coordinate of the upper left pixel location.
  716.      * @param w     The width of the pixel rectangle.
  717.      * @param h     The height of the pixel rectangle.
  718.      * @param fArray     The input samples in a float array.
  719.      * @param data     The DataBuffer containing the image data.
  720.      */
  721.     public void setPixel(int x, int y, int w, int h,
  722.              float fArray[], DataBuffer data) {
  723.     int Offset=0;
  724.  
  725.     for (int i=y; i<(y+h); i++) {
  726.         for (int j=x; j<(x+w); j++) {
  727.         for(int k=0; k<numBands; k++) {
  728.             setSample(j, i, k, fArray[Offset++], data);
  729.         }
  730.         }
  731.     }
  732.     }
  733.       
  734.     /**
  735.      * Sets all samples for a rectangle of pixels from a double array containing
  736.      * one sample per array element.
  737.      * @param x     The X coordinate of the upper left pixel location.
  738.      * @param y     The Y coordinate of the upper left pixel location.
  739.      * @param w     The width of the pixel rectangle.
  740.      * @param h     The height of the pixel rectangle.
  741.      * @param dArray     The input samples in a double array.
  742.      * @param data     The DataBuffer containing the image data.
  743.      */
  744.     public void setPixel(int x, int y, int w, int h,
  745.              double dArray[], DataBuffer data) {
  746.     int Offset=0;
  747.     
  748.     for (int i=y; i<(y+h); i++) {
  749.         for (int j=x; j<(x+w); j++) {
  750.         for (int k=0; k<numBands; k++) {
  751.             setSample(j, i, k, dArray[k], data);
  752.         }
  753.         }
  754.     }
  755.     }
  756.       
  757.     /** 
  758.      * Sets a sample in the specified band for the pixel located at (x,y)
  759.      * in the DataBuffer using an int for input.
  760.      * @param x     The X coordinate of the pixel location.
  761.      * @param y     The Y coordinate of the pixel location.
  762.      * @param b     The band to set.
  763.      * @param s     The input sample as an int.
  764.      * @param data     The DataBuffer containing the image data.
  765.      */
  766.     public abstract void setSample(int x, int y, int b, 
  767.                                    int s,
  768.                                    DataBuffer data);
  769.  
  770.     /** 
  771.      * Sets a sample in the specified band for the pixel located at (x,y)
  772.      * in the DataBuffer using a float for input.
  773.      * @param x     The X coordinate of the pixel location.
  774.      * @param y     The Y coordinate of the pixel location.
  775.      * @param b     The band to set.
  776.      * @param s     The input sample as a float.
  777.      * @param data     The DataBuffer containing the image data.
  778.      */
  779.     public void setSample(int x, int y, int b,
  780.               float s ,
  781.               DataBuffer data) {
  782.     int sample = (int)s;
  783.  
  784.     setSample(x, y, b, sample, data);
  785.     }
  786.     
  787.     /** 
  788.      * Sets a sample in the specified band for the pixel located at (x,y)
  789.      * in the DataBuffer using a double for input.
  790.      * @param x     The X coordinate of the pixel location.
  791.      * @param y     The Y coordinate of the pixel location.
  792.      * @param b     The band to set.
  793.      * @param s     The input sample as a double.
  794.      * @param data     The DataBuffer containing the image data.
  795.      */
  796.     public void setSample(int x, int y, int b,
  797.               double s,
  798.               DataBuffer data) {
  799.     int sample = (int)s;
  800.  
  801.     setSample(x, y, b, sample, data);
  802.     }
  803.  
  804.     /**
  805.      * Sets the samples in the specified band for the specified rectangle
  806.      * of pixels from an int array containing one sample per array element.
  807.      * @param x     The X coordinate of the upper left pixel location.
  808.      * @param y     The Y coordinate of the upper left pixel location.
  809.      * @param w     The width of the pixel rectangle.
  810.      * @param h     The height of the pixel rectangle.
  811.      * @param b     The band to set.
  812.      * @param iArray     The input samples in an int array.
  813.      * @param data      The DataBuffer containing the image data.
  814.      */
  815.     public void setSample(int x, int y, int w, int h, int b,
  816.               int iArray[], DataBuffer data) {
  817.     
  818.     int Offset=0;
  819.     
  820.     for (int i=y; i<(y+h); i++) {
  821.         for (int j=x; j<(x+w); j++) {
  822.         setSample(j, i, b, iArray[Offset++], data);
  823.         }
  824.     }
  825.     }
  826.  
  827.     /**
  828.      * Sets the samples in the specified band for the specified rectangle
  829.      * of pixels from a float array containing one sample per array element.
  830.      * @param x     The X coordinate of the upper left pixel location.
  831.      * @param y     The Y coordinate of the upper left pixel location.
  832.      * @param w     The width of the pixel rectangle.
  833.      * @param h     The height of the pixel rectangle.
  834.      * @param b     The band to set.
  835.      * @param fArray     The input samples in a float array.
  836.      * @param data     The DataBuffer containing the image data.
  837.      */
  838.     public void setSample(int x, int y, int w, int h, int b,
  839.               float fArray[], DataBuffer data) {
  840.     int Offset=0;
  841.     
  842.     for (int i=y; i<(y+h); i++) {
  843.         for (int j=x; j<(x+w); j++) {
  844.         setSample(j, i, b, fArray[Offset++], data);
  845.         }
  846.     }
  847.     }
  848.  
  849.     /**
  850.      * Sets the samples in the specified band for the specified rectangle
  851.      * of pixels from a double array containing one sample per array element.
  852.      * @param x     The X coordinate of the upper left pixel location.
  853.      * @param y     The Y coordinate of the upper left pixel location.
  854.      * @param w     The width of the pixel rectangle.
  855.      * @param h     The height of the pixel rectangle.
  856.      * @param b     The band to set.
  857.      * @param dArray     The input samples in a double array.
  858.      * @param data     The DataBuffer containing the image data.
  859.      */
  860.     public void setSample(int x, int y, int w, int h, int b,
  861.               double dArray[], DataBuffer data) {
  862.     int Offset=0;
  863.  
  864.     for (int i=y; i<(y+h); i++) {
  865.         for (int j=x; j<(x+w); j++) {
  866.         setSample(j, i, b, dArray[Offset++], data);
  867.         }
  868.     }
  869.     }
  870.  
  871.     /**
  872.      *  Creates a SampleModel which describes data in this SampleModel's
  873.      *  format, but with a different width and height.
  874.      */
  875.     public abstract SampleModel createCompatibleSampleModel(int w, int h);
  876.     
  877.     /**
  878.      * This creates a new SampleModel with the requested 
  879.      * width and height and with a subset of the bands of this
  880.      * SampleModel. 
  881.      */
  882.     public abstract SampleModel createSubsetSampleModel(int w,
  883.                             int h, int bands[]);
  884.     
  885.     /** 
  886.      * Creates a DataBuffer that corresponds to this SampleModel.
  887.      * The DataBuffer's width and height will match this SampleModel's.
  888.      */
  889.     public abstract DataBuffer createCompatibleDataBuffer();
  890.  
  891.     /** 
  892.      * Creates a DataBuffer that corresponds to this SampleModel,
  893.      * with a different width and height.
  894.      */
  895.     public abstract DataBuffer
  896.     createCompatibleDataBuffer(int width, int height);
  897.  
  898.     /** Returns the minimum sample value for all bands. */
  899.     public float getMinSampleValue() {
  900.      return minMinSampleValue;
  901.     }
  902.       
  903.     /** Returns the minimum sample value for the specified band. */
  904.     public float getMinSampleValue(int band) {
  905.      return minSampleValue[band];
  906.     }
  907.       
  908.     /** Returns the maximum sample value for all bands. */
  909.     public float getMaxSampleValue() {
  910.      return maxMaxSampleValue;
  911.     }
  912.  
  913.     /** Returns the maximum sample value for the specified band. */
  914.     public float getMaxSampleValue(int band) {
  915.      return maxSampleValue[band];
  916.     }
  917.  
  918.     /** Returns the size in bits of samples for all bands. */
  919.     public abstract int[] getSampleSize();
  920.   
  921.     /** Returns the size in bits of samples for the specified band. */
  922.     public abstract int getSampleSize(int band);
  923. }
  924.  
  925.  
  926.  
  927.  
  928.