< prev index next >

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

Print this page


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


  42  * as integers.
  43  * <p>
  44  * <a id="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}.


  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 


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


  42  * as integers.
  43  * <p>
  44  * <a id="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}.


  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 


< prev index next >