1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17/** 18 * @author Igor V. Stolyarov 19 * @version $Revision$ 20 */ 21 22package java.awt.image; 23 24/** 25 * The Class DataBufferDouble is the subclass of DataBuffer for the case where 26 * the underlying data is of type double. 27 * 28 * @since Android 1.0 29 */ 30public final class DataBufferDouble extends DataBuffer { 31 32 /** 33 * The data. 34 */ 35 double data[][]; 36 37 /** 38 * Instantiates a new data buffer of type double. 39 * 40 * @param dataArrays 41 * the data arrays to copy the data from. 42 * @param size 43 * the length (number of elements) to use from the data arrays. 44 * @param offsets 45 * the starting indices for reading the data from the internal 46 * data arrays. 47 */ 48 public DataBufferDouble(double dataArrays[][], int size, int offsets[]) { 49 super(TYPE_DOUBLE, size, dataArrays.length, offsets); 50 data = dataArrays.clone(); 51 } 52 53 /** 54 * Instantiates a new data buffer of type double. 55 * 56 * @param dataArrays 57 * the data arrays to copy the data from. 58 * @param size 59 * the length (number of elements) to use from the data arrays. 60 */ 61 public DataBufferDouble(double dataArrays[][], int size) { 62 super(TYPE_DOUBLE, size, dataArrays.length); 63 data = dataArrays.clone(); 64 } 65 66 /** 67 * Instantiates a new data buffer of type double with a single underlying 68 * array of data. 69 * 70 * @param dataArray 71 * the data array to copy the data from. 72 * @param size 73 * the length (number of elements) to use. 74 * @param offset 75 * the starting index to use when reading the data. 76 */ 77 public DataBufferDouble(double dataArray[], int size, int offset) { 78 super(TYPE_DOUBLE, size, 1, offset); 79 data = new double[1][]; 80 data[0] = dataArray; 81 } 82 83 /** 84 * Instantiates a new data buffer of type double with a single underlying 85 * array of data starting at index 0. 86 * 87 * @param dataArray 88 * the data array to copy the data from. 89 * @param size 90 * the length (number of elements) to use. 91 */ 92 public DataBufferDouble(double dataArray[], int size) { 93 super(TYPE_DOUBLE, size); 94 data = new double[1][]; 95 data[0] = dataArray; 96 } 97 98 /** 99 * Instantiates a new empty data buffer of type double with offsets equal to 100 * zero. 101 * 102 * @param size 103 * the length (number of elements) to use from the data arrays. 104 * @param numBanks 105 * the number of data arrays to create. 106 */ 107 public DataBufferDouble(int size, int numBanks) { 108 super(TYPE_DOUBLE, size, numBanks); 109 data = new double[numBanks][]; 110 int i = 0; 111 while (i < numBanks) { 112 data[i++] = new double[size]; 113 } 114 } 115 116 /** 117 * Instantiates a new empty data buffer of type double with a single 118 * underlying array of data starting at index 0. 119 * 120 * @param size 121 * the length (number of elements) to use. 122 */ 123 public DataBufferDouble(int size) { 124 super(TYPE_DOUBLE, size); 125 data = new double[1][]; 126 data[0] = new double[size]; 127 } 128 129 @Override 130 public void setElem(int bank, int i, int val) { 131 data[bank][offsets[bank] + i] = val; 132 notifyChanged(); 133 } 134 135 @Override 136 public void setElemFloat(int bank, int i, float val) { 137 data[bank][offsets[bank] + i] = val; 138 notifyChanged(); 139 } 140 141 @Override 142 public void setElemDouble(int bank, int i, double val) { 143 data[bank][offsets[bank] + i] = val; 144 notifyChanged(); 145 } 146 147 @Override 148 public void setElem(int i, int val) { 149 data[0][offset + i] = val; 150 notifyChanged(); 151 } 152 153 @Override 154 public int getElem(int bank, int i) { 155 return (int)(data[bank][offsets[bank] + i]); 156 } 157 158 @Override 159 public float getElemFloat(int bank, int i) { 160 return (float)(data[bank][offsets[bank] + i]); 161 } 162 163 @Override 164 public double getElemDouble(int bank, int i) { 165 return data[bank][offsets[bank] + i]; 166 } 167 168 @Override 169 public void setElemFloat(int i, float val) { 170 data[0][offset + i] = val; 171 notifyChanged(); 172 } 173 174 @Override 175 public void setElemDouble(int i, double val) { 176 data[0][offset + i] = val; 177 notifyChanged(); 178 } 179 180 /** 181 * Gets the data of the specified internal data array. 182 * 183 * @param bank 184 * the index of the desired data array. 185 * @return the data. 186 */ 187 public double[] getData(int bank) { 188 notifyTaken(); 189 return data[bank]; 190 } 191 192 @Override 193 public int getElem(int i) { 194 return (int)(data[0][offset + i]); 195 } 196 197 @Override 198 public float getElemFloat(int i) { 199 return (float)(data[0][offset + i]); 200 } 201 202 @Override 203 public double getElemDouble(int i) { 204 return data[0][offset + i]; 205 } 206 207 /** 208 * Gets the bank data. 209 * 210 * @return the bank data. 211 */ 212 public double[][] getBankData() { 213 notifyTaken(); 214 return data.clone(); 215 } 216 217 /** 218 * Gets the data of the first data array. 219 * 220 * @return the data. 221 */ 222 public double[] getData() { 223 notifyTaken(); 224 return data[0]; 225 } 226} 227