01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26: package com.sun.perseus.j2d;
27:
28: import javax.microedition.lcdui.Image;
29:
30: /**
31: * Class for 2D Raster Images.
32: *
33: * @version $Id: RasterImage.java,v 1.4 2006/04/21 06:34:58 st125089 Exp $
34: */
35: public class RasterImage {
36:
37: Image image;
38:
39: /**
40: * The cached pixel array.
41: */
42: int[] argb;
43:
44: /**
45: */
46: RasterImage(Image img) {
47: if (img == null) {
48: throw new NullPointerException();
49: }
50:
51: image = img;
52: }
53:
54: /**
55: * @return the image width.
56: */
57: public int getWidth() {
58: return image.getWidth();
59: }
60:
61: /**
62: * @return the image height.
63: */
64: public int getHeight() {
65: return image.getHeight();
66: }
67:
68: /**
69: * @return a pixel array where the image data is stored in
70: * single pixel packed format 0xaarrggbb, with a
71: * scanline stride equal to the image width and a
72: * zero offset in the returned array. The returned
73: * array is of size width * height.
74: */
75: public int[] getRGB() {
76:
77: if (argb != null) {
78: return argb;
79: }
80:
81: int w = image.getWidth();
82: int h = image.getHeight();
83:
84: argb = new int[w * h];
85:
86: image.getRGB(argb, 0, w, 0, 0, w, h);
87:
88: return argb;
89:
90: }
91:
92: }
|