Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
nsColor.cpp File Reference
#include "plstr.h"
#include "nsColor.h"
#include "nsColorNames.h"
#include "nsString.h"
#include "nscore.h"
#include "nsCoord.h"
#include "nsUnitConversion.h"
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIScreen.h"
#include "nsIScreenManager.h"
#include <math.h>
#include "prprf.h"

Go to the source code of this file.

Functions

static int ComponentValue (const char *aColorSpec, int aLen, int color, int dpc)
 NS_GFX_ (PRBool) NS_HexToRGB(const nsString &aColorSpec
nscolor *aResult
NS_LossyConvertUCS2toASCII 
bufferStr (aColorSpec)
return NS_ASCIIHexToRGB (bufferStr, aResult)
 if ((nameLen==3)||(nameLen==6))
nscolor *aResult
NS_LossyConvertUCS2toASCII 
buffer (aColorSpec)
 if ('#'==colorSpec[0])
 if (3< nameLen)
 NS_GFX_ (void) NS_RGBToHex(nscolor aColor
 PR_snprintf (buf, sizeof(buf),"#%02x%02x%02x", NS_GET_R(aColor), NS_GET_G(aColor), NS_GET_B(aColor))
 CopyASCIItoUTF16 (buf, aResult)
nsAFlatCString &aResult aResult SetLength (7)
 NS_ASSERTION (aResult.Length()==7,"small SetLength failed, use an autostring instead!")
 PR_snprintf (buf, 8,"#%02x%02x%02x", NS_GET_R(aColor), NS_GET_G(aColor), NS_GET_B(aColor))
 NS_GFX_ (nscolor) NS_BrightenColor(nscolor inColor)
 MOZ_BLEND (r, 0, NS_GET_R(aBG), bgAlpha)
 MOZ_BLEND (g, 0, NS_GET_G(aBG), bgAlpha)
 MOZ_BLEND (b, 0, NS_GET_B(aBG), bgAlpha)
 MOZ_BLEND (r, r, NS_GET_R(aFG), fgAlpha)
 MOZ_BLEND (g, g, NS_GET_G(aFG), fgAlpha)
 MOZ_BLEND (b, b, NS_GET_B(aFG), fgAlpha)
 MOZ_BLEND (a, a, 255, fgAlpha)
return NS_RGBA (r, g, b, a)
static float HSL_HueToRGB (float m1, float m2, float h)
 if (l<=0.5f)
return NS_RGB (r, g, b)

Variables

nscolor *aResult const char * buffer = aColorSpec.get()
int nameLen = aColorSpec.Length()
return PR_FALSE
const char * colorSpec = buffer.get()
nsAString &aResult char buf [10] = aResult.BeginWriting()
nscolor *aResult nsColorName id = nsColorNames::LookupName(aColorName)
nscolor aFG PRIntn bgAlpha = NS_GET_A(aBG)
PRIntn r = PRUint8(255 * HSL_HueToRGB(m1, m2, h + 1.0f/3.0f))
PRIntn g = PRUint8(255 * HSL_HueToRGB(m1, m2, h))
PRIntn b = PRUint8(255 * HSL_HueToRGB(m1, m2, h - 1.0f/3.0f))
PRIntn a = bgAlpha
PRIntn fgAlpha = NS_GET_A(aFG)
float s
float m1
float m2

Function Documentation

static int ComponentValue ( const char *  aColorSpec,
int  aLen,
int  color,
int  dpc 
) [static]

Definition at line 52 of file nsColor.cpp.

{
  int component = 0;
  int index = (color * dpc);
  if (2 < dpc) {
    dpc = 2;
  }
  while (--dpc >= 0) {
    char ch = ((index < aLen) ? aColorSpec[index++] : '0');
    if (('0' <= ch) && (ch <= '9')) {
      component = (component * 16) + (ch - '0');
    } else if ((('a' <= ch) && (ch <= 'f')) || 
               (('A' <= ch) && (ch <= 'F'))) {
      // "ch&7" handles lower and uppercase hex alphabetics
      component = (component * 16) + (ch & 7) + 9;
    }
    else {  // not a hex digit, treat it like 0
      component = (component * 16);
    }
  }
  return component;
}

Here is the caller graph for this function:

static float HSL_HueToRGB ( float  m1,
float  m2,
float  h 
) [static]

Definition at line 350 of file nsColor.cpp.

{
  if (h < 0.0f)
    h += 1.0f;
  if (h > 1.0f)
    h -= 1.0f;
  if (h < (float)(1.0/6.0))
    return m1 + (m2 - m1)*h*6.0f;
  if (h < (float)(1.0/2.0))
    return m2;
  if (h < (float)(2.0/3.0))
    return m1 + (m2 - m1)*((float)(2.0/3.0) - h)*6.0f;
  return m1;      
}
if ( (nameLen==3)||(nameLen==6)  )

Definition at line 89 of file nsColor.cpp.

                                        {
    // Make sure the digits are legal
    for (int i = 0; i < nameLen; i++) {
      char ch = buffer[i];
      if (((ch >= '0') && (ch <= '9')) ||
          ((ch >= 'a') && (ch <= 'f')) ||
          ((ch >= 'A') && (ch <= 'F'))) {
        // Legal character
        continue;
      }
      // Whoops. Illegal character.
      return PR_FALSE;
    }

    // Convert the ascii to binary
    int dpc = ((3 == nameLen) ? 1 : 2);
    // Translate components from hex to binary
    int r = ComponentValue(buffer, nameLen, 0, dpc);
    int g = ComponentValue(buffer, nameLen, 1, dpc);
    int b = ComponentValue(buffer, nameLen, 2, dpc);
    if (dpc == 1) {
      // Scale single digit component to an 8 bit value. Replicate the
      // single digit to compute the new value.
      r = (r << 4) | r;
      g = (g << 4) | g;
      b = (b << 4) | b;
    }
    NS_ASSERTION((r >= 0) && (r <= 255), "bad r");
    NS_ASSERTION((g >= 0) && (g <= 255), "bad g");
    NS_ASSERTION((b >= 0) && (b <= 255), "bad b");
    if (nsnull != aResult) {
      *aResult = NS_RGB(r, g, b);
    }
    return PR_TRUE;
  }

Here is the call graph for this function:

if ( '#'  = colorSpec[0])

Definition at line 137 of file nsColor.cpp.

                           {
    ++colorSpec;
    --nameLen;
  }
if ( )

Definition at line 142 of file nsColor.cpp.

                   {
    // Convert the ascii to binary
    int dpc = (nameLen / 3) + (((nameLen % 3) != 0) ? 1 : 0);
    if (4 < dpc) {
      dpc = 4;
    }

    // Translate components from hex to binary
    int r = ComponentValue(colorSpec, nameLen, 0, dpc);
    int g = ComponentValue(colorSpec, nameLen, 1, dpc);
    int b = ComponentValue(colorSpec, nameLen, 2, dpc);
    NS_ASSERTION((r >= 0) && (r <= 255), "bad r");
    NS_ASSERTION((g >= 0) && (g <= 255), "bad g");
    NS_ASSERTION((b >= 0) && (b <= 255), "bad b");
    if (nsnull != aResult) {
      *aResult = NS_RGB(r, g, b);
    }
  }

Here is the call graph for this function:

if ( l<=0.  5f)

Definition at line 371 of file nsColor.cpp.

                 {
    m2 = l*(s+1);
  } else {
MOZ_BLEND ( r  ,
,
NS_GET_R(aBG)  ,
bgAlpha   
)
MOZ_BLEND ( g  ,
,
NS_GET_G(aBG)  ,
bgAlpha   
)
MOZ_BLEND ( b  ,
,
NS_GET_B(aBG)  ,
bgAlpha   
)
MOZ_BLEND ( r  ,
r  ,
NS_GET_R(aFG ,
fgAlpha   
)
MOZ_BLEND ( g  ,
g  ,
NS_GET_G(aFG ,
fgAlpha   
)
MOZ_BLEND ( b  ,
b  ,
NS_GET_B(aFG ,
fgAlpha   
)
MOZ_BLEND ( a  ,
a  ,
255  ,
fgAlpha   
)
NS_ASSERTION ( aResult.  Length() = =7,
"small SetLength  failed,
use an autostring instead!"   
)
NS_GFX_ ( PRBool  ) const
NS_GFX_ ( void  )

Definition at line 199 of file nsColor.cpp.

{
  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));
}

Here is the call graph for this function:

return NS_RGB ( r  ,
g  ,
b   
)
return NS_RGBA ( r  ,
g  ,
b  ,
a   
)

Here is the caller graph for this function:

PR_snprintf ( buf  ,
sizeof(buf ,
"#%02x%02x%02x"  ,
NS_GET_R(aColor)  ,
NS_GET_G(aColor)  ,
NS_GET_B(aColor)   
)
PR_snprintf ( buf  ,
,
"#%02x%02x%02x"  ,
NS_GET_R(aColor)  ,
NS_GET_G(aColor)  ,
NS_GET_B(aColor)   
)

Here is the caller graph for this function:


Variable Documentation

Definition at line 327 of file nsColor.cpp.

b = PRUint8(255 * HSL_HueToRGB(m1, m2, h - 1.0f/3.0f))

Definition at line 327 of file nsColor.cpp.

nscolor aFG PRIntn bgAlpha = NS_GET_A(aBG)

Definition at line 326 of file nsColor.cpp.

char* buf = aResult.BeginWriting()

Definition at line 170 of file nsColor.cpp.

nscolor* aResult const char* buffer = aColorSpec.get()

Definition at line 86 of file nsColor.cpp.

const char* colorSpec = buffer.get()

Definition at line 136 of file nsColor.cpp.

PRIntn fgAlpha = NS_GET_A(aFG)

Definition at line 336 of file nsColor.cpp.

float float l PRUint8 g = PRUint8(255 * HSL_HueToRGB(m1, m2, h))

Definition at line 327 of file nsColor.cpp.

XPTInterfaceDescriptor * id = nsColorNames::LookupName(aColorName)

Definition at line 188 of file nsColor.cpp.

float m1

Definition at line 370 of file nsColor.cpp.

float m2

Definition at line 370 of file nsColor.cpp.

int nameLen = aColorSpec.Length()

Definition at line 88 of file nsColor.cpp.

Definition at line 126 of file nsColor.cpp.

r = PRUint8(255 * HSL_HueToRGB(m1, m2, h + 1.0f/3.0f))

Definition at line 327 of file nsColor.cpp.

float s

Definition at line 367 of file nsColor.cpp.