1 /* Copyright (C) 2000 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
11 import gnu
.gcj
.RawData
;
14 * Structure containing image data that resides on the client side.
15 * The format, depth and offset attributes of an XImage determines how
16 * bitfields are encoded in a raster image. However, it does not
17 * determine how a color is encoded into a bitfield. I.e. the XImage
18 * pixel values in a specific structure, but does not determine what
19 * colors that will be used to represent these pixel values on the
22 * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
26 /** This object reference points to the data, hindering garbage
27 collection of the data. */
30 // Must match definitions in X.h:
31 public static final int XYBITMAP_FORMAT
= 0,
35 // Must match definitions in X.h:
36 public static final int LEAST_SIGNIFICANT_B_FIRST_ORDER
= 0,
37 MOST_SIGNIFICANT_B_FIRST_ORDER
= 1;
39 public XImage(Visual visual
, int depth
, int format
, int xoffset
,
40 int width
, int height
, int bitmapPad
,
43 this(visual
, depth
, format
, xoffset
, width
, height
, bitmapPad
,
49 public XImage(Visual visual
, int depth
, int format
, int xoffset
,
50 int width
, int height
, int bitmapPad
,
51 int bytesPerLine
, int bitsPerPixel
)
53 if (visual
== null) throw new
54 NullPointerException("a visual must be specified");
56 init(visual
, depth
, format
, xoffset
, width
, height
,
57 bitmapPad
, bytesPerLine
, bitsPerPixel
);
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
);
64 private native void init(Visual visual
, int width
, int height
);
67 public XImage(Visual visual
, int width
, int height
)
69 this(visual
, width
, height
,
70 true // Automatically allocate memory
75 * Create a new XImage.
77 * @param allocate specifies whether to automatically allocate
78 * memory for the image. It is possible to create the data array
79 * elsewhere, so that we can for instance use a DataBufferUShort as
80 * data. Ie. not limit ourself to byte arrays. This is done by
81 * passing false and calling a setData() method manually after
84 public XImage(Visual visual
, int width
, int height
, boolean allocate
)
87 throw new NullPointerException("a visual must be specified");
89 init(visual
, width
, height
);
93 /* Now that Xlib has figured out the appropriate bytes per
94 line, we can allocate memory for the image. */
95 // FIXME: What about formats with several layers/bands?
96 byte[] data
= new byte[getBytesPerLine()*height
];
103 * Attach image data to this XImage.
105 * @param offset the index of the first actual data element in the array.
107 public void setData(byte[] data
, int offset
)
110 internalSetData(data
, offset
);
114 * Attach image data to this XImage.
116 * @param offset the index of the first actual data element in the
117 * array. Note: this is short offset, not a byte offset.
119 public void setData(short[] data
, int offset
)
122 internalSetData(data
, offset
);
126 * Attach image data to this XImage
128 * @param offset the index of the first actual data element in the array.
129 * Note: this is not a byte offset.
131 public void setData(int[] data
, int offset
)
134 internalSetData(data
, offset
);
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
);
141 protected native void finalize();
143 boolean ownsData
= false;
144 RawData structure
= null;
146 public final native int getWidth();
147 public final native int getHeight();
148 public final native int getDepth();
149 public final native int getFormat();
151 public final boolean isZPixmapFormat()
153 return getFormat() == ZPIXMAP_FORMAT
;
158 * Get the xoffset. The xoffset avoids the need of shifting the
159 * scanlines into place.
161 public final native int getXOffset();
163 public native final int getBytesPerLine();
164 public native final int getBitsPerPixel();
166 public native final int getImageByteOrder();
167 public native final int getBitmapBitOrder();
168 public native final int getBitmapUnit();
169 public native final int getBitmapPad();
172 // True/Direct Color specific:
173 public native int getRedMask();
174 public native int getGreenMask();
175 public native int getBlueMask();
179 * Set a pixel value at a given position in the image. This method
180 * is slow. Don't use it, except as a fall-back.
182 public native final void setPixel(int x
, int y
, int pixel
);
184 public String
toString()
190 format
= "ZPixmapFormat";
196 String imageByteOrder
;
197 switch(getImageByteOrder())
199 case LEAST_SIGNIFICANT_B_FIRST_ORDER
:
200 imageByteOrder
= "leastSignificantByteFirst";
202 case MOST_SIGNIFICANT_B_FIRST_ORDER
:
203 imageByteOrder
= "mostSignificantByteFirst";
206 imageByteOrder
= "unknwon";
209 String bitmapBitOrder
;
210 switch(getBitmapBitOrder())
212 case LEAST_SIGNIFICANT_B_FIRST_ORDER
:
213 bitmapBitOrder
= "leastSignificantBitFirst";
215 case MOST_SIGNIFICANT_B_FIRST_ORDER
:
216 bitmapBitOrder
= "mostSignificantBitFirst";
219 bitmapBitOrder
= "unknown";
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
+