tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / kits / interface / ColorTools.cpp
blobe4aea31624ab7c7e8b126756c33069cc3cbed0b5
1 /*
2 Open Tracker License
4 Terms and Conditions
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
35 /*******************************************************************************
37 / File: ColorTools.cpp
39 / Description: Additional experimental color manipulation functions.
41 / Copyright 2000, Be Incorporated, All Rights Reserved
43 *******************************************************************************/
45 #include "ColorTools.h"
47 #if B_BEOS_VERSION <= B_BEOS_VERSION_MAUI
49 namespace BExperimental {
51 #if DEBUG
52 #define DB_INLINE
53 #else
54 #define DB_INLINE inline
55 #endif
57 static DB_INLINE void mix_color_func(rgb_color* target, const rgb_color other, uint8 amount)
59 target->red = (uint8)( ((int16(other.red)-int16(target->red))*amount)/255
60 + target->red );
61 target->green = (uint8)( ((int16(other.green)-int16(target->green))*amount)/255
62 + target->green );
63 target->blue = (uint8)( ((int16(other.blue)-int16(target->blue))*amount)/255
64 + target->blue );
65 target->alpha = (uint8)( ((int16(other.alpha)-int16(target->alpha))*amount)/255
66 + target->alpha );
69 static DB_INLINE void blend_color_func(rgb_color* target, const rgb_color other, uint8 amount)
71 const uint8 alphaMix = (uint8)( ((int16(other.alpha)-int16(255-target->alpha))*amount)/255
72 + (255-target->alpha) );
73 target->red = (uint8)( ((int16(other.red)-int16(target->red))*alphaMix)/255
74 + target->red );
75 target->green = (uint8)( ((int16(other.green)-int16(target->green))*alphaMix)/255
76 + target->green );
77 target->blue = (uint8)( ((int16(other.blue)-int16(target->blue))*alphaMix)/255
78 + target->blue );
79 target->alpha = (uint8)( ((int16(other.alpha)-int16(target->alpha))*amount)/255
80 + target->alpha );
83 static DB_INLINE void disable_color_func(rgb_color* target, const rgb_color background)
85 blend_color_func(target, background, 255-70);
88 // --------------------------------------------------------------------------
90 rgb_color mix_color(rgb_color color1, rgb_color color2, uint8 amount)
92 mix_color_func(&color1, color2, amount);
93 return color1;
96 rgb_color blend_color(rgb_color color1, rgb_color color2, uint8 amount)
98 blend_color_func(&color1, color2, amount);
99 return color1;
102 rgb_color disable_color(rgb_color color, rgb_color background)
104 disable_color_func(&color, background);
105 return color;
110 #endif