From: <eli...@us...> - 2008-04-07 09:23:34
|
Revision: 2972 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=2972&view=rev Author: elias_naur Date: 2008-04-07 02:23:27 -0700 (Mon, 07 Apr 2008) Log Message: ----------- Linux: Use icon mask as monochrome to please some xorg versions Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2008-04-06 22:15:16 UTC (rev 2971) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2008-04-07 09:23:27 UTC (rev 2972) @@ -997,10 +997,11 @@ throw new UnsupportedOperationException(); } - private static void convertIcon(ByteBuffer icon, int width, int height, ByteBuffer icon_rgb, ByteBuffer icon_mask) { - int x = 0; - int y = 5; - byte r,g,b,a; + private static ByteBuffer convertIcon(ByteBuffer icon, int width, int height) { + ByteBuffer icon_rgb = BufferUtils.createByteBuffer(icon.capacity()); + int x; + int y; + byte r,g,b; int depth = 4; @@ -1009,18 +1010,38 @@ r = icon.get((x*4)+(y*width*4)); g = icon.get((x*4)+(y*width*4)+1); b = icon.get((x*4)+(y*width*4)+2); - a = icon.get((x*4)+(y*width*4)+3); icon_rgb.put((x*depth)+(y*width*depth), b); // blue icon_rgb.put((x*depth)+(y*width*depth)+1, g); // green icon_rgb.put((x*depth)+(y*width*depth)+2, r); - icon_mask.put((x*depth)+(y*width*depth), a); - icon_mask.put((x*depth)+(y*width*depth)+1, a); - icon_mask.put((x*depth)+(y*width*depth)+2, a); } } + return icon_rgb; } + private static ByteBuffer convertIconMask(ByteBuffer icon, int width, int height) { + ByteBuffer icon_mask = BufferUtils.createByteBuffer((icon.capacity()/4)/8); + int x; + int y; + byte a; + + int depth = 4; + + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + a = icon.get((x*4)+(y*width*4)+3); + + int mask_index = x + y*width; + int mask_byte_index = mask_index/8; + int mask_bit_index = mask_index%8; + byte bit = (((int)a) & 0xff) >= 127 ? (byte)1 : (byte)0; + byte new_byte = (byte)((icon_mask.get(mask_byte_index) | (bit<<mask_bit_index)) & 0xff); + icon_mask.put(mask_byte_index, new_byte); + } + } + return icon_mask; + } + /** * Sets one or more icons for the Display. * <ul> @@ -1041,11 +1062,9 @@ for (int i=0;i<icons.length;i++) { int size = icons[i].limit() / 4; int dimension = (int)Math.sqrt(size); - int cap = icons[i].capacity(); - ByteBuffer icon_rgb = BufferUtils.createByteBuffer(cap); - ByteBuffer icon_mask = BufferUtils.createByteBuffer(cap); - convertIcon(icons[i], dimension, dimension, icon_rgb, icon_mask); - nSetWindowIcon(getDisplay(), getWindow(), icon_rgb, icon_mask, cap, dimension, dimension); + ByteBuffer icon_rgb = convertIcon(icons[i], dimension, dimension); + ByteBuffer icon_mask = convertIconMask(icons[i], dimension, dimension); + nSetWindowIcon(getDisplay(), getWindow(), icon_rgb, icon_rgb.capacity(), icon_mask, icon_mask.capacity(), dimension, dimension); return 1; } return 0; @@ -1060,7 +1079,7 @@ } } - private static native void nSetWindowIcon(long display, long window, ByteBuffer icon_rgb, ByteBuffer icon_mask, int icon_size, int width, int height); + private static native void nSetWindowIcon(long display, long window, ByteBuffer icon_rgb, int icon_rgb_size, ByteBuffer icon_mask, int icon_mask_size, int width, int height); public int getWidth() { return Display.getDisplayMode().getWidth(); Modified: trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c =================================================================== --- trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2008-04-06 22:15:16 UTC (rev 2971) +++ trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2008-04-07 09:23:27 UTC (rev 2972) @@ -398,8 +398,8 @@ jawt.Unlock(env); } -static Pixmap createPixmapFromBuffer(JNIEnv *env, Display *disp, Window window, char *data, int data_size, int width, int height) { - Pixmap pixmap = XCreatePixmap(disp, window, width, height, current_depth); +static Pixmap createPixmapFromBuffer(JNIEnv *env, Display *disp, Window window, char *data, int data_size, int width, int height, int format, int depth) { + Pixmap pixmap = XCreatePixmap(disp, window, width, height, depth); /* We need to copy the image data since XDestroyImage will also free its data buffer, which can't be allowed * since the data buffer is managed by the jvm (it's the storage for the direct ByteBuffer) */ @@ -408,15 +408,15 @@ if (icon_copy == NULL) { XFreePixmap(disp, pixmap); throwException(env, "malloc failed"); - return 0; + return None; } memcpy(icon_copy, data, data_size); - XImage *image = XCreateImage(disp, current_visual, current_depth, ZPixmap, 0, icon_copy, width, height, 32, 0); + XImage *image = XCreateImage(disp, current_visual, depth, format, 0, icon_copy, width, height, 32, 0); if (image == NULL) { XFreePixmap(disp, pixmap); free(icon_copy); throwException(env, "XCreateImage failed"); - return 0; + return None; } GC gc = XCreateGC(disp, pixmap, 0, NULL); @@ -427,12 +427,12 @@ return pixmap; } -static void setIcon(JNIEnv *env, Display *disp, Window window, char *rgb_data, char *mask_data, int icon_size, int width, int height) { +static void setIcon(JNIEnv *env, Display *disp, Window window, char *rgb_data, int rgb_size, char *mask_data, int mask_size, int width, int height) { freeIconPixmap(disp); - current_icon_pixmap = createPixmapFromBuffer(env, disp, window, rgb_data, icon_size, width, height); + current_icon_pixmap = createPixmapFromBuffer(env, disp, window, rgb_data, rgb_size, width, height, ZPixmap, current_depth); if ((*env)->ExceptionCheck(env)) return; - current_icon_mask_pixmap = createPixmapFromBuffer(env, disp, window, mask_data, icon_size, width, height); + current_icon_mask_pixmap = createPixmapFromBuffer(env, disp, window, mask_data, mask_size, width, height, XYPixmap, 1); if ((*env)->ExceptionCheck(env)) { freeIconPixmap(disp); return; @@ -442,14 +442,14 @@ } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSetWindowIcon - (JNIEnv *env, jclass clazz, jlong display, jlong window_ptr, jobject icon_rgb_buffer, jobject icon_mask_buffer, jint icon_size, jint width, jint height) + (JNIEnv *env, jclass clazz, jlong display, jlong window_ptr, jobject icon_rgb_buffer, jint rgb_size, jobject icon_mask_buffer, jint mask_size, jint width, jint height) { Display *disp = (Display *)(intptr_t)display; Window window = (Window)window_ptr; char *rgb_data= (char *)(*env)->GetDirectBufferAddress(env, icon_rgb_buffer); char *mask_data= (char *)(*env)->GetDirectBufferAddress(env, icon_mask_buffer); - setIcon(env, disp, window, rgb_data, mask_data, icon_size, width, height); + setIcon(env, disp, window, rgb_data, rgb_size, mask_data, mask_size, width, height); } JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nUngrabKeyboard(JNIEnv *env, jclass unused, jlong display_ptr) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |