BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / soundrecorder / DrawingTidbits.cpp
blobf9534af351f19168b4380ec66464e6f9b81bbaef
1 /*
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
6 * and Producers)
7 */
9 #include <Bitmap.h>
10 #include <Debug.h>
11 #include <Screen.h>
13 #include "DrawingTidbits.h"
15 rgb_color
16 ShiftColor(rgb_color color, float percent)
18 rgb_color result = {
19 ShiftComponent(color.red, percent),
20 ShiftComponent(color.green, percent),
21 ShiftComponent(color.blue, percent),
25 return result;
28 static bool
29 CompareColors(const rgb_color a, const rgb_color b)
31 return a.red == b.red
32 && a.green == b.green
33 && a.blue == b.blue
34 && a.alpha == b.alpha;
37 bool
38 operator==(const rgb_color &a, const rgb_color &b)
40 return CompareColors(a, b);
43 bool
44 operator!=(const rgb_color &a, const rgb_color &b)
46 return !CompareColors(a, b);
49 void
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;
66 void
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;