Bug 588735 - Mirror glass caption buttons for rtl windows. r=roc, a=blocking-betaN.
[mozilla-central.git] / gfx / src / nsColor.h
blob9887a685028885585143a6e832819a9e5fbbd60f
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsColor_h___
39 #define nsColor_h___
41 #include "gfxCore.h"
42 #include "nscore.h"
44 class nsAString;
45 class nsString;
46 class nsCString;
48 // A color is a 32 bit unsigned integer with four components: R, G, B
49 // and A.
50 typedef PRUint32 nscolor;
52 // Make a color out of r,g,b values. This assumes that the r,g,b values are
53 // properly constrained to 0-255. This also assumes that a is 255.
54 #define NS_RGB(_r,_g,_b) \
55 ((nscolor) ((255 << 24) | ((_b)<<16) | ((_g)<<8) | (_r)))
57 // Make a color out of r,g,b,a values. This assumes that the r,g,b,a
58 // values are properly constrained to 0-255.
59 #define NS_RGBA(_r,_g,_b,_a) \
60 ((nscolor) (((_a) << 24) | ((_b)<<16) | ((_g)<<8) | (_r)))
62 // Extract color components from nscolor
63 #define NS_GET_R(_rgba) ((PRUint8) ((_rgba) & 0xff))
64 #define NS_GET_G(_rgba) ((PRUint8) (((_rgba) >> 8) & 0xff))
65 #define NS_GET_B(_rgba) ((PRUint8) (((_rgba) >> 16) & 0xff))
66 #define NS_GET_A(_rgba) ((PRUint8) (((_rgba) >> 24) & 0xff))
68 // Fast approximate division by 255. It has the property that
69 // for all 0 <= n <= 255*255, FAST_DIVIDE_BY_255(n) == n/255.
70 // But it only uses two adds and two shifts instead of an
71 // integer division (which is expensive on many processors).
73 // equivalent to target=v/255
74 #define FAST_DIVIDE_BY_255(target,v) \
75 PR_BEGIN_MACRO \
76 unsigned tmp_ = v; \
77 target = ((tmp_ << 8) + tmp_ + 255) >> 16; \
78 PR_END_MACRO
80 // Translate a hex string to a color. Return true if it parses ok,
81 // otherwise return false.
82 // This accepts only 3 or 6 digits
83 NS_GFX_(PRBool) NS_HexToRGB(const nsString& aBuf, nscolor* aResult);
85 // Compose one NS_RGB color onto another. The result is what
86 // you get if you draw aFG on top of aBG with operator OVER.
87 NS_GFX_(nscolor) NS_ComposeColors(nscolor aBG, nscolor aFG);
89 // Translate a hex string to a color. Return true if it parses ok,
90 // otherwise return false.
91 // This version accepts 1 to 9 digits (missing digits are 0)
92 NS_GFX_(PRBool) NS_LooseHexToRGB(const nsString& aBuf, nscolor* aResult);
94 // There is no function to translate a color to a hex string, because
95 // the hex-string syntax does not support transparency.
97 // Translate a color name to a color. Return true if it parses ok,
98 // otherwise return false.
99 NS_GFX_(PRBool) NS_ColorNameToRGB(const nsAString& aBuf, nscolor* aResult);
101 // function to convert from HSL color space to RGB color space
102 // the float parameters are all expected to be in the range 0-1
103 NS_GFX_(nscolor) NS_HSL2RGB(float h, float s, float l);
105 #endif /* nsColor_h___ */