Source Code Cross Referenced for DataBufferFloat.java in  » 6.0-JDK-Core » AWT » java » awt » image » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » AWT » java.awt.image 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 2000-2007 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025
026        package java.awt.image;
027
028        import static sun.java2d.StateTrackable.State.*;
029
030        /**
031         * This class extends <code>DataBuffer</code> and stores data internally
032         * in <code>float</code> form.
033         * <p>
034         * <a name="optimizations">
035         * Note that some implementations may function more efficiently
036         * if they can maintain control over how the data for an image is
037         * stored.
038         * For example, optimizations such as caching an image in video
039         * memory require that the implementation track all modifications
040         * to that data.
041         * Other implementations may operate better if they can store the
042         * data in locations other than a Java array.
043         * To maintain optimum compatibility with various optimizations
044         * it is best to avoid constructors and methods which expose the
045         * underlying storage as a Java array as noted below in the
046         * documentation for those methods.
047         * </a>
048         *
049         * @since 1.4
050         */
051
052        public final class DataBufferFloat extends DataBuffer {
053
054            /** The array of data banks. */
055            float bankdata[][];
056
057            /** A reference to the default data bank. */
058            float data[];
059
060            /**
061             * Constructs a <code>float</code>-based <code>DataBuffer</code>
062             * with a specified size.
063             *
064             * @param size The number of elements in the DataBuffer.
065             */
066            public DataBufferFloat(int size) {
067                super (STABLE, TYPE_FLOAT, size);
068                data = new float[size];
069                bankdata = new float[1][];
070                bankdata[0] = data;
071            }
072
073            /**
074             * Constructs a <code>float</code>-based <code>DataBuffer</code>
075             * with a specified number of banks, all of which are of a
076             * specified size.
077             *
078             * @param size The number of elements in each bank of the
079             * <code>DataBuffer</code>.
080             * @param numBanks The number of banks in the
081             *        <code>DataBuffer</code>.
082             */
083            public DataBufferFloat(int size, int numBanks) {
084                super (STABLE, TYPE_FLOAT, size, numBanks);
085                bankdata = new float[numBanks][];
086                for (int i = 0; i < numBanks; i++) {
087                    bankdata[i] = new float[size];
088                }
089                data = bankdata[0];
090            }
091
092            /**
093             * Constructs a <code>float</code>-based <code>DataBuffer</code>
094             * with the specified data array.  Only the first
095             * <code>size</code> elements are available for use by this
096             * <code>DataBuffer</code>.  The array must be large enough to
097             * hold <code>size</code> elements.
098             * <p>
099             * Note that {@code DataBuffer} objects created by this constructor
100             * may be incompatible with <a href="#optimizations">performance
101             * optimizations</a> used by some implementations (such as caching
102             * an associated image in video memory).
103             *
104             * @param dataArray An array of <code>float</code>s to be used as the
105             *                  first and only bank of this <code>DataBuffer</code>.
106             * @param size The number of elements of the array to be used.
107             */
108            public DataBufferFloat(float dataArray[], int size) {
109                super (UNTRACKABLE, TYPE_FLOAT, size);
110                data = dataArray;
111                bankdata = new float[1][];
112                bankdata[0] = data;
113            }
114
115            /**
116             * Constructs a <code>float</code>-based <code>DataBuffer</code>
117             * with the specified data array.  Only the elements between
118             * <code>offset</code> and <code>offset + size - 1</code> are
119             * available for use by this <code>DataBuffer</code>.  The array
120             * must be large enough to hold <code>offset + size</code>
121             * elements.
122             * <p>
123             * Note that {@code DataBuffer} objects created by this constructor
124             * may be incompatible with <a href="#optimizations">performance
125             * optimizations</a> used by some implementations (such as caching
126             * an associated image in video memory).
127             *
128             * @param dataArray An array of <code>float</code>s to be used as the
129             *                  first and only bank of this <code>DataBuffer</code>.
130             * @param size The number of elements of the array to be used.
131             * @param offset The offset of the first element of the array
132             *               that will be used.
133             */
134            public DataBufferFloat(float dataArray[], int size, int offset) {
135                super (UNTRACKABLE, TYPE_FLOAT, size, 1, offset);
136                data = dataArray;
137                bankdata = new float[1][];
138                bankdata[0] = data;
139            }
140
141            /**
142             * Constructs a <code>float</code>-based <code>DataBuffer</code>
143             * with the specified data arrays.  Only the first
144             * <code>size</code> elements of each array are available for use
145             * by this <code>DataBuffer</code>.  The number of banks will be
146             * equal to <code>dataArray.length</code>.
147             * <p>
148             * Note that {@code DataBuffer} objects created by this constructor
149             * may be incompatible with <a href="#optimizations">performance
150             * optimizations</a> used by some implementations (such as caching
151             * an associated image in video memory).
152             *
153             * @param dataArray An array of arrays of <code>float</code>s to be
154             *                  used as the banks of this <code>DataBuffer</code>.
155             * @param size The number of elements of each array to be used.
156             */
157            public DataBufferFloat(float dataArray[][], int size) {
158                super (UNTRACKABLE, TYPE_FLOAT, size, dataArray.length);
159                bankdata = (float[][]) dataArray.clone();
160                data = bankdata[0];
161            }
162
163            /**
164             * Constructs a <code>float</code>-based <code>DataBuffer</code>
165             * with the specified data arrays, size, and per-bank offsets.
166             * The number of banks is equal to <code>dataArray.length</code>.
167             * Each array must be at least as large as <code>size</code> plus the
168             * corresponding offset.  There must be an entry in the offsets
169             * array for each data array.
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 An array of arrays of <code>float</code>s to be
177             *                  used as the banks of this <code>DataBuffer</code>.
178             * @param size The number of elements of each array to be used.
179             * @param offsets An array of integer offsets, one for each bank.
180             */
181            public DataBufferFloat(float dataArray[][], int size, int offsets[]) {
182                super (UNTRACKABLE, TYPE_FLOAT, size, dataArray.length, offsets);
183                bankdata = (float[][]) dataArray.clone();
184                data = bankdata[0];
185            }
186
187            /** 
188             * Returns the default (first) <code>float</code> data array. 
189             * <p>
190             * Note that calling this method may cause this {@code DataBuffer}
191             * object to be incompatible with <a href="#optimizations">performance
192             * optimizations</a> used by some implementations (such as caching
193             * an associated image in video memory).
194             *
195             * @return the first float data array.     
196             */
197            public float[] getData() {
198                theTrackable.setUntrackable();
199                return data;
200            }
201
202            /** 
203             * Returns the data array for the specified bank. 
204             * <p>
205             * Note that calling this method may cause this {@code DataBuffer}
206             * object to be incompatible with <a href="#optimizations">performance
207             * optimizations</a> used by some implementations (such as caching
208             * an associated image in video memory).
209             *
210             * @param bank the data array
211             * @return the data array specified by <code>bank</code>.
212             */
213            public float[] getData(int bank) {
214                theTrackable.setUntrackable();
215                return bankdata[bank];
216            }
217
218            /** 
219             * Returns the data array for all banks. 
220             * <p>
221             * Note that calling this method may cause this {@code DataBuffer}
222             * object to be incompatible with <a href="#optimizations">performance
223             * optimizations</a> used by some implementations (such as caching
224             * an associated image in video memory).
225             *
226             * @return all data arrays for this data buffer.
227             */
228            public float[][] getBankData() {
229                theTrackable.setUntrackable();
230                return (float[][]) bankdata.clone();
231            }
232
233            /**
234             * Returns the requested data array element from the first
235             * (default) bank as an <code>int</code>.
236             *
237             * @param i The desired data array element.
238             *
239             * @return The data entry as an <code>int</code>.
240             * @see #setElem(int, int)
241             * @see #setElem(int, int, int)
242             */
243            public int getElem(int i) {
244                return (int) (data[i + offset]);
245            }
246
247            /**
248             * Returns the requested data array element from the specified
249             * bank as an <code>int</code>.
250             *
251             * @param bank The bank number.
252             * @param i The desired data array element.
253             *
254             * @return The data entry as an <code>int</code>.
255             * @see #setElem(int, int)
256             * @see #setElem(int, int, int)
257             */
258            public int getElem(int bank, int i) {
259                return (int) (bankdata[bank][i + offsets[bank]]);
260            }
261
262            /**
263             * Sets the requested data array element in the first (default)
264             * bank to the given <code>int</code>.
265             *
266             * @param i The desired data array element.
267             * @param val The value to be set.
268             * @see #getElem(int)
269             * @see #getElem(int, int)
270             */
271            public void setElem(int i, int val) {
272                data[i + offset] = (float) val;
273                theTrackable.markDirty();
274            }
275
276            /**
277             * Sets the requested data array element in the specified bank to
278             * the given <code>int</code>.
279             *
280             * @param bank The bank number.
281             * @param i The desired data array element.
282             * @param val The value to be set.
283             * @see #getElem(int)
284             * @see #getElem(int, int)
285             */
286            public void setElem(int bank, int i, int val) {
287                bankdata[bank][i + offsets[bank]] = (float) val;
288                theTrackable.markDirty();
289            }
290
291            /**
292             * Returns the requested data array element from the first
293             * (default) bank as a <code>float</code>.
294             *
295             * @param i The desired data array element.
296             *
297             * @return The data entry as a <code>float</code>.
298             * @see #setElemFloat(int, float)
299             * @see #setElemFloat(int, int, float)
300             */
301            public float getElemFloat(int i) {
302                return data[i + offset];
303            }
304
305            /**
306             * Returns the requested data array element from the specified
307             * bank as a <code>float</code>.
308             *
309             * @param bank The bank number.
310             * @param i The desired data array element.
311             *
312             * @return The data entry as a <code>float</code>.
313             * @see #setElemFloat(int, float)
314             * @see #setElemFloat(int, int, float)
315             */
316            public float getElemFloat(int bank, int i) {
317                return bankdata[bank][i + offsets[bank]];
318            }
319
320            /**
321             * Sets the requested data array element in the first (default)
322             * bank to the given <code>float</code>.
323             *
324             * @param i The desired data array element.
325             * @param val The value to be set.
326             * @see #getElemFloat(int)
327             * @see #getElemFloat(int, int)
328             */
329            public void setElemFloat(int i, float val) {
330                data[i + offset] = val;
331                theTrackable.markDirty();
332            }
333
334            /**
335             * Sets the requested data array element in the specified bank to
336             * the given <code>float</code>.
337             *
338             * @param bank The bank number.
339             * @param i The desired data array element.
340             * @param val The value to be set.
341             * @see #getElemFloat(int)       
342             * @see #getElemFloat(int, int)
343             */
344            public void setElemFloat(int bank, int i, float val) {
345                bankdata[bank][i + offsets[bank]] = val;
346                theTrackable.markDirty();
347            }
348
349            /**
350             * Returns the requested data array element from the first
351             * (default) bank as a <code>double</code>.
352             *
353             * @param i The desired data array element.
354             *
355             * @return The data entry as a <code>double</code>.
356             * @see #setElemDouble(int, double)  
357             * @see #setElemDouble(int, int, double)
358             */
359            public double getElemDouble(int i) {
360                return (double) data[i + offset];
361            }
362
363            /**
364             * Returns the requested data array element from the specified
365             * bank as a <code>double</code>.
366             *
367             * @param bank The bank number.
368             * @param i The desired data array element.
369             *
370             * @return The data entry as a <code>double</code>.
371             * @see #setElemDouble(int, double)
372             * @see #setElemDouble(int, int, double)
373             */
374            public double getElemDouble(int bank, int i) {
375                return (double) bankdata[bank][i + offsets[bank]];
376            }
377
378            /**
379             * Sets the requested data array element in the first (default)
380             * bank to the given <code>double</code>.
381             *
382             * @param i The desired data array element.
383             * @param val The value to be set.
384             * @see #getElemDouble(int)
385             * @see #getElemDouble(int, int)
386             */
387            public void setElemDouble(int i, double val) {
388                data[i + offset] = (float) val;
389                theTrackable.markDirty();
390            }
391
392            /**
393             * Sets the requested data array element in the specified bank to
394             * the given <code>double</code>.
395             *
396             * @param bank The bank number.
397             * @param i The desired data array element.
398             * @param val The value to be set.
399             * @see #getElemDouble(int)        
400             * @see #getElemDouble(int, int)
401             */
402            public void setElemDouble(int bank, int i, double val) {
403                bankdata[bank][i + offsets[bank]] = (float) val;
404                theTrackable.markDirty();
405            }
406        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.