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


001:        /*
002:         * $RCSfile: MlibBinarizeOpImage.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:55:51 $
010:         * $State: Exp $
011:         */
012:        package com.sun.media.jai.mlib;
013:
014:        import java.awt.image.RenderedImage;
015:        import javax.media.jai.ImageLayout;
016:        import javax.media.jai.Interpolation;
017:        import java.util.Map;
018:        import java.awt.Rectangle;
019:        import java.awt.image.Raster;
020:        import java.awt.image.WritableRaster;
021:        import java.awt.image.DataBuffer;
022:        import java.awt.image.SampleModel;
023:        import java.awt.image.ColorModel;
024:        import java.awt.image.PackedColorModel;
025:        import java.awt.image.MultiPixelPackedSampleModel;
026:        import javax.media.jai.ImageLayout;
027:        import javax.media.jai.PlanarImage;
028:        import javax.media.jai.PointOpImage;
029:        import com.sun.medialib.mlib.*;
030:        import com.sun.media.jai.util.ImageUtil;
031:        import com.sun.media.jai.util.JDKWorkarounds;
032:
033:        /**
034:         * A mediaLib class extending <code>PointOpImage</code> to
035:         * binarize images to bileval images.
036:         * <p> <pre>
037:         *   dst(i,j) = src(i,j) > threshvalue? 1: 0;
038:         *
039:         * @see com.sun.media.jai.operator.BinarizeOpImage
040:         * @see javax.media.jai.operator.BinarizeDescriptor
041:         *
042:         */
043:        class MlibBinarizeOpImage extends PointOpImage {
044:
045:            /** 
046:             * threshold value
047:             */
048:            private double thresh;
049:
050:            /**
051:             * Constructs a <code>MlibBinarizeOpImage</code> 
052:             * from a <code>RenderedImage</code> source, thresh value.
053:             * 
054:             * @param source a <code>RenderedImage</code>.
055:             * @param layout an <code>ImageLayout</code> optionally containing
056:             *        the tile grid layout, <code>SampleModel</code>, and
057:             *        <code>ColorModel</code>, or <code>null</code>.
058:
059:             *        from this <code>OpImage</code>, or <code>null</code>.  If
060:             *        <code>null</code>, no caching will be performed.
061:
062:             * @param thresh Threshold value.
063:             *
064:             * @throws IllegalArgumentException if combining the
065:             *         source bounds with the layout parameter results in negative
066:             *         output width or height.
067:             */
068:            public MlibBinarizeOpImage(RenderedImage source,
069:                    ImageLayout layout, Map config, double thresh) {
070:
071:                super (source, layoutHelper(source, layout, config), config,
072:                        true);
073:
074:                this .thresh = thresh;
075:            }
076:
077:            // set the OpImage's SM to be MultiPixelPackedSampleModel
078:            private static ImageLayout layoutHelper(RenderedImage source,
079:                    ImageLayout il, Map config) {
080:
081:                ImageLayout layout = (il == null) ? new ImageLayout()
082:                        : (ImageLayout) il.clone();
083:
084:                SampleModel sm = layout.getSampleModel(source);
085:                if (!ImageUtil.isBinary(sm)) {
086:                    sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
087:                            layout.getTileWidth(source), layout
088:                                    .getTileHeight(source), 1);
089:                    layout.setSampleModel(sm);
090:                }
091:
092:                ColorModel cm = layout.getColorModel(null);
093:                if (cm == null
094:                        || !JDKWorkarounds.areCompatibleDataModels(sm, cm)) {
095:                    layout.setColorModel(ImageUtil.getCompatibleColorModel(sm,
096:                            config));
097:                }
098:
099:                return layout;
100:            }
101:
102:            /**
103:             * 
104:             * @param sources   an array of sources, guarantee to provide all
105:             *                  necessary source data for computing the rectangle.
106:             * @param dest      a tile that contains the rectangle to be computed.
107:             * @param destRect  the rectangle within this OpImage to be processed.
108:             */
109:            protected void computeRect(Raster[] sources, WritableRaster dest,
110:                    Rectangle destRect) {
111:
112:                Raster source = sources[0];
113:
114:                Rectangle srcRect = mapDestRect(destRect, 0);
115:
116:                // Hack: derive the source format tag as if it was writing to
117:                // a destination with the same layout as itself.
118:                int sourceFormatTag = MediaLibAccessor.findCompatibleTag(
119:                        sources, source);
120:
121:                // Hard-code the destination format tag as we know that the image
122:                // has a binary layout.
123:                int destFormatTag = dest.getSampleModel().getDataType()
124:                        | MediaLibAccessor.BINARY | MediaLibAccessor.UNCOPIED;
125:
126:                MediaLibAccessor srcAccessor = new MediaLibAccessor(source,
127:                        srcRect, sourceFormatTag, false);
128:                MediaLibAccessor dstAccessor = new MediaLibAccessor(dest,
129:                        destRect, destFormatTag, true);
130:
131:                mediaLibImage srcML[], dstML[];
132:
133:                switch (srcAccessor.getDataType()) {
134:                case DataBuffer.TYPE_BYTE:
135:                case DataBuffer.TYPE_USHORT:
136:                case DataBuffer.TYPE_SHORT:
137:                case DataBuffer.TYPE_INT:
138:                    srcML = srcAccessor.getMediaLibImages();
139:                    dstML = dstAccessor.getMediaLibImages();
140:                    for (int i = 0; i < dstML.length; i++) {
141:                        //XXX
142:                        //medialib version is not inclusive
143:                        //pure java version is inclusive
144:                        //thus medialib version is the same
145:                        //as the java version with thresh value decremented by 1
146:                        Image.Thresh1(dstML[i], srcML[i],
147:                                new int[] { (int) thresh - 1 }, // decrease by 1
148:                                new int[] { 1 }, new int[] { 0 });
149:                    }
150:                    break;
151:                case DataBuffer.TYPE_FLOAT:
152:                case DataBuffer.TYPE_DOUBLE:
153:                    srcML = srcAccessor.getMediaLibImages();
154:                    dstML = dstAccessor.getMediaLibImages();
155:                    for (int i = 0; i < dstML.length; i++) {
156:                        Image.Thresh1_Fp(dstML[i], srcML[i],
157:                                new double[] { thresh }, new double[] { 1.0D },
158:                                new double[] { 0.0D });
159:                    }
160:                    break;
161:                default:
162:                    String className = this .getClass().getName();
163:                    throw new RuntimeException(JaiI18N.getString("Generic2"));
164:                }
165:
166:                if (dstAccessor.isDataCopy()) {
167:                    dstAccessor.clampDataArrays();
168:                    dstAccessor.copyDataToRaster();
169:                }
170:            }
171:
172:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.