Source Code Cross Referenced for DataBufferDouble.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>double</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 DataBufferDouble extends DataBuffer {
053
054            /** The array of data banks. */
055            double bankdata[][];
056
057            /** A reference to the default data bank. */
058            double data[];
059
060            /**
061             * Constructs a <code>double</code>-based <code>DataBuffer</code>
062             * with a specified size.
063             *
064             * @param size The number of elements in the <code>DataBuffer</code>.
065             */
066            public DataBufferDouble(int size) {
067                super (STABLE, TYPE_DOUBLE, size);
068                data = new double[size];
069                bankdata = new double[1][];
070                bankdata[0] = data;
071            }
072
073            /**
074             * Constructs a <code>double</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 <code>DataBuffer</code>.
081             */
082            public DataBufferDouble(int size, int numBanks) {
083                super (STABLE, TYPE_DOUBLE, size, numBanks);
084                bankdata = new double[numBanks][];
085                for (int i = 0; i < numBanks; i++) {
086                    bankdata[i] = new double[size];
087                }
088                data = bankdata[0];
089            }
090
091            /**
092             * Constructs a <code>double</code>-based <code>DataBuffer</code>
093             * with the specified data array.  Only the first
094             * <code>size</code> elements are available for use by this
095             * <code>DataBuffer</code>.  The array must be large enough to
096             * hold <code>size</code> elements.
097             * <p>
098             * Note that {@code DataBuffer} objects created by this constructor
099             * may be incompatible with <a href="#optimizations">performance
100             * optimizations</a> used by some implementations (such as caching
101             * an associated image in video memory).
102             *
103             * @param dataArray An array of <code>double</code>s to be used as the
104             *                  first and only bank of this <code>DataBuffer</code>.
105             * @param size The number of elements of the array to be used.
106             */
107            public DataBufferDouble(double dataArray[], int size) {
108                super (UNTRACKABLE, TYPE_DOUBLE, size);
109                data = dataArray;
110                bankdata = new double[1][];
111                bankdata[0] = data;
112            }
113
114            /**
115             * Constructs a <code>double</code>-based <code>DataBuffer</code>
116             * with the specified data array.  Only the elements between
117             * <code>offset</code> and <code>offset + size - 1</code> are
118             * available for use by this <code>DataBuffer</code>.  The array
119             * must be large enough to hold <code>offset + size</code> elements.
120             * <p>
121             * Note that {@code DataBuffer} objects created by this constructor
122             * may be incompatible with <a href="#optimizations">performance
123             * optimizations</a> used by some implementations (such as caching
124             * an associated image in video memory).
125             *
126             * @param dataArray An array of <code>double</code>s to be used as the
127             *                  first and only bank of this <code>DataBuffer</code>.
128             * @param size The number of elements of the array to be used.
129             * @param offset The offset of the first element of the array
130             *               that will be used.
131             */
132            public DataBufferDouble(double dataArray[], int size, int offset) {
133                super (UNTRACKABLE, TYPE_DOUBLE, size, 1, offset);
134                data = dataArray;
135                bankdata = new double[1][];
136                bankdata[0] = data;
137            }
138
139            /**
140             * Constructs a <code>double</code>-based <code>DataBuffer</code>
141             * with the specified data arrays.  Only the first
142             * <code>size</code> elements of each array are available for use
143             * by this <code>DataBuffer</code>.  The number of banks will be
144             * equal <code>to dataArray.length</code>.
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 An array of arrays of <code>double</code>s to be
152             *        used as the banks of this <code>DataBuffer</code>.
153             * @param size The number of elements of each array to be used.
154             */
155            public DataBufferDouble(double dataArray[][], int size) {
156                super (UNTRACKABLE, TYPE_DOUBLE, size, dataArray.length);
157                bankdata = (double[][]) dataArray.clone();
158                data = bankdata[0];
159            }
160
161            /**
162             * Constructs a <code>double</code>-based <code>DataBuffer</code>
163             * with the specified data arrays, size, and per-bank offsets.
164             * The number of banks is equal to dataArray.length.  Each array
165             * must be at least as large as <code>size</code> plus the
166             * corresponding offset.  There must be an entry in the
167             * <code>offsets</code> array for each data array.
168             * <p>
169             * Note that {@code DataBuffer} objects created by this constructor
170             * may be incompatible with <a href="#optimizations">performance
171             * optimizations</a> used by some implementations (such as caching
172             * an associated image in video memory).
173             *
174             * @param dataArray An array of arrays of <code>double</code>s to be
175             *        used as the banks of this <code>DataBuffer</code>.
176             * @param size The number of elements of each array to be used.
177             * @param offsets An array of integer offsets, one for each bank.
178             */
179            public DataBufferDouble(double dataArray[][], int size,
180                    int offsets[]) {
181                super (UNTRACKABLE, TYPE_DOUBLE, size, dataArray.length, offsets);
182                bankdata = (double[][]) dataArray.clone();
183                data = bankdata[0];
184            }
185
186            /** 
187             * Returns the default (first) <code>double</code> data array. 
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 double data array.
195             */
196            public double[] getData() {
197                theTrackable.setUntrackable();
198                return data;
199            }
200
201            /** 
202             * Returns the data array for the specified bank. 
203             * <p>
204             * Note that calling this method may cause this {@code DataBuffer}
205             * object to be incompatible with <a href="#optimizations">performance
206             * optimizations</a> used by some implementations (such as caching
207             * an associated image in video memory).
208             *
209             * @param bank the data array
210             * @return the data array specified by <code>bank</code>.
211             */
212            public double[] getData(int bank) {
213                theTrackable.setUntrackable();
214                return bankdata[bank];
215            }
216
217            /** 
218             * Returns the data array for all banks. 
219             * <p>
220             * Note that calling this method may cause this {@code DataBuffer}
221             * object to be incompatible with <a href="#optimizations">performance
222             * optimizations</a> used by some implementations (such as caching
223             * an associated image in video memory).
224             *
225             * @return all data arrays from this data buffer.
226             */
227            public double[][] getBankData() {
228                theTrackable.setUntrackable();
229                return (double[][]) bankdata.clone();
230            }
231
232            /**
233             * Returns the requested data array element from the first
234             * (default) bank as an <code>int</code>.
235             *
236             * @param i The desired data array element.
237             * @return The data entry as an <code>int</code>.
238             * @see #setElem(int, int)
239             * @see #setElem(int, int, int)
240             */
241            public int getElem(int i) {
242                return (int) (data[i + offset]);
243            }
244
245            /**
246             * Returns the requested data array element from the specified
247             * bank as an <code>int</code>.
248             *
249             * @param bank The bank number.
250             * @param i The desired data array element.
251             *
252             * @return The data entry as an <code>int</code>.
253             * @see #setElem(int, int)
254             * @see #setElem(int, int, int)
255             */
256            public int getElem(int bank, int i) {
257                return (int) (bankdata[bank][i + offsets[bank]]);
258            }
259
260            /**
261             * Sets the requested data array element in the first (default)
262             * bank to the given <code>int</code>.
263             *
264             * @param i The desired data array element.
265             * @param val The value to be set.
266             * @see #getElem(int)
267             * @see #getElem(int, int)
268             */
269            public void setElem(int i, int val) {
270                data[i + offset] = (double) val;
271                theTrackable.markDirty();
272            }
273
274            /**
275             * Sets the requested data array element in the specified bank
276             * to the given <code>int</code>.
277             *
278             * @param bank The bank number.
279             * @param i The desired data array element.
280             * @param val The value to be set.
281             * @see #getElem(int)
282             * @see #getElem(int, int)
283             */
284            public void setElem(int bank, int i, int val) {
285                bankdata[bank][i + offsets[bank]] = (double) val;
286                theTrackable.markDirty();
287            }
288
289            /**
290             * Returns the requested data array element from the first
291             * (default) bank as a <code>float</code>.
292             *
293             * @param i The desired data array element.
294             *
295             * @return The data entry as a <code>float</code>.
296             * @see #setElemFloat(int, float)
297             * @see #setElemFloat(int, int, float)
298             */
299            public float getElemFloat(int i) {
300                return (float) data[i + offset];
301            }
302
303            /**
304             * Returns the requested data array element from the specified
305             * bank as a <code>float</code>.
306             *
307             * @param bank The bank number.
308             * @param i The desired data array element.
309             *
310             * @return The data entry as a <code>float</code>.
311             * @see #setElemFloat(int, float)
312             * @see #setElemFloat(int, int, float)
313             */
314            public float getElemFloat(int bank, int i) {
315                return (float) bankdata[bank][i + offsets[bank]];
316            }
317
318            /**
319             * Sets the requested data array element in the first (default)
320             * bank to the given <code>float</code>.
321             *
322             * @param i The desired data array element.
323             * @param val The value to be set.
324             * @see #getElemFloat(int)
325             * @see #getElemFloat(int, int)
326             */
327            public void setElemFloat(int i, float val) {
328                data[i + offset] = (double) val;
329                theTrackable.markDirty();
330            }
331
332            /**
333             * Sets the requested data array element in the specified bank to
334             * the given <code>float</code>.
335             *
336             * @param bank The bank number.
337             * @param i The desired data array element.
338             * @param val The value to be set.
339             * @see #getElemFloat(int)       
340             * @see #getElemFloat(int, int)
341             */
342            public void setElemFloat(int bank, int i, float val) {
343                bankdata[bank][i + offsets[bank]] = (double) val;
344                theTrackable.markDirty();
345            }
346
347            /**
348             * Returns the requested data array element from the first
349             * (default) bank as a <code>double</code>.
350             *
351             * @param i The desired data array element.
352             *
353             * @return The data entry as a <code>double</code>.
354             * @see #setElemDouble(int, double)  
355             * @see #setElemDouble(int, int, double)
356             */
357            public double getElemDouble(int i) {
358                return data[i + offset];
359            }
360
361            /**
362             * Returns the requested data array element from the specified
363             * bank as a <code>double</code>.
364             *
365             * @param bank The bank number.
366             * @param i The desired data array element.
367             *
368             * @return The data entry as a <code>double</code>.
369             * @see #setElemDouble(int, double)
370             * @see #setElemDouble(int, int, double)
371             */
372            public double getElemDouble(int bank, int i) {
373                return bankdata[bank][i + offsets[bank]];
374            }
375
376            /**
377             * Sets the requested data array element in the first (default)
378             * bank to the given <code>double</code>.
379             *
380             * @param i The desired data array element.
381             * @param val The value to be set.
382             * @see #getElemDouble(int)
383             * @see #getElemDouble(int, int)
384             */
385            public void setElemDouble(int i, double val) {
386                data[i + offset] = val;
387                theTrackable.markDirty();
388            }
389
390            /**
391             * Sets the requested data array element in the specified bank to
392             * the given <code>double</code>.
393             *
394             * @param bank The bank number.
395             * @param i The desired data array element.
396             * @param val The value to be set.
397             * @see #getElemDouble(int)        
398             * @see #getElemDouble(int, int)
399             */
400            public void setElemDouble(int bank, int i, double val) {
401                bankdata[bank][i + offsets[bank]] = val;
402                theTrackable.markDirty();
403            }
404        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.