1/* 2Open Tracker License 3 4Terms and Conditions 5 6Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 8Permission is hereby granted, free of charge, to any person obtaining a copy of 9this software and associated documentation files (the "Software"), to deal in 10the Software without restriction, including without limitation the rights to 11use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12of the Software, and to permit persons to whom the Software is furnished to do 13so, subject to the following conditions: 14 15The above copyright notice and this permission notice applies to all licensees 16and shall be included in all copies or substantial portions of the Software. 17 18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 23WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 25Except as contained in this notice, the name of Be Incorporated shall not be 26used in advertising or otherwise to promote the sale, use or other dealings in 27this Software without prior written authorization from Be Incorporated. 28 29Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 30of Be Incorporated in the United States and other countries. Other brand product 31names are registered trademarks or trademarks of their respective holders. 32All rights reserved. 33*/ 34 35/******************************************************************************* 36/ 37/ File: ColorTools.cpp 38/ 39/ Description: Additional experimental color manipulation functions. 40/ 41/ Copyright 2000, Be Incorporated, All Rights Reserved 42/ 43*******************************************************************************/ 44 45#include "ColorTools.h" 46 47#if B_BEOS_VERSION <= B_BEOS_VERSION_MAUI 48 49namespace BExperimental { 50 51#if DEBUG 52#define DB_INLINE 53#else 54#define DB_INLINE inline 55#endif 56 57static DB_INLINE void mix_color_func(rgb_color* target, const rgb_color other, uint8 amount) 58{ 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 ); 67} 68 69static DB_INLINE void blend_color_func(rgb_color* target, const rgb_color other, uint8 amount) 70{ 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 ); 81} 82 83static DB_INLINE void disable_color_func(rgb_color* target, const rgb_color background) 84{ 85 blend_color_func(target, background, 255-70); 86} 87 88// -------------------------------------------------------------------------- 89 90rgb_color mix_color(rgb_color color1, rgb_color color2, uint8 amount) 91{ 92 mix_color_func(&color1, color2, amount); 93 return color1; 94} 95 96rgb_color blend_color(rgb_color color1, rgb_color color2, uint8 amount) 97{ 98 blend_color_func(&color1, color2, amount); 99 return color1; 100} 101 102rgb_color disable_color(rgb_color color, rgb_color background) 103{ 104 disable_color_func(&color, background); 105 return color; 106} 107 108} 109 110#endif 111