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


001:        /*
002:         * $RCSfile: RandomIterFallback.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:43 $
010:         * $State: Exp $
011:         */
012:        package com.sun.media.jai.iterator;
013:
014:        import java.awt.Rectangle;
015:        import java.awt.image.DataBuffer;
016:        import java.awt.image.Raster;
017:        import java.awt.image.RenderedImage;
018:        import java.awt.image.SampleModel;
019:        import javax.media.jai.PlanarImage;
020:        import javax.media.jai.iterator.RandomIter;
021:
022:        /**
023:         * @since EA2
024:         */
025:        public class RandomIterFallback implements  RandomIter {
026:
027:            protected RenderedImage im;
028:            protected Rectangle boundsRect;
029:
030:            protected SampleModel sampleModel;
031:
032:            protected int xID;
033:            protected int yID;
034:            protected int sampleModelTranslateX;
035:            protected int sampleModelTranslateY;
036:            protected DataBuffer dataBuffer = null;
037:
038:            protected int boundsX;
039:            protected int boundsY;
040:
041:            protected int[] xTiles;
042:            protected int[] yTiles;
043:
044:            public RandomIterFallback(RenderedImage im, Rectangle bounds) {
045:                this .im = im;
046:
047:                Rectangle imBounds = new Rectangle(im.getMinX(), im.getMinY(),
048:                        im.getWidth(), im.getHeight());
049:                this .boundsRect = imBounds.intersection(bounds);
050:                this .sampleModel = im.getSampleModel();
051:
052:                int x = boundsRect.x;
053:                int y = boundsRect.y;
054:                int width = boundsRect.width;
055:                int height = boundsRect.height;
056:
057:                this .boundsX = boundsRect.x;
058:                this .boundsY = boundsRect.y;
059:                this .xTiles = new int[width];
060:                this .yTiles = new int[height];
061:
062:                int tileWidth = im.getTileWidth();
063:                int tileGridXOffset = im.getTileGridXOffset();
064:                int minTileX = PlanarImage.XToTileX(x, tileGridXOffset,
065:                        tileWidth);
066:                int offsetX = x
067:                        - PlanarImage.tileXToX(minTileX, tileGridXOffset,
068:                                tileWidth);
069:                int tileX = minTileX;
070:
071:                for (int i = 0; i < width; i++) {
072:                    xTiles[i] = tileX;
073:                    ++offsetX;
074:                    if (offsetX == tileWidth) {
075:                        ++tileX;
076:                        offsetX = 0;
077:                    }
078:                }
079:
080:                int tileHeight = im.getTileHeight();
081:                int tileGridYOffset = im.getTileGridYOffset();
082:                int minTileY = PlanarImage.YToTileY(y, tileGridYOffset,
083:                        tileHeight);
084:                int offsetY = y
085:                        - PlanarImage.tileYToY(minTileY, tileGridYOffset,
086:                                tileHeight);
087:                int tileY = minTileY;
088:
089:                for (int i = 0; i < height; i++) {
090:                    yTiles[i] = tileY;
091:                    ++offsetY;
092:                    if (offsetY == tileHeight) {
093:                        ++tileY;
094:                        offsetY = 0;
095:                    }
096:                }
097:            }
098:
099:            /**
100:             * Sets dataBuffer to the correct buffer for the pixel
101:             * (x, y) = (xLocal + boundsRect.x, yLocal + boundsRect.y).
102:             *
103:             * @param xLocal the X coordinate in the local coordinate system.
104:             * @param yLocal the Y coordinate in the local coordinate system.
105:             */
106:            private void makeCurrent(int xLocal, int yLocal) {
107:                int xIDNew = xTiles[xLocal];
108:                int yIDNew = yTiles[yLocal];
109:
110:                if ((xIDNew != xID) || (yIDNew != yID) || (dataBuffer == null)) {
111:                    xID = xIDNew;
112:                    yID = yIDNew;
113:                    Raster tile = im.getTile(xID, yID);
114:
115:                    this .dataBuffer = tile.getDataBuffer();
116:                    this .sampleModelTranslateX = tile
117:                            .getSampleModelTranslateX();
118:                    this .sampleModelTranslateY = tile
119:                            .getSampleModelTranslateY();
120:                }
121:            }
122:
123:            public int getSample(int x, int y, int b) {
124:                makeCurrent(x - boundsX, y - boundsY);
125:                return sampleModel.getSample(x - sampleModelTranslateX, y
126:                        - sampleModelTranslateY, b, dataBuffer);
127:            }
128:
129:            public float getSampleFloat(int x, int y, int b) {
130:                makeCurrent(x - boundsX, y - boundsY);
131:                return sampleModel.getSampleFloat(x - sampleModelTranslateX, y
132:                        - sampleModelTranslateY, b, dataBuffer);
133:            }
134:
135:            public double getSampleDouble(int x, int y, int b) {
136:                makeCurrent(x - boundsX, y - boundsY);
137:                return sampleModel.getSampleDouble(x - sampleModelTranslateX, y
138:                        - sampleModelTranslateY, b, dataBuffer);
139:            }
140:
141:            public int[] getPixel(int x, int y, int[] iArray) {
142:                makeCurrent(x - boundsX, y - boundsY);
143:                return sampleModel.getPixel(x - sampleModelTranslateX, y
144:                        - sampleModelTranslateY, iArray, dataBuffer);
145:            }
146:
147:            public float[] getPixel(int x, int y, float[] fArray) {
148:                makeCurrent(x - boundsX, y - boundsY);
149:                return sampleModel.getPixel(x - sampleModelTranslateX, y
150:                        - sampleModelTranslateY, fArray, dataBuffer);
151:            }
152:
153:            public double[] getPixel(int x, int y, double[] dArray) {
154:                makeCurrent(x - boundsX, y - boundsY);
155:                return sampleModel.getPixel(x - sampleModelTranslateX, y
156:                        - sampleModelTranslateY, dArray, dataBuffer);
157:            }
158:
159:            public void done() {
160:                xTiles = null;
161:                yTiles = null;
162:                dataBuffer = null;
163:            }
164:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.