bpp-core3  3.0.0
ColorTools.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_GRAPHICS_COLORTOOLS_H
6 #define BPP_GRAPHICS_COLORTOOLS_H
7 
8 
9 #include "../Exceptions.h"
10 #include "../Text/TextTools.h"
11 #include "RgbColor.h"
12 
13 namespace bpp
14 {
19 {
20 public:
22  virtual ~ColorTools() {}
23 
24 public:
33  static std::vector<RGBColor> gradient(unsigned int n, const RGBColor& low, const RGBColor& high);
34 
44  static std::vector<RGBColor> gradient(unsigned int n, const RGBColor& low, const RGBColor& mid, const RGBColor& high);
45 
50  static RGBColor gray(double level)
51  {
52  unsigned int i = (unsigned int)round(255 * level);
53  return RGBColor(i, i, i);
54  }
55 
74  static RGBColor cmyk2rgb(double c, double m, double y, double k)
75  {
76  unsigned int r = static_cast<unsigned int>(round(255 * (1. - c) * (1. - k)));
77  unsigned int g = static_cast<unsigned int>(round(255 * (1. - m) * (1. - k)));
78  unsigned int b = static_cast<unsigned int>(round(255 * (1. - y) * (1. - k)));
79  return RGBColor(r, g, b);
80  }
81 
82 public:
83  static const RGBColor RED;
84  static const RGBColor GREEN;
85  static const RGBColor BLUE;
86  static const RGBColor BLACK;
87  static const RGBColor WHITE;
88  static const RGBColor YELLOW;
89  static const RGBColor CYAN;
90  static const RGBColor MAGENTA;
91  static const RGBColor ORANGE;
92 };
93 } // end of namespace bpp.
94 #endif // BPP_GRAPHICS_COLORTOOLS_H
static const RGBColor CYAN
Definition: ColorTools.h:89
static const RGBColor BLUE
Definition: ColorTools.h:85
static const RGBColor RED
Definition: ColorTools.h:83
static const RGBColor YELLOW
Definition: ColorTools.h:88
static const RGBColor BLACK
Definition: ColorTools.h:86
static RGBColor cmyk2rgb(double c, double m, double y, double k)
Get a RGBColor from a cyan-magenta-yellow-key description.
Definition: ColorTools.h:74
virtual ~ColorTools()
Definition: ColorTools.h:22
Describe a color according to its red, green and blue componants.
Definition: RgbColor.h:21
static const RGBColor ORANGE
Definition: ColorTools.h:91
static const RGBColor GREEN
Definition: ColorTools.h:84
static RGBColor gray(double level)
Definition: ColorTools.h:50
Provide tools to deal with color objects.
Definition: ColorTools.h:18
static const RGBColor MAGENTA
Definition: ColorTools.h:90
static const RGBColor WHITE
Definition: ColorTools.h:87
static std::vector< RGBColor > gradient(unsigned int n, const RGBColor &low, const RGBColor &high)
Create a set of colors according to a gradient defined by two extrema.
Definition: ColorTools.cpp:22