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 shorts. 42 * <p> 43 * <a name="optimizations"> 44 * Note that some implementations may function more efficiently 45 * if they can maintain control over how the data for an image is 46 * stored. 47 * For example, optimizations such as caching an image in video 48 * memory require that the implementation track all modifications 49 * to that data. 50 * Other implementations may operate better if they can store the 51 * data in locations other than a Java array. 52 * To maintain optimum compatibility with various optimizations 53 * it is best to avoid constructors and methods which expose the 54 * underlying storage as a Java array as noted below in the 55 * documentation for those methods. 56 * </a> 57 */ 58 public final class DataBufferShort extends DataBuffer 59 { 60 /** The default data bank. */ 61 short data[]; 62 63 /** All data banks */ 64 short bankdata[][]; 65 66 /** 67 * Constructs a short-based <CODE>DataBuffer</CODE> with a single bank and the 68 * specified size. 69 * 70 * @param size The size of the <CODE>DataBuffer</CODE>. 71 */ 72 public DataBufferShort(int size) { 73 super(STABLE, TYPE_SHORT,size); 74 data = new short[size]; 75 bankdata = new short[1][]; 76 bankdata[0] = data; 77 } 78 79 /** 80 * Constructs a short-based <CODE>DataBuffer</CODE> with the specified number of 81 * banks all of which are the specified size. 82 * 83 * @param size The size of the banks in the <CODE>DataBuffer</CODE>. 84 * @param numBanks The number of banks in the a<CODE>DataBuffer</CODE>. 85 */ 86 public DataBufferShort(int size, int numBanks) { 87 super(STABLE, TYPE_SHORT,size,numBanks); 88 bankdata = new short[numBanks][]; 89 for (int i= 0; i < numBanks; i++) { 90 bankdata[i] = new short[size]; 91 } 92 data = bankdata[0]; 93 } 94 95 /** 96 * Constructs a short-based <CODE>DataBuffer</CODE> with a single bank using the 97 * specified array. 98 * Only the first <CODE>size</CODE> elements should be used by accessors of 99 * this <CODE>DataBuffer</CODE>. <CODE>dataArray</CODE> must be large enough to 100 * hold <CODE>size</CODE> elements. 101 * <p> 102 * Note that {@code DataBuffer} objects created by this constructor 103 * may be incompatible with <a href="#optimizations">performance 104 * optimizations</a> used by some implementations (such as caching 105 * an associated image in video memory). 106 * 107 * @param dataArray The short array for the <CODE>DataBuffer</CODE>. 108 * @param size The size of the <CODE>DataBuffer</CODE> bank. 109 */ 110 public DataBufferShort(short dataArray[], int size) { 111 super(UNTRACKABLE, TYPE_SHORT, size); 112 data = dataArray; 113 bankdata = new short[1][]; 114 bankdata[0] = data; 115 } 116 117 /** 118 * Constructs a short-based <CODE>DataBuffer</CODE> with a single bank using the 119 * specified array, size, and offset. <CODE>dataArray</CODE> must have at least 120 * <CODE>offset</CODE> + <CODE>size</CODE> elements. Only elements <CODE>offset</CODE> 121 * through <CODE>offset</CODE> + <CODE>size</CODE> - 1 122 * should be used by accessors of this <CODE>DataBuffer</CODE>. 123 * <p> 124 * Note that {@code DataBuffer} objects created by this constructor 125 * may be incompatible with <a href="#optimizations">performance 126 * optimizations</a> used by some implementations (such as caching 127 * an associated image in video memory). 128 * 129 * @param dataArray The short array for the <CODE>DataBuffer</CODE>. 130 * @param size The size of the <CODE>DataBuffer</CODE> bank. 131 * @param offset The offset into the <CODE>dataArray</CODE>. 132 */ 133 public DataBufferShort(short dataArray[], int size, int offset) { 134 super(UNTRACKABLE, TYPE_SHORT, size, 1, offset); 135 data = dataArray; 136 bankdata = new short[1][]; 137 bankdata[0] = data; 138 } 139 140 /** 141 * Constructs a short-based <CODE>DataBuffer</CODE> with the specified arrays. 142 * The number of banks will be equal to <CODE>dataArray.length</CODE>. 143 * Only the first <CODE>size</CODE> elements of each array should be used by 144 * accessors of this <CODE>DataBuffer</CODE>. 145 * <p> 146 * Note that {@code DataBuffer} objects created by this constructor 147 * may be incompatible with <a href="#optimizations">performance 148 * optimizations</a> used by some implementations (such as caching 149 * an associated image in video memory). 150 * 151 * @param dataArray The short arrays for the <CODE>DataBuffer</CODE>. 152 * @param size The size of the banks in the <CODE>DataBuffer</CODE>. 153 */ 154 public DataBufferShort(short dataArray[][], int size) { 155 super(UNTRACKABLE, TYPE_SHORT, size, dataArray.length); 156 bankdata = dataArray.clone(); 157 data = bankdata[0]; 158 } 159 160 /** 161 * Constructs a short-based <CODE>DataBuffer</CODE> with the specified arrays, size, 162 * and offsets. 163 * The number of banks is equal to <CODE>dataArray.length</CODE>. Each array must 164 * be at least as large as <CODE>size</CODE> + the corresponding offset. There must 165 * be an entry in the offset array for each <CODE>dataArray</CODE> entry. For each 166 * bank, only elements <CODE>offset</CODE> through 167 * <CODE>offset</CODE> + <CODE>size</CODE> - 1 should be 168 * used by accessors of this <CODE>DataBuffer</CODE>. 169 * <p> 170 * Note that {@code DataBuffer} objects created by this constructor 171 * may be incompatible with <a href="#optimizations">performance 172 * optimizations</a> used by some implementations (such as caching 173 * an associated image in video memory). 174 * 175 * @param dataArray The short arrays for the <CODE>DataBuffer</CODE>. 176 * @param size The size of the banks in the <CODE>DataBuffer</CODE>. 177 * @param offsets The offsets into each array. 178 */ 179 public DataBufferShort(short dataArray[][], int size, int offsets[]) { 180 super(UNTRACKABLE, TYPE_SHORT, size, dataArray.length, offsets); 181 bankdata = dataArray.clone(); 182 data = bankdata[0]; 183 } 184 185 /** 186 * Returns the default (first) byte data array. 187 * <p> 188 * Note that calling this method may cause this {@code DataBuffer} 189 * object to be incompatible with <a href="#optimizations">performance 190 * optimizations</a> used by some implementations (such as caching 191 * an associated image in video memory). 192 * 193 * @return The first short data array. 194 */ 195 public short[] getData() { 196 theTrackable.setUntrackable(); | 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 shorts. 42 * <p> 43 * <a name="optimizations"> 44 * Note that some implementations may function more efficiently 45 * if they can maintain control over how the data for an image is 46 * stored. 47 * For example, optimizations such as caching an image in video 48 * memory require that the implementation track all modifications 49 * to that data. 50 * Other implementations may operate better if they can store the 51 * data in locations other than a Java array. 52 * To maintain optimum compatibility with various optimizations 53 * it is best to avoid constructors and methods which expose the 54 * underlying storage as a Java array as noted below in the 55 * documentation for those methods. 56 * </a> 57 */ 58 public final class DataBufferShort extends DataBuffer 59 { 60 /** The default data bank. */ 61 short data[]; 62 63 /** All data banks */ 64 short bankdata[][]; 65 66 /** 67 * Constructs a short-based {@code DataBuffer} with a single bank and the 68 * specified size. 69 * 70 * @param size The size of the {@code DataBuffer}. 71 */ 72 public DataBufferShort(int size) { 73 super(STABLE, TYPE_SHORT,size); 74 data = new short[size]; 75 bankdata = new short[1][]; 76 bankdata[0] = data; 77 } 78 79 /** 80 * Constructs a short-based {@code DataBuffer} with the specified number of 81 * banks all of which are the specified size. 82 * 83 * @param size The size of the banks in the {@code DataBuffer}. 84 * @param numBanks The number of banks in the a {@code DataBuffer}. 85 */ 86 public DataBufferShort(int size, int numBanks) { 87 super(STABLE, TYPE_SHORT,size,numBanks); 88 bankdata = new short[numBanks][]; 89 for (int i= 0; i < numBanks; i++) { 90 bankdata[i] = new short[size]; 91 } 92 data = bankdata[0]; 93 } 94 95 /** 96 * Constructs a short-based {@code DataBuffer} with a single bank using the 97 * specified array. 98 * Only the first {@code size} elements should be used by accessors of 99 * this {@code DataBuffer}. {@code dataArray} must be large enough to 100 * hold {@code size} elements. 101 * <p> 102 * Note that {@code DataBuffer} objects created by this constructor 103 * may be incompatible with <a href="#optimizations">performance 104 * optimizations</a> used by some implementations (such as caching 105 * an associated image in video memory). 106 * 107 * @param dataArray The short array for the {@code DataBuffer}. 108 * @param size The size of the {@code DataBuffer} bank. 109 */ 110 public DataBufferShort(short dataArray[], int size) { 111 super(UNTRACKABLE, TYPE_SHORT, size); 112 data = dataArray; 113 bankdata = new short[1][]; 114 bankdata[0] = data; 115 } 116 117 /** 118 * Constructs a short-based {@code DataBuffer} with a single bank using the 119 * specified array, size, and offset. {@code dataArray} must have at least 120 * {@code offset} + {@code size} elements. Only elements {@code offset} 121 * through {@code offset} + {@code size} - 1 122 * should be used by accessors of this {@code DataBuffer}. 123 * <p> 124 * Note that {@code DataBuffer} objects created by this constructor 125 * may be incompatible with <a href="#optimizations">performance 126 * optimizations</a> used by some implementations (such as caching 127 * an associated image in video memory). 128 * 129 * @param dataArray The short array for the {@code DataBuffer}. 130 * @param size The size of the {@code DataBuffer} bank. 131 * @param offset The offset into the {@code dataArray}. 132 */ 133 public DataBufferShort(short dataArray[], int size, int offset) { 134 super(UNTRACKABLE, TYPE_SHORT, size, 1, offset); 135 data = dataArray; 136 bankdata = new short[1][]; 137 bankdata[0] = data; 138 } 139 140 /** 141 * Constructs a short-based {@code DataBuffer} with the specified arrays. 142 * The number of banks will be equal to {@code dataArray.length}. 143 * Only the first {@code size} elements of each array should be used by 144 * accessors of this {@code DataBuffer}. 145 * <p> 146 * Note that {@code DataBuffer} objects created by this constructor 147 * may be incompatible with <a href="#optimizations">performance 148 * optimizations</a> used by some implementations (such as caching 149 * an associated image in video memory). 150 * 151 * @param dataArray The short arrays for the {@code DataBuffer}. 152 * @param size The size of the banks in the {@code DataBuffer}. 153 */ 154 public DataBufferShort(short dataArray[][], int size) { 155 super(UNTRACKABLE, TYPE_SHORT, size, dataArray.length); 156 bankdata = dataArray.clone(); 157 data = bankdata[0]; 158 } 159 160 /** 161 * Constructs a short-based {@code DataBuffer} with the specified arrays, size, 162 * and offsets. 163 * The number of banks is equal to {@code dataArray.length}. Each array must 164 * be at least as large as {@code size} + the corresponding offset. There must 165 * be an entry in the offset array for each {@code dataArray} entry. For each 166 * bank, only elements {@code offset} through 167 * {@code offset} + {@code size} - 1 should be 168 * used by accessors of this {@code DataBuffer}. 169 * <p> 170 * Note that {@code DataBuffer} objects created by this constructor 171 * may be incompatible with <a href="#optimizations">performance 172 * optimizations</a> used by some implementations (such as caching 173 * an associated image in video memory). 174 * 175 * @param dataArray The short arrays for the {@code DataBuffer}. 176 * @param size The size of the banks in the {@code DataBuffer}. 177 * @param offsets The offsets into each array. 178 */ 179 public DataBufferShort(short dataArray[][], int size, int offsets[]) { 180 super(UNTRACKABLE, TYPE_SHORT, size, dataArray.length, offsets); 181 bankdata = dataArray.clone(); 182 data = bankdata[0]; 183 } 184 185 /** 186 * Returns the default (first) byte data array. 187 * <p> 188 * Note that calling this method may cause this {@code DataBuffer} 189 * object to be incompatible with <a href="#optimizations">performance 190 * optimizations</a> used by some implementations (such as caching 191 * an associated image in video memory). 192 * 193 * @return The first short data array. 194 */ 195 public short[] getData() { 196 theTrackable.setUntrackable(); |