< prev index next >

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

Print this page




  50  *  {@link DataBuffer#TYPE_SHORT TYPE_SHORT},
  51  *  {@link DataBuffer#TYPE_INT TYPE_INT},
  52  *  {@link DataBuffer#TYPE_FLOAT TYPE_FLOAT} and
  53  *  {@link DataBuffer#TYPE_DOUBLE TYPE_DOUBLE} datatypes.
  54  */
  55 
  56 public class PixelInterleavedSampleModel extends ComponentSampleModel
  57 {
  58     /**
  59      * Constructs a PixelInterleavedSampleModel with the specified parameters.
  60      * The number of bands will be given by the length of the bandOffsets
  61      * array.
  62      * @param dataType  The data type for storing samples.
  63      * @param w         The width (in pixels) of the region of
  64      *                  image data described.
  65      * @param h         The height (in pixels) of the region of
  66      *                  image data described.
  67      * @param pixelStride The pixel stride of the image data.
  68      * @param scanlineStride The line stride of the image data.
  69      * @param bandOffsets The offsets of all bands.
  70      * @throws IllegalArgumentException if <code>w</code> or
  71      *         <code>h</code> is not greater than 0
  72      * @throws IllegalArgumentException if any offset between bands is
  73      *         greater than the scanline stride
  74      * @throws IllegalArgumentException if the product of
  75      *         <code>pixelStride</code> and <code>w</code> is greater
  76      *         than <code>scanlineStride</code>
  77      * @throws IllegalArgumentException if <code>pixelStride</code> is
  78      *         less than any offset between bands
  79      * @throws IllegalArgumentException if <code>dataType</code> is not
  80      *         one of the supported data types
  81      */
  82     public PixelInterleavedSampleModel(int dataType,
  83                                        int w, int h,
  84                                        int pixelStride,
  85                                        int scanlineStride,
  86                                        int bandOffsets[]) {
  87         super(dataType, w, h, pixelStride, scanlineStride, bandOffsets);
  88         int minBandOff=this.bandOffsets[0];
  89         int maxBandOff=this.bandOffsets[0];
  90         for (int i=1; i<this.bandOffsets.length; i++) {
  91             minBandOff = Math.min(minBandOff,this.bandOffsets[i]);
  92             maxBandOff = Math.max(maxBandOff,this.bandOffsets[i]);
  93         }
  94         maxBandOff -= minBandOff;
  95         if (maxBandOff > scanlineStride) {
  96             throw new IllegalArgumentException("Offsets between bands must be"+
  97                                                " less than the scanline "+
  98                                                " stride");
  99         }
 100         if (pixelStride*w > scanlineStride) {
 101             throw new IllegalArgumentException("Pixel stride times width "+
 102                                                "must be less than or "+
 103                                                "equal to the scanline "+
 104                                                "stride");
 105         }
 106         if (pixelStride < maxBandOff) {
 107             throw new IllegalArgumentException("Pixel stride must be greater"+
 108                                                " than or equal to the offsets"+
 109                                                " between bands");
 110         }
 111     }
 112 
 113     /**
 114      * Creates a new PixelInterleavedSampleModel with the specified
 115      * width and height.  The new PixelInterleavedSampleModel will have the
 116      * same number of bands, storage data type, and pixel stride
 117      * as this PixelInterleavedSampleModel.  The band offsets may be
 118      * compressed such that the minimum of all of the band offsets is zero.
 119      * @param w the width of the resulting <code>SampleModel</code>
 120      * @param h the height of the resulting <code>SampleModel</code>
 121      * @return a new <code>SampleModel</code> with the specified width
 122      *         and height.
 123      * @throws IllegalArgumentException if <code>w</code> or
 124      *         <code>h</code> is not greater than 0
 125      */
 126     public SampleModel createCompatibleSampleModel(int w, int h) {
 127         int minBandoff=bandOffsets[0];
 128         int numBands = bandOffsets.length;
 129         for (int i=1; i < numBands; i++) {
 130             if (bandOffsets[i] < minBandoff) {
 131                 minBandoff = bandOffsets[i];
 132             }
 133         }
 134         int[] bandOff;
 135         if (minBandoff > 0) {
 136             bandOff = new int[numBands];
 137             for (int i=0; i < numBands; i++) {
 138                 bandOff[i] = bandOffsets[i] - minBandoff;
 139             }
 140         }
 141         else {
 142             bandOff = bandOffsets;
 143         }
 144         return new PixelInterleavedSampleModel(dataType, w, h, pixelStride,




  50  *  {@link DataBuffer#TYPE_SHORT TYPE_SHORT},
  51  *  {@link DataBuffer#TYPE_INT TYPE_INT},
  52  *  {@link DataBuffer#TYPE_FLOAT TYPE_FLOAT} and
  53  *  {@link DataBuffer#TYPE_DOUBLE TYPE_DOUBLE} datatypes.
  54  */
  55 
  56 public class PixelInterleavedSampleModel extends ComponentSampleModel
  57 {
  58     /**
  59      * Constructs a PixelInterleavedSampleModel with the specified parameters.
  60      * The number of bands will be given by the length of the bandOffsets
  61      * array.
  62      * @param dataType  The data type for storing samples.
  63      * @param w         The width (in pixels) of the region of
  64      *                  image data described.
  65      * @param h         The height (in pixels) of the region of
  66      *                  image data described.
  67      * @param pixelStride The pixel stride of the image data.
  68      * @param scanlineStride The line stride of the image data.
  69      * @param bandOffsets The offsets of all bands.
  70      * @throws IllegalArgumentException if {@code w} or
  71      *         {@code h} is not greater than 0
  72      * @throws IllegalArgumentException if any offset between bands is
  73      *         greater than the scanline stride
  74      * @throws IllegalArgumentException if the product of
  75      *         {@code pixelStride} and {@code w} is greater
  76      *         than {@code scanlineStride}
  77      * @throws IllegalArgumentException if {@code pixelStride} is
  78      *         less than any offset between bands
  79      * @throws IllegalArgumentException if {@code dataType} is not
  80      *         one of the supported data types
  81      */
  82     public PixelInterleavedSampleModel(int dataType,
  83                                        int w, int h,
  84                                        int pixelStride,
  85                                        int scanlineStride,
  86                                        int bandOffsets[]) {
  87         super(dataType, w, h, pixelStride, scanlineStride, bandOffsets);
  88         int minBandOff=this.bandOffsets[0];
  89         int maxBandOff=this.bandOffsets[0];
  90         for (int i=1; i<this.bandOffsets.length; i++) {
  91             minBandOff = Math.min(minBandOff,this.bandOffsets[i]);
  92             maxBandOff = Math.max(maxBandOff,this.bandOffsets[i]);
  93         }
  94         maxBandOff -= minBandOff;
  95         if (maxBandOff > scanlineStride) {
  96             throw new IllegalArgumentException("Offsets between bands must be"+
  97                                                " less than the scanline "+
  98                                                " stride");
  99         }
 100         if (pixelStride*w > scanlineStride) {
 101             throw new IllegalArgumentException("Pixel stride times width "+
 102                                                "must be less than or "+
 103                                                "equal to the scanline "+
 104                                                "stride");
 105         }
 106         if (pixelStride < maxBandOff) {
 107             throw new IllegalArgumentException("Pixel stride must be greater"+
 108                                                " than or equal to the offsets"+
 109                                                " between bands");
 110         }
 111     }
 112 
 113     /**
 114      * Creates a new PixelInterleavedSampleModel with the specified
 115      * width and height.  The new PixelInterleavedSampleModel will have the
 116      * same number of bands, storage data type, and pixel stride
 117      * as this PixelInterleavedSampleModel.  The band offsets may be
 118      * compressed such that the minimum of all of the band offsets is zero.
 119      * @param w the width of the resulting {@code SampleModel}
 120      * @param h the height of the resulting {@code SampleModel}
 121      * @return a new {@code SampleModel} with the specified width
 122      *         and height.
 123      * @throws IllegalArgumentException if {@code w} or
 124      *         {@code h} is not greater than 0
 125      */
 126     public SampleModel createCompatibleSampleModel(int w, int h) {
 127         int minBandoff=bandOffsets[0];
 128         int numBands = bandOffsets.length;
 129         for (int i=1; i < numBands; i++) {
 130             if (bandOffsets[i] < minBandoff) {
 131                 minBandoff = bandOffsets[i];
 132             }
 133         }
 134         int[] bandOff;
 135         if (minBandoff > 0) {
 136             bandOff = new int[numBands];
 137             for (int i=0; i < numBands; i++) {
 138                 bandOff[i] = bandOffsets[i] - minBandoff;
 139             }
 140         }
 141         else {
 142             bandOff = bandOffsets;
 143         }
 144         return new PixelInterleavedSampleModel(dataType, w, h, pixelStride,


< prev index next >