From e2596d8efafcad678611d38a6d56362e8debad2b Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 7 Apr 2008 09:23:27 +0000 Subject: [PATCH] Linux: Use icon mask as monochrome to please some xorg versions --- src/java/org/lwjgl/opengl/LinuxDisplay.java | 47 +++++++++++++++------ src/native/linux/org_lwjgl_opengl_Display.c | 20 ++++----- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/java/org/lwjgl/opengl/LinuxDisplay.java b/src/java/org/lwjgl/opengl/LinuxDisplay.java index 1c94fed3..84e3ded3 100644 --- a/src/java/org/lwjgl/opengl/LinuxDisplay.java +++ b/src/java/org/lwjgl/opengl/LinuxDisplay.java @@ -997,10 +997,11 @@ final class LinuxDisplay implements DisplayImplementation { 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,16 +1010,36 @@ final class LinuxDisplay implements DisplayImplementation { 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<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 @@ static void setIcon(JNIEnv *env, Display *disp, Window window, char *rgb_data, c } 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) {