2004/01/13 19:27:17
[org.ibex.core.git] / src / org / xwt / plat / X11.cc
index 8012340..6b5c370 100644 (file)
@@ -123,38 +123,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;