1:
8:
9: package ;
10:
11: import ;
12:
13:
24: public class XImage
25: {
26:
28: Object dataRef;
29:
30:
31: public static final int XYBITMAP_FORMAT = 0,
32: XYPIXMAP_FORMAT = 1,
33: ZPIXMAP_FORMAT = 2;
34:
35:
36: public static final int LEAST_SIGNIFICANT_B_FIRST_ORDER = 0,
37: MOST_SIGNIFICANT_B_FIRST_ORDER = 1;
38:
39: public XImage(Visual visual, int depth, int format, int xoffset,
40: int width, int height, int bitmapPad,
41: int bytesPerLine)
42: {
43: this(visual, depth, format, xoffset, width, height, bitmapPad,
44: bytesPerLine,
45: 0
46: );
47: }
48:
49: public XImage(Visual visual, int depth, int format, int xoffset,
50: int width, int height, int bitmapPad,
51: int bytesPerLine, int bitsPerPixel)
52: {
53: if (visual == null) throw new
54: NullPointerException("a visual must be specified");
55:
56: init(visual, depth, format, xoffset, width, height,
57: bitmapPad, bytesPerLine, bitsPerPixel);
58: }
59:
60: public native void init(Visual visual, int depth, int format, int xoffset,
61: int width, int height, int bitmapPad,
62: int bytesPerLine, int bitsPerPixel);
63:
64: private native void init(Visual visual, int width, int height);
65:
66:
67: public XImage(Visual visual, int width, int height)
68: {
69: this(visual, width, height,
70: true
71: );
72: }
73:
74:
84: public XImage(Visual visual, int width, int height, boolean allocate)
85: {
86: if (visual == null)
87: throw new NullPointerException("a visual must be specified");
88:
89: init(visual, width, height);
90:
91: if (allocate)
92: {
93:
95:
96: byte[] data = new byte[getBytesPerLine()*height];
97:
98: setData(data, 0);
99: }
100: }
101:
102:
107: public void setData(byte[] data, int offset)
108: {
109: dataRef = data;
110: internalSetData(data, offset);
111: }
112:
113:
119: public void setData(short[] data, int offset)
120: {
121: dataRef = data;
122: internalSetData(data, offset);
123: }
124:
125:
131: public void setData(int[] data, int offset)
132: {
133: dataRef = data;
134: internalSetData(data, offset);
135: }
136:
137: private native void internalSetData(byte[] data, int offset);
138: private native void internalSetData(short[] data, int offset);
139: private native void internalSetData(int[] data, int offset);
140:
141: protected native void finalize();
142:
143: boolean ownsData = false;
144: RawData structure = null;
145:
146: public final native int getWidth();
147: public final native int getHeight();
148: public final native int getDepth();
149: public final native int getFormat();
150:
151: public final boolean isZPixmapFormat()
152: {
153: return getFormat() == ZPIXMAP_FORMAT;
154: }
155:
156:
157:
161: public final native int getXOffset();
162:
163: public native final int getBytesPerLine();
164: public native final int getBitsPerPixel();
165:
166: public native final int getImageByteOrder();
167: public native final int getBitmapBitOrder();
168: public native final int getBitmapUnit();
169: public native final int getBitmapPad();
170:
171:
172:
173: public native int getRedMask();
174: public native int getGreenMask();
175: public native int getBlueMask();
176:
177:
178:
182: public native final void setPixel(int x, int y, int pixel);
183:
184: public String toString()
185: {
186: String format;
187: switch(getFormat())
188: {
189: case ZPIXMAP_FORMAT:
190: format = "ZPixmapFormat";
191: break;
192: default:
193: format = "unknown";
194: }
195:
196: String imageByteOrder;
197: switch(getImageByteOrder())
198: {
199: case LEAST_SIGNIFICANT_B_FIRST_ORDER:
200: imageByteOrder = "leastSignificantByteFirst";
201: break;
202: case MOST_SIGNIFICANT_B_FIRST_ORDER:
203: imageByteOrder = "mostSignificantByteFirst";
204: break;
205: default:
206: imageByteOrder = "unknwon";
207: }
208:
209: String bitmapBitOrder;
210: switch(getBitmapBitOrder())
211: {
212: case LEAST_SIGNIFICANT_B_FIRST_ORDER:
213: bitmapBitOrder = "leastSignificantBitFirst";
214: break;
215: case MOST_SIGNIFICANT_B_FIRST_ORDER:
216: bitmapBitOrder = "mostSignificantBitFirst";
217: break;
218: default:
219: bitmapBitOrder = "unknown";
220: }
221:
222: return getClass().getName() + "[" + format +
223: ", width=" + getWidth() +
224: ", height=" + getHeight() +
225: ", bytesPerLine=" + getBytesPerLine() +
226: ", xoffset=" + getXOffset() +
227: ", depth=" + getDepth() +
228: ", bitsPerPixel=" + getBitsPerPixel() +
229: ", bitmapUnit=" + getBitmapUnit() +
230: ", bitmapPad=" + getBitmapPad() +
231: ", byteOrder=" + imageByteOrder +
232: ", bitOrder=" + bitmapBitOrder +
233: "]";
234: }
235: }