0N/A/*
2362N/A * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.awt.image;
0N/A
0N/Aimport static sun.java2d.StateTrackable.State.*;
0N/A
0N/A/**
0N/A * This class extends <code>DataBuffer</code> and stores data internally
0N/A * in <code>float</code> form.
0N/A * <p>
0N/A * <a name="optimizations">
0N/A * Note that some implementations may function more efficiently
0N/A * if they can maintain control over how the data for an image is
0N/A * stored.
0N/A * For example, optimizations such as caching an image in video
0N/A * memory require that the implementation track all modifications
0N/A * to that data.
0N/A * Other implementations may operate better if they can store the
0N/A * data in locations other than a Java array.
0N/A * To maintain optimum compatibility with various optimizations
0N/A * it is best to avoid constructors and methods which expose the
0N/A * underlying storage as a Java array as noted below in the
0N/A * documentation for those methods.
0N/A * </a>
0N/A *
0N/A * @since 1.4
0N/A */
0N/A
0N/Apublic final class DataBufferFloat extends DataBuffer {
0N/A
0N/A /** The array of data banks. */
0N/A float bankdata[][];
0N/A
0N/A /** A reference to the default data bank. */
0N/A float data[];
0N/A
0N/A /**
0N/A * Constructs a <code>float</code>-based <code>DataBuffer</code>
0N/A * with a specified size.
0N/A *
0N/A * @param size The number of elements in the DataBuffer.
0N/A */
0N/A public DataBufferFloat(int size) {
0N/A super(STABLE, TYPE_FLOAT, size);
0N/A data = new float[size];
0N/A bankdata = new float[1][];
0N/A bankdata[0] = data;
0N/A }
0N/A
0N/A /**
0N/A * Constructs a <code>float</code>-based <code>DataBuffer</code>
0N/A * with a specified number of banks, all of which are of a
0N/A * specified size.
0N/A *
0N/A * @param size The number of elements in each bank of the
0N/A * <code>DataBuffer</code>.
0N/A * @param numBanks The number of banks in the
0N/A * <code>DataBuffer</code>.
0N/A */
0N/A public DataBufferFloat(int size, int numBanks) {
0N/A super(STABLE, TYPE_FLOAT, size, numBanks);
0N/A bankdata = new float[numBanks][];
0N/A for (int i= 0; i < numBanks; i++) {
0N/A bankdata[i] = new float[size];
0N/A }
0N/A data = bankdata[0];
0N/A }
0N/A
0N/A /**
0N/A * Constructs a <code>float</code>-based <code>DataBuffer</code>
0N/A * with the specified data array. Only the first
0N/A * <code>size</code> elements are available for use by this
0N/A * <code>DataBuffer</code>. The array must be large enough to
0N/A * hold <code>size</code> elements.
0N/A * <p>
0N/A * Note that {@code DataBuffer} objects created by this constructor
0N/A * may be incompatible with <a href="#optimizations">performance
0N/A * optimizations</a> used by some implementations (such as caching
0N/A * an associated image in video memory).
0N/A *
0N/A * @param dataArray An array of <code>float</code>s to be used as the
0N/A * first and only bank of this <code>DataBuffer</code>.
0N/A * @param size The number of elements of the array to be used.
0N/A */
0N/A public DataBufferFloat(float dataArray[], int size) {
0N/A super(UNTRACKABLE, TYPE_FLOAT, size);
0N/A data = dataArray;
0N/A bankdata = new float[1][];
0N/A bankdata[0] = data;
0N/A }
0N/A
0N/A /**
0N/A * Constructs a <code>float</code>-based <code>DataBuffer</code>
0N/A * with the specified data array. Only the elements between
0N/A * <code>offset</code> and <code>offset + size - 1</code> are
0N/A * available for use by this <code>DataBuffer</code>. The array
0N/A * must be large enough to hold <code>offset + size</code>
0N/A * elements.
0N/A * <p>
0N/A * Note that {@code DataBuffer} objects created by this constructor
0N/A * may be incompatible with <a href="#optimizations">performance
0N/A * optimizations</a> used by some implementations (such as caching
0N/A * an associated image in video memory).
0N/A *
0N/A * @param dataArray An array of <code>float</code>s to be used as the
0N/A * first and only bank of this <code>DataBuffer</code>.
0N/A * @param size The number of elements of the array to be used.
0N/A * @param offset The offset of the first element of the array
0N/A * that will be used.
0N/A */
0N/A public DataBufferFloat(float dataArray[], int size, int offset) {
0N/A super(UNTRACKABLE, TYPE_FLOAT, size, 1, offset);
0N/A data = dataArray;
0N/A bankdata = new float[1][];
0N/A bankdata[0] = data;
0N/A }
0N/A
0N/A /**
0N/A * Constructs a <code>float</code>-based <code>DataBuffer</code>
0N/A * with the specified data arrays. Only the first
0N/A * <code>size</code> elements of each array are available for use
0N/A * by this <code>DataBuffer</code>. The number of banks will be
0N/A * equal to <code>dataArray.length</code>.
0N/A * <p>
0N/A * Note that {@code DataBuffer} objects created by this constructor
0N/A * may be incompatible with <a href="#optimizations">performance
0N/A * optimizations</a> used by some implementations (such as caching
0N/A * an associated image in video memory).
0N/A *
0N/A * @param dataArray An array of arrays of <code>float</code>s to be
0N/A * used as the banks of this <code>DataBuffer</code>.
0N/A * @param size The number of elements of each array to be used.
0N/A */
0N/A public DataBufferFloat(float dataArray[][], int size) {
0N/A super(UNTRACKABLE, TYPE_FLOAT, size, dataArray.length);
0N/A bankdata = (float[][]) dataArray.clone();
0N/A data = bankdata[0];
0N/A }
0N/A
0N/A /**
0N/A * Constructs a <code>float</code>-based <code>DataBuffer</code>
0N/A * with the specified data arrays, size, and per-bank offsets.
0N/A * The number of banks is equal to <code>dataArray.length</code>.
0N/A * Each array must be at least as large as <code>size</code> plus the
0N/A * corresponding offset. There must be an entry in the offsets
0N/A * array for each data array.
0N/A * <p>
0N/A * Note that {@code DataBuffer} objects created by this constructor
0N/A * may be incompatible with <a href="#optimizations">performance
0N/A * optimizations</a> used by some implementations (such as caching
0N/A * an associated image in video memory).
0N/A *
0N/A * @param dataArray An array of arrays of <code>float</code>s to be
0N/A * used as the banks of this <code>DataBuffer</code>.
0N/A * @param size The number of elements of each array to be used.
0N/A * @param offsets An array of integer offsets, one for each bank.
0N/A */
0N/A public DataBufferFloat(float dataArray[][], int size, int offsets[]) {
0N/A super(UNTRACKABLE, TYPE_FLOAT, size,dataArray.length, offsets);
0N/A bankdata = (float[][]) dataArray.clone();
0N/A data = bankdata[0];
0N/A }
0N/A
0N/A /**
0N/A * Returns the default (first) <code>float</code> data array.
0N/A * <p>
0N/A * Note that calling this method may cause this {@code DataBuffer}
0N/A * object to be incompatible with <a href="#optimizations">performance
0N/A * optimizations</a> used by some implementations (such as caching
0N/A * an associated image in video memory).
0N/A *
0N/A * @return the first float data array.
0N/A */
0N/A public float[] getData() {
0N/A theTrackable.setUntrackable();
0N/A return data;
0N/A }
0N/A
0N/A /**
0N/A * Returns the data array for the specified bank.
0N/A * <p>
0N/A * Note that calling this method may cause this {@code DataBuffer}
0N/A * object to be incompatible with <a href="#optimizations">performance
0N/A * optimizations</a> used by some implementations (such as caching
0N/A * an associated image in video memory).
0N/A *
0N/A * @param bank the data array
0N/A * @return the data array specified by <code>bank</code>.
0N/A */
0N/A public float[] getData(int bank) {
0N/A theTrackable.setUntrackable();
0N/A return bankdata[bank];
0N/A }
0N/A
0N/A /**
0N/A * Returns the data array for all banks.
0N/A * <p>
0N/A * Note that calling this method may cause this {@code DataBuffer}
0N/A * object to be incompatible with <a href="#optimizations">performance
0N/A * optimizations</a> used by some implementations (such as caching
0N/A * an associated image in video memory).
0N/A *
0N/A * @return all data arrays for this data buffer.
0N/A */
0N/A public float[][] getBankData() {
0N/A theTrackable.setUntrackable();
0N/A return (float[][]) bankdata.clone();
0N/A }
0N/A
0N/A /**
0N/A * Returns the requested data array element from the first
0N/A * (default) bank as an <code>int</code>.
0N/A *
0N/A * @param i The desired data array element.
0N/A *
0N/A * @return The data entry as an <code>int</code>.
0N/A * @see #setElem(int, int)
0N/A * @see #setElem(int, int, int)
0N/A */
0N/A public int getElem(int i) {
0N/A return (int)(data[i+offset]);
0N/A }
0N/A
0N/A /**
0N/A * Returns the requested data array element from the specified
0N/A * bank as an <code>int</code>.
0N/A *
0N/A * @param bank The bank number.
0N/A * @param i The desired data array element.
0N/A *
0N/A * @return The data entry as an <code>int</code>.
0N/A * @see #setElem(int, int)
0N/A * @see #setElem(int, int, int)
0N/A */
0N/A public int getElem(int bank, int i) {
0N/A return (int)(bankdata[bank][i+offsets[bank]]);
0N/A }
0N/A
0N/A /**
0N/A * Sets the requested data array element in the first (default)
0N/A * bank to the given <code>int</code>.
0N/A *
0N/A * @param i The desired data array element.
0N/A * @param val The value to be set.
0N/A * @see #getElem(int)
0N/A * @see #getElem(int, int)
0N/A */
0N/A public void setElem(int i, int val) {
0N/A data[i+offset] = (float)val;
0N/A theTrackable.markDirty();
0N/A }
0N/A
0N/A /**
0N/A * Sets the requested data array element in the specified bank to
0N/A * the given <code>int</code>.
0N/A *
0N/A * @param bank The bank number.
0N/A * @param i The desired data array element.
0N/A * @param val The value to be set.
0N/A * @see #getElem(int)
0N/A * @see #getElem(int, int)
0N/A */
0N/A public void setElem(int bank, int i, int val) {
0N/A bankdata[bank][i+offsets[bank]] = (float)val;
0N/A theTrackable.markDirty();
0N/A }
0N/A
0N/A /**
0N/A * Returns the requested data array element from the first
0N/A * (default) bank as a <code>float</code>.
0N/A *
0N/A * @param i The desired data array element.
0N/A *
0N/A * @return The data entry as a <code>float</code>.
0N/A * @see #setElemFloat(int, float)
0N/A * @see #setElemFloat(int, int, float)
0N/A */
0N/A public float getElemFloat(int i) {
0N/A return data[i+offset];
0N/A }
0N/A
0N/A /**
0N/A * Returns the requested data array element from the specified
0N/A * bank as a <code>float</code>.
0N/A *
0N/A * @param bank The bank number.
0N/A * @param i The desired data array element.
0N/A *
0N/A * @return The data entry as a <code>float</code>.
0N/A * @see #setElemFloat(int, float)
0N/A * @see #setElemFloat(int, int, float)
0N/A */
0N/A public float getElemFloat(int bank, int i) {
0N/A return bankdata[bank][i+offsets[bank]];
0N/A }
0N/A
0N/A /**
0N/A * Sets the requested data array element in the first (default)
0N/A * bank to the given <code>float</code>.
0N/A *
0N/A * @param i The desired data array element.
0N/A * @param val The value to be set.
0N/A * @see #getElemFloat(int)
0N/A * @see #getElemFloat(int, int)
0N/A */
0N/A public void setElemFloat(int i, float val) {
0N/A data[i+offset] = val;
0N/A theTrackable.markDirty();
0N/A }
0N/A
0N/A /**
0N/A * Sets the requested data array element in the specified bank to
0N/A * the given <code>float</code>.
0N/A *
0N/A * @param bank The bank number.
0N/A * @param i The desired data array element.
0N/A * @param val The value to be set.
0N/A * @see #getElemFloat(int)
0N/A * @see #getElemFloat(int, int)
0N/A */
0N/A public void setElemFloat(int bank, int i, float val) {
0N/A bankdata[bank][i+offsets[bank]] = val;
0N/A theTrackable.markDirty();
0N/A }
0N/A
0N/A /**
0N/A * Returns the requested data array element from the first
0N/A * (default) bank as a <code>double</code>.
0N/A *
0N/A * @param i The desired data array element.
0N/A *
0N/A * @return The data entry as a <code>double</code>.
0N/A * @see #setElemDouble(int, double)
0N/A * @see #setElemDouble(int, int, double)
0N/A */
0N/A public double getElemDouble(int i) {
0N/A return (double)data[i+offset];
0N/A }
0N/A
0N/A /**
0N/A * Returns the requested data array element from the specified
0N/A * bank as a <code>double</code>.
0N/A *
0N/A * @param bank The bank number.
0N/A * @param i The desired data array element.
0N/A *
0N/A * @return The data entry as a <code>double</code>.
0N/A * @see #setElemDouble(int, double)
0N/A * @see #setElemDouble(int, int, double)
0N/A */
0N/A public double getElemDouble(int bank, int i) {
0N/A return (double)bankdata[bank][i+offsets[bank]];
0N/A }
0N/A
0N/A /**
0N/A * Sets the requested data array element in the first (default)
0N/A * bank to the given <code>double</code>.
0N/A *
0N/A * @param i The desired data array element.
0N/A * @param val The value to be set.
0N/A * @see #getElemDouble(int)
0N/A * @see #getElemDouble(int, int)
0N/A */
0N/A public void setElemDouble(int i, double val) {
0N/A data[i+offset] = (float)val;
0N/A theTrackable.markDirty();
0N/A }
0N/A
0N/A /**
0N/A * Sets the requested data array element in the specified bank to
0N/A * the given <code>double</code>.
0N/A *
0N/A * @param bank The bank number.
0N/A * @param i The desired data array element.
0N/A * @param val The value to be set.
0N/A * @see #getElemDouble(int)
0N/A * @see #getElemDouble(int, int)
0N/A */
0N/A public void setElemDouble(int bank, int i, double val) {
0N/A bankdata[bank][i+offsets[bank]] = (float)val;
0N/A theTrackable.markDirty();
0N/A }
0N/A}