2 * Copyright 2005, Jérôme Duval. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers
13 #include "DrawingTidbits.h"
16 ShiftColor(rgb_color color
, float percent
)
19 ShiftComponent(color
.red
, percent
),
20 ShiftComponent(color
.green
, percent
),
21 ShiftComponent(color
.blue
, percent
),
29 CompareColors(const rgb_color a
, const rgb_color b
)
34 && a
.alpha
== b
.alpha
;
38 operator==(const rgb_color
&a
, const rgb_color
&b
)
40 return CompareColors(a
, b
);
44 operator!=(const rgb_color
&a
, const rgb_color
&b
)
46 return !CompareColors(a
, b
);
50 ReplaceColor(BBitmap
*bitmap
, rgb_color from
, rgb_color to
)
52 ASSERT(bitmap
->ColorSpace() == B_CMAP8
);
53 // other color spaces not implemented yet
55 BScreen
screen(B_MAIN_SCREEN_ID
);
56 uint32 fromIndex
= screen
.IndexForColor(from
);
57 uint32 toIndex
= screen
.IndexForColor(to
);
59 uchar
*bits
= (uchar
*)bitmap
->Bits();
60 int32 bitsLength
= bitmap
->BitsLength();
61 for (int32 index
= 0; index
< bitsLength
; index
++)
62 if (bits
[index
] == fromIndex
)
63 bits
[index
] = toIndex
;
67 ReplaceTransparentColor(BBitmap
*bitmap
, rgb_color with
)
69 ASSERT(bitmap
->ColorSpace() == B_CMAP8
);
70 // other color spaces not implemented yet
72 BScreen
screen(B_MAIN_SCREEN_ID
);
73 uint8 withIndex
= screen
.IndexForColor(with
);
75 uchar
*bits
= (uchar
*)bitmap
->Bits();
76 int32 bitsLength
= bitmap
->BitsLength();
77 for (int32 index
= 0; index
< bitsLength
; index
++)
78 if (bits
[index
] == B_TRANSPARENT_8_BIT
)
79 bits
[index
] = withIndex
;