changes made after tupshins reconstruction
[org.ibex.core.git] / src / org / xwt / plat / X11.cc
index 8012340..2bdb083 100644 (file)
@@ -69,13 +69,14 @@ static void ensureShmSize(int size) {
 void org::xwt::plat::X11$X11PixelBuffer::fastDrawPicture(org::xwt::Picture* s,
                                                          jint dx, jint dy, jint cx1, jint cy1, jint cx2, jint cy2) {
     org::xwt::plat::X11$X11Picture* source = (org::xwt::plat::X11$X11Picture*)s;
-    
+
     if (source->doublebuf->stipple != NULL) {
         XSetClipMask(display, (*((GC*)clipped_gc)), *((Pixmap*)source->doublebuf->stipple));
-        XSetClipOrigin(display, (*((GC*)clipped_gc)), cx1 - dx, cy1 - dy);
+        XSetClipOrigin(display, (*((GC*)clipped_gc)), dx, dy);
     } else {
         XSetClipMask(display, (*((GC*)clipped_gc)), None);
     }
+
     XCopyArea(display,
               *((Pixmap*)source->doublebuf->pm), (*((Pixmap*)pm)), (*((GC*)clipped_gc)),
               cx1 - dx, cy1 - dy, cx2 - cx1, cy2 - cy1, cx1, cy1);
@@ -123,38 +124,43 @@ void org::xwt::plat::X11$X11PixelBuffer::slowDrawPicture(org::xwt::Picture* s,
             int source_green = (sourcepixel & 0x0000FF00) >> 8;
             int source_blue = (sourcepixel & 0x000000FF);
             int red = 0, blue = 0, green = 0;
-            
+            int targetpixel;
             if (alpha == 0x00) continue;
             if (alpha != 0xFF) {
-                int targetpixel;
                 switch (xi->bits_per_pixel) {
                 case 8: targetpixel = (int)(*current_pixel); break;
+                case 15:
                 case 16: targetpixel = (int)(*((uint16_t*)current_pixel)); break;
-                case 24: targetpixel = (((int)*current_pixel) << 16) | (((int)*(current_pixel + 1)) << 8) | (((int)*(current_pixel + 2))); break;
+
+                // FIXME assumes endianness...
+                case 24: targetpixel =
+                           (((int)*current_pixel) << 16) |
+                           (((int)*(current_pixel + 1)) << 8) |
+                           (((int)*(current_pixel + 2))); break;
                 case 32: targetpixel = *((int*)current_pixel); break;
                 default: org::xwt::Platform::criticalAbort(JvNewStringLatin1("ERROR: bpp not a multiple of 8!"));
                 }
-                
                 targetpixel -= colormap_info->base_pixel;
-                
+
                 // if you're on some wierd display that isn't either RGB or BGR, that's your problem, not mine
                 if (colormap_info->red_mult > colormap_info->green_mult && colormap_info->green_mult > colormap_info->blue_mult) {
                     red = targetpixel / colormap_info->red_mult;
                     green = (targetpixel - red * colormap_info->red_mult) / colormap_info->green_mult;
-                    blue = (targetpixel - red * colormap_info->red_mult - green * colormap_info->green_mult) / colormap_info->blue_mult;
+                    blue = (targetpixel-red * colormap_info->red_mult-green * colormap_info->green_mult)/colormap_info->blue_mult;
                 } else {
                     blue = targetpixel / colormap_info->blue_mult;
                     green = (targetpixel - blue * colormap_info->blue_mult) / colormap_info->green_mult;
-                    red = (targetpixel - blue * colormap_info->blue_mult - green * colormap_info->green_mult) / colormap_info->red_mult;
+                    red = (targetpixel-blue * colormap_info->blue_mult-green * colormap_info->green_mult)/colormap_info->red_mult;
                 }
             }
-            
-            red = ((source_red * colormap_info->red_max * alpha) + (red * 0xFF * (0xFF - alpha))) / (0xFF * 0xFF);
-            green = ((source_green * colormap_info->green_max * alpha) + (green * 0xFF * (0xFF - alpha))) / (0xFF * 0xFF);
-            blue = ((source_blue * colormap_info->blue_max * alpha) + (blue * 0xFF * (0xFF - alpha))) / (0xFF * 0xFF);
-            uint32_t destpixel = red * colormap_info->red_mult + green * colormap_info->green_mult +
-                blue * colormap_info->blue_mult + colormap_info->base_pixel;
-
+            red = ((source_red * (colormap_info->red_max) * alpha) + (red * 0xFF * (0xFF - alpha))) / (0xFF * 0xFF);
+            green = ((source_green * (colormap_info->green_max) * alpha)+(green * 0xFF * (0xFF - alpha))) / (0xFF * 0xFF);
+            blue = ((source_blue * (colormap_info->blue_max) * alpha) + (blue * 0xFF * (0xFF - alpha))) / (0xFF * 0xFF);
+            uint32_t destpixel =
+              (red * colormap_info->red_mult) +
+              (green * colormap_info->green_mult) +
+              (blue * colormap_info->blue_mult) +
+              colormap_info->base_pixel;
             switch (xi->bits_per_pixel) {
             case 8: *current_pixel = (char)(destpixel & 0xFF); break;
             case 16: *((uint16_t*)current_pixel) = (uint16_t)destpixel; break;