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 23 * 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 import static sun.java2d.StateTrackable.State.*; 39 40 /** 41 * This class extends <CODE>DataBuffer</CODE> and stores data internally as 42 * shorts. Values stored in the short array(s) of this <CODE>DataBuffer</CODE> 43 * are treated as unsigned values. 44 * <p> 45 * <a name="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</CODE> with a single bank and the 70 * specified size. 71 * 72 * @param size The size of the <CODE>DataBuffer</CODE>. 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</CODE> 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</CODE>. 86 * @param numBanks The number of banks in the a<CODE>DataBuffer</CODE>. 87 */ 88 public DataBufferUShort(int size, int numBanks) { 89 super(STABLE, TYPE_USHORT, size, numBanks); 90 bankdata = new short[numBanks][]; 91 for (int i= 0; i < numBanks; i++) { 92 bankdata[i] = new short[size]; 93 } 94 data = bankdata[0]; 95 } 96 97 /** 98 * Constructs an unsigned-short based <CODE>DataBuffer</CODE> with a single bank 99 * using the specified array. 100 * Only the first <CODE>size</CODE> elements should be used by accessors of 101 * this <CODE>DataBuffer</CODE>. <CODE>dataArray</CODE> must be large enough to 102 * hold <CODE>size</CODE> 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</CODE>. 110 * @param size The size of the <CODE>DataBuffer</CODE> 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</CODE> with a single bank 124 * using the specified array, size, and offset. <CODE>dataArray</CODE> must have at 125 * least <CODE>offset</CODE> + <CODE>size</CODE> elements. Only elements 126 * <CODE>offset</CODE> through <CODE>offset</CODE> + <CODE>size</CODE> - 1 should 127 * be used by accessors of this <CODE>DataBuffer</CODE>. 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</CODE>. 135 * @param size The size of the <CODE>DataBuffer</CODE> bank. 136 * @param offset The offset into the <CODE>dataArray</CODE>. 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</CODE> with the specified arrays. 154 * The number of banks will be equal to <CODE>dataArray.length</CODE>. 155 * Only the first <CODE>size</CODE> elements of each array should be used by 156 * accessors of this <CODE>DataBuffer</CODE>. 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</CODE>. 164 * @param size The size of the banks in the <CODE>DataBuffer</CODE>. 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</CODE> with specified arrays, 183 * size, and offsets. 184 * The number of banks is equal to <CODE>dataArray.length</CODE>. Each array must 185 * be at least as large as <CODE>size</CODE> + the corresponding offset. There must 186 * be an entry in the offset array for each <CODE>dataArray</CODE> entry. For each 187 * bank, only elements <CODE>offset</CODE> through 188 * <CODE>offset</CODE> + <CODE>size</CODE> - 1 should be 189 * used by accessors of this <CODE>DataBuffer</CODE>. 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</CODE>. 197 * @param size The size of the banks in the <CODE>DataBuffer</CODE>. 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]; | 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 23 * 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 import static sun.java2d.StateTrackable.State.*; 39 40 /** 41 * This class extends {@code DataBuffer} and stores data internally as 42 * shorts. Values stored in the short array(s) of this {@code DataBuffer} 43 * are treated as unsigned values. 44 * <p> 45 * <a name="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}. 87 */ 88 public DataBufferUShort(int size, int numBanks) { 89 super(STABLE, TYPE_USHORT, size, numBanks); 90 bankdata = new short[numBanks][]; 91 for (int i= 0; i < numBanks; i++) { 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]; |