Dead
[official-gcc.git] / gomp-20050608-branch / libjava / gnu / gcj / xlib / XImage.java
blob5460549e0a5aebc10c02680735a90bbd2476d891
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
7 details. */
9 package gnu.gcj.xlib;
11 import gnu.gcj.RawData;
13 /**
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
20 * screen.
22 * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
24 public class XImage
26 /** This object reference points to the data, hindering garbage
27 collection of the data. */
28 Object dataRef;
30 // Must match definitions in X.h:
31 public static final int XYBITMAP_FORMAT = 0,
32 XYPIXMAP_FORMAT = 1,
33 ZPIXMAP_FORMAT = 2;
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,
41 int bytesPerLine)
43 this(visual, depth, format, xoffset, width, height, bitmapPad,
44 bytesPerLine,
45 0 // bitsPerPixel
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
74 /**
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
82 * creation.
84 public XImage(Visual visual, int width, int height, boolean allocate)
86 if (visual == null)
87 throw new NullPointerException("a visual must be specified");
89 init(visual, width, height);
91 if (allocate)
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];
98 setData(data, 0);
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)
109 dataRef = data;
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)
121 dataRef = data;
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)
133 dataRef = data;
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;
157 /**
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()
186 String format;
187 switch(getFormat())
189 case ZPIXMAP_FORMAT:
190 format = "ZPixmapFormat";
191 break;
192 default:
193 format = "unknown";
196 String imageByteOrder;
197 switch(getImageByteOrder())
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";
209 String bitmapBitOrder;
210 switch(getBitmapBitOrder())
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";
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 "]";