< prev index next >

src/java.desktop/share/classes/java/awt/image/DataBufferShort.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


  41  * This class extends {@code DataBuffer} and stores data internally as shorts.
  42  * <p>
  43  * <a id="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}.


  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();
 197         return data;
 198     }
 199 


   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


  41  * This class extends {@code DataBuffer} and stores data internally as shorts.
  42  * <p>
  43  * <a id="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}.


  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();
 197         return data;
 198     }
 199 


< prev index next >