gfx/src/nsColor.h
author B2G Bumper Bot <release+b2gbumper@mozilla.com>
Fri, 31 Jan 2014 14:05:12 -0800
changeset 182343 4c86e7c1f546598713e5e1565b033562b4ed2be8
parent 165252 cf1b692cd29ad58c59f3a463b9360ffdb69a39f8
child 209753 1218c119a5d4789b455f0950984adc41c22c6b98
permissions -rw-r--r--
Bumping gaia.json for 4 gaia revision(s) a=gaia-bump ======== https://hg.mozilla.org/integration/gaia-central/rev/4188cf82dc3f Author: Miller Medeiros <miller@millermedeiros.com> Desc: Merge pull request #15630 from millermedeiros/803238-two-months-week-view Bug 803238 - Week view: If the text to display by default in the title (e.g. dow, month, year) exceeds the view length, use short names for day of week, month, year, etc r=gaye ======== https://hg.mozilla.org/integration/gaia-central/rev/41feabe49307 Author: Miller Medeiros <miller@millermedeiros.com> Desc: Bug 803238 - Week view: If the text to display by default in the title (e.g. dow, month, year) exceeds the view length, use short names for day of week, month, year, etc ======== https://hg.mozilla.org/integration/gaia-central/rev/c5b6fcb663c7 Author: Miller Medeiros <miller@millermedeiros.com> Desc: Merge pull request #15384 from millermedeiros/916411-long-title Bug 916411 - [fugu][Buri][Calendar]The event display abnormally when title/where/notes is long r=gaye ======== https://hg.mozilla.org/integration/gaia-central/rev/a1ecc59659e1 Author: millermedeiros <miller@millermedeiros.com> Desc: Bug 916411 - [fugu][Buri][Calendar]The event display abnormally when title/where/notes is long

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef nsColor_h___
#define nsColor_h___

#include <stddef.h>                     // for size_t
#include <stdint.h>                     // for uint8_t, uint32_t
#include "gfxCore.h"                    // for NS_GFX_
#include "nscore.h"                     // for nsAString

class nsAString;
class nsString;
class nsCString;

// A color is a 32 bit unsigned integer with four components: R, G, B
// and A.
typedef uint32_t nscolor;

// Make a color out of r,g,b values. This assumes that the r,g,b values are
// properly constrained to 0-255. This also assumes that a is 255.
#define NS_RGB(_r,_g,_b) \
  ((nscolor) ((255 << 24) | ((_b)<<16) | ((_g)<<8) | (_r)))

// Make a color out of r,g,b,a values. This assumes that the r,g,b,a
// values are properly constrained to 0-255.
#define NS_RGBA(_r,_g,_b,_a) \
  ((nscolor) (((_a) << 24) | ((_b)<<16) | ((_g)<<8) | (_r)))

// Extract color components from nscolor
#define NS_GET_R(_rgba) ((uint8_t) ((_rgba) & 0xff))
#define NS_GET_G(_rgba) ((uint8_t) (((_rgba) >> 8) & 0xff))
#define NS_GET_B(_rgba) ((uint8_t) (((_rgba) >> 16) & 0xff))
#define NS_GET_A(_rgba) ((uint8_t) (((_rgba) >> 24) & 0xff))

// Fast approximate division by 255. It has the property that
// for all 0 <= n <= 255*255, FAST_DIVIDE_BY_255(n) == n/255.
// But it only uses two adds and two shifts instead of an 
// integer division (which is expensive on many processors).
//
// equivalent to target=v/255
#define FAST_DIVIDE_BY_255(target,v)               \
  PR_BEGIN_MACRO                                   \
    unsigned tmp_ = v;                             \
    target = ((tmp_ << 8) + tmp_ + 255) >> 16;     \
  PR_END_MACRO

// Translate a hex string to a color. Return true if it parses ok,
// otherwise return false.
// This accepts only 3 or 6 digits
NS_GFX_(bool) NS_HexToRGB(const nsAString& aBuf, nscolor* aResult);

// Compose one NS_RGB color onto another. The result is what
// you get if you draw aFG on top of aBG 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_(bool) NS_LooseHexToRGB(const nsString& aBuf, nscolor* aResult);

// There is no function to translate a color to a hex string, because
// the hex-string syntax does not support transparency.

// Translate a color name to a color. Return true if it parses ok,
// otherwise return false.
NS_GFX_(bool) NS_ColorNameToRGB(const nsAString& aBuf, nscolor* aResult);

// Returns an array of all possible color names, and sets
// *aSizeArray to the size of that array. Do NOT call |free()| on this array.
NS_GFX_(const char * const *) NS_AllColorNames(size_t *aSizeArray);

// 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);

// Return a color name for the given nscolor.  If there is no color
// name for it, returns null.  If there are multiple possible color
// names for the given color, the first one in nsColorNameList.h
// (which is generally the first one in alphabetical order) will be
// returned.
NS_GFX_(const char*) NS_RGBToColorName(nscolor aColor);

#endif /* nsColor_h___ */