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


001:        /*
002:         * $RCSfile: CodecRIFUtil.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.2 $
009:         * $Date: 2006/06/17 00:02:28 $
010:         * $State: Exp $
011:         */
012:        package com.sun.media.jai.opimage;
013:
014:        import java.awt.RenderingHints;
015:        import java.awt.image.RenderedImage;
016:        import java.awt.image.renderable.ParameterBlock;
017:        import java.awt.image.renderable.RenderedImageFactory;
018:        import java.io.IOException;
019:        import javax.media.jai.ImageLayout;
020:        import javax.media.jai.JAI;
021:        import javax.media.jai.OpImage;
022:        import javax.media.jai.TileCache;
023:        import javax.media.jai.util.ImagingException;
024:        import javax.media.jai.util.ImagingListener;
025:        import com.sun.media.jai.codec.ImageCodec;
026:        import com.sun.media.jai.codec.ImageDecoder;
027:        import com.sun.media.jai.codec.ImageDecodeParam;
028:        import com.sun.media.jai.codec.SeekableStream;
029:        import com.sun.media.jai.util.DisposableNullOpImage;
030:        import com.sun.media.jai.util.ImageUtil;
031:
032:        public class CodecRIFUtil {
033:
034:            private CodecRIFUtil() {
035:            }
036:
037:            public static RenderedImage create(String type,
038:                    ParameterBlock paramBlock, RenderingHints renderHints) {
039:                ImagingListener listener = ImageUtil
040:                        .getImagingListener(renderHints);
041:
042:                SeekableStream source = (SeekableStream) paramBlock
043:                        .getObjectParameter(0);
044:
045:                ImageDecodeParam param = null;
046:                if (paramBlock.getNumParameters() > 1) {
047:                    param = (ImageDecodeParam) paramBlock.getObjectParameter(1);
048:                }
049:                int page = 0;
050:                if (paramBlock.getNumParameters() > 2) {
051:                    page = paramBlock.getIntParameter(2);
052:                }
053:
054:                ImageDecoder dec = ImageCodec.createImageDecoder(type, source,
055:                        param);
056:                try {
057:                    int bound = OpImage.OP_IO_BOUND;
058:                    ImageLayout layout = RIFUtil
059:                            .getImageLayoutHint(renderHints);
060:
061:                    if (renderHints != null) {
062:                        RenderingHints.Key key;
063:
064:                        key = JAI.KEY_OPERATION_BOUND;
065:                        if (renderHints.containsKey(key)) {
066:                            bound = ((Integer) renderHints.get(key)).intValue();
067:                        }
068:                    }
069:
070:                    // Set flag indicating that a recovery may be attempted if
071:                    // an OutOfMemoryError occurs during the decodeAsRenderedImage()
072:                    // call - which is only possible if the stream can seek backwards.
073:                    boolean canAttemptRecovery = source.canSeekBackwards();
074:
075:                    // Save the stream position prior to decodeAsRenderedImage().
076:                    long streamPosition = Long.MIN_VALUE;
077:                    if (canAttemptRecovery) {
078:                        try {
079:                            streamPosition = source.getFilePointer();
080:                        } catch (IOException ioe) {
081:                            listener.errorOccurred(JaiI18N
082:                                    .getString("StreamRIF1"), ioe,
083:                                    CodecRIFUtil.class, false);
084:                            // Unset the recovery attempt flag but otherwise
085:                            // ignore the exception.
086:                            canAttemptRecovery = false;
087:                        }
088:                    }
089:
090:                    OpImage image = null;
091:                    try {
092:                        // Attempt to create an OpImage from the decoder image.
093:                        image = new DisposableNullOpImage(dec
094:                                .decodeAsRenderedImage(page), layout,
095:                                renderHints, bound);
096:                    } catch (OutOfMemoryError memoryError) {
097:                        // Ran out of memory - may be due to the decoder being
098:                        // obliged to read the entire image when it creates the
099:                        // RenderedImage it returns.
100:                        if (canAttemptRecovery) {
101:                            // First flush the cache if one is defined.
102:                            TileCache cache = image != null ? image
103:                                    .getTileCache() : RIFUtil
104:                                    .getTileCacheHint(renderHints);
105:                            if (cache != null) {
106:                                cache.flush();
107:                            }
108:
109:                            // Force garbage collection.
110:                            System.gc(); //slow
111:
112:                            // Reposition the stream before the previous decoding.
113:                            source.seek(streamPosition);
114:
115:                            // Retry image decoding.
116:                            image = new DisposableNullOpImage(dec
117:                                    .decodeAsRenderedImage(page), layout,
118:                                    renderHints, bound);
119:                        } else {
120:                            // Re-throw the error.
121:                            String message = JaiI18N.getString("CodecRIFUtil0");
122:                            listener.errorOccurred(message,
123:                                    new ImagingException(message, memoryError),
124:                                    CodecRIFUtil.class, false);
125:                            //                    throw memoryError;
126:                        }
127:                    }
128:
129:                    return image;
130:                } catch (Exception e) {
131:                    listener.errorOccurred(JaiI18N.getString("CodecRIFUtil1"),
132:                            e, CodecRIFUtil.class, false);
133:                    //            e.printStackTrace();
134:                    return null;
135:                }
136:            }
137:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.