1 | /* Copyright (C) 2000, 2002 Free Software Foundation
|
---|
2 |
|
---|
3 | This file is part of GNU Classpath.
|
---|
4 |
|
---|
5 | GNU Classpath is free software; you can redistribute it and/or modify
|
---|
6 | it under the terms of the GNU General Public License as published by
|
---|
7 | the Free Software Foundation; either version 2, or (at your option)
|
---|
8 | any later version.
|
---|
9 |
|
---|
10 | GNU Classpath is distributed in the hope that it will be useful, but
|
---|
11 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
13 | General Public License for more details.
|
---|
14 |
|
---|
15 | You should have received a copy of the GNU General Public License
|
---|
16 | along with GNU Classpath; see the file COPYING. If not, write to the
|
---|
17 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
---|
18 | 02111-1307 USA.
|
---|
19 |
|
---|
20 | Linking this library statically or dynamically with other modules is
|
---|
21 | making a combined work based on this library. Thus, the terms and
|
---|
22 | conditions of the GNU General Public License cover the whole
|
---|
23 | combination.
|
---|
24 |
|
---|
25 | As a special exception, the copyright holders of this library give you
|
---|
26 | permission to link this library with independent modules to produce an
|
---|
27 | executable, regardless of the license terms of these independent
|
---|
28 | modules, and to copy and distribute the resulting executable under
|
---|
29 | terms of your choice, provided that you also meet, for each linked
|
---|
30 | independent module, the terms and conditions of the license of that
|
---|
31 | module. An independent module is a module which is not derived from
|
---|
32 | or based on this library. If you modify this library, you may extend
|
---|
33 | this exception to your version of the library, but you are not
|
---|
34 | obligated to do so. If you do not wish to do so, delete this
|
---|
35 | exception statement from your version. */
|
---|
36 |
|
---|
37 | package gnu.java.awt;
|
---|
38 |
|
---|
39 | import java.awt.geom.*;
|
---|
40 | import java.awt.image.*;
|
---|
41 | import java.awt.RenderingHints;
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * This raster copy operation assumes that both source and destination
|
---|
45 | * sample models are tightly pixel packed and contain the same number
|
---|
46 | * of bands.
|
---|
47 | *
|
---|
48 | * @throws java.lang.ClassCastException if the sample models of the
|
---|
49 | * rasters are not of type ComponentSampleModel.
|
---|
50 | *
|
---|
51 | * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
|
---|
52 | */
|
---|
53 | public class ComponentDataBlitOp implements RasterOp
|
---|
54 | {
|
---|
55 | public static ComponentDataBlitOp INSTANCE = new ComponentDataBlitOp();
|
---|
56 |
|
---|
57 | public WritableRaster filter(Raster src, WritableRaster dest)
|
---|
58 | {
|
---|
59 | if (dest == null)
|
---|
60 | dest = createCompatibleDestRaster(src);
|
---|
61 |
|
---|
62 | DataBuffer srcDB = src.getDataBuffer();
|
---|
63 | DataBuffer destDB = dest.getDataBuffer();
|
---|
64 |
|
---|
65 | ComponentSampleModel srcSM = (ComponentSampleModel) src.getSampleModel();
|
---|
66 | ComponentSampleModel destSM = (ComponentSampleModel) dest.getSampleModel();
|
---|
67 |
|
---|
68 |
|
---|
69 | // Calculate offset to data in the underlying arrays:
|
---|
70 |
|
---|
71 | int srcScanlineStride = srcSM.getScanlineStride();
|
---|
72 | int destScanlineStride = destSM.getScanlineStride();
|
---|
73 | int srcX = src.getMinX() - src.getSampleModelTranslateX();
|
---|
74 | int srcY = src.getMinY() - src.getSampleModelTranslateY();
|
---|
75 | int destX = dest.getMinX() - dest.getSampleModelTranslateX();
|
---|
76 | int destY = dest.getMinY() - dest.getSampleModelTranslateY();
|
---|
77 |
|
---|
78 | int numBands = srcSM.getNumBands();
|
---|
79 |
|
---|
80 | /* We can't use getOffset(x, y) from the sample model since we
|
---|
81 | don't want the band offset added in. */
|
---|
82 |
|
---|
83 | int srcOffset =
|
---|
84 | numBands*srcX + srcScanlineStride*srcY + // from sample model
|
---|
85 | srcDB.getOffset(); // from data buffer
|
---|
86 |
|
---|
87 | int destOffset =
|
---|
88 | numBands*destX + destScanlineStride*destY + // from sample model
|
---|
89 | destDB.getOffset(); // from data buffer
|
---|
90 |
|
---|
91 | // Determine how much, and how many times to blit.
|
---|
92 |
|
---|
93 | int rowSize = src.getWidth()*numBands;
|
---|
94 | int h = src.getHeight();
|
---|
95 |
|
---|
96 | if ((rowSize == srcScanlineStride) &&
|
---|
97 | (rowSize == destScanlineStride))
|
---|
98 | {
|
---|
99 | // collapse scan line blits to one large blit.
|
---|
100 | rowSize *= h;
|
---|
101 | h = 1;
|
---|
102 | }
|
---|
103 |
|
---|
104 |
|
---|
105 | // Do blitting
|
---|
106 |
|
---|
107 | Object srcArray = Buffers.getData(srcDB);
|
---|
108 | Object destArray = Buffers.getData(destDB);
|
---|
109 |
|
---|
110 | for (int yd = 0; yd<h; yd++)
|
---|
111 | {
|
---|
112 | System.arraycopy(srcArray, srcOffset,
|
---|
113 | destArray, destOffset,
|
---|
114 | rowSize);
|
---|
115 | srcOffset += srcScanlineStride;
|
---|
116 | destOffset += destScanlineStride;
|
---|
117 | }
|
---|
118 |
|
---|
119 |
|
---|
120 | return dest;
|
---|
121 | }
|
---|
122 |
|
---|
123 | public Rectangle2D getBounds2D(Raster src)
|
---|
124 | {
|
---|
125 | return src.getBounds();
|
---|
126 | }
|
---|
127 |
|
---|
128 | public WritableRaster createCompatibleDestRaster(Raster src) {
|
---|
129 |
|
---|
130 | /* FIXME: Maybe we should explicitly create a raster with a
|
---|
131 | tightly pixel packed sample model, rather than assuming
|
---|
132 | that the createCompatibleWritableRaster() method in Raster
|
---|
133 | will create one. */
|
---|
134 |
|
---|
135 | return src.createCompatibleWritableRaster();
|
---|
136 | }
|
---|
137 |
|
---|
138 | public Point2D getPoint2D(Point2D srcPoint, Point2D destPoint)
|
---|
139 | {
|
---|
140 | if (destPoint == null)
|
---|
141 | return (Point2D) srcPoint.clone();
|
---|
142 |
|
---|
143 | destPoint.setLocation(srcPoint);
|
---|
144 | return destPoint;
|
---|
145 | }
|
---|
146 |
|
---|
147 | public RenderingHints getRenderingHints()
|
---|
148 | {
|
---|
149 | throw new UnsupportedOperationException("not implemented");
|
---|
150 | }
|
---|
151 | }
|
---|