Welcome to mirror list, hosted at ThFree Co, Russian Federation.

color.hpp « drape - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c2291e63623f9166efbb281fac2527535879be64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once

#include "base/math.hpp"

#include <cstdint>
#include <sstream>
#include <string>

namespace dp
{
struct Color
{
  Color();
  explicit Color(uint32_t rgba);
  Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha);

  uint8_t GetRed() const;
  uint8_t GetGreen() const;
  uint8_t GetBlue() const;
  uint8_t GetAlpha() const;

  float GetRedF() const;
  float GetGreenF() const;
  float GetBlueF() const;
  float GetAlphaF() const;

  bool operator==(Color const & other) const { return m_rgba == other.m_rgba; }
  bool operator!=(Color const & other) const { return m_rgba != other.m_rgba; }
  bool operator<(Color const & other) const { return m_rgba < other.m_rgba; }

  Color operator*(float s) const
  {
    return Color(static_cast<uint8_t>(base::clamp(GetRedF() * s, 0.0f, 1.0f) * 255.0f),
                 static_cast<uint8_t>(base::clamp(GetGreenF() * s, 0.0f, 1.0f) * 255.0f),
                 static_cast<uint8_t>(base::clamp(GetBlueF() * s, 0.0f, 1.0f) * 255.0f), GetAlpha());
  }

  static Color Black() { return Color(0, 0, 0, 255); }
  static Color White() { return Color(255, 255, 255, 255); }
  static Color Red() { return Color(255, 0, 0, 255); }
  static Color Blue() { return Color(0, 0, 255, 255); }
  static Color Green() { return Color(0, 255, 0, 255); }
  static Color Yellow() { return Color(255, 255, 0, 255); }
  static Color Transparent() { return Color(0, 0, 0, 0); }

private:
  uint32_t m_rgba;
};

inline uint8_t ExtractRed(uint32_t argb);
inline uint8_t ExtractGreen(uint32_t argb);
inline uint8_t ExtractBlue(uint32_t argb);
inline uint8_t ExtractAlpha(uint32_t argb);
Color Extract(uint32_t argb);
Color Extract(uint32_t xrgb, uint8_t a);

inline std::string DebugPrint(Color const & c)
{
  std::ostringstream out;
  out << "[R = " << static_cast<uint32_t>(c.GetRed())
      << ", G = " << static_cast<uint32_t>(c.GetGreen())
      << ", B = " << static_cast<uint32_t>(c.GetBlue())
      << ", A = " << static_cast<uint32_t>(c.GetAlpha()) << "]";
  return out.str();
}
}  // namespace dp