Source Code Cross Referenced for EncodeDescriptor.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » javax » media » jai » operator » 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 » javax.media.jai.operator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: EncodeDescriptor.java,v $
003:         *
004:         * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * Use is subject to license terms.
007:         *
008:         * $Revision: 1.1 $
009:         * $Date: 2005/02/11 04:57:34 $
010:         * $State: Exp $
011:         */
012:        package javax.media.jai.operator;
013:
014:        import com.sun.media.jai.codec.ImageCodec;
015:        import com.sun.media.jai.codec.ImageEncodeParam;
016:        import java.awt.RenderingHints;
017:        import java.awt.image.RenderedImage;
018:        import java.awt.image.renderable.ParameterBlock;
019:        import java.io.File;
020:        import java.io.IOException;
021:        import java.io.OutputStream;
022:        import javax.media.jai.JAI;
023:        import javax.media.jai.OperationDescriptorImpl;
024:        import javax.media.jai.ParameterBlockJAI;
025:        import javax.media.jai.RenderedOp;
026:        import javax.media.jai.registry.RenderedRegistryMode;
027:
028:        /**
029:         * An <code>OperationDescriptor</code> describing the "Encode" operation.
030:         *
031:         * The "Encode" operation writes an image to a given <code>OutputStream</code>
032:         * in a specified format using the supplied encoding parameters.
033:         *
034:         * <p> The third parameter contains an instance of
035:         * <code>ImageEncodeParam</code> to be used during the decoding.  It
036:         * may be set to <code>null</code> in order to perform default
037:         * encoding, or equivalently may be omitted.  If
038:         * non-<code>null</code>, it must be of the correct class type for the
039:         * selected format.
040:         *
041:         * <p><b> The classes in the <code>com.sun.media.jai.codec</code>
042:         * package are not a committed part of the JAI API.  Future releases
043:         * of JAI will make use of new classes in their place.  This
044:         * class will change accordingly.</b>
045:         * 
046:         * <p><table border=1>
047:         * <caption>Resource List</caption>
048:         * <tr><th>Name</th>        <th>Value</th></tr>
049:         * <tr><td>GlobalName</td>  <td>encode</td></tr>
050:         * <tr><td>LocalName</td>   <td>encode</td></tr>
051:         * <tr><td>Vendor</td>      <td>com.sun.media.jai</td></tr>
052:         * <tr><td>Description</td> <td>Stores an image to an OutputStream.</td></tr>
053:         * <tr><td>DocURL</td>      <td>http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/EncodeDescriptor.html</td></tr>
054:         * <tr><td>Version</td>     <td>1.0</td></tr>
055:         * <tr><td>arg0Desc</td>    <td>The OutputStream to write to.</td></tr>
056:         * <tr><td>arg1Desc</td>    <td>The format of the created file.</td></tr>
057:         * <tr><td>arg2Desc</td>    <td>The encoding parameters.</td></tr>
058:         * </table></p>
059:         *
060:         * <p><table border=1>
061:         * <caption>Parameter List</caption>
062:         * <tr><th>Name</th>          <th>Class Type</th>
063:         *                            <th>Default Value</th></tr>
064:         * <tr><td>stream</td>        <td>java.io.OutputStream</td>
065:         *                            <td>NO_PARAMETER_DEFAULT</td>
066:         * <tr><td>format</td>        <td>java.lang.String</td>
067:         *                            <td>"tiff"</td>
068:         * <tr><td>param</td>         <td>com.sun.media.jai.codec.ImageEncodeParam</td>
069:         *                            <td>null</td>
070:         * </table></p>
071:         *
072:         * @see javax.media.jai.OperationDescriptor
073:         */
074:        public class EncodeDescriptor extends OperationDescriptorImpl {
075:
076:            /**
077:             * The resource strings that provide the general documentation and
078:             * specify the parameter list for the "Encode" operation.
079:             */
080:            private static final String[][] resources = {
081:                    { "GlobalName", "Encode" },
082:                    { "LocalName", "Encode" },
083:                    { "Vendor", "com.sun.media.jai" },
084:                    { "Description", JaiI18N.getString("EncodeDescriptor0") },
085:                    {
086:                            "DocURL",
087:                            "http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/operator/EncodeDescriptor.html" },
088:                    { "Version", JaiI18N.getString("DescriptorVersion") },
089:                    { "arg0Desc", JaiI18N.getString("EncodeDescriptor1") },
090:                    { "arg1Desc", JaiI18N.getString("EncodeDescriptor2") },
091:                    { "arg2Desc", JaiI18N.getString("EncodeDescriptor3") } };
092:
093:            /** The parameter names for the "Encode" operation. */
094:            private static final String[] paramNames = { "stream", "format",
095:                    "param" };
096:
097:            /** The parameter class types for the "Encode" operation. */
098:            private static final Class[] paramClasses = {
099:                    java.io.OutputStream.class, java.lang.String.class,
100:                    com.sun.media.jai.codec.ImageEncodeParam.class };
101:
102:            /** The parameter default values for the "Encode" operation. */
103:            private static final Object[] paramDefaults = {
104:                    NO_PARAMETER_DEFAULT, "tiff", null };
105:
106:            private static final String[] supportedModes = { "rendered" };
107:
108:            /** Constructor. */
109:            public EncodeDescriptor() {
110:                super (resources, supportedModes, 1, paramNames, paramClasses,
111:                        paramDefaults, null);
112:            }
113:
114:            /**
115:             * Validates the input source and parameters.
116:             *
117:             * <p> In addition to the standard checks performed by the
118:             * superclass method, this method checks that the format name is
119:             * recognized and is capable of encoding the source image using
120:             * the encoding parameter "param", if non-<code>null</code>.
121:             */
122:            public boolean validateArguments(String modeName,
123:                    ParameterBlock args, StringBuffer msg) {
124:
125:                if (!modeName.equalsIgnoreCase("rendered"))
126:                    return true;
127:
128:                // Fool the superclass method if length < 3
129:                if (args.getNumParameters() < 3) {
130:                    args = (ParameterBlock) args.clone();
131:                    args.set(null, 2);
132:                }
133:
134:                if (!super .validateArguments(modeName, args, msg)) {
135:                    return false;
136:                }
137:
138:                // Retrieve the format.
139:                String format = (String) args.getObjectParameter(1);
140:
141:                // Retrieve the associated ImageCodec.
142:                ImageCodec codec = ImageCodec.getCodec(format);
143:
144:                // Check for null codec.
145:                if (codec == null) {
146:                    msg.append(getName() + " "
147:                            + JaiI18N.getString("EncodeDescriptor4"));
148:                    return false;
149:                }
150:
151:                // Retrieve the ImageEncodeParam object.
152:                ImageEncodeParam param = (ImageEncodeParam) args
153:                        .getObjectParameter(2);
154:
155:                RenderedImage src = args.getRenderedSource(0);
156:
157:                // Verify that the image can be encoded with the given parameters.
158:                if (!codec.canEncodeImage(src, param)) {
159:                    msg.append(getName() + " "
160:                            + JaiI18N.getString("EncodeDescriptor5"));
161:                    return false;
162:                }
163:
164:                return true;
165:            }
166:
167:            /**
168:             * Returns true indicating that the operation should be rendered
169:             * immediately during a call to <code>JAI.create()</code>.
170:             *
171:             * @see javax.media.jai.OperationDescriptor
172:             */
173:            public boolean isImmediate() {
174:                return true;
175:            }
176:
177:            /**
178:             * Stores an image to an OutputStream.
179:             *
180:             * <p>Creates a <code>ParameterBlockJAI</code> from all
181:             * supplied arguments except <code>hints</code> and invokes
182:             * {@link JAI#create(String,ParameterBlock,RenderingHints)}.
183:             *
184:             * @see JAI
185:             * @see ParameterBlockJAI
186:             * @see RenderedOp
187:             *
188:             * @param source0 <code>RenderedImage</code> source 0.
189:             * @param stream The OutputStream to write to.
190:             * @param format The format of the created file.
191:             * May be <code>null</code>.
192:             * @param param The encoding parameters.
193:             * May be <code>null</code>.
194:             * @param hints The <code>RenderingHints</code> to use.
195:             * May be <code>null</code>.
196:             * @return The <code>RenderedOp</code> destination.
197:             * @throws IllegalArgumentException if <code>source0</code> is <code>null</code>.
198:             * @throws IllegalArgumentException if <code>stream</code> is <code>null</code>.
199:             */
200:            public static RenderedOp create(RenderedImage source0,
201:                    OutputStream stream, String format, ImageEncodeParam param,
202:                    RenderingHints hints) {
203:                ParameterBlockJAI pb = new ParameterBlockJAI("Encode",
204:                        RenderedRegistryMode.MODE_NAME);
205:
206:                pb.setSource("source0", source0);
207:
208:                pb.setParameter("stream", stream);
209:                pb.setParameter("format", format);
210:                pb.setParameter("param", param);
211:
212:                return JAI.create("Encode", pb, hints);
213:            }
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.