Home | History | Annotate | Download | only in image
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 /**
     18  * @author Igor V. Stolyarov
     19  * @version $Revision$
     20  */
     21 
     22 package java.awt.image;
     23 
     24 /**
     25  * The Class DataBufferInt is the subclass of DataBuffer for the case where the
     26  * underlying data is of type integer.
     27  *
     28  * @since Android 1.0
     29  */
     30 public final class DataBufferInt extends DataBuffer {
     31 
     32     /**
     33      * The data.
     34      */
     35     int data[][];
     36 
     37     /**
     38      * Instantiates a new data buffer of type integer.
     39      *
     40      * @param dataArrays
     41      *            the data arrays to copy the data from.
     42      * @param size
     43      *            the length (number of elements) to use from the data arrays.
     44      * @param offsets
     45      *            the starting indices for reading the data from the internal
     46      *            data arrays.
     47      */
     48     public DataBufferInt(int dataArrays[][], int size, int offsets[]) {
     49         super(TYPE_INT, size, dataArrays.length, offsets);
     50         data = dataArrays.clone();
     51     }
     52 
     53     /**
     54      * Instantiates a new data buffer of type integer.
     55      *
     56      * @param dataArrays
     57      *            the data arrays to copy the data from.
     58      * @param size
     59      *            the length (number of elements) to use from the data arrays.
     60      */
     61     public DataBufferInt(int dataArrays[][], int size) {
     62         super(TYPE_INT, size, dataArrays.length);
     63         data = dataArrays.clone();
     64     }
     65 
     66     /**
     67      * Instantiates a new data buffer of type integer with a single underlying
     68      * array of data.
     69      *
     70      * @param dataArray
     71      *            the data array to copy the data from.
     72      * @param size
     73      *            the length (number of elements) to use.
     74      * @param offset
     75      *            the starting index to use when reading the data.
     76      */
     77     public DataBufferInt(int dataArray[], int size, int offset) {
     78         super(TYPE_INT, size, 1, offset);
     79         data = new int[1][];
     80         data[0] = dataArray;
     81     }
     82 
     83     /**
     84      * Instantiates a new data buffer of type integer with a single underlying
     85      * array of data starting at index 0.
     86      *
     87      * @param dataArray
     88      *            the data array to copy the data from.
     89      * @param size
     90      *            the length (number of elements) to use.
     91      */
     92     public DataBufferInt(int dataArray[], int size) {
     93         super(TYPE_INT, size);
     94         data = new int[1][];
     95         data[0] = dataArray;
     96     }
     97 
     98     /**
     99      * Instantiates a new empty data buffer of type integer with offsets equal
    100      * to zero.
    101      *
    102      * @param size
    103      *            the length (number of elements) to use from the data arrays.
    104      * @param numBanks
    105      *            the number of data arrays to create.
    106      */
    107     public DataBufferInt(int size, int numBanks) {
    108         super(TYPE_INT, size, numBanks);
    109         data = new int[numBanks][];
    110         int i = 0;
    111         while (i < numBanks) {
    112             data[i++] = new int[size];
    113         }
    114     }
    115 
    116     /**
    117      * Instantiates a new empty data buffer of type integer with a single
    118      * underlying array of data starting at index 0.
    119      *
    120      * @param size
    121      *            the length (number of elements) to use.
    122      */
    123     public DataBufferInt(int size) {
    124         super(TYPE_INT, size);
    125         data = new int[1][];
    126         data[0] = new int[size];
    127     }
    128 
    129     @Override
    130     public void setElem(int bank, int i, int val) {
    131         data[bank][offsets[bank] + i] = val;
    132         notifyChanged();
    133     }
    134 
    135     @Override
    136     public void setElem(int i, int val) {
    137         data[0][offset + i] = val;
    138         notifyChanged();
    139     }
    140 
    141     @Override
    142     public int getElem(int bank, int i) {
    143         return data[bank][offsets[bank] + i];
    144     }
    145 
    146     /**
    147      * Gets the data of the specified internal data array.
    148      *
    149      * @param bank
    150      *            the index of the desired data array.
    151      * @return the data.
    152      */
    153     public int[] getData(int bank) {
    154         notifyTaken();
    155         return data[bank];
    156     }
    157 
    158     @Override
    159     public int getElem(int i) {
    160         return data[0][offset + i];
    161     }
    162 
    163     /**
    164      * Gets the bank data.
    165      *
    166      * @return the bank data.
    167      */
    168     public int[][] getBankData() {
    169         notifyTaken();
    170         return data.clone();
    171     }
    172 
    173     /**
    174      * Gets the data of the first data array.
    175      *
    176      * @return the data.
    177      */
    178     public int[] getData() {
    179         notifyTaken();
    180         return data[0];
    181     }
    182 }
    183