Bug 422620 - "Remove NS_BrightenColor and NS_DarkenColor" [p=alfredkayser@gmail.com (Alfred Kayser) r=vlad a1.9=damons]
authorreed@reedloden.com
Fri, 14 Mar 2008 09:27:14 -0700
changeset 13079 3e389aa50b72f4e8c268411e3bef9fc0fafd19f0
parent 13078 9ea8962a1716f46755ca99ebe66ed173924c2b10
child 13080 2507258a1578c4798304b98a1893332e21bdf21d
push idunknown
push userunknown
push dateunknown
reviewersvlad
bugs422620
milestone1.9b5pre
Bug 422620 - "Remove NS_BrightenColor and NS_DarkenColor" [p=alfredkayser@gmail.com (Alfred Kayser) r=vlad a1.9=damons]
gfx/public/nsColor.h
gfx/src/nsColor.cpp
--- a/gfx/public/nsColor.h
+++ b/gfx/public/nsColor.h
@@ -80,46 +80,34 @@ typedef PRUint32 nscolor;
 // Blending macro
 //
 // equivalent to target=(bg*(255-alpha)+fg*alpha)/255
 #define MOZ_BLEND(target, bg, fg, alpha) \
         FAST_DIVIDE_BY_255(target, (bg)*(255-(alpha)) + (fg)*(alpha))
 
 // Translate a hex string to a color. Return true if it parses ok,
 // otherwise return false.
-// This accepts only 3, 6 or 9 digits
+// This accepts only 3 or 6 digits
 NS_GFX_(PRBool) NS_HexToRGB(const nsString& aBuf, nscolor* aResult);
-NS_GFX_(PRBool) NS_ASCIIHexToRGB(const nsCString& aBuf,
-                                            nscolor* aResult);
 
 // Compose one NS_RGB color onto another. The result is what you get
 // if you draw aBG onto RGBA(0,0,0,0) and then aFG on top of that,
 // with operator OVER.
 NS_GFX_(nscolor) NS_ComposeColors(nscolor aBG, nscolor aFG);
 
 // Translate a hex string to a color. Return true if it parses ok,
 // otherwise return false.
 // This version accepts 1 to 9 digits (missing digits are 0)
 NS_GFX_(PRBool) NS_LooseHexToRGB(const nsString& aBuf, nscolor* aResult);
 
 // Translate a color to a hex string and prepend a '#'.
 // The returned string is always 7 characters including a '#' character.
 NS_GFX_(void) NS_RGBToHex(nscolor aColor, nsAString& aResult);
-NS_GFX_(void) NS_RGBToASCIIHex(nscolor aColor,
-                                          nsCString& aResult);
 
 // Translate a color name to a color. Return true if it parses ok,
 // otherwise return false.
 NS_GFX_(PRBool) NS_ColorNameToRGB(const nsAString& aBuf, nscolor* aResult);
 
-// Special method to brighten a Color and have it shift to white when
-// fully saturated.
-NS_GFX_(nscolor) NS_BrightenColor(nscolor inColor);
-
-// Special method to darken a Color and have it shift to black when
-// darkest component underflows
-NS_GFX_(nscolor) NS_DarkenColor(nscolor inColor);
-
 // function to convert from HSL color space to RGB color space
 // the float parameters are all expected to be in the range 0-1
 NS_GFX_(nscolor) NS_HSL2RGB(float h, float s, float l);
 
 #endif /* nsColor_h___ */
--- a/gfx/src/nsColor.cpp
+++ b/gfx/src/nsColor.cpp
@@ -64,22 +64,16 @@ static int ComponentValue(const PRUnicha
     }
     else {  // not a hex digit, treat it like 0
       component = (component * 16);
     }
   }
   return component;
 }
 
-NS_GFX_(PRBool) NS_ASCIIHexToRGB(const nsCString& aColorSpec,
-                                            nscolor* aResult)
-{
-  return NS_HexToRGB(NS_ConvertASCIItoUTF16(aColorSpec), aResult);
-}
-
 NS_GFX_(PRBool) NS_HexToRGB(const nsString& aColorSpec,
                                        nscolor* aResult)
 {
   const PRUnichar* buffer = aColorSpec.get();
 
   int nameLen = aColorSpec.Length();
   if ((nameLen == 3) || (nameLen == 6)) {
     // Make sure the digits are legal
@@ -160,163 +154,29 @@ NS_GFX_(PRBool) NS_LooseHexToRGB(const n
 NS_GFX_(void) NS_RGBToHex(nscolor aColor, nsAString& aResult)
 {
   char buf[10];
   PR_snprintf(buf, sizeof(buf), "#%02x%02x%02x",
               NS_GET_R(aColor), NS_GET_G(aColor), NS_GET_B(aColor));
   CopyASCIItoUTF16(buf, aResult);
 }
 
-NS_GFX_(void) NS_RGBToASCIIHex(nscolor aColor,
-                                          nsAFlatCString& aResult)
-{
-  aResult.SetLength(7);
-  NS_ASSERTION(aResult.Length() == 7, "small SetLength failed, use an autostring instead!");
-  char *buf = aResult.BeginWriting();
-  PR_snprintf(buf, 8, "#%02x%02x%02x",
-              NS_GET_R(aColor), NS_GET_G(aColor), NS_GET_B(aColor));
-}
-
 NS_GFX_(PRBool) NS_ColorNameToRGB(const nsAString& aColorName, nscolor* aResult)
 {
   nsColorName id = nsColorNames::LookupName(aColorName);
   if (eColorName_UNKNOWN < id) {
     NS_ASSERTION(id < eColorName_COUNT, "LookupName mess up");
     if (nsnull != aResult) {
       *aResult = nsColorNames::kColors[id];
     }
     return PR_TRUE;
   }
   return PR_FALSE;
 }
 
-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));
-}
-
-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));
-}
-
 NS_GFX_(nscolor)
 NS_ComposeColors(nscolor aBG, nscolor aFG)
 {
   PRIntn bgAlpha = NS_GET_A(aBG);
   PRIntn r, g, b, a;
 
   // First compute what we get drawing aBG onto RGBA(0,0,0,0)
   MOZ_BLEND(r, 0, NS_GET_R(aBG), bgAlpha);