0N/A/*
2362N/A * Copyright (c) 1997, 2002, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.java2d;
0N/A
0N/Aimport java.awt.Composite;
0N/Aimport java.awt.CompositeContext;
0N/Aimport java.awt.AlphaComposite;
0N/Aimport java.awt.image.ColorModel;
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.awt.image.Raster;
0N/Aimport java.awt.image.WritableRaster;
0N/Aimport sun.awt.image.BufImgSurfaceData;
0N/Aimport sun.java2d.loops.XORComposite;
0N/Aimport sun.java2d.loops.CompositeType;
0N/Aimport sun.java2d.loops.Blit;
0N/A
0N/Apublic class SunCompositeContext implements CompositeContext {
0N/A ColorModel srcCM;
0N/A ColorModel dstCM;
0N/A Composite composite;
0N/A CompositeType comptype;
0N/A
0N/A public SunCompositeContext(AlphaComposite ac,
0N/A ColorModel s, ColorModel d)
0N/A {
0N/A if (s == null) {
0N/A throw new NullPointerException("Source color model cannot be null");
0N/A }
0N/A if (d == null) {
0N/A throw new NullPointerException("Destination color model cannot be null");
0N/A }
0N/A srcCM = s;
0N/A dstCM = d;
0N/A this.composite = ac;
0N/A this.comptype = CompositeType.forAlphaComposite(ac);
0N/A }
0N/A
0N/A public SunCompositeContext(XORComposite xc,
0N/A ColorModel s, ColorModel d)
0N/A {
0N/A if (s == null) {
0N/A throw new NullPointerException("Source color model cannot be null");
0N/A }
0N/A if (d == null) {
0N/A throw new NullPointerException("Destination color model cannot be null");
0N/A }
0N/A srcCM = s;
0N/A dstCM = d;
0N/A this.composite = xc;
0N/A this.comptype = CompositeType.Xor;
0N/A }
0N/A
0N/A /**
0N/A * Release resources allocated for context.
0N/A */
0N/A public void dispose() {
0N/A }
0N/A
0N/A /**
0N/A * This method composes the two source tiles
0N/A * and places the result in the destination tile. Note that
0N/A * the destination can be the same object as either
0N/A * the first or second source.
0N/A * @param src1 The first source tile for the compositing operation.
0N/A * @param src2 The second source tile for the compositing operation.
0N/A * @param dst The tile where the result of the operation is stored.
0N/A */
0N/A public void compose(Raster srcArg, Raster dstIn, WritableRaster dstOut) {
0N/A WritableRaster src;
0N/A int w;
0N/A int h;
0N/A
0N/A if (dstIn != dstOut) {
0N/A dstOut.setDataElements(0, 0, dstIn);
0N/A }
0N/A
0N/A // REMIND: We should be able to create a SurfaceData from just
0N/A // a non-writable Raster and a ColorModel. Since we need to
0N/A // create a SurfaceData from a BufferedImage then we need to
0N/A // make a WritableRaster since it is needed to construct a
0N/A // BufferedImage.
0N/A if (srcArg instanceof WritableRaster) {
0N/A src = (WritableRaster) srcArg;
0N/A } else {
0N/A src = srcArg.createCompatibleWritableRaster();
0N/A src.setDataElements(0, 0, srcArg);
0N/A }
0N/A
0N/A w = Math.min(src.getWidth(), dstIn.getWidth());
0N/A h = Math.min(src.getHeight(), dstIn.getHeight());
0N/A
0N/A BufferedImage srcImg = new BufferedImage(srcCM, src,
0N/A srcCM.isAlphaPremultiplied(),
0N/A null);
0N/A BufferedImage dstImg = new BufferedImage(dstCM, dstOut,
0N/A dstCM.isAlphaPremultiplied(),
0N/A null);
0N/A
0N/A SurfaceData srcData = BufImgSurfaceData.createData(srcImg);
0N/A SurfaceData dstData = BufImgSurfaceData.createData(dstImg);
0N/A Blit blit = Blit.getFromCache(srcData.getSurfaceType(),
0N/A comptype,
0N/A dstData.getSurfaceType());
0N/A blit.Blit(srcData, dstData, composite, null, 0, 0, 0, 0, w, h);
0N/A }
0N/A}