1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     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 Alexey A. Petrenko
19 * @version $Revision$
20 */
21package org.apache.harmony.awt.gl.image;
22
23import java.awt.Graphics;
24import java.awt.GraphicsConfiguration;
25import java.awt.Rectangle;
26import java.awt.image.BufferedImage;
27import java.awt.image.ColorModel;
28import java.awt.image.WritableRaster;
29
30import org.apache.harmony.awt.gl.CommonGraphics2D;
31import org.apache.harmony.awt.gl.Surface;
32import org.apache.harmony.awt.gl.render.JavaBlitter;
33import org.apache.harmony.awt.gl.render.NativeImageBlitter;
34
35/**
36 * BufferedImageGraphics2D is implementation of CommonGraphics2D for
37 * drawing on buffered images.
38 */
39public class BufferedImageGraphics2D extends CommonGraphics2D {
40    private BufferedImage bi = null;
41    private Rectangle bounds = null;
42
43    public BufferedImageGraphics2D(BufferedImage bi) {
44        super();
45        this.bi = bi;
46        this.bounds = new Rectangle(0, 0, bi.getWidth(), bi.getHeight());
47        clip(bounds);
48        dstSurf = Surface.getImageSurface(bi);
49        if(dstSurf.isNativeDrawable()){
50            blitter = NativeImageBlitter.getInstance();
51        }else{
52            blitter = JavaBlitter.getInstance();
53        }
54    }
55
56    @Override
57    public void copyArea(int x, int y, int width, int height, int dx, int dy) {
58    }
59
60    @Override
61    public Graphics create() {
62        BufferedImageGraphics2D res = new BufferedImageGraphics2D(bi);
63        copyInternalFields(res);
64        return res;
65    }
66
67    @Override
68    public GraphicsConfiguration getDeviceConfiguration() {
69        return null;
70    }
71
72    public ColorModel getColorModel() {
73        return bi.getColorModel();
74    }
75
76    public WritableRaster getWritableRaster() {
77        return bi.getRaster();
78    }
79}