< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 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} or {@code h}
 115      *         is not greater than 0
 116      * @throws IllegalArgumentException if the product of {@code w}
 117      *         and {@code h} is greater than
 118      *         {@code Integer.MAX_VALUE}
 119      * @throws IllegalArgumentException if {@code dataType} is not
 120      *         one of the supported data types
 121      */
 122     public SampleModel(int dataType, int w, int h, int numBands)
 123     {
 124         long size = (long)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;


   1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 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} or {@code h}
 115      *         is not greater than 0
 116      * @throws IllegalArgumentException if the product of {@code w}
 117      *         and {@code h} is greater than
 118      *         {@code Integer.MAX_VALUE}
 119      * @throws IllegalArgumentException if {@code dataType} is not
 120      *         one of the supported data types
 121      */
 122     public SampleModel(int dataType, int w, int h, int numBands)
 123     {
 124         long size = (long)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;


< prev index next >