01: /*
02: *
03: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
04: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License version
08: * 2 only, as published by the Free Software Foundation.
09: *
10: * This program 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 version 2 for more details (a copy is
14: * included at /legal/license.txt).
15: *
16: * You should have received a copy of the GNU General Public License
17: * version 2 along with this work; if not, write to the Free Software
18: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19: * 02110-1301 USA
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
22: * Clara, CA 95054 or visit www.sun.com if you need additional
23: * information or have any questions.
24: */
25:
26: package com.sun.pisces;
27:
28: import javax.microedition.lcdui.Graphics;
29:
30: public final class GraphicsSurfaceDestination implements
31: SurfaceDestination {
32: private final Graphics g;
33:
34: public GraphicsSurfaceDestination(Graphics g) {
35: this .g = g;
36: initialize();
37: }
38:
39: public void drawSurface(Surface ps, int srcX, int srcY, int dstX,
40: int dstY, int width, int height, float opacity) {
41: if (ps instanceof AbstractSurface) {
42: drawSurfaceImpl(g, (AbstractSurface) ps, srcX, srcY, dstX,
43: dstY, width, height, opacity);
44: return;
45: }
46:
47: int srcW = ps.getWidth();
48: int srcH = ps.getHeight();
49:
50: if (srcX < 0) {
51: dstX -= srcX;
52: width += srcX;
53: srcX = 0;
54: }
55:
56: if (srcY < 0) {
57: dstY -= srcY;
58: height += srcY;
59: srcY = 0;
60: }
61:
62: if ((srcX + width) > srcW) {
63: width = srcW - srcX;
64: }
65:
66: if ((srcY + height) > srcH) {
67: height = srcH - srcY;
68: }
69:
70: if ((width > 0) && (height > 0) && (opacity > 0)) {
71: int size = width * height;
72: int[] srcRGB = new int[size];
73:
74: ps.getRGB(srcRGB, 0, width, srcX, srcY, width, height);
75: drawRGBImpl(g, srcRGB, 0, width, dstX, dstY, width, height,
76: opacity);
77: }
78: }
79:
80: public void drawRGB(int[] argb, int offset, int scanLength, int x,
81: int y, int width, int height, float opacity) {
82: drawRGBImpl(g, argb, offset, scanLength, x, y, width, height,
83: opacity);
84: }
85:
86: private native void initialize();
87:
88: private static native void drawSurfaceImpl(Graphics g,
89: AbstractSurface ps, int srcX, int srcY, int dstX, int dstY,
90: int width, int height, float opacity);
91:
92: private static native void drawRGBImpl(Graphics g, int[] argb,
93: int offset, int scanLength, int x, int y, int width,
94: int height, float opacity);
95: }
|