[haiku-commits] r36549 - in haiku/trunk: headers/private/interface src/kits/interface

Author: stippi
Date: 2010-04-30 13:29:14 +0200 (Fri, 30 Apr 2010)
New Revision: 36549
Changeset: http://dev.haiku-os.org/changeset/36549/haiku

Modified:
   haiku/trunk/headers/private/interface/ColorConversion.h
   haiku/trunk/src/kits/interface/ColorConversion.cpp
Log:
 * Introduced PaletteConverter::IndexForRGBA32() which checks if the alpha
   component of a 32 bit color is below 128 and returns the special CMAP8 index
   for indicating transparency.
 * Changed the WriteCMAP() color conversion function to expext a 32bit RGBA
   value and use IndexForRGBA32().
 * Adapted B_CMAP8 target color space case of ConvertBits() to the new
   semantics.

This allows transparency in bitmaps when converting B_RGBA32 bitmaps to
B_CMAP8, tested only for this case and working as expected.


Modified: haiku/trunk/headers/private/interface/ColorConversion.h
===================================================================
--- haiku/trunk/headers/private/interface/ColorConversion.h     2010-04-30 
10:00:44 UTC (rev 36548)
+++ haiku/trunk/headers/private/interface/ColorConversion.h     2010-04-30 
11:29:14 UTC (rev 36549)
@@ -38,6 +38,7 @@
        inline uint8 IndexForRGB16(uint8 red, uint8 green, uint8 blue) const;
        inline uint8 IndexForRGB24(uint32 rgb) const;
        inline uint8 IndexForRGB24(uint8 red, uint8 green, uint8 blue) const;
+       inline uint8 IndexForRGBA32(uint32 rgba) const;
        inline uint8 IndexForGray(uint8 gray) const;
 
        inline const rgb_color &RGBColorForIndex(uint8 index) const;

Modified: haiku/trunk/src/kits/interface/ColorConversion.cpp
===================================================================
--- haiku/trunk/src/kits/interface/ColorConversion.cpp  2010-04-30 10:00:44 UTC 
(rev 36548)
+++ haiku/trunk/src/kits/interface/ColorConversion.cpp  2010-04-30 11:29:14 UTC 
(rev 36549)
@@ -308,6 +308,23 @@
 }
 
 
+/*!    \brief Returns the palette color index closest to a given RGBA 32 color.
+
+       The object must be properly initialized.
+
+       \param rgb The RGB 32A color value (R[31:24]G[23:16]B[15:8]A[7:0]).
+       \return The palette color index for the supplied color.
+*/
+inline
+uint8
+PaletteConverter::IndexForRGBA32(uint32 rgba) const
+{
+       if ((rgba & 0x000000ff) < 128)
+               return B_TRANSPARENT_MAGIC_CMAP8;
+       return IndexForRGB24(rgba);
+}
+
+
 /*!    \brief Returns the palette color index closest to a given Gray 8 color.
 
        The object must be properly initialized.
@@ -539,7 +556,7 @@
 void
 WriteCMAP8(uint8 **dest, uint8 *data, int32 index)
 {
-       **dest = sPaletteConverter.IndexForRGB15(*(uint16 *)data);
+       **dest = sPaletteConverter.IndexForRGBA32(*(uint32 *)data);
        (*dest)++;
 }
 
@@ -836,11 +853,11 @@
                case B_CMAP8:
                        PaletteConverter::InitializeDefault();
                        ConvertBits(srcBits, (uint8 *)dstBits, srcBitsLength,
-                               dstBitsLength, redShift - 15, greenShift - 10, 
blueShift - 5,
-                               0, 0, 0x7c00, 0x03e0, 0x001f, 0x0000, 
srcBytesPerRow,
-                               dstBytesPerRow, srcBitsPerPixel, 8, 
srcColorSpace,
-                               dstColorSpace, srcOffset, dstOffset, width, 
height, srcSwap,
-                               false, srcFunc, WriteCMAP8);
+                               dstBitsLength, redShift - 32, greenShift - 24, 
blueShift - 16,
+                               alphaShift - 8, alphaBits, 0xff000000, 
0x00ff0000, 0x0000ff00,
+                               0x000000ff, srcBytesPerRow, dstBytesPerRow, 
srcBitsPerPixel, 8,
+                               srcColorSpace, dstColorSpace, srcOffset, 
dstOffset,
+                               width, height, srcSwap, false, srcFunc, 
WriteCMAP8);
                        break;
 
                default:


Other related posts:

  • » [haiku-commits] r36549 - in haiku/trunk: headers/private/interface src/kits/interface - superstippi