001: /*
002: * @(#)QtSubimage.java 1.12 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: package java.awt;
028:
029: import java.awt.image.CropImageFilter;
030: import java.awt.image.FilteredImageSource;
031: import java.awt.image.ImageObserver;
032:
033: /** @version 1.7, 03/13/02 */
034:
035: /** An offscreen image created by BufferedImage.getSubimage(int width, int height). As it is not
036: possible to create a graphics from an image produced
037: through the image producer/consumer model this class exists to allow us to get the graphics
038: for a subimage image. */
039:
040: class QtSubimage extends QtImage {
041: private int originX, originY;
042: private int subWidth, subHeight;
043:
044: QtSubimage(QtImage img, int x, int y, int width, int height) {
045: super (img);
046:
047: originX = x;
048: originY = y;
049:
050: subWidth = width;
051: subHeight = height;
052:
053: started = true;
054:
055: producer = new FilteredImageSource(img.getSource(),
056: new CropImageFilter(x, y, width, height));
057: }
058:
059: public Graphics getGraphics() {
060: return new QtGraphics(this , originX, originY);
061: }
062:
063: public int getRGB(int x, int y) {
064: if (x < 0 || y < 0 || x >= subWidth || y >= subHeight)
065: throw new java.lang.ArrayIndexOutOfBoundsException(x + y
066: * subWidth);
067:
068: return super .getRGB(x + originX, y + originY);
069: }
070:
071: public int[] getRGB(int startX, int startY, int w, int h,
072: int[] rgbArray, int offset, int scansize) {
073: if (startX < 0 || startY < 0 || startX + w > subWidth
074: || startY + h > subHeight)
075: throw new java.lang.ArrayIndexOutOfBoundsException(startX
076: + startY * subWidth);
077:
078: return super .getRGB(startX + originX, startY + originY, w, h,
079: rgbArray, offset, scansize);
080: }
081:
082: public void setRGB(int x, int y, int rgb) {
083: if (x < 0 || y < 0 || x >= subWidth || y >= subHeight)
084: throw new java.lang.ArrayIndexOutOfBoundsException(x + y
085: * subWidth);
086:
087: super .setRGB(x + originX, y + originY, rgb);
088: }
089:
090: public void setRGB(int startX, int startY, int w, int h,
091: int[] rgbArray, int offset, int scansize) {
092: if (startX < 0 || startY < 0 || startX + w > subWidth
093: || startY + h > subHeight)
094: throw new java.lang.ArrayIndexOutOfBoundsException(startX
095: + startY * subWidth);
096:
097: super .setRGB(startX + originX, startY + originY, w, h,
098: rgbArray, offset, scansize);
099: }
100:
101: public int getWidth() {
102: return subWidth;
103: }
104:
105: public int getWidth(ImageObserver observer) {
106: if (width == -1)
107: addObserver(observer);
108:
109: return subWidth;
110: }
111:
112: public int getHeight() {
113: return subHeight;
114: }
115:
116: public int getHeight(ImageObserver observer) {
117: if (height == -1)
118: addObserver(observer);
119:
120: return subHeight;
121: }
122:
123: void drawImage(int psd, int x, int y, Color bg) {
124: super .drawImage(psd, x, y, x + subWidth - 1, y + subHeight - 1,
125: originX, originY, originX + subWidth - 1, originY
126: + subHeight - 1, bg);
127: }
128:
129: void drawImage(int psd, int dx1, int dy1, int dx2, int dy2,
130: int sx1, int sy1, int sx2, int sy2, Color bg) {
131: super.drawImage(psd, dx1, dy1, dx2, dy2, sx1 + originX, sy1
132: + originY, sx2 + originX, sy2 + originY, bg);
133: }
134:
135: }
|