Source Code Cross Referenced for FormatCRIF.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: FormatCRIF.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: 2005/05/12 18:24:32 $
010:         * $State: Exp $
011:         */
012:        package com.sun.media.jai.opimage;
013:
014:        import java.awt.RenderingHints;
015:        import java.awt.image.ColorModel;
016:        import java.awt.image.RenderedImage;
017:        import java.awt.image.SampleModel;
018:        import java.awt.image.renderable.ParameterBlock;
019:        import java.util.Map;
020:        import javax.media.jai.CRIFImpl;
021:        import javax.media.jai.ImageLayout;
022:        import javax.media.jai.JAI;
023:        import javax.media.jai.OpImage;
024:        import javax.media.jai.NullOpImage;
025:        import javax.media.jai.RasterFactory;
026:        import com.sun.media.jai.util.JDKWorkarounds;
027:
028:        /**
029:         * A <code>CRIF</code> supporting the "Format" operation in the rendered
030:         * and renderable image layers.
031:         *
032:         * @see javax.media.jai.operator.FormatDescriptor
033:         * @see FormatOpImage
034:         *
035:         *
036:         * @since EA4
037:         */
038:        public class FormatCRIF extends CRIFImpl {
039:
040:            /** Constructor. */
041:            public FormatCRIF() {
042:                super ("format");
043:            }
044:
045:            /**
046:             * Creates a new instance of <code>FormatOpImage</code> in the
047:             * rendered layer.
048:             *
049:             * @param args   The source image and data type
050:             * @param hints  Contains destination image layout.
051:             */
052:            public RenderedImage create(ParameterBlock args,
053:                    RenderingHints renderHints) {
054:
055:                // Get the source image and the data type parameter.
056:                RenderedImage src = args.getRenderedSource(0);
057:                Integer datatype = (Integer) args.getObjectParameter(0);
058:                int type = datatype.intValue();
059:
060:                // Get ImageLayout from renderHints if any.
061:                ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
062:
063:                // If there is no change return the source image directly.
064:                if (layout == null
065:                        && type == src.getSampleModel().getDataType()) {
066:                    return src;
067:                }
068:
069:                // Create or clone the ImageLayout.
070:                if (layout == null) {
071:                    layout = new ImageLayout(src);
072:                } else {
073:                    layout = (ImageLayout) layout.clone();
074:                }
075:
076:                boolean isDataTypeChange = false;
077:
078:                // Get prospective destination SampleModel.
079:                SampleModel sampleModel = layout.getSampleModel(src);
080:
081:                // Create a new SampleModel if the type is not as desired.
082:                if (sampleModel.getDataType() != type) {
083:                    int tileWidth = layout.getTileWidth(src);
084:                    int tileHeight = layout.getTileHeight(src);
085:                    int numBands = src.getSampleModel().getNumBands();
086:
087:                    SampleModel csm = RasterFactory.createComponentSampleModel(
088:                            sampleModel, type, tileWidth, tileHeight, numBands);
089:
090:                    layout.setSampleModel(csm);
091:                    isDataTypeChange = true;
092:                }
093:
094:                // Check ColorModel.
095:                ColorModel colorModel = layout.getColorModel(null);
096:                if (colorModel != null
097:                        && !JDKWorkarounds.areCompatibleDataModels(layout
098:                                .getSampleModel(src), colorModel)) {
099:                    // Clear the mask bit if incompatible.
100:                    layout.unsetValid(ImageLayout.COLOR_MODEL_MASK);
101:                }
102:
103:                // Check whether anything but the ColorModel is changing.
104:                if (layout.getSampleModel(src) == src.getSampleModel()
105:                        && layout.getMinX(src) == src.getMinX()
106:                        && layout.getMinY(src) == src.getMinY()
107:                        && layout.getWidth(src) == src.getWidth()
108:                        && layout.getHeight(src) == src.getHeight()
109:                        && layout.getTileWidth(src) == src.getTileWidth()
110:                        && layout.getTileHeight(src) == src.getTileHeight()
111:                        && layout.getTileGridXOffset(src) == src
112:                                .getTileGridXOffset()
113:                        && layout.getTileGridYOffset(src) == src
114:                                .getTileGridYOffset()) {
115:
116:                    if (layout.getColorModel(src) == src.getColorModel()) {
117:                        // Nothing changed: return the source directly.
118:                        return src;
119:                    } else {
120:                        // Remove TileCache hint from RenderingHints if present.
121:                        RenderingHints hints = renderHints;
122:                        if (hints != null
123:                                && hints.containsKey(JAI.KEY_TILE_CACHE)) {
124:                            hints = new RenderingHints((Map) renderHints);
125:                            hints.remove(JAI.KEY_TILE_CACHE);
126:                        }
127:
128:                        // Only the ColorModel is changing.
129:                        return new NullOpImage(src, layout, hints,
130:                                OpImage.OP_IO_BOUND);
131:                    }
132:                }
133:
134:                if (isDataTypeChange == true) {
135:
136:                    // Add JAI.KEY_REPLACE_INDEX_COLOR_MODEL hint to renderHints
137:                    if (renderHints == null) {
138:                        renderHints = new RenderingHints(
139:                                JAI.KEY_REPLACE_INDEX_COLOR_MODEL, Boolean.TRUE);
140:
141:                    } else if (!renderHints
142:                            .containsKey(JAI.KEY_REPLACE_INDEX_COLOR_MODEL)) {
143:                        // If the user specified a value for this hint, we don't
144:                        // want to change that
145:                        renderHints.put(JAI.KEY_REPLACE_INDEX_COLOR_MODEL,
146:                                Boolean.TRUE);
147:                    }
148:                }
149:
150:                return new CopyOpImage(src, renderHints, layout);
151:            }
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.