1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }