Source Code Cross Referenced for WritableRaster.java in  » Apache-Harmony-Java-SE » java-package » java » awt » image » 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 » Apache Harmony Java SE » java package » java.awt.image 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Igor V. Stolyarov
019:         * @version $Revision$
020:         */package java.awt.image;
021:
022:        import java.awt.Point;
023:        import java.awt.Rectangle;
024:
025:        import org.apache.harmony.awt.internal.nls.Messages;
026:
027:        public class WritableRaster extends Raster {
028:
029:            protected WritableRaster(SampleModel sampleModel,
030:                    DataBuffer dataBuffer, Rectangle aRegion,
031:                    Point sampleModelTranslate, WritableRaster parent) {
032:                super (sampleModel, dataBuffer, aRegion, sampleModelTranslate,
033:                        parent);
034:            }
035:
036:            protected WritableRaster(SampleModel sampleModel,
037:                    DataBuffer dataBuffer, Point origin) {
038:                this (sampleModel, dataBuffer, new Rectangle(origin.x, origin.y,
039:                        sampleModel.width, sampleModel.height), origin, null);
040:            }
041:
042:            protected WritableRaster(SampleModel sampleModel, Point origin) {
043:                this (sampleModel, sampleModel.createDataBuffer(),
044:                        new Rectangle(origin.x, origin.y, sampleModel.width,
045:                                sampleModel.height), origin, null);
046:            }
047:
048:            public void setDataElements(int x, int y, Object inData) {
049:                sampleModel.setDataElements(x - sampleModelTranslateX, y
050:                        - sampleModelTranslateY, inData, dataBuffer);
051:            }
052:
053:            public void setDataElements(int x, int y, int w, int h,
054:                    Object inData) {
055:                sampleModel.setDataElements(x - sampleModelTranslateX, y
056:                        - sampleModelTranslateY, w, h, inData, dataBuffer);
057:            }
058:
059:            public WritableRaster createWritableChild(int parentX, int parentY,
060:                    int w, int h, int childMinX, int childMinY, int bandList[]) {
061:                if (w <= 0 || h <= 0) {
062:                    // awt.244=Width or Height of child Raster is less than or equal to zero
063:                    throw new RasterFormatException(Messages
064:                            .getString("awt.244")); //$NON-NLS-1$
065:                }
066:
067:                if (parentX < this .minX || parentX + w > this .minX + this .width) {
068:                    // awt.245=parentX disposes outside Raster
069:                    throw new RasterFormatException(Messages
070:                            .getString("awt.245")); //$NON-NLS-1$
071:                }
072:
073:                if (parentY < this .minY
074:                        || parentY + h > this .minY + this .height) {
075:                    // awt.246=parentY disposes outside Raster
076:                    throw new RasterFormatException(Messages
077:                            .getString("awt.246")); //$NON-NLS-1$
078:                }
079:
080:                if ((long) parentX + w > Integer.MAX_VALUE) {
081:                    // awt.247=parentX + w results in integer overflow
082:                    throw new RasterFormatException(Messages
083:                            .getString("awt.247")); //$NON-NLS-1$
084:                }
085:
086:                if ((long) parentY + h > Integer.MAX_VALUE) {
087:                    // awt.248=parentY + h results in integer overflow
088:                    throw new RasterFormatException(Messages
089:                            .getString("awt.248")); //$NON-NLS-1$
090:                }
091:
092:                if ((long) childMinX + w > Integer.MAX_VALUE) {
093:                    // awt.249=childMinX + w results in integer overflow
094:                    throw new RasterFormatException(Messages
095:                            .getString("awt.249")); //$NON-NLS-1$
096:                }
097:
098:                if ((long) childMinY + h > Integer.MAX_VALUE) {
099:                    // awt.24A=childMinY + h results in integer overflow
100:                    throw new RasterFormatException(Messages
101:                            .getString("awt.24A")); //$NON-NLS-1$
102:                }
103:
104:                SampleModel childModel;
105:
106:                if (bandList == null) {
107:                    childModel = sampleModel;
108:                } else {
109:                    childModel = sampleModel.createSubsetSampleModel(bandList);
110:                }
111:
112:                int childTranslateX = childMinX - parentX;
113:                int childTranslateY = childMinY - parentY;
114:
115:                return new WritableRaster(childModel, dataBuffer,
116:                        new Rectangle(childMinX, childMinY, w, h), new Point(
117:                                childTranslateX + sampleModelTranslateX,
118:                                childTranslateY + sampleModelTranslateY), this );
119:            }
120:
121:            public WritableRaster createWritableTranslatedChild(int childMinX,
122:                    int childMinY) {
123:                return createWritableChild(minX, minY, width, height,
124:                        childMinX, childMinY, null);
125:            }
126:
127:            public WritableRaster getWritableParent() {
128:                return (WritableRaster) parent;
129:            }
130:
131:            public void setRect(Raster srcRaster) {
132:                setRect(0, 0, srcRaster);
133:            }
134:
135:            public void setRect(int dx, int dy, Raster srcRaster) {
136:                int w = srcRaster.getWidth();
137:                int h = srcRaster.getHeight();
138:
139:                int srcX = srcRaster.getMinX();
140:                int srcY = srcRaster.getMinY();
141:
142:                int dstX = srcX + dx;
143:                int dstY = srcY + dy;
144:
145:                if (dstX < this .minX) {
146:                    int minOffX = this .minX - dstX;
147:                    w -= minOffX;
148:                    dstX = this .minX;
149:                    srcX += minOffX;
150:                }
151:
152:                if (dstY < this .minY) {
153:                    int minOffY = this .minY - dstY;
154:                    h -= minOffY;
155:                    dstY = this .minY;
156:                    srcY += minOffY;
157:                }
158:
159:                if (dstX + w > this .minX + this .width) {
160:                    int maxOffX = (dstX + w) - (this .minX + this .width);
161:                    w -= maxOffX;
162:                }
163:
164:                if (dstY + h > this .minY + this .height) {
165:                    int maxOffY = (dstY + h) - (this .minY + this .height);
166:                    h -= maxOffY;
167:                }
168:
169:                if (w <= 0 || h <= 0) {
170:                    return;
171:                }
172:
173:                switch (sampleModel.getDataType()) {
174:                case DataBuffer.TYPE_BYTE:
175:                case DataBuffer.TYPE_SHORT:
176:                case DataBuffer.TYPE_USHORT:
177:                case DataBuffer.TYPE_INT:
178:                    int iPixelsLine[] = null;
179:                    for (int i = 0; i < h; i++) {
180:                        iPixelsLine = srcRaster.getPixels(srcX, srcY + i, w, 1,
181:                                iPixelsLine);
182:                        setPixels(dstX, dstY + i, w, 1, iPixelsLine);
183:                    }
184:                    break;
185:
186:                case DataBuffer.TYPE_FLOAT:
187:                    float fPixelsLine[] = null;
188:                    for (int i = 0; i < h; i++) {
189:                        fPixelsLine = srcRaster.getPixels(srcX, srcY + i, w, 1,
190:                                fPixelsLine);
191:                        setPixels(dstX, dstY + i, w, 1, fPixelsLine);
192:                    }
193:                    break;
194:
195:                case DataBuffer.TYPE_DOUBLE:
196:                    double dPixelsLine[] = null;
197:                    for (int i = 0; i < h; i++) {
198:                        dPixelsLine = srcRaster.getPixels(srcX, srcY + i, w, 1,
199:                                dPixelsLine);
200:                        setPixels(dstX, dstY + i, w, 1, dPixelsLine);
201:                    }
202:                    break;
203:                }
204:            }
205:
206:            public void setDataElements(int x, int y, Raster inRaster) {
207:                int dstX = x + inRaster.getMinX();
208:                int dstY = y + inRaster.getMinY();
209:
210:                int w = inRaster.getWidth();
211:                int h = inRaster.getHeight();
212:
213:                if (dstX < this .minX || dstX + w > this .minX + this .width
214:                        || dstY < this .minY
215:                        || dstY + h > this .minY + this .height) {
216:                    // awt.63=Coordinates are not in bounds
217:                    throw new ArrayIndexOutOfBoundsException(Messages
218:                            .getString("awt.63")); //$NON-NLS-1$
219:                }
220:
221:                int srcX = inRaster.getMinX();
222:                int srcY = inRaster.getMinY();
223:                Object line = null;
224:
225:                for (int i = 0; i < h; i++) {
226:                    line = inRaster.getDataElements(srcX, srcY + i, w, 1, line);
227:                    setDataElements(dstX, dstY + i, w, 1, line);
228:                }
229:            }
230:
231:            public void setPixel(int x, int y, int iArray[]) {
232:                sampleModel.setPixel(x - sampleModelTranslateX, y
233:                        - sampleModelTranslateY, iArray, dataBuffer);
234:            }
235:
236:            public void setPixel(int x, int y, float fArray[]) {
237:                sampleModel.setPixel(x - sampleModelTranslateX, y
238:                        - sampleModelTranslateY, fArray, dataBuffer);
239:            }
240:
241:            public void setPixel(int x, int y, double dArray[]) {
242:                sampleModel.setPixel(x - sampleModelTranslateX, y
243:                        - sampleModelTranslateY, dArray, dataBuffer);
244:            }
245:
246:            public void setPixels(int x, int y, int w, int h, int iArray[]) {
247:                sampleModel.setPixels(x - sampleModelTranslateX, y
248:                        - sampleModelTranslateY, w, h, iArray, dataBuffer);
249:            }
250:
251:            public void setPixels(int x, int y, int w, int h, float fArray[]) {
252:                sampleModel.setPixels(x - sampleModelTranslateX, y
253:                        - sampleModelTranslateY, w, h, fArray, dataBuffer);
254:            }
255:
256:            public void setPixels(int x, int y, int w, int h, double dArray[]) {
257:                sampleModel.setPixels(x - sampleModelTranslateX, y
258:                        - sampleModelTranslateY, w, h, dArray, dataBuffer);
259:            }
260:
261:            public void setSamples(int x, int y, int w, int h, int b,
262:                    int iArray[]) {
263:                sampleModel.setSamples(x - sampleModelTranslateX, y
264:                        - sampleModelTranslateY, w, h, b, iArray, dataBuffer);
265:            }
266:
267:            public void setSamples(int x, int y, int w, int h, int b,
268:                    float fArray[]) {
269:                sampleModel.setSamples(x - sampleModelTranslateX, y
270:                        - sampleModelTranslateY, w, h, b, fArray, dataBuffer);
271:            }
272:
273:            public void setSamples(int x, int y, int w, int h, int b,
274:                    double dArray[]) {
275:                sampleModel.setSamples(x - sampleModelTranslateX, y
276:                        - sampleModelTranslateY, w, h, b, dArray, dataBuffer);
277:            }
278:
279:            public void setSample(int x, int y, int b, int s) {
280:                sampleModel.setSample(x - sampleModelTranslateX, y
281:                        - sampleModelTranslateY, b, s, dataBuffer);
282:            }
283:
284:            public void setSample(int x, int y, int b, float s) {
285:                sampleModel.setSample(x - sampleModelTranslateX, y
286:                        - sampleModelTranslateY, b, s, dataBuffer);
287:            }
288:
289:            public void setSample(int x, int y, int b, double s) {
290:                sampleModel.setSample(x - sampleModelTranslateX, y
291:                        - sampleModelTranslateY, b, s, dataBuffer);
292:            }
293:
294:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.