made color handling code in css part of the gfx color utilities.

This commit is contained in:
michaelp%netscape.com 1998-07-27 21:07:47 +00:00
Родитель a3288e5006
Коммит b636c3052c
7 изменённых файлов: 188 добавлений и 419 удалений

Просмотреть файл

@ -109,3 +109,176 @@ extern "C" NS_GFX_(PRBool) NS_ColorNameToRGB(const char* aColorName, nscolor* aR
} }
return PR_FALSE; return PR_FALSE;
} }
// Weird color computing code stolen from winfe which was stolen
// from the xfe which was written originally by Eric Bina. So there.
#define RED_LUMINOSITY 30
#define GREEN_LUMINOSITY 59
#define BLUE_LUMINOSITY 11
#define INTENSITY_FACTOR 25
#define LIGHT_FACTOR 0
#define LUMINOSITY_FACTOR 75
#define MAX_COLOR 255
#define COLOR_DARK_THRESHOLD 51
#define COLOR_LIGHT_THRESHOLD 204
extern "C" NS_GFX_(void) NS_Get3DColors(nscolor aResult[2], nscolor aColor)
{
int rb = NS_GET_R(aColor);
int gb = NS_GET_G(aColor);
int bb = NS_GET_B(aColor);
int intensity = (rb + gb + bb) / 3;
int luminosity =
((RED_LUMINOSITY * rb) / 100) +
((GREEN_LUMINOSITY * gb) / 100) +
((BLUE_LUMINOSITY * bb) / 100);
int brightness = ((intensity * INTENSITY_FACTOR) +
(luminosity * LUMINOSITY_FACTOR)) / 100;
int f0, f1;
if (brightness < COLOR_DARK_THRESHOLD) {
f0 = 30;
f1 = 50;
} else if (brightness > COLOR_LIGHT_THRESHOLD) {
f0 = 45;
f1 = 50;
} else {
f0 = 30 + (brightness * (45 - 30) / MAX_COLOR);
f1 = f0;
}
int r = rb - (f0 * rb / 100);
int g = gb - (f0 * gb / 100);
int b = bb - (f0 * bb / 100);
aResult[0] = NS_RGB(r, g, b);
r = rb + (f1 * (MAX_COLOR - rb) / 100);
if (r > 255) r = 255;
g = gb + (f1 * (MAX_COLOR - gb) / 100);
if (g > 255) g = 255;
b = bb + (f1 * (MAX_COLOR - bb) / 100);
if (b > 255) b = 255;
aResult[1] = NS_RGB(r, g, b);
}
extern "C" NS_GFX_(nscolor) NS_BrightenColor(nscolor inColor)
{
PRIntn r, g, b, max, over;
r = NS_GET_R(inColor);
g = NS_GET_G(inColor);
b = NS_GET_B(inColor);
//10% of max color increase across the board
r += 25;
g += 25;
b += 25;
//figure out which color is largest
if (r > g)
{
if (b > r)
max = b;
else
max = r;
}
else
{
if (b > g)
max = b;
else
max = g;
}
//if we overflowed on this max color, increase
//other components by the overflow amount
if (max > 255)
{
over = max - 255;
if (max == r)
{
g += over;
b += over;
}
else if (max == g)
{
r += over;
b += over;
}
else
{
r += over;
g += over;
}
}
//clamp
if (r > 255)
r = 255;
if (g > 255)
g = 255;
if (b > 255)
b = 255;
return NS_RGBA(r, g, b, NS_GET_A(inColor));
}
extern "C" NS_GFX_(nscolor) NS_DarkenColor(nscolor inColor)
{
PRIntn r, g, b, max;
r = NS_GET_R(inColor);
g = NS_GET_G(inColor);
b = NS_GET_B(inColor);
//10% of max color decrease across the board
r -= 25;
g -= 25;
b -= 25;
//figure out which color is largest
if (r > g)
{
if (b > r)
max = b;
else
max = r;
}
else
{
if (b > g)
max = b;
else
max = g;
}
//if we underflowed on this max color, decrease
//other components by the underflow amount
if (max < 0)
{
if (max == r)
{
g += max;
b += max;
}
else if (max == g)
{
r += max;
b += max;
}
else
{
r += max;
g += max;
}
}
//clamp
if (r < 0)
r = 0;
if (g < 0)
g = 0;
if (b < 0)
b = 0;
return NS_RGBA(r, g, b, NS_GET_A(inColor));
}

Просмотреть файл

@ -49,4 +49,16 @@ extern "C" NS_GFX_(PRBool) NS_HexToRGB(const char* aBuf, nscolor* aResult);
// otherwise return false. // otherwise return false.
extern "C" NS_GFX_(PRBool) NS_ColorNameToRGB(const char* aBuf, nscolor* aResult); extern "C" NS_GFX_(PRBool) NS_ColorNameToRGB(const char* aBuf, nscolor* aResult);
// Weird color computing code stolen from winfe which was stolen
// from the xfe which was written originally by Eric Bina. So there.
extern "C" NS_GFX_(void) NS_Get3DColors(nscolor aResult[2], nscolor aColor);
// Special method to brighten a Color and have it shift to white when
// fully saturated.
extern "C" NS_GFX_(nscolor) NS_BrightenColor(nscolor inColor);
// Special method to darken a Color and have it shift to black when
// darkest component underflows
extern "C" NS_GFX_(nscolor) NS_DarkenColor(nscolor inColor);
#endif /* nsColor_h___ */ #endif /* nsColor_h___ */

Просмотреть файл

@ -37,189 +37,6 @@
// Weird color computing code stolen from winfe which was stolen
// from the xfe which was written originally by Eric Bina. So there.
const int nsCSSRendering::RED_LUMINOSITY = 30;
const int nsCSSRendering::GREEN_LUMINOSITY = 59;
const int nsCSSRendering::BLUE_LUMINOSITY = 11;
const int nsCSSRendering::INTENSITY_FACTOR = 25;
const int nsCSSRendering::LIGHT_FACTOR = 0;
const int nsCSSRendering::LUMINOSITY_FACTOR = 75;
const int nsCSSRendering::MAX_COLOR = 255;
const int nsCSSRendering::COLOR_DARK_THRESHOLD = 51;
const int nsCSSRendering::COLOR_LIGHT_THRESHOLD = 204;
void nsCSSRendering::Get3DColors(nscolor aResult[2], nscolor aColor)
{
int rb = NS_GET_R(aColor);
int gb = NS_GET_G(aColor);
int bb = NS_GET_B(aColor);
int intensity = (rb + gb + bb) / 3;
int luminosity =
((RED_LUMINOSITY * rb) / 100) +
((GREEN_LUMINOSITY * gb) / 100) +
((BLUE_LUMINOSITY * bb) / 100);
int brightness = ((intensity * INTENSITY_FACTOR) +
(luminosity * LUMINOSITY_FACTOR)) / 100;
int f0, f1;
if (brightness < COLOR_DARK_THRESHOLD) {
f0 = 30;
f1 = 50;
} else if (brightness > COLOR_LIGHT_THRESHOLD) {
f0 = 45;
f1 = 50;
} else {
f0 = 30 + (brightness * (45 - 30) / MAX_COLOR);
f1 = f0;
}
int r = rb - (f0 * rb / 100);
int g = gb - (f0 * gb / 100);
int b = bb - (f0 * bb / 100);
aResult[0] = NS_RGB(r, g, b);
r = rb + (f1 * (MAX_COLOR - rb) / 100);
if (r > 255) r = 255;
g = gb + (f1 * (MAX_COLOR - gb) / 100);
if (g > 255) g = 255;
b = bb + (f1 * (MAX_COLOR - bb) / 100);
if (b > 255) b = 255;
aResult[1] = NS_RGB(r, g, b);
}
/**
* Special method to brighten a Color and have it shift to white when
* fully saturated.
*/
nscolor nsCSSRendering::Brighten(nscolor inColor)
{
PRIntn r, g, b, max, over;
r = NS_GET_R(inColor);
g = NS_GET_G(inColor);
b = NS_GET_B(inColor);
//10% of max color increase across the board
r += 25;
g += 25;
b += 25;
//figure out which color is largest
if (r > g)
{
if (b > r)
max = b;
else
max = r;
}
else
{
if (b > g)
max = b;
else
max = g;
}
//if we overflowed on this max color, increase
//other components by the overflow amount
if (max > 255)
{
over = max - 255;
if (max == r)
{
g += over;
b += over;
}
else if (max == g)
{
r += over;
b += over;
}
else
{
r += over;
g += over;
}
}
//clamp
if (r > 255)
r = 255;
if (g > 255)
g = 255;
if (b > 255)
b = 255;
return NS_RGBA(r, g, b, NS_GET_A(inColor));
}
/**
* Special method to darken a Color and have it shift to black when
* darkest component underflows
*/
nscolor nsCSSRendering::Darken(nscolor inColor)
{
PRIntn r, g, b, max;
r = NS_GET_R(inColor);
g = NS_GET_G(inColor);
b = NS_GET_B(inColor);
//10% of max color decrease across the board
r -= 25;
g -= 25;
b -= 25;
//figure out which color is largest
if (r > g)
{
if (b > r)
max = b;
else
max = r;
}
else
{
if (b > g)
max = b;
else
max = g;
}
//if we underflowed on this max color, decrease
//other components by the underflow amount
if (max < 0)
{
if (max == r)
{
g += max;
b += max;
}
else if (max == g)
{
r += max;
b += max;
}
else
{
r += max;
g += max;
}
}
//clamp
if (r < 0)
r = 0;
if (g < 0)
g = 0;
if (b < 0)
b = 0;
return NS_RGBA(r, g, b, NS_GET_A(inColor));
}
/** /**
* Make a bevel color * Make a bevel color
*/ */
@ -242,7 +59,7 @@ nscolor nsCSSRendering::MakeBevelColor(PRIntn whichSide, PRUint8 style,
{ {
// Given a background color and a border color // Given a background color and a border color
// calculate the color used for the shading // calculate the color used for the shading
Get3DColors(colors, baseColor); NS_Get3DColors(colors, baseColor);
} }

Просмотреть файл

@ -54,31 +54,6 @@ public:
const nsRect& aBounds, const nsRect& aBounds,
const nsStyleColor& aColor); const nsStyleColor& aColor);
/**
* Special method to brighten a Color and have it shift to white when
* fully saturated.
*/
static nscolor Brighten(nscolor inColor);
/**
* Special method to darken a Color and have it shift to black when
* darkest component underflows
*/
static nscolor Darken(nscolor inColor);
// Weird color computing code stolen from winfe which was stolen
// from the xfe which was written originally by Eric Bina. So there.
static void Get3DColors(nscolor aResult[2], nscolor aColor);
static const int RED_LUMINOSITY;
static const int GREEN_LUMINOSITY;
static const int BLUE_LUMINOSITY;
static const int INTENSITY_FACTOR;
static const int LIGHT_FACTOR;
static const int LUMINOSITY_FACTOR;
static const int MAX_COLOR;
static const int COLOR_DARK_THRESHOLD;
static const int COLOR_LIGHT_THRESHOLD;
protected: protected:
static nscolor MakeBevelColor(PRIntn whichSide, PRUint8 style, static nscolor MakeBevelColor(PRIntn whichSide, PRUint8 style,
nscolor baseColor, nscolor baseColor,

Просмотреть файл

@ -181,7 +181,7 @@ HRuleFrame::Paint(nsIPresContext& aPresContext,
{ {
// XXX Get correct color by finding the first parent that actually // XXX Get correct color by finding the first parent that actually
// specifies a color. // specifies a color.
nsCSSRendering::Get3DColors(colors, color->mBackgroundColor); NS_Get3DColors(colors, color->mBackgroundColor);
} }
// Draw a "shadowed" box around the rule area // Draw a "shadowed" box around the rule area

Просмотреть файл

@ -37,189 +37,6 @@
// Weird color computing code stolen from winfe which was stolen
// from the xfe which was written originally by Eric Bina. So there.
const int nsCSSRendering::RED_LUMINOSITY = 30;
const int nsCSSRendering::GREEN_LUMINOSITY = 59;
const int nsCSSRendering::BLUE_LUMINOSITY = 11;
const int nsCSSRendering::INTENSITY_FACTOR = 25;
const int nsCSSRendering::LIGHT_FACTOR = 0;
const int nsCSSRendering::LUMINOSITY_FACTOR = 75;
const int nsCSSRendering::MAX_COLOR = 255;
const int nsCSSRendering::COLOR_DARK_THRESHOLD = 51;
const int nsCSSRendering::COLOR_LIGHT_THRESHOLD = 204;
void nsCSSRendering::Get3DColors(nscolor aResult[2], nscolor aColor)
{
int rb = NS_GET_R(aColor);
int gb = NS_GET_G(aColor);
int bb = NS_GET_B(aColor);
int intensity = (rb + gb + bb) / 3;
int luminosity =
((RED_LUMINOSITY * rb) / 100) +
((GREEN_LUMINOSITY * gb) / 100) +
((BLUE_LUMINOSITY * bb) / 100);
int brightness = ((intensity * INTENSITY_FACTOR) +
(luminosity * LUMINOSITY_FACTOR)) / 100;
int f0, f1;
if (brightness < COLOR_DARK_THRESHOLD) {
f0 = 30;
f1 = 50;
} else if (brightness > COLOR_LIGHT_THRESHOLD) {
f0 = 45;
f1 = 50;
} else {
f0 = 30 + (brightness * (45 - 30) / MAX_COLOR);
f1 = f0;
}
int r = rb - (f0 * rb / 100);
int g = gb - (f0 * gb / 100);
int b = bb - (f0 * bb / 100);
aResult[0] = NS_RGB(r, g, b);
r = rb + (f1 * (MAX_COLOR - rb) / 100);
if (r > 255) r = 255;
g = gb + (f1 * (MAX_COLOR - gb) / 100);
if (g > 255) g = 255;
b = bb + (f1 * (MAX_COLOR - bb) / 100);
if (b > 255) b = 255;
aResult[1] = NS_RGB(r, g, b);
}
/**
* Special method to brighten a Color and have it shift to white when
* fully saturated.
*/
nscolor nsCSSRendering::Brighten(nscolor inColor)
{
PRIntn r, g, b, max, over;
r = NS_GET_R(inColor);
g = NS_GET_G(inColor);
b = NS_GET_B(inColor);
//10% of max color increase across the board
r += 25;
g += 25;
b += 25;
//figure out which color is largest
if (r > g)
{
if (b > r)
max = b;
else
max = r;
}
else
{
if (b > g)
max = b;
else
max = g;
}
//if we overflowed on this max color, increase
//other components by the overflow amount
if (max > 255)
{
over = max - 255;
if (max == r)
{
g += over;
b += over;
}
else if (max == g)
{
r += over;
b += over;
}
else
{
r += over;
g += over;
}
}
//clamp
if (r > 255)
r = 255;
if (g > 255)
g = 255;
if (b > 255)
b = 255;
return NS_RGBA(r, g, b, NS_GET_A(inColor));
}
/**
* Special method to darken a Color and have it shift to black when
* darkest component underflows
*/
nscolor nsCSSRendering::Darken(nscolor inColor)
{
PRIntn r, g, b, max;
r = NS_GET_R(inColor);
g = NS_GET_G(inColor);
b = NS_GET_B(inColor);
//10% of max color decrease across the board
r -= 25;
g -= 25;
b -= 25;
//figure out which color is largest
if (r > g)
{
if (b > r)
max = b;
else
max = r;
}
else
{
if (b > g)
max = b;
else
max = g;
}
//if we underflowed on this max color, decrease
//other components by the underflow amount
if (max < 0)
{
if (max == r)
{
g += max;
b += max;
}
else if (max == g)
{
r += max;
b += max;
}
else
{
r += max;
g += max;
}
}
//clamp
if (r < 0)
r = 0;
if (g < 0)
g = 0;
if (b < 0)
b = 0;
return NS_RGBA(r, g, b, NS_GET_A(inColor));
}
/** /**
* Make a bevel color * Make a bevel color
*/ */
@ -242,7 +59,7 @@ nscolor nsCSSRendering::MakeBevelColor(PRIntn whichSide, PRUint8 style,
{ {
// Given a background color and a border color // Given a background color and a border color
// calculate the color used for the shading // calculate the color used for the shading
Get3DColors(colors, baseColor); NS_Get3DColors(colors, baseColor);
} }

Просмотреть файл

@ -54,31 +54,6 @@ public:
const nsRect& aBounds, const nsRect& aBounds,
const nsStyleColor& aColor); const nsStyleColor& aColor);
/**
* Special method to brighten a Color and have it shift to white when
* fully saturated.
*/
static nscolor Brighten(nscolor inColor);
/**
* Special method to darken a Color and have it shift to black when
* darkest component underflows
*/
static nscolor Darken(nscolor inColor);
// Weird color computing code stolen from winfe which was stolen
// from the xfe which was written originally by Eric Bina. So there.
static void Get3DColors(nscolor aResult[2], nscolor aColor);
static const int RED_LUMINOSITY;
static const int GREEN_LUMINOSITY;
static const int BLUE_LUMINOSITY;
static const int INTENSITY_FACTOR;
static const int LIGHT_FACTOR;
static const int LUMINOSITY_FACTOR;
static const int MAX_COLOR;
static const int COLOR_DARK_THRESHOLD;
static const int COLOR_LIGHT_THRESHOLD;
protected: protected:
static nscolor MakeBevelColor(PRIntn whichSide, PRUint8 style, static nscolor MakeBevelColor(PRIntn whichSide, PRUint8 style,
nscolor baseColor, nscolor baseColor,