source: trunk/gcc/libjava/gnu/java/awt/ComponentDataBlitOp.java

Last change on this file was 2, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.9 KB
Line 
1/* Copyright (C) 2000, 2002 Free Software Foundation
2
3This file is part of GNU Classpath.
4
5GNU Classpath is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation; either version 2, or (at your option)
8any later version.
9
10GNU Classpath is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with GNU Classpath; see the file COPYING. If not, write to the
17Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1802111-1307 USA.
19
20Linking this library statically or dynamically with other modules is
21making a combined work based on this library. Thus, the terms and
22conditions of the GNU General Public License cover the whole
23combination.
24
25As a special exception, the copyright holders of this library give you
26permission to link this library with independent modules to produce an
27executable, regardless of the license terms of these independent
28modules, and to copy and distribute the resulting executable under
29terms of your choice, provided that you also meet, for each linked
30independent module, the terms and conditions of the license of that
31module. An independent module is a module which is not derived from
32or based on this library. If you modify this library, you may extend
33this exception to your version of the library, but you are not
34obligated to do so. If you do not wish to do so, delete this
35exception statement from your version. */
36
37package gnu.java.awt;
38
39import java.awt.geom.*;
40import java.awt.image.*;
41import 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 */
53public 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}
Note: See TracBrowser for help on using the repository browser.