Source Code Cross Referenced for PipelineUtil.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » ca » forklabs » media » jai » opimage » Java Source Code / Java DocumentationJava Source Code and Java Documentation

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 geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » Java Advanced Imaging » ca.forklabs.media.jai.opimage 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#) $Header: /cvs/jai-operators/src/main/ca/forklabs/media/jai/opimage/PipelineUtil.java,v 1.3 2007/07/05 18:26:59 forklabs Exp $
003:         *
004:         * Copyright (C) 2007  Forklabs Daniel Léonard
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         */
020:
021:        package ca.forklabs.media.jai.opimage;
022:
023:        import java.awt.RenderingHints;
024:        import java.awt.image.RenderedImage;
025:        import java.awt.image.renderable.ParameterBlock;
026:        import java.awt.image.renderable.RenderableImage;
027:        import java.util.Collection;
028:        import javax.media.jai.CollectionImage;
029:        import javax.media.jai.JAI;
030:        import ca.forklabs.media.jai.operator.PipelineDescriptor;
031:
032:        class PipelineUtil {
033:
034:            //---------------------------
035:            // Class variables
036:            //---------------------------
037:
038:            /**
039:             * Specializes the call to the correct JAI factory method.
040:             * @param   <T>   the type of image the specialization is for.
041:             */
042:            public static abstract class Specialization<T> {
043:
044:                /**
045:                 * Extracts the source object from the parameter block.
046:                 * @param   pb   the parameter block.
047:                 * @return   the source object.
048:                 */
049:                public abstract T getSource(ParameterBlock pb);
050:
051:                /**
052:                 * Calls the correct JAI factory method.
053:                 * @param   operator   the operator.
054:                 * @param   pb   the parameter block.
055:                 * @param   hints   rendering hints.
056:                 * @return   the image created.
057:                 */
058:                public abstract T create(String operator, ParameterBlock pb,
059:                        RenderingHints hints);
060:
061:            }
062:
063:            /** Specialization for the rendered pipeline. */
064:            public static final Specialization<RenderedImage> RENDERED = new Specialization<RenderedImage>() {
065:                @Override
066:                @SuppressWarnings("unchecked")
067:                public RenderedImage getSource(ParameterBlock pb) {
068:                    RenderedImage source = null;
069:
070:                    CollectionImage collection = (CollectionImage) pb
071:                            .getSource(0);
072:                    if (0 != collection.size()) {
073:                        source = (RenderedImage) collection.get(0);
074:                    }
075:
076:                    return source;
077:                }
078:
079:                @Override
080:                public RenderedImage create(String operator, ParameterBlock pb,
081:                        RenderingHints hints) {
082:                    RenderedImage image = JAI.create(operator, pb, hints);
083:                    return image;
084:                }
085:            };
086:
087:            /** Specialization for the renderable pipeline. */
088:            public static final Specialization<RenderableImage> RENDERABLE = new Specialization<RenderableImage>() {
089:                @Override
090:                @SuppressWarnings("unchecked")
091:                public RenderableImage getSource(ParameterBlock pb) {
092:                    RenderableImage source = null;
093:
094:                    CollectionImage collection = (CollectionImage) pb
095:                            .getSource(0);
096:                    if (0 != collection.size()) {
097:                        source = (RenderableImage) collection.get(0);
098:                    }
099:
100:                    return source;
101:                }
102:
103:                @Override
104:                public RenderableImage create(String operator,
105:                        ParameterBlock pb, RenderingHints hints) {
106:                    RenderableImage image = JAI.createRenderable(operator, pb,
107:                            hints);
108:                    return image;
109:                }
110:            };
111:
112:            /** Specialization for the collection pipeline. */
113:            public static final Specialization<Collection<?>> COLLECTION = new Specialization<Collection<?>>() {
114:                @Override
115:                public Collection<?> getSource(ParameterBlock pb) {
116:                    Collection<?> source = (Collection<?>) pb.getSource(0);
117:                    return source;
118:                }
119:
120:                @Override
121:                public Collection<?> create(String operator, ParameterBlock pb,
122:                        RenderingHints hints) {
123:                    Collection<?> image = JAI.createCollection(operator, pb,
124:                            hints);
125:                    return image;
126:                }
127:            };
128:
129:            /** Specialization for the renderable collection pipeline. */
130:            public static final Specialization<Collection<?>> RENDERABLE_COLLECTION = new Specialization<Collection<?>>() {
131:                @Override
132:                public Collection<?> getSource(ParameterBlock pb) {
133:                    Collection<?> source = (Collection<?>) pb.getSource(0);
134:                    return source;
135:                }
136:
137:                @Override
138:                public Collection<?> create(String operator, ParameterBlock pb,
139:                        RenderingHints hints) {
140:                    Collection<?> image = JAI.createRenderableCollection(
141:                            operator, pb, hints);
142:                    return image;
143:                }
144:            };
145:
146:            //---------------------------
147:            // Constructor
148:            //---------------------------
149:
150:            /**
151:             * Let no one instanciate.
152:             */
153:            private PipelineUtil() {
154:                // nothing
155:            }
156:
157:            //---------------------------
158:            // Class methods
159:            //---------------------------
160:
161:            /**
162:             * Gets the name of the operations.
163:             * @param   pb   the parameter block.
164:             * @return   the names.
165:             */
166:            public static String[] getOperators(ParameterBlock pb) {
167:                String[] operators = (String[]) pb
168:                        .getObjectParameter(PipelineDescriptor.OPERATIONS_PARAMETER_INDEX);
169:                return operators;
170:            }
171:
172:            /**
173:             * Gets the parameter of the operations.
174:             * @param   pb   the parameter block.
175:             * @return   the parameters.
176:             */
177:            public static ParameterBlock[] getParameters(ParameterBlock pb) {
178:                ParameterBlock[] parameters = (ParameterBlock[]) pb
179:                        .getObjectParameter(PipelineDescriptor.PARAMETERS_PARAMETER_INDEX);
180:                return parameters;
181:            }
182:
183:            /**
184:             * Does the pipeline.
185:             * @param   pb   the parameter block.
186:             * @param   hints   rendering hints.
187:             * @param   specialization   specialization depending on the mode.
188:             *
189:             * @param   <T>   the type of image.
190:             *
191:             * @return   the result of the pipeline.
192:             */
193:            @SuppressWarnings("unchecked")
194:            public static <T> T doPipeline(ParameterBlock pb,
195:                    RenderingHints hints, Specialization<T> specialization) {
196:                T source = specialization.getSource(pb);
197:                String[] operators = PipelineUtil.getOperators(pb);
198:                ParameterBlock[] parameters = PipelineUtil.getParameters(pb);
199:
200:                // for each operation, the source is
201:                // the sink of the last operation
202:                T sink = source;
203:                for (int i = 0, len = operators.length; i < len; i++) {
204:                    String operator = operators[i];
205:                    ParameterBlock parameter = parameters[i];
206:
207:                    if (null != sink) {
208:                        parameter.addSource(sink);
209:                    }
210:
211:                    sink = specialization.create(operator, parameter, hints);
212:                }
213:
214:                return sink;
215:            }
216:
217:        }
218:
219:        /*
220:         * $Log: PipelineUtil.java,v $
221:         * Revision 1.3  2007/07/05 18:26:59  forklabs
222:         * Now uses CollectionImage instead of lists.
223:         *
224:         * Revision 1.2  2007/06/13 18:57:21  forklabs
225:         * Changed parent to use CollectionDescriptor.
226:         *
227:         * Revision 1.1  2007/06/07 23:39:19  forklabs
228:         * Operator pipeline is now on all four modes.
229:         *
230:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.