View Javadoc

1   /*
2    *  MicroEmulator
3    *  Copyright (C) 2001 Bartek Teodorczyk <barteo@barteo.net>
4    *
5    *  This library is free software; you can redistribute it and/or
6    *  modify it under the terms of the GNU Lesser General Public
7    *  License as published by the Free Software Foundation; either
8    *  version 2.1 of the License, or (at your option) any later version.
9    *
10   *  This library is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   *  Lesser General Public License for more details.
14   *
15   *  You should have received a copy of the GNU Lesser General Public
16   *  License along with this library; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19   
20  package org.microemu.device.swt;
21  
22  import org.eclipse.swt.graphics.ImageData;
23  import org.microemu.app.ui.swt.SwtDeviceComponent;
24  
25  
26  public class SwtImmutableImage extends javax.microedition.lcdui.Image
27  {
28  	org.eclipse.swt.graphics.Image img;
29  
30    
31  	public SwtImmutableImage(org.eclipse.swt.graphics.Image image)
32  	{
33  		img = image;
34  	}
35    
36    
37  	public SwtImmutableImage(SwtMutableImage image)
38    	{
39  		img = SwtDeviceComponent.createImage(image.getImage());
40    	}
41  
42  
43  	public int getHeight()
44  	{
45  		return img.getBounds().height;
46  	}
47  
48  
49  	public org.eclipse.swt.graphics.Image getImage()
50  	{
51  		return img;
52  	}
53  
54  
55  	public int getWidth()
56  	{
57  		return img.getBounds().width;
58  	}  
59  	
60  	
61  	public void getRGB(int[] argb, int offset, int scanlength, int x, int y, int width, int height) 
62  	{
63          if (width <= 0 || height <= 0) {
64              return;
65          }
66          if (x < 0 || y < 0 || x + width > getWidth() || y + height > getHeight()) {
67              throw new IllegalArgumentException("Specified area exceeds bounds of image");
68          }
69          if ((scanlength < 0 ? -scanlength : scanlength) < width) {
70              throw new IllegalArgumentException("abs value of scanlength is less than width");
71          }
72          if (argb == null) { 
73              throw new NullPointerException("null rgbData");
74          }
75          if (offset < 0 || offset + width > argb.length) {
76              throw new ArrayIndexOutOfBoundsException();
77          }
78          if (scanlength < 0) { 
79              if (offset + scanlength*(height-1) < 0) {
80                  throw new ArrayIndexOutOfBoundsException();
81              }
82          } else {
83              if (offset + scanlength*(height-1) + width > argb.length) {
84                  throw new ArrayIndexOutOfBoundsException();
85              }
86          }
87                  
88          ImageData imageData = img.getImageData();
89          for (int i = 0; i < height; i++) {
90          		imageData.getPixels(x, y + i, width, argb, offset + i * scanlength);
91          }
92  	}
93    
94  }