src/share/classes/java/awt/image/DataBufferInt.java

Print this page


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


 137         bankdata = new int[1][];
 138         bankdata[0] = data;
 139     }
 140 
 141     /**
 142      * Constructs an integer-based <CODE>DataBuffer</CODE> with the specified arrays.
 143      * The number of banks will be equal to <CODE>dataArray.length</CODE>.
 144      * Only the first <CODE>size</CODE> elements of each array should be used by
 145      * accessors of this <CODE>DataBuffer</CODE>.
 146      * <p>
 147      * Note that {@code DataBuffer} objects created by this constructor
 148      * may be incompatible with <a href="#optimizations">performance
 149      * optimizations</a> used by some implementations (such as caching
 150      * an associated image in video memory).
 151      *
 152      * @param dataArray The integer arrays for the <CODE>DataBuffer</CODE>.
 153      * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
 154      */
 155     public DataBufferInt(int dataArray[][], int size) {
 156         super(UNTRACKABLE, TYPE_INT, size, dataArray.length);
 157         bankdata = (int [][]) dataArray.clone();
 158         data = bankdata[0];
 159     }
 160 
 161     /**
 162      * Constructs an integer-based <CODE>DataBuffer</CODE> with the specified arrays, size,
 163      * and offsets.
 164      * The number of banks is equal to <CODE>dataArray.length</CODE>.  Each array must
 165      * be at least as large as <CODE>size</CODE> + the corresponding offset.   There must
 166      * be an entry in the offset array for each <CODE>dataArray</CODE> entry.  For each
 167      * bank, only elements <CODE>offset</CODE> through
 168      * <CODE>offset</CODE> + <CODE>size</CODE> - 1 should be
 169      * used by accessors of this <CODE>DataBuffer</CODE>.
 170      * <p>
 171      * Note that {@code DataBuffer} objects created by this constructor
 172      * may be incompatible with <a href="#optimizations">performance
 173      * optimizations</a> used by some implementations (such as caching
 174      * an associated image in video memory).
 175      *
 176      * @param dataArray The integer arrays for the <CODE>DataBuffer</CODE>.
 177      * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
 178      * @param offsets The offsets into each array.
 179      */
 180     public DataBufferInt(int dataArray[][], int size, int offsets[]) {
 181         super(UNTRACKABLE, TYPE_INT, size, dataArray.length, offsets);
 182         bankdata = (int [][]) dataArray.clone();
 183         data = bankdata[0];
 184     }
 185 
 186     /**
 187      * Returns the default (first) int data array in <CODE>DataBuffer</CODE>.
 188      * <p>
 189      * Note that calling this method may cause this {@code DataBuffer}
 190      * object to be incompatible with <a href="#optimizations">performance
 191      * optimizations</a> used by some implementations (such as caching
 192      * an associated image in video memory).
 193      *
 194      * @return The first integer data array.
 195      */
 196     public int[] getData() {
 197         theTrackable.setUntrackable();
 198         return data;
 199     }
 200 
 201     /**
 202      * Returns the data array for the specified bank.


 209      * @param bank The bank whose data array you want to get.
 210      * @return The data array for the specified bank.
 211      */
 212     public int[] getData(int bank) {
 213         theTrackable.setUntrackable();
 214         return bankdata[bank];
 215     }
 216 
 217     /**
 218      * Returns the data arrays for all banks.
 219      * <p>
 220      * Note that calling this method may cause this {@code DataBuffer}
 221      * object to be incompatible with <a href="#optimizations">performance
 222      * optimizations</a> used by some implementations (such as caching
 223      * an associated image in video memory).
 224      *
 225      * @return All of the data arrays.
 226      */
 227     public int[][] getBankData() {
 228         theTrackable.setUntrackable();
 229         return (int [][]) bankdata.clone();
 230     }
 231 
 232     /**
 233      * Returns the requested data array element from the first (default) bank.
 234      *
 235      * @param i The data array element you want to get.
 236      * @return The requested data array element as an integer.
 237      * @see #setElem(int, int)
 238      * @see #setElem(int, int, int)
 239      */
 240     public int getElem(int i) {
 241         return data[i+offset];
 242     }
 243 
 244     /**
 245      * Returns the requested data array element from the specified bank.
 246      *
 247      * @param bank The bank from which you want to get a data array element.
 248      * @param i The data array element you want to get.
 249      * @return The requested data array element as an integer.


 261      * @param i The data array element you want to set.
 262      * @param val The integer value to which you want to set the data array element.
 263      * @see #getElem(int)
 264      * @see #getElem(int, int)
 265      */
 266     public void setElem(int i, int val) {
 267         data[i+offset] = val;
 268         theTrackable.markDirty();
 269     }
 270 
 271     /**
 272      * Sets the requested data array element in the specified bank
 273      * to the integer value <CODE>i</CODE>.
 274      * @param bank The bank in which you want to set the data array element.
 275      * @param i The data array element you want to set.
 276      * @param val The integer value to which you want to set the specified data array element.
 277      * @see #getElem(int)
 278      * @see #getElem(int, int)
 279      */
 280     public void setElem(int bank, int i, int val) {
 281         bankdata[bank][i+offsets[bank]] = (int)val;
 282         theTrackable.markDirty();
 283     }
 284 }
   1 /*
   2  * Copyright (c) 1997, 2014, 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


 137         bankdata = new int[1][];
 138         bankdata[0] = data;
 139     }
 140 
 141     /**
 142      * Constructs an integer-based <CODE>DataBuffer</CODE> with the specified arrays.
 143      * The number of banks will be equal to <CODE>dataArray.length</CODE>.
 144      * Only the first <CODE>size</CODE> elements of each array should be used by
 145      * accessors of this <CODE>DataBuffer</CODE>.
 146      * <p>
 147      * Note that {@code DataBuffer} objects created by this constructor
 148      * may be incompatible with <a href="#optimizations">performance
 149      * optimizations</a> used by some implementations (such as caching
 150      * an associated image in video memory).
 151      *
 152      * @param dataArray The integer arrays for the <CODE>DataBuffer</CODE>.
 153      * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
 154      */
 155     public DataBufferInt(int dataArray[][], int size) {
 156         super(UNTRACKABLE, TYPE_INT, size, dataArray.length);
 157         bankdata = dataArray.clone();
 158         data = bankdata[0];
 159     }
 160 
 161     /**
 162      * Constructs an integer-based <CODE>DataBuffer</CODE> with the specified arrays, size,
 163      * and offsets.
 164      * The number of banks is equal to <CODE>dataArray.length</CODE>.  Each array must
 165      * be at least as large as <CODE>size</CODE> + the corresponding offset.   There must
 166      * be an entry in the offset array for each <CODE>dataArray</CODE> entry.  For each
 167      * bank, only elements <CODE>offset</CODE> through
 168      * <CODE>offset</CODE> + <CODE>size</CODE> - 1 should be
 169      * used by accessors of this <CODE>DataBuffer</CODE>.
 170      * <p>
 171      * Note that {@code DataBuffer} objects created by this constructor
 172      * may be incompatible with <a href="#optimizations">performance
 173      * optimizations</a> used by some implementations (such as caching
 174      * an associated image in video memory).
 175      *
 176      * @param dataArray The integer arrays for the <CODE>DataBuffer</CODE>.
 177      * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
 178      * @param offsets The offsets into each array.
 179      */
 180     public DataBufferInt(int dataArray[][], int size, int offsets[]) {
 181         super(UNTRACKABLE, TYPE_INT, size, dataArray.length, offsets);
 182         bankdata = dataArray.clone();
 183         data = bankdata[0];
 184     }
 185 
 186     /**
 187      * Returns the default (first) int data array in <CODE>DataBuffer</CODE>.
 188      * <p>
 189      * Note that calling this method may cause this {@code DataBuffer}
 190      * object to be incompatible with <a href="#optimizations">performance
 191      * optimizations</a> used by some implementations (such as caching
 192      * an associated image in video memory).
 193      *
 194      * @return The first integer data array.
 195      */
 196     public int[] getData() {
 197         theTrackable.setUntrackable();
 198         return data;
 199     }
 200 
 201     /**
 202      * Returns the data array for the specified bank.


 209      * @param bank The bank whose data array you want to get.
 210      * @return The data array for the specified bank.
 211      */
 212     public int[] getData(int bank) {
 213         theTrackable.setUntrackable();
 214         return bankdata[bank];
 215     }
 216 
 217     /**
 218      * Returns the data arrays for all banks.
 219      * <p>
 220      * Note that calling this method may cause this {@code DataBuffer}
 221      * object to be incompatible with <a href="#optimizations">performance
 222      * optimizations</a> used by some implementations (such as caching
 223      * an associated image in video memory).
 224      *
 225      * @return All of the data arrays.
 226      */
 227     public int[][] getBankData() {
 228         theTrackable.setUntrackable();
 229         return bankdata.clone();
 230     }
 231 
 232     /**
 233      * Returns the requested data array element from the first (default) bank.
 234      *
 235      * @param i The data array element you want to get.
 236      * @return The requested data array element as an integer.
 237      * @see #setElem(int, int)
 238      * @see #setElem(int, int, int)
 239      */
 240     public int getElem(int i) {
 241         return data[i+offset];
 242     }
 243 
 244     /**
 245      * Returns the requested data array element from the specified bank.
 246      *
 247      * @param bank The bank from which you want to get a data array element.
 248      * @param i The data array element you want to get.
 249      * @return The requested data array element as an integer.


 261      * @param i The data array element you want to set.
 262      * @param val The integer value to which you want to set the data array element.
 263      * @see #getElem(int)
 264      * @see #getElem(int, int)
 265      */
 266     public void setElem(int i, int val) {
 267         data[i+offset] = val;
 268         theTrackable.markDirty();
 269     }
 270 
 271     /**
 272      * Sets the requested data array element in the specified bank
 273      * to the integer value <CODE>i</CODE>.
 274      * @param bank The bank in which you want to set the data array element.
 275      * @param i The data array element you want to set.
 276      * @param val The integer value to which you want to set the specified data array element.
 277      * @see #getElem(int)
 278      * @see #getElem(int, int)
 279      */
 280     public void setElem(int bank, int i, int val) {
 281         bankdata[bank][i+offsets[bank]] = val;
 282         theTrackable.markDirty();
 283     }
 284 }