From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- libjava/gnu/gcj/xlib/XImage.java | 235 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 libjava/gnu/gcj/xlib/XImage.java (limited to 'libjava/gnu/gcj/xlib/XImage.java') diff --git a/libjava/gnu/gcj/xlib/XImage.java b/libjava/gnu/gcj/xlib/XImage.java new file mode 100644 index 000000000..5460549e0 --- /dev/null +++ b/libjava/gnu/gcj/xlib/XImage.java @@ -0,0 +1,235 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.gcj.xlib; + +import gnu.gcj.RawData; + +/** + * Structure containing image data that resides on the client side. + * The format, depth and offset attributes of an XImage determines how + * bitfields are encoded in a raster image. However, it does not + * determine how a color is encoded into a bitfield. I.e. the XImage + * pixel values in a specific structure, but does not determine what + * colors that will be used to represent these pixel values on the + * screen. + * + * @author Rolf W. Rasmussen + */ +public class XImage +{ + /** This object reference points to the data, hindering garbage + collection of the data. */ + Object dataRef; + + // Must match definitions in X.h: + public static final int XYBITMAP_FORMAT = 0, + XYPIXMAP_FORMAT = 1, + ZPIXMAP_FORMAT = 2; + + // Must match definitions in X.h: + public static final int LEAST_SIGNIFICANT_B_FIRST_ORDER = 0, + MOST_SIGNIFICANT_B_FIRST_ORDER = 1; + + public XImage(Visual visual, int depth, int format, int xoffset, + int width, int height, int bitmapPad, + int bytesPerLine) + { + this(visual, depth, format, xoffset, width, height, bitmapPad, + bytesPerLine, + 0 // bitsPerPixel + ); + } + + public XImage(Visual visual, int depth, int format, int xoffset, + int width, int height, int bitmapPad, + int bytesPerLine, int bitsPerPixel) + { + if (visual == null) throw new + NullPointerException("a visual must be specified"); + + init(visual, depth, format, xoffset, width, height, + bitmapPad, bytesPerLine, bitsPerPixel); + } + + public native void init(Visual visual, int depth, int format, int xoffset, + int width, int height, int bitmapPad, + int bytesPerLine, int bitsPerPixel); + + private native void init(Visual visual, int width, int height); + + + public XImage(Visual visual, int width, int height) + { + this(visual, width, height, + true // Automatically allocate memory + ); + } + + /** + * Create a new XImage. + * + * @param allocate specifies whether to automatically allocate + * memory for the image. It is possible to create the data array + * elsewhere, so that we can for instance use a DataBufferUShort as + * data. Ie. not limit ourself to byte arrays. This is done by + * passing false and calling a setData() method manually after + * creation. + */ + public XImage(Visual visual, int width, int height, boolean allocate) + { + if (visual == null) + throw new NullPointerException("a visual must be specified"); + + init(visual, width, height); + + if (allocate) + { + /* Now that Xlib has figured out the appropriate bytes per + line, we can allocate memory for the image. */ + // FIXME: What about formats with several layers/bands? + byte[] data = new byte[getBytesPerLine()*height]; + + setData(data, 0); + } + } + + /** + * Attach image data to this XImage. + * + * @param offset the index of the first actual data element in the array. + */ + public void setData(byte[] data, int offset) + { + dataRef = data; + internalSetData(data, offset); + } + + /** + * Attach image data to this XImage. + * + * @param offset the index of the first actual data element in the + * array. Note: this is short offset, not a byte offset. + */ + public void setData(short[] data, int offset) + { + dataRef = data; + internalSetData(data, offset); + } + + /** + * Attach image data to this XImage + * + * @param offset the index of the first actual data element in the array. + * Note: this is not a byte offset. + */ + public void setData(int[] data, int offset) + { + dataRef = data; + internalSetData(data, offset); + } + + private native void internalSetData(byte[] data, int offset); + private native void internalSetData(short[] data, int offset); + private native void internalSetData(int[] data, int offset); + + protected native void finalize(); + + boolean ownsData = false; + RawData structure = null; + + public final native int getWidth(); + public final native int getHeight(); + public final native int getDepth(); + public final native int getFormat(); + + public final boolean isZPixmapFormat() + { + return getFormat() == ZPIXMAP_FORMAT; + } + + + /** + * Get the xoffset. The xoffset avoids the need of shifting the + * scanlines into place. + */ + public final native int getXOffset(); + + public native final int getBytesPerLine(); + public native final int getBitsPerPixel(); + + public native final int getImageByteOrder(); + public native final int getBitmapBitOrder(); + public native final int getBitmapUnit(); + public native final int getBitmapPad(); + + + // True/Direct Color specific: + public native int getRedMask(); + public native int getGreenMask(); + public native int getBlueMask(); + + + /** + * Set a pixel value at a given position in the image. This method + * is slow. Don't use it, except as a fall-back. + */ + public native final void setPixel(int x, int y, int pixel); + + public String toString() + { + String format; + switch(getFormat()) + { + case ZPIXMAP_FORMAT: + format = "ZPixmapFormat"; + break; + default: + format = "unknown"; + } + + String imageByteOrder; + switch(getImageByteOrder()) + { + case LEAST_SIGNIFICANT_B_FIRST_ORDER: + imageByteOrder = "leastSignificantByteFirst"; + break; + case MOST_SIGNIFICANT_B_FIRST_ORDER: + imageByteOrder = "mostSignificantByteFirst"; + break; + default: + imageByteOrder = "unknwon"; + } + + String bitmapBitOrder; + switch(getBitmapBitOrder()) + { + case LEAST_SIGNIFICANT_B_FIRST_ORDER: + bitmapBitOrder = "leastSignificantBitFirst"; + break; + case MOST_SIGNIFICANT_B_FIRST_ORDER: + bitmapBitOrder = "mostSignificantBitFirst"; + break; + default: + bitmapBitOrder = "unknown"; + } + + return getClass().getName() + "[" + format + + ", width=" + getWidth() + + ", height=" + getHeight() + + ", bytesPerLine=" + getBytesPerLine() + + ", xoffset=" + getXOffset() + + ", depth=" + getDepth() + + ", bitsPerPixel=" + getBitsPerPixel() + + ", bitmapUnit=" + getBitmapUnit() + + ", bitmapPad=" + getBitmapPad() + + ", byteOrder=" + imageByteOrder + + ", bitOrder=" + bitmapBitOrder + + "]"; + } +} -- cgit v1.2.3