01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Igor V. Stolyarov
19: * @version $Revision$
20: */package org.apache.harmony.awt.gl;
21:
22: import java.awt.Composite;
23: import java.awt.CompositeContext;
24: import java.awt.image.ColorModel;
25: import java.awt.image.Raster;
26: import java.awt.image.WritableRaster;
27:
28: import org.apache.harmony.awt.gl.ImageSurface;
29: import org.apache.harmony.awt.gl.render.NativeImageBlitter;
30: import org.apache.harmony.awt.internal.nls.Messages;
31:
32: /**
33: * This class represent implementation of the CompositeContext interface
34: */
35: public class ICompositeContext implements CompositeContext {
36: Composite composite;
37: ColorModel srcCM, dstCM;
38: ImageSurface srcSurf, dstSurf;
39:
40: public ICompositeContext(Composite comp, ColorModel src,
41: ColorModel dst) {
42: composite = comp;
43: srcCM = src;
44: dstCM = dst;
45: }
46:
47: public void dispose() {
48: srcSurf.dispose();
49: dstSurf.dispose();
50: }
51:
52: public void compose(Raster srcIn, Raster dstIn,
53: WritableRaster dstOut) {
54:
55: if (!srcCM.isCompatibleRaster(srcIn)) {
56: // awt.48=The srcIn raster is incompatible with src ColorModel
57: throw new IllegalArgumentException(Messages
58: .getString("awt.48")); //$NON-NLS-1$
59: }
60:
61: if (!dstCM.isCompatibleRaster(dstIn)) {
62: // awt.49=The dstIn raster is incompatible with dst ColorModel
63: throw new IllegalArgumentException(Messages
64: .getString("awt.49")); //$NON-NLS-1$
65: }
66:
67: if (dstIn != dstOut) {
68: if (!dstCM.isCompatibleRaster(dstOut)) {
69: // awt.4A=The dstOut raster is incompatible with dst ColorModel
70: throw new IllegalArgumentException(Messages
71: .getString("awt.4A")); //$NON-NLS-1$
72: }
73: dstOut.setDataElements(0, 0, dstIn);
74: }
75: WritableRaster src;
76: if (srcIn instanceof WritableRaster) {
77: src = (WritableRaster) srcIn;
78: } else {
79: src = srcIn.createCompatibleWritableRaster();
80: src.setDataElements(0, 0, srcIn);
81: }
82: srcSurf = new ImageSurface(srcCM, src);
83: dstSurf = new ImageSurface(dstCM, dstOut);
84:
85: int w = Math.min(srcIn.getWidth(), dstOut.getWidth());
86: int h = Math.min(srcIn.getHeight(), dstOut.getHeight());
87:
88: NativeImageBlitter.getInstance().blit(0, 0, srcSurf, 0, 0,
89: dstSurf, w, h, composite, null, null);
90:
91: }
92:
93: }
|