Source Code Cross Referenced for CropImageFilter.java in  » 6.0-JDK-Modules » j2me » 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 » 6.0 JDK Modules » j2me » java.awt.image 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)CropImageFilter.java	1.15 06/10/10
003:         *
004:         * Copyright  1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation. 
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt). 
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA 
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions. 
025:         *
026:         */
027:
028:        package java.awt.image;
029:
030:        import java.awt.image.ImageConsumer;
031:        import java.awt.image.ColorModel;
032:        import java.util.Hashtable;
033:        import java.awt.Rectangle;
034:
035:        /**
036:         * An ImageFilter class for cropping images.
037:         * This class extends the basic ImageFilter Class to extract a given
038:         * rectangular region of an existing Image and provide a source for a
039:         * new image containing just the extracted region.  It is meant to
040:         * be used in conjunction with a FilteredImageSource object to produce
041:         * cropped versions of existing images.
042:         *
043:         * @see FilteredImageSource
044:         * @see ImageFilter
045:         *
046:         * @version	1.10 08/19/02
047:         * @author 	Jim Graham
048:         */
049:        public class CropImageFilter extends ImageFilter {
050:            int cropX;
051:            int cropY;
052:            int cropW;
053:            int cropH;
054:
055:            /**
056:             * Constructs a CropImageFilter that extracts the absolute rectangular
057:             * region of pixels from its source Image as specified by the x, y,
058:             * w, and h parameters.
059:             * @param x the x location of the top of the rectangle to be extracted
060:             * @param y the y location of the top of the rectangle to be extracted
061:             * @param w the width of the rectangle to be extracted
062:             * @param h the height of the rectangle to be extracted
063:             */
064:            public CropImageFilter(int x, int y, int w, int h) {
065:                cropX = x;
066:                cropY = y;
067:                cropW = w;
068:                cropH = h;
069:            }
070:
071:            /**
072:             * Passes along  the properties from the source object after adding a
073:             * property indicating the cropped region.
074:             */
075:            public void setProperties(Hashtable props) {
076:                props = (Hashtable) props.clone();
077:                props
078:                        .put("croprect", new Rectangle(cropX, cropY, cropW,
079:                                cropH));
080:                super .setProperties(props);
081:            }
082:
083:            /**
084:             * Override the source image's dimensions and pass the dimensions
085:             * of the rectangular cropped region to the ImageConsumer.
086:             * @see ImageConsumer
087:             */
088:            public void setDimensions(int w, int h) {
089:                consumer.setDimensions(cropW, cropH);
090:            }
091:
092:            /**
093:             * Determine whether the delivered byte pixels intersect the region to
094:             * be extracted and passes through only that subset of pixels that
095:             * appear in the output region.
096:             */
097:            public void setPixels(int x, int y, int w, int h, ColorModel model,
098:                    byte pixels[], int off, int scansize) {
099:                int x1 = x;
100:                if (x1 < cropX) {
101:                    x1 = cropX;
102:                }
103:                // 6232366.
104:                // int x2 = x + w;
105:                int x2 = addWithoutOverflow(x, w);
106:                if (x2 > cropX + cropW) {
107:                    x2 = cropX + cropW;
108:                }
109:                int y1 = y;
110:                if (y1 < cropY) {
111:                    y1 = cropY;
112:                }
113:                // 6232366.
114:                // int y2 = y + h;
115:                int y2 = addWithoutOverflow(y, h);
116:                if (y2 > cropY + cropH) {
117:                    y2 = cropY + cropH;
118:                }
119:                if (x1 >= x2 || y1 >= y2) {
120:                    return;
121:                }
122:                consumer.setPixels(x1 - cropX, y1 - cropY, (x2 - x1),
123:                        (y2 - y1), model, pixels, off + (y1 - y) * scansize
124:                                + (x1 - x), scansize);
125:            }
126:
127:            /**
128:             * Determine if the delivered int pixels intersect the region to
129:             * be extracted and pass through only that subset of pixels that
130:             * appear in the output region.
131:             */
132:            public void setPixels(int x, int y, int w, int h, ColorModel model,
133:                    int pixels[], int off, int scansize) {
134:                int x1 = x;
135:                if (x1 < cropX) {
136:                    x1 = cropX;
137:                }
138:                // 6232366.
139:                // int x2 = x + w;
140:                int x2 = addWithoutOverflow(x, w);
141:                if (x2 > cropX + cropW) {
142:                    x2 = cropX + cropW;
143:                }
144:                int y1 = y;
145:                if (y1 < cropY) {
146:                    y1 = cropY;
147:                }
148:                // 6232366.
149:                // int y2 = y + h;
150:                int y2 = addWithoutOverflow(y, h);
151:                if (y2 > cropY + cropH) {
152:                    y2 = cropY + cropH;
153:                }
154:                if (x1 >= x2 || y1 >= y2) {
155:                    return;
156:                }
157:                consumer.setPixels(x1 - cropX, y1 - cropY, (x2 - x1),
158:                        (y2 - y1), model, pixels, off + (y1 - y) * scansize
159:                                + (x1 - x), scansize);
160:            }
161:
162:            // 6232366.
163:            // TCK: ImageConsumer.setPixels(int,int,int,int,ColorModel,int[],int,int)
164:            // is not called for some cases.
165:            //check for potential overflow (see bug 4801285)
166:            private int addWithoutOverflow(int x, int w) {
167:                int x2 = x + w;
168:                if (x > 0 && w > 0 && x2 < 0) {
169:                    x2 = Integer.MAX_VALUE;
170:                } else if (x < 0 && w < 0 && x2 > 0) {
171:                    x2 = Integer.MIN_VALUE;
172:                }
173:                return x2;
174:            }
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.