1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
27 #include "DrawingTidbits.h"
30 ShiftComponent(uchar component, float percent)
32 // change the color by <percent>, make sure we aren't rounding
33 // off significant bits
35 return (uchar)(component * (2 - percent));
37 return (uchar)(255 - percent * (255 - component));
41 ShiftColor(rgb_color color, float percent)
44 ShiftComponent(color.red, percent),
45 ShiftComponent(color.green, percent),
46 ShiftComponent(color.blue, percent),
54 CompareColors(const rgb_color a, const rgb_color b)
59 && a.alpha == b.alpha;
63 operator==(const rgb_color &a, const rgb_color &b)
65 return CompareColors(a, b);
69 operator!=(const rgb_color &a, const rgb_color &b)
71 return !CompareColors(a, b);
75 ReplaceColor(BBitmap *bitmap, rgb_color from, rgb_color to)
77 ASSERT(bitmap->ColorSpace() == B_COLOR_8_BIT); // other color spaces not implemented yet
79 BScreen screen(B_MAIN_SCREEN_ID);
80 uint32 fromIndex = screen.IndexForColor(from);
81 uint32 toIndex = screen.IndexForColor(to);
83 uchar *bits = (uchar *)bitmap->Bits();
84 int32 bitsLength = bitmap->BitsLength();
85 for (int32 index = 0; index < bitsLength; index++)
86 if (bits[index] == fromIndex)
87 bits[index] = toIndex;
91 ReplaceTransparentColor(BBitmap *bitmap, rgb_color with)
93 ASSERT(bitmap->ColorSpace() == B_COLOR_8_BIT); // other color spaces not implemented yet
95 BScreen screen(B_MAIN_SCREEN_ID);
96 uint32 withIndex = screen.IndexForColor(with);
98 uchar *bits = (uchar *)bitmap->Bits();
99 int32 bitsLength = bitmap->BitsLength();
100 for (int32 index = 0; index < bitsLength; index++)
101 if (bits[index] == B_TRANSPARENT_8_BIT)
102 bits[index] = withIndex;