< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1997, 2017, 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


  43  * are treated as unsigned values.
  44  * <p>
  45  * <a id="optimizations">
  46  * Note that some implementations may function more efficiently
  47  * if they can maintain control over how the data for an image is
  48  * stored.
  49  * For example, optimizations such as caching an image in video
  50  * memory require that the implementation track all modifications
  51  * to that data.
  52  * Other implementations may operate better if they can store the
  53  * data in locations other than a Java array.
  54  * To maintain optimum compatibility with various optimizations
  55  * it is best to avoid constructors and methods which expose the
  56  * underlying storage as a Java array as noted below in the
  57  * documentation for those methods.
  58  * </a>
  59  */
  60 public final class DataBufferUShort extends DataBuffer
  61 {
  62     /** The default data bank. */
  63     short data[];
  64 
  65     /** All data banks */
  66     short bankdata[][];
  67 
  68     /**
  69      * Constructs an unsigned-short based {@code DataBuffer} with a single bank and the
  70      * specified size.
  71      *
  72      * @param size The size of the {@code DataBuffer}.
  73      */
  74     public DataBufferUShort(int size) {
  75         super(STABLE, TYPE_USHORT, size);
  76         data = new short[size];
  77         bankdata = new short[1][];
  78         bankdata[0] = data;
  79     }
  80 
  81     /**
  82      * Constructs an unsigned-short based {@code DataBuffer} with the specified number of
  83      * banks, all of which are the specified size.
  84      *
  85      * @param size The size of the banks in the {@code DataBuffer}.
  86      * @param numBanks The number of banks in the a {@code DataBuffer}.


  92             bankdata[i] = new short[size];
  93         }
  94         data = bankdata[0];
  95     }
  96 
  97     /**
  98      * Constructs an unsigned-short based {@code DataBuffer} with a single bank
  99      * using the specified array.
 100      * Only the first {@code size} elements should be used by accessors of
 101      * this {@code DataBuffer}.  {@code dataArray} must be large enough to
 102      * hold {@code size} elements.
 103      * <p>
 104      * Note that {@code DataBuffer} objects created by this constructor
 105      * may be incompatible with <a href="#optimizations">performance
 106      * optimizations</a> used by some implementations (such as caching
 107      * an associated image in video memory).
 108      *
 109      * @param dataArray The unsigned-short array for the {@code DataBuffer}.
 110      * @param size The size of the {@code DataBuffer} bank.
 111      */
 112     public DataBufferUShort(short dataArray[], int size) {
 113         super(UNTRACKABLE, TYPE_USHORT, size);
 114         if (dataArray == null) {
 115             throw new NullPointerException("dataArray is null");
 116         }
 117         data = dataArray;
 118         bankdata = new short[1][];
 119         bankdata[0] = data;
 120     }
 121 
 122     /**
 123      * Constructs an unsigned-short based {@code DataBuffer} with a single bank
 124      * using the specified array, size, and offset.  {@code dataArray} must have at
 125      * least {@code offset} + {@code size} elements.  Only elements
 126      * {@code offset} through {@code offset} + {@code size} - 1 should
 127      * be used by accessors of this {@code DataBuffer}.
 128      * <p>
 129      * Note that {@code DataBuffer} objects created by this constructor
 130      * may be incompatible with <a href="#optimizations">performance
 131      * optimizations</a> used by some implementations (such as caching
 132      * an associated image in video memory).
 133      *
 134      * @param dataArray The unsigned-short array for the {@code DataBuffer}.
 135      * @param size The size of the {@code DataBuffer} bank.
 136      * @param offset The offset into the {@code dataArray}.
 137      */
 138     public DataBufferUShort(short dataArray[], int size, int offset) {
 139         super(UNTRACKABLE, TYPE_USHORT, size, 1, offset);
 140         if (dataArray == null) {
 141             throw new NullPointerException("dataArray is null");
 142         }
 143         if ((size+offset) > dataArray.length) {
 144             throw new IllegalArgumentException("Length of dataArray is less "+
 145                                                " than size+offset.");
 146         }
 147         data = dataArray;
 148         bankdata = new short[1][];
 149         bankdata[0] = data;
 150     }
 151 
 152     /**
 153      * Constructs an unsigned-short based {@code DataBuffer} with the specified arrays.
 154      * The number of banks will be equal to {@code dataArray.length}.
 155      * Only the first {@code size} elements of each array should be used by
 156      * accessors of this {@code DataBuffer}.
 157      * <p>
 158      * Note that {@code DataBuffer} objects created by this constructor
 159      * may be incompatible with <a href="#optimizations">performance
 160      * optimizations</a> used by some implementations (such as caching
 161      * an associated image in video memory).
 162      *
 163      * @param dataArray The unsigned-short arrays for the {@code DataBuffer}.
 164      * @param size The size of the banks in the {@code DataBuffer}.
 165      */
 166     public DataBufferUShort(short dataArray[][], int size) {
 167         super(UNTRACKABLE, TYPE_USHORT, size, dataArray.length);
 168         if (dataArray == null) {
 169             throw new NullPointerException("dataArray is null");
 170         }
 171         for (int i=0; i < dataArray.length; i++) {
 172             if (dataArray[i] == null) {
 173                 throw new NullPointerException("dataArray["+i+"] is null");
 174             }
 175         }
 176 
 177         bankdata = dataArray.clone();
 178         data = bankdata[0];
 179     }
 180 
 181     /**
 182      * Constructs an unsigned-short based {@code DataBuffer} with specified arrays,
 183      * size, and offsets.
 184      * The number of banks is equal to {@code dataArray.length}.  Each array must
 185      * be at least as large as {@code size} + the corresponding offset.   There must
 186      * be an entry in the offset array for each {@code dataArray} entry.  For each
 187      * bank, only elements {@code offset} through
 188      * {@code offset} + {@code size} - 1 should be
 189      * used by accessors of this {@code DataBuffer}.
 190      * <p>
 191      * Note that {@code DataBuffer} objects created by this constructor
 192      * may be incompatible with <a href="#optimizations">performance
 193      * optimizations</a> used by some implementations (such as caching
 194      * an associated image in video memory).
 195      *
 196      * @param dataArray The unsigned-short arrays for the {@code DataBuffer}.
 197      * @param size The size of the banks in the {@code DataBuffer}.
 198      * @param offsets The offsets into each array.
 199      */
 200     public DataBufferUShort(short dataArray[][], int size, int offsets[]) {
 201         super(UNTRACKABLE, TYPE_USHORT, size, dataArray.length, offsets);
 202         if (dataArray == null) {
 203             throw new NullPointerException("dataArray is null");
 204         }
 205         for (int i=0; i < dataArray.length; i++) {
 206             if (dataArray[i] == null) {
 207                 throw new NullPointerException("dataArray["+i+"] is null");
 208             }
 209             if ((size+offsets[i]) > dataArray[i].length) {
 210                 throw new IllegalArgumentException("Length of dataArray["+i+
 211                                                    "] is less than size+"+
 212                                                    "offsets["+i+"].");
 213             }
 214 
 215         }
 216         bankdata = dataArray.clone();
 217         data = bankdata[0];
 218     }
 219 
 220     /**


   1 /*
   2  * Copyright (c) 1997, 2018, 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


  43  * are treated as unsigned values.
  44  * <p>
  45  * <a id="optimizations">
  46  * Note that some implementations may function more efficiently
  47  * if they can maintain control over how the data for an image is
  48  * stored.
  49  * For example, optimizations such as caching an image in video
  50  * memory require that the implementation track all modifications
  51  * to that data.
  52  * Other implementations may operate better if they can store the
  53  * data in locations other than a Java array.
  54  * To maintain optimum compatibility with various optimizations
  55  * it is best to avoid constructors and methods which expose the
  56  * underlying storage as a Java array as noted below in the
  57  * documentation for those methods.
  58  * </a>
  59  */
  60 public final class DataBufferUShort extends DataBuffer
  61 {
  62     /** The default data bank. */
  63     short[] data;
  64 
  65     /** All data banks */
  66     short[][] bankdata;
  67 
  68     /**
  69      * Constructs an unsigned-short based {@code DataBuffer} with a single bank and the
  70      * specified size.
  71      *
  72      * @param size The size of the {@code DataBuffer}.
  73      */
  74     public DataBufferUShort(int size) {
  75         super(STABLE, TYPE_USHORT, size);
  76         data = new short[size];
  77         bankdata = new short[1][];
  78         bankdata[0] = data;
  79     }
  80 
  81     /**
  82      * Constructs an unsigned-short based {@code DataBuffer} with the specified number of
  83      * banks, all of which are the specified size.
  84      *
  85      * @param size The size of the banks in the {@code DataBuffer}.
  86      * @param numBanks The number of banks in the a {@code DataBuffer}.


  92             bankdata[i] = new short[size];
  93         }
  94         data = bankdata[0];
  95     }
  96 
  97     /**
  98      * Constructs an unsigned-short based {@code DataBuffer} with a single bank
  99      * using the specified array.
 100      * Only the first {@code size} elements should be used by accessors of
 101      * this {@code DataBuffer}.  {@code dataArray} must be large enough to
 102      * hold {@code size} elements.
 103      * <p>
 104      * Note that {@code DataBuffer} objects created by this constructor
 105      * may be incompatible with <a href="#optimizations">performance
 106      * optimizations</a> used by some implementations (such as caching
 107      * an associated image in video memory).
 108      *
 109      * @param dataArray The unsigned-short array for the {@code DataBuffer}.
 110      * @param size The size of the {@code DataBuffer} bank.
 111      */
 112     public DataBufferUShort(short[] dataArray, int size) {
 113         super(UNTRACKABLE, TYPE_USHORT, size);
 114         if (dataArray == null) {
 115             throw new NullPointerException("dataArray is null");
 116         }
 117         data = dataArray;
 118         bankdata = new short[1][];
 119         bankdata[0] = data;
 120     }
 121 
 122     /**
 123      * Constructs an unsigned-short based {@code DataBuffer} with a single bank
 124      * using the specified array, size, and offset.  {@code dataArray} must have at
 125      * least {@code offset} + {@code size} elements.  Only elements
 126      * {@code offset} through {@code offset} + {@code size} - 1 should
 127      * be used by accessors of this {@code DataBuffer}.
 128      * <p>
 129      * Note that {@code DataBuffer} objects created by this constructor
 130      * may be incompatible with <a href="#optimizations">performance
 131      * optimizations</a> used by some implementations (such as caching
 132      * an associated image in video memory).
 133      *
 134      * @param dataArray The unsigned-short array for the {@code DataBuffer}.
 135      * @param size The size of the {@code DataBuffer} bank.
 136      * @param offset The offset into the {@code dataArray}.
 137      */
 138     public DataBufferUShort(short[] dataArray, int size, int offset) {
 139         super(UNTRACKABLE, TYPE_USHORT, size, 1, offset);
 140         if (dataArray == null) {
 141             throw new NullPointerException("dataArray is null");
 142         }
 143         if ((size+offset) > dataArray.length) {
 144             throw new IllegalArgumentException("Length of dataArray is less "+
 145                                                " than size+offset.");
 146         }
 147         data = dataArray;
 148         bankdata = new short[1][];
 149         bankdata[0] = data;
 150     }
 151 
 152     /**
 153      * Constructs an unsigned-short based {@code DataBuffer} with the specified arrays.
 154      * The number of banks will be equal to {@code dataArray.length}.
 155      * Only the first {@code size} elements of each array should be used by
 156      * accessors of this {@code DataBuffer}.
 157      * <p>
 158      * Note that {@code DataBuffer} objects created by this constructor
 159      * may be incompatible with <a href="#optimizations">performance
 160      * optimizations</a> used by some implementations (such as caching
 161      * an associated image in video memory).
 162      *
 163      * @param dataArray The unsigned-short arrays for the {@code DataBuffer}.
 164      * @param size The size of the banks in the {@code DataBuffer}.
 165      */
 166     public DataBufferUShort(short[][] dataArray, int size) {
 167         super(UNTRACKABLE, TYPE_USHORT, size, dataArray.length);
 168         if (dataArray == null) {
 169             throw new NullPointerException("dataArray is null");
 170         }
 171         for (int i=0; i < dataArray.length; i++) {
 172             if (dataArray[i] == null) {
 173                 throw new NullPointerException("dataArray["+i+"] is null");
 174             }
 175         }
 176 
 177         bankdata = dataArray.clone();
 178         data = bankdata[0];
 179     }
 180 
 181     /**
 182      * Constructs an unsigned-short based {@code DataBuffer} with specified arrays,
 183      * size, and offsets.
 184      * The number of banks is equal to {@code dataArray.length}.  Each array must
 185      * be at least as large as {@code size} + the corresponding offset.   There must
 186      * be an entry in the offset array for each {@code dataArray} entry.  For each
 187      * bank, only elements {@code offset} through
 188      * {@code offset} + {@code size} - 1 should be
 189      * used by accessors of this {@code DataBuffer}.
 190      * <p>
 191      * Note that {@code DataBuffer} objects created by this constructor
 192      * may be incompatible with <a href="#optimizations">performance
 193      * optimizations</a> used by some implementations (such as caching
 194      * an associated image in video memory).
 195      *
 196      * @param dataArray The unsigned-short arrays for the {@code DataBuffer}.
 197      * @param size The size of the banks in the {@code DataBuffer}.
 198      * @param offsets The offsets into each array.
 199      */
 200     public DataBufferUShort(short[][] dataArray, int size, int[] offsets) {
 201         super(UNTRACKABLE, TYPE_USHORT, size, dataArray.length, offsets);
 202         if (dataArray == null) {
 203             throw new NullPointerException("dataArray is null");
 204         }
 205         for (int i=0; i < dataArray.length; i++) {
 206             if (dataArray[i] == null) {
 207                 throw new NullPointerException("dataArray["+i+"] is null");
 208             }
 209             if ((size+offsets[i]) > dataArray[i].length) {
 210                 throw new IllegalArgumentException("Length of dataArray["+i+
 211                                                    "] is less than size+"+
 212                                                    "offsets["+i+"].");
 213             }
 214 
 215         }
 216         bankdata = dataArray.clone();
 217         data = bankdata[0];
 218     }
 219 
 220     /**


< prev index next >