* Removed unused MakeBlendColor().

* At least 15 bit mode is broken, and should probably be removed.
* Cleanup - do we really need this class?


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16247 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-02-06 11:47:13 +00:00
parent 0098d20af2
commit d5ffccabb7
2 changed files with 187 additions and 261 deletions

View File

@ -1,87 +1,58 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: RGBColor.h
// Author: DarkWyrm <bpmagic@columbus.rr.com>
// Description: Color encapsulation class for the app_server
//
//------------------------------------------------------------------------------
#ifndef RGBCOLOR_H_
#define RGBCOLOR_H_
/*
* Copyright 2001-2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm <bpmagic@columbus.rr.com>
*/
#ifndef RGB_COLOR_H
#define RGB_COLOR_H
#include <GraphicsDefs.h>
/*!
\class RGBColor RGBColor.h
\brief A color class to encapsulate color space ugliness in the app_server
RGBColors can be used to perform tasks much more difficult using rgb_colors. This
class is limited to the app_server because of the access to the system palette for
looking up the 32-bit value to each color index.
*/
class RGBColor
{
public:
RGBColor(uint8 r, uint8 g, uint8 b, uint8 a=255);
RGBColor(int r, int g, int b, int a=255);
RGBColor(const rgb_color &col);
RGBColor(uint16 col);
RGBColor(uint8 col);
RGBColor(const RGBColor &col);
RGBColor();
void PrintToStream() const;
uint8 GetColor8() const;
uint16 GetColor15() const;
uint16 GetColor16() const;
rgb_color GetColor32() const;
void SetColor(uint8 r, uint8 g, uint8 b, uint8 a=255);
void SetColor(int r, int g, int b, int a=255);
void SetColor(uint16 color16);
void SetColor(uint8 color8);
void SetColor(const rgb_color &color);
void SetColor(const RGBColor &col);
RGBColor MakeBlendColor(const RGBColor &color, const float &position);
const RGBColor & operator=(const RGBColor &col);
const RGBColor & operator=(const rgb_color &col);
bool operator==(const rgb_color &col) const;
bool operator==(const RGBColor &col) const;
class RGBColor {
public:
RGBColor(uint8 r, uint8 g, uint8 b, uint8 a=255);
RGBColor(int r, int g, int b, int a=255);
RGBColor(const rgb_color &col);
RGBColor(uint16 col);
RGBColor(uint8 col);
RGBColor(const RGBColor &col);
RGBColor();
bool IsTransparentMagic() const;
uint8 GetColor8() const;
uint16 GetColor15() const;
uint16 GetColor16() const;
rgb_color GetColor32() const;
protected:
rgb_color color32;
void SetColor(uint8 r, uint8 g, uint8 b, uint8 a=255);
void SetColor(int r, int g, int b, int a=255);
void SetColor(uint16 color16);
void SetColor(uint8 color8);
void SetColor(const rgb_color &color);
void SetColor(const RGBColor &col);
// caching
mutable uint16 color16;
mutable uint16 color15;
mutable uint8 color8;
mutable bool update8;
mutable bool update15;
mutable bool update16;
const RGBColor & operator=(const RGBColor &col);
const RGBColor & operator=(const rgb_color &col);
bool operator==(const rgb_color &col) const;
bool operator==(const RGBColor &col) const;
bool IsTransparentMagic() const;
void PrintToStream() const;
protected:
rgb_color fColor32;
// caching
mutable uint16 fColor16;
mutable uint16 fColor15;
mutable uint8 fColor8;
mutable bool fUpdate8;
mutable bool fUpdate15;
mutable bool fUpdate16;
};
#endif
#endif // RGB_COLOR_H

View File

@ -1,38 +1,20 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, Haiku, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: RGBColor.cpp
// Author: DarkWyrm <bpmagic@columbus.rr.com>
// Description: Color encapsulation class for the app_server
//
//------------------------------------------------------------------------------
/*
* Copyright 2001-2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm <bpmagic@columbus.rr.com>
*/
// Standard Includes -----------------------------------------------------------
#include <stdio.h>
// Local Includes --------------------------------------------------------------
#include "RGBColor.h"
#include "SystemPalette.h"
#include <ColorUtils.h>
#include <stdio.h>
/*!
\brief Create an RGBColor from specified values
\param red red
@ -45,6 +27,7 @@ RGBColor::RGBColor(uint8 r, uint8 g, uint8 b, uint8 a)
SetColor(r,g,b,a);
}
/*!
\brief Create an RGBColor from specified values
\param red red
@ -54,112 +37,122 @@ RGBColor::RGBColor(uint8 r, uint8 g, uint8 b, uint8 a)
*/
RGBColor::RGBColor(int r, int g, int b, int a)
{
SetColor(r,g,b,a);
SetColor(r, g, b, a);
}
/*!
\brief Create an RGBColor from an rgb_color
\param col color to initialize from
\param color color to initialize from
*/
RGBColor::RGBColor(const rgb_color &col)
RGBColor::RGBColor(const rgb_color &color)
{
SetColor(col);
SetColor(color);
}
/*!
\brief Create an RGBColor from a 16-bit RGBA color
\param col color to initialize from
\param color color to initialize from
*/
RGBColor::RGBColor(uint16 col)
RGBColor::RGBColor(uint16 color)
{
SetColor(col);
SetColor(color);
}
/*!
\brief Create an RGBColor from an index color
\param col color to initialize from
\param color color to initialize from
*/
RGBColor::RGBColor(uint8 col)
RGBColor::RGBColor(uint8 color)
{
SetColor(col);
SetColor(color);
}
/*!
\brief Copy Contructor
\param col color to initialize from
\param color color to initialize from
*/
RGBColor::RGBColor(const RGBColor &col)
RGBColor::RGBColor(const RGBColor &color)
{
color32=col.color32;
color16=col.color16;
color8=col.color8;
update8=col.update8;
update16=col.update16;
fColor32 = color.fColor32;
fColor16 = color.fColor16;
fColor8 = color.fColor8;
fUpdate8 = color.fUpdate8;
fUpdate16 = color.fUpdate16;
}
/*!
\brief Create an RGBColor with the values(0,0,0,0)
*/
RGBColor::RGBColor()
{
SetColor(0,0,0,0);
update8=update16=false;
SetColor(0, 0, 0, 0);
}
/*!
\brief Returns the color as the closest 8-bit color in the palette
\return The palette index for the current color
*/
uint8 RGBColor::GetColor8() const
uint8
RGBColor::GetColor8() const
{
if(update8)
{
color8=FindClosestColor(SystemPalette(), color32);
update8=false;
if (fUpdate8) {
fColor8 = FindClosestColor(SystemPalette(), fColor32);
fUpdate8 = false;
}
return color8;
return fColor8;
}
/*!
\brief Returns the color as the closest 15-bit color
\return 15-bit value of the current color plus 1-bit alpha
*/
uint16 RGBColor::GetColor15() const
uint16
RGBColor::GetColor15() const
{
if(update15)
{
color15=FindClosestColor15(color32);
update15=false;
if (fUpdate15) {
fColor15 = FindClosestColor15(fColor32);
fUpdate15 = false;
}
return color15;
return fColor15;
}
/*!
\brief Returns the color as the closest 16-bit color
\return 16-bit value of the current color
*/
uint16 RGBColor::GetColor16() const
uint16
RGBColor::GetColor16() const
{
if(update16)
{
color16=FindClosestColor16(color32);
update16=false;
if (fUpdate16) {
fColor16 = FindClosestColor16(fColor32);
fUpdate16 = false;
}
return color16;
return fColor16;
}
/*!
\brief Returns the color as a 32-bit color
\return current color, including alpha
*/
rgb_color RGBColor::GetColor32() const
rgb_color
RGBColor::GetColor32() const
{
return color32;
return fColor32;
}
/*!
\brief Set the object to specified values
\param red red
@ -167,16 +160,18 @@ rgb_color RGBColor::GetColor32() const
\param blue blue
\param alpha alpha, defaults to 255
*/
void RGBColor::SetColor(uint8 r, uint8 g, uint8 b, uint8 a)
void
RGBColor::SetColor(uint8 r, uint8 g, uint8 b, uint8 a)
{
color32.red=r;
color32.green=g;
color32.blue=b;
color32.alpha=a;
update8=update16=true;
fColor32.red = r;
fColor32.green = g;
fColor32.blue = b;
fColor32.alpha = a;
fUpdate8 = fUpdate16 = true;
}
/*!
\brief Set the object to specified values
\param red red
@ -184,185 +179,145 @@ void RGBColor::SetColor(uint8 r, uint8 g, uint8 b, uint8 a)
\param blue blue
\param alpha alpha, defaults to 255
*/
void RGBColor::SetColor(int r, int g, int b, int a)
void
RGBColor::SetColor(int r, int g, int b, int a)
{
color32.red=(uint8)r;
color32.green=(uint8)g;
color32.blue=(uint8)b;
color32.alpha=(uint8)a;
fColor32.red = (uint8)r;
fColor32.green = (uint8)g;
fColor32.blue = (uint8)b;
fColor32.alpha = (uint8)a;
update8=update16=true;
fUpdate8 = fUpdate16 = true;
}
/*!
\brief Set the object to specified value
\param col16 color to copy
*/
void RGBColor::SetColor(uint16 col16)
void
RGBColor::SetColor(uint16 col16)
{
color16=col16;
SetRGBColor(&color32,col16);
fColor16 = col16;
SetRGBColor(&fColor32,col16);
update8=true;
update16=false;
fUpdate8 = true;
fUpdate16 = false;
}
/*!
\brief Set the object to specified index in the palette
\param col8 color to copy
*/
void RGBColor::SetColor(uint8 col8)
void
RGBColor::SetColor(uint8 col8)
{
color8=col8;
color32=SystemPalette()[col8];
fColor8 = col8;
fColor32 = SystemPalette()[col8];
update8=false;
update16=true;
fUpdate8 = false;
fUpdate16 = true;
}
/*!
\brief Set the object to specified color
\param color color to copy
*/
void RGBColor::SetColor(const rgb_color &color)
void
RGBColor::SetColor(const rgb_color &color)
{
color32=color;
update8=update16=true;
fColor32 = color;
fUpdate8 = fUpdate16 = true;
}
/*!
\brief Set the object to specified color
\param col color to copy
\param color color to copy
*/
void
RGBColor::SetColor(const RGBColor &col)
RGBColor::SetColor(const RGBColor &color)
{
color32 = col.color32;
color16 = col.color16;
color8 = col.color8;
update8 = col.update8;
update16 = col.update16;
fColor32 = color.fColor32;
fColor16 = color.fColor16;
fColor8 = color.fColor8;
fUpdate8 = color.fUpdate8;
fUpdate16 = color.fUpdate16;
}
/*!
\brief Set the object to specified color
\param col color to copy
\param color color to copy
*/
const RGBColor&
RGBColor::operator=(const RGBColor &col)
RGBColor::operator=(const RGBColor &color)
{
color32 = col.color32;
color16 = col.color16;
color8 = col.color8;
update8 = col.update8;
update16 = col.update16;
fColor32 = color.fColor32;
fColor16 = color.fColor16;
fColor8 = color.fColor8;
fUpdate8 = color.fUpdate8;
fUpdate16 = color.fUpdate16;
return *this;
}
/*!
\brief Set the object to specified color
\param col color to copy
\param color color to copy
*/
const RGBColor&
RGBColor::operator=(const rgb_color &col)
RGBColor::operator=(const rgb_color &color)
{
color32 = col;
update8 = update16 = true;
fColor32 = color;
fUpdate8 = fUpdate16 = true;
return *this;
}
/*!
\brief Returns a color blended between the object's value and
another color.
\param color The other color to be blended with.
\param position A weighted percentage of the second color to use. 0 <= value <= 1.0
\return The blended color
If the position passed to this function is invalid, the starting
color will be returned.
*/
RGBColor RGBColor::MakeBlendColor(const RGBColor &color, const float &position)
{
rgb_color col=color32;
rgb_color col2=color.color32;
rgb_color newcol={0,0,0,0};
float mod=0;
int16 delta;
if(position<0 || position>1)
return *this;
delta=int16(col2.red)-int16(col.red);
mod=col.red + (position * delta);
newcol.red=uint8(mod);
if(mod>255 )
newcol.red=255;
if(mod<0 )
newcol.red=0;
delta=int16(col2.green)-int16(col.green);
mod=col.green + (position * delta);
newcol.green=uint8(mod);
if(mod>255 )
newcol.green=255;
if(mod<0 )
newcol.green=0;
delta=int16(col2.blue)-int16(col.blue);
mod=col.blue + (position * delta);
newcol.blue=uint8(mod);
if(mod>255 )
newcol.blue=255;
if(mod<0 )
newcol.blue=0;
delta=int8(col2.alpha)-int8(col.alpha);
mod=col.alpha + (position * delta);
newcol.alpha=uint8(mod);
if(mod>255 )
newcol.alpha=255;
if(mod<0 )
newcol.alpha=0;
return RGBColor(newcol);
}
/*!
\brief Prints the 32-bit values of the color to standard out
*/
void RGBColor::PrintToStream(void) const
void
RGBColor::PrintToStream(void) const
{
printf("RGBColor (%u,%u,%u,%u)\n", color32.red,color32.green,color32.blue,color32.alpha);
printf("RGBColor(%u,%u,%u,%u)\n",
fColor32.red, fColor32.green, fColor32.blue, fColor32.alpha);
}
/*!
\brief Overloaded comaparison
\return true if all color elements are exactly equal
*/
bool RGBColor::operator==(const rgb_color &col) const
bool
RGBColor::operator==(const rgb_color &color) const
{
return color32.red == col.red &&
color32.green == col.green &&
color32.blue == col.blue &&
color32.alpha == col.alpha;
return fColor32.red == color.red
&& fColor32.green == color.green
&& fColor32.blue == color.blue
&& fColor32.alpha == color.alpha;
}
/*!
\brief Overloaded comaparison
\return true if all color elements are exactly equal
*/
bool RGBColor::operator==(const RGBColor &col) const
bool
RGBColor::operator==(const RGBColor &color) const
{
return color32.red == col.color32.red &&
color32.green == col.color32.green &&
color32.blue == col.color32.blue &&
color32.alpha == col.color32.alpha;
return fColor32.red == color.fColor32.red
&& fColor32.green == color.fColor32.green
&& fColor32.blue == color.fColor32.blue
&& fColor32.alpha == color.fColor32.alpha;
}
// IsTransparentMagic
bool
RGBColor::IsTransparentMagic() const
{