Source Code Cross Referenced for Kernel.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 1997-1999 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        /**
029         * The <code>Kernel</code> class defines a matrix that describes how a 
030         * specified pixel and its surrounding pixels affect the value 
031         * computed for the pixel's position in the output image of a filtering
032         * operation.  The X origin and Y origin indicate the kernel matrix element
033         * that corresponds to the pixel position for which an output value is
034         * being computed.
035         *
036         * @see ConvolveOp
037         * @version 10 Feb 1997
038         */
039        public class Kernel implements  Cloneable {
040            private int width;
041            private int height;
042            private int xOrigin;
043            private int yOrigin;
044            private float data[];
045
046            private static native void initIDs();
047
048            static {
049                ColorModel.loadLibraries();
050                initIDs();
051            }
052
053            /**
054             * Constructs a <code>Kernel</code> object from an array of floats.  
055             * The first <code>width</code>*<code>height</code> elements of 
056             * the <code>data</code> array are copied.  
057             * If the length of the <code>data</code> array is less 
058             * than width*height, an <code>IllegalArgumentException</code> is thrown.
059             * The X origin is (width-1)/2 and the Y origin is (height-1)/2.
060             * @param width         width of the kernel
061             * @param height        height of the kernel
062             * @param data          kernel data in row major order
063             * @throws IllegalArgumentException if the length of <code>data</code>
064             *         is less than the product of <code>width</code> and 
065             *         <code>height</code>
066             */
067            public Kernel(int width, int height, float data[]) {
068                this .width = width;
069                this .height = height;
070                this .xOrigin = (width - 1) >> 1;
071                this .yOrigin = (height - 1) >> 1;
072                int len = width * height;
073                if (data.length < len) {
074                    throw new IllegalArgumentException("Data array too small "
075                            + "(is " + data.length + " and should be " + len);
076                }
077                this .data = new float[len];
078                System.arraycopy(data, 0, this .data, 0, len);
079
080            }
081
082            /**
083             * Returns the X origin of this <code>Kernel</code>.
084             * @return the X origin.
085             */
086            final public int getXOrigin() {
087                return xOrigin;
088            }
089
090            /**
091             * Returns the Y origin of this <code>Kernel</code>.
092             * @return the Y origin.
093             */
094            final public int getYOrigin() {
095                return yOrigin;
096            }
097
098            /**
099             * Returns the width of this <code>Kernel</code>.
100             * @return the width of this <code>Kernel</code>.
101             */
102            final public int getWidth() {
103                return width;
104            }
105
106            /**
107             * Returns the height of this <code>Kernel</code>.
108             * @return the height of this <code>Kernel</code>.
109             */
110            final public int getHeight() {
111                return height;
112            }
113
114            /**
115             * Returns the kernel data in row major order.  
116             * The <code>data</code> array is returned.  If <code>data</code> 
117             * is <code>null</code>, a new array is allocated.
118             * @param data  if non-null, contains the returned kernel data
119             * @return the <code>data</code> array containing the kernel data 
120             *         in row major order or, if <code>data</code> is 
121             *         <code>null</code>, a newly allocated array containing 
122             *         the kernel data in row major order
123             * @throws IllegalArgumentException if <code>data</code> is less
124             *         than the size of this <code>Kernel</code>
125             */
126            final public float[] getKernelData(float[] data) {
127                if (data == null) {
128                    data = new float[this .data.length];
129                } else if (data.length < this .data.length) {
130                    throw new IllegalArgumentException("Data array too small "
131                            + "(should be " + this .data.length + " but is "
132                            + data.length + " )");
133                }
134                System.arraycopy(this .data, 0, data, 0, this .data.length);
135
136                return data;
137            }
138
139            /**
140             * Clones this object.
141             * @return a clone of this object.
142             */
143            public Object clone() {
144                try {
145                    return super .clone();
146                } catch (CloneNotSupportedException e) {
147                    // this shouldn't happen, since we are Cloneable
148                    throw new InternalError();
149                }
150            }
151        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.