gfx/src/nsColor.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsColor_h___
michael@0 7 #define nsColor_h___
michael@0 8
michael@0 9 #include <stddef.h> // for size_t
michael@0 10 #include <stdint.h> // for uint8_t, uint32_t
michael@0 11 #include "gfxCore.h" // for NS_GFX_
michael@0 12 #include "nscore.h" // for nsAString
michael@0 13
michael@0 14 class nsAString;
michael@0 15 class nsString;
michael@0 16 class nsCString;
michael@0 17
michael@0 18 // A color is a 32 bit unsigned integer with four components: R, G, B
michael@0 19 // and A.
michael@0 20 typedef uint32_t nscolor;
michael@0 21
michael@0 22 // Make a color out of r,g,b values. This assumes that the r,g,b values are
michael@0 23 // properly constrained to 0-255. This also assumes that a is 255.
michael@0 24 #define NS_RGB(_r,_g,_b) \
michael@0 25 ((nscolor) ((255 << 24) | ((_b)<<16) | ((_g)<<8) | (_r)))
michael@0 26
michael@0 27 // Make a color out of r,g,b,a values. This assumes that the r,g,b,a
michael@0 28 // values are properly constrained to 0-255.
michael@0 29 #define NS_RGBA(_r,_g,_b,_a) \
michael@0 30 ((nscolor) (((_a) << 24) | ((_b)<<16) | ((_g)<<8) | (_r)))
michael@0 31
michael@0 32 // Extract color components from nscolor
michael@0 33 #define NS_GET_R(_rgba) ((uint8_t) ((_rgba) & 0xff))
michael@0 34 #define NS_GET_G(_rgba) ((uint8_t) (((_rgba) >> 8) & 0xff))
michael@0 35 #define NS_GET_B(_rgba) ((uint8_t) (((_rgba) >> 16) & 0xff))
michael@0 36 #define NS_GET_A(_rgba) ((uint8_t) (((_rgba) >> 24) & 0xff))
michael@0 37
michael@0 38 // Fast approximate division by 255. It has the property that
michael@0 39 // for all 0 <= n <= 255*255, FAST_DIVIDE_BY_255(n) == n/255.
michael@0 40 // But it only uses two adds and two shifts instead of an
michael@0 41 // integer division (which is expensive on many processors).
michael@0 42 //
michael@0 43 // equivalent to target=v/255
michael@0 44 #define FAST_DIVIDE_BY_255(target,v) \
michael@0 45 PR_BEGIN_MACRO \
michael@0 46 unsigned tmp_ = v; \
michael@0 47 target = ((tmp_ << 8) + tmp_ + 255) >> 16; \
michael@0 48 PR_END_MACRO
michael@0 49
michael@0 50 // Translate a hex string to a color. Return true if it parses ok,
michael@0 51 // otherwise return false.
michael@0 52 // This accepts only 3 or 6 digits
michael@0 53 NS_GFX_(bool) NS_HexToRGB(const nsAString& aBuf, nscolor* aResult);
michael@0 54
michael@0 55 // Compose one NS_RGB color onto another. The result is what
michael@0 56 // you get if you draw aFG on top of aBG with operator OVER.
michael@0 57 NS_GFX_(nscolor) NS_ComposeColors(nscolor aBG, nscolor aFG);
michael@0 58
michael@0 59 // Translate a hex string to a color. Return true if it parses ok,
michael@0 60 // otherwise return false.
michael@0 61 // This version accepts 1 to 9 digits (missing digits are 0)
michael@0 62 NS_GFX_(bool) NS_LooseHexToRGB(const nsString& aBuf, nscolor* aResult);
michael@0 63
michael@0 64 // There is no function to translate a color to a hex string, because
michael@0 65 // the hex-string syntax does not support transparency.
michael@0 66
michael@0 67 // Translate a color name to a color. Return true if it parses ok,
michael@0 68 // otherwise return false.
michael@0 69 NS_GFX_(bool) NS_ColorNameToRGB(const nsAString& aBuf, nscolor* aResult);
michael@0 70
michael@0 71 // Returns an array of all possible color names, and sets
michael@0 72 // *aSizeArray to the size of that array. Do NOT call |free()| on this array.
michael@0 73 NS_GFX_(const char * const *) NS_AllColorNames(size_t *aSizeArray);
michael@0 74
michael@0 75 // function to convert from HSL color space to RGB color space
michael@0 76 // the float parameters are all expected to be in the range 0-1
michael@0 77 NS_GFX_(nscolor) NS_HSL2RGB(float h, float s, float l);
michael@0 78
michael@0 79 // Return a color name for the given nscolor. If there is no color
michael@0 80 // name for it, returns null. If there are multiple possible color
michael@0 81 // names for the given color, the first one in nsColorNameList.h
michael@0 82 // (which is generally the first one in alphabetical order) will be
michael@0 83 // returned.
michael@0 84 NS_GFX_(const char*) NS_RGBToColorName(nscolor aColor);
michael@0 85
michael@0 86 #endif /* nsColor_h___ */

mercurial