Source Code Cross Referenced for JPEGRegistryEntry.java in  » Graphic-Library » batik » org » apache » batik » ext » awt » image » codec » jpeg » 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 » Graphic Library » batik » org.apache.batik.ext.awt.image.codec.jpeg 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Licensed to the Apache Software Foundation (ASF) under one or more
004:           contributor license agreements.  See the NOTICE file distributed with
005:           this work for additional information regarding copyright ownership.
006:           The ASF licenses this file to You under the Apache License, Version 2.0
007:           (the "License"); you may not use this file except in compliance with
008:           the License.  You may obtain a copy of the License at
009:
010:               http://www.apache.org/licenses/LICENSE-2.0
011:
012:           Unless required by applicable law or agreed to in writing, software
013:           distributed under the License is distributed on an "AS IS" BASIS,
014:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:           See the License for the specific language governing permissions and
016:           limitations under the License.
017:
018:         */
019:        package org.apache.batik.ext.awt.image.codec.jpeg;
020:
021:        import java.awt.geom.Rectangle2D;
022:        import java.awt.image.BufferedImage;
023:        import java.awt.image.ColorModel;
024:        import java.awt.image.WritableRaster;
025:        import java.io.IOException;
026:        import java.io.InputStream;
027:
028:        import org.apache.batik.ext.awt.image.GraphicsUtil;
029:        import org.apache.batik.ext.awt.image.renderable.DeferRable;
030:        import org.apache.batik.ext.awt.image.renderable.Filter;
031:        import org.apache.batik.ext.awt.image.renderable.RedRable;
032:        import org.apache.batik.ext.awt.image.rendered.Any2sRGBRed;
033:        import org.apache.batik.ext.awt.image.rendered.FormatRed;
034:        import org.apache.batik.ext.awt.image.rendered.CachableRed;
035:        import org.apache.batik.ext.awt.image.spi.ImageTagRegistry;
036:        import org.apache.batik.ext.awt.image.spi.MagicNumberRegistryEntry;
037:        import org.apache.batik.util.ParsedURL;
038:
039:        import com.sun.image.codec.jpeg.JPEGCodec;
040:        import com.sun.image.codec.jpeg.JPEGImageDecoder;
041:        import com.sun.image.codec.jpeg.TruncatedFileException;
042:
043:        /**
044:         *
045:         * @version $Id: JPEGRegistryEntry.java 501094 2007-01-29 16:35:37Z deweese $
046:         */
047:        public class JPEGRegistryEntry extends MagicNumberRegistryEntry {
048:
049:            static final byte[] sigJPEG = { (byte) 0xFF, (byte) 0xd8,
050:                    (byte) 0xFF };
051:            static final String[] exts = { "jpeg", "jpg" };
052:            static final String[] mimeTypes = { "image/jpeg", "image/jpg" };
053:            static final MagicNumber[] magicNumbers = { new MagicNumber(0,
054:                    sigJPEG) };
055:
056:            public JPEGRegistryEntry() {
057:                super ("JPEG", exts, mimeTypes, magicNumbers);
058:            }
059:
060:            /**
061:             * Decode the Stream into a RenderableImage
062:             *
063:             * @param inIS The input stream that contains the image.
064:             * @param origURL The original URL, if any, for documentation
065:             *                purposes only.  This may be null.
066:             * @param needRawData If true the image returned should not have
067:             *                    any default color correction the file may
068:             *                    specify applied.
069:             */
070:            public Filter handleStream(InputStream inIS, ParsedURL origURL,
071:                    boolean needRawData) {
072:                final DeferRable dr = new DeferRable();
073:                final InputStream is = inIS;
074:                final String errCode;
075:                final Object[] errParam;
076:                if (origURL != null) {
077:                    errCode = ERR_URL_FORMAT_UNREADABLE;
078:                    errParam = new Object[] { "JPEG", origURL };
079:                } else {
080:                    errCode = ERR_STREAM_FORMAT_UNREADABLE;
081:                    errParam = new Object[] { "JPEG" };
082:                }
083:
084:                Thread t = new Thread() {
085:                    public void run() {
086:                        Filter filt;
087:                        try {
088:                            JPEGImageDecoder decoder;
089:                            decoder = JPEGCodec.createJPEGDecoder(is);
090:                            BufferedImage image;
091:                            try {
092:                                image = decoder.decodeAsBufferedImage();
093:                            } catch (TruncatedFileException tfe) {
094:                                image = tfe.getBufferedImage();
095:                                // Should probably draw some indication
096:                                // that this is a partial image....
097:                                if (image == null)
098:                                    throw new IOException(
099:                                            "JPEG File was truncated");
100:                            }
101:                            dr.setBounds(new Rectangle2D.Double(0, 0, image
102:                                    .getWidth(), image.getHeight()));
103:                            CachableRed cr;
104:                            cr = GraphicsUtil.wrap(image);
105:                            cr = new Any2sRGBRed(cr);
106:                            cr = new FormatRed(cr, GraphicsUtil.sRGB_Unpre);
107:                            WritableRaster wr = (WritableRaster) cr.getData();
108:                            ColorModel cm = cr.getColorModel();
109:                            image = new BufferedImage(cm, wr, cm
110:                                    .isAlphaPremultiplied(), null);
111:                            cr = GraphicsUtil.wrap(image);
112:                            filt = new RedRable(cr);
113:                        } catch (IOException ioe) {
114:                            // Something bad happened here...
115:                            filt = ImageTagRegistry.getBrokenLinkImage(
116:                                    JPEGRegistryEntry.this , errCode, errParam);
117:                        } catch (ThreadDeath td) {
118:                            filt = ImageTagRegistry.getBrokenLinkImage(
119:                                    JPEGRegistryEntry.this , errCode, errParam);
120:                            dr.setSource(filt);
121:                            throw td;
122:                        } catch (Throwable t) {
123:                            filt = ImageTagRegistry.getBrokenLinkImage(
124:                                    JPEGRegistryEntry.this, errCode, errParam);
125:                        }
126:
127:                        dr.setSource(filt);
128:                    }
129:                };
130:                t.start();
131:                return dr;
132:            }
133:        }
ww__w.___ja_v___a___2_s__.___c___o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.