< prev index next >

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

Print this page




  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
  42  * as integers.
  43  * <p>
  44  * <a name="optimizations">
  45  * Note that some implementations may function more efficiently
  46  * if they can maintain control over how the data for an image is
  47  * stored.
  48  * For example, optimizations such as caching an image in video
  49  * memory require that the implementation track all modifications
  50  * to that data.
  51  * Other implementations may operate better if they can store the
  52  * data in locations other than a Java array.
  53  * To maintain optimum compatibility with various optimizations
  54  * it is best to avoid constructors and methods which expose the
  55  * underlying storage as a Java array as noted below in the
  56  * documentation for those methods.
  57  * </a>
  58  */
  59 public final class DataBufferInt extends DataBuffer
  60 {
  61     /** The default data bank. */
  62     int data[];
  63 
  64     /** All data banks */
  65     int bankdata[][];
  66 
  67     /**
  68      * Constructs an integer-based <CODE>DataBuffer</CODE> with a single bank
  69      * and the specified size.
  70      *
  71      * @param size The size of the <CODE>DataBuffer</CODE>.
  72      */
  73     public DataBufferInt(int size) {
  74         super(STABLE, TYPE_INT, size);
  75         data = new int[size];
  76         bankdata = new int[1][];
  77         bankdata[0] = data;
  78     }
  79 
  80     /**
  81      * Constructs an integer-based <CODE>DataBuffer</CODE> with the specified number of
  82      * banks, all of which are the specified size.
  83      *
  84      * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
  85      * @param numBanks The number of banks in the a<CODE>DataBuffer</CODE>.
  86      */
  87     public DataBufferInt(int size, int numBanks) {
  88         super(STABLE, TYPE_INT, size, numBanks);
  89         bankdata = new int[numBanks][];
  90         for (int i= 0; i < numBanks; i++) {
  91             bankdata[i] = new int[size];
  92         }
  93         data = bankdata[0];
  94     }
  95 
  96     /**
  97      * Constructs an integer-based <CODE>DataBuffer</CODE> with a single bank using the
  98      * specified array.
  99      * Only the first <CODE>size</CODE> elements should be used by accessors of
 100      * this <CODE>DataBuffer</CODE>.  <CODE>dataArray</CODE> must be large enough to
 101      * hold <CODE>size</CODE> elements.
 102      * <p>
 103      * Note that {@code DataBuffer} objects created by this constructor
 104      * may be incompatible with <a href="#optimizations">performance
 105      * optimizations</a> used by some implementations (such as caching
 106      * an associated image in video memory).
 107      *
 108      * @param dataArray The integer array for the <CODE>DataBuffer</CODE>.
 109      * @param size The size of the <CODE>DataBuffer</CODE> bank.
 110      */
 111     public DataBufferInt(int dataArray[], int size) {
 112         super(UNTRACKABLE, TYPE_INT, size);
 113         data = dataArray;
 114         bankdata = new int[1][];
 115         bankdata[0] = data;
 116     }
 117 
 118     /**
 119      * Constructs an integer-based <CODE>DataBuffer</CODE> with a single bank using the
 120      * specified array, size, and offset.  <CODE>dataArray</CODE> must have at least
 121      * <CODE>offset</CODE> + <CODE>size</CODE> elements.  Only elements <CODE>offset</CODE>
 122      * through <CODE>offset</CODE> + <CODE>size</CODE> - 1
 123      * should be used by accessors of this <CODE>DataBuffer</CODE>.
 124      * <p>
 125      * Note that {@code DataBuffer} objects created by this constructor
 126      * may be incompatible with <a href="#optimizations">performance
 127      * optimizations</a> used by some implementations (such as caching
 128      * an associated image in video memory).
 129      *
 130      * @param dataArray The integer array for the <CODE>DataBuffer</CODE>.
 131      * @param size The size of the <CODE>DataBuffer</CODE> bank.
 132      * @param offset The offset into the <CODE>dataArray</CODE>.
 133      */
 134     public DataBufferInt(int dataArray[], int size, int offset) {
 135         super(UNTRACKABLE, TYPE_INT, size, 1, offset);
 136         data = dataArray;
 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.
 203      * <p>
 204      * Note that calling this method may cause this {@code DataBuffer}
 205      * object to be incompatible with <a href="#optimizations">performance
 206      * optimizations</a> used by some implementations (such as caching
 207      * an associated image in video memory).


 253     public int getElem(int bank, int i) {
 254         return bankdata[bank][i+offsets[bank]];
 255     }
 256 
 257     /**
 258      * Sets the requested data array element in the first (default) bank
 259      * to the specified value.
 260      *
 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 }


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


 253     public int getElem(int bank, int i) {
 254         return bankdata[bank][i+offsets[bank]];
 255     }
 256 
 257     /**
 258      * Sets the requested data array element in the first (default) bank
 259      * to the specified value.
 260      *
 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}.
 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 }
< prev index next >