WPILibC++  2020.3.2
Color8Bit.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2019 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <algorithm>
11 
12 #include "Color.h"
13 
14 namespace frc {
15 
19 class Color8Bit {
20  public:
21  constexpr Color8Bit() = default;
22 
30  constexpr Color8Bit(int r, int g, int b)
31  : red(std::clamp(r, 0, 255)),
32  green(std::clamp(g, 0, 255)),
33  blue(std::clamp(b, 0, 255)) {}
34 
40  constexpr Color8Bit(const Color& color)
41  : red(color.red * 255),
42  green(color.green * 255),
43  blue(color.blue * 255) {}
44 
45  constexpr operator Color() const {
46  return Color(red / 255.0, green / 255.0, blue / 255.0);
47  }
48 
49  int red = 0;
50  int green = 0;
51  int blue = 0;
52 };
53 
54 inline bool operator==(const Color8Bit& c1, const Color8Bit& c2) {
55  return c1.red == c2.red && c1.green == c2.green && c1.blue == c2.blue;
56 }
57 
58 } // namespace frc
frc::Color8Bit::Color8Bit
constexpr Color8Bit(int r, int g, int b)
Constructs a Color8Bit.
Definition: Color8Bit.h:30
frc::Color
Represents colors that can be used with Addressable LEDs.
Definition: Color.h:19
frc::Color8Bit::Color8Bit
constexpr Color8Bit(const Color &color)
Constructs a Color8Bit from a Color.
Definition: Color8Bit.h:40
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
frc::Color8Bit
Represents colors that can be used with Addressable LEDs.
Definition: Color8Bit.h:19