• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #include "pw_display/color.h"
16 
17 #include "pw_display/colors_endesga64.h"
18 #include "pw_display/colors_pico8.h"
19 #include "pw_unit_test/framework.h"
20 
21 namespace pw::display {
22 namespace {
23 
TEST(ColorsPico8Rgb565,EncodedRgb565)24 TEST(ColorsPico8Rgb565, EncodedRgb565) {
25   EXPECT_EQ(colors::rgb565::pico8::kDarkBlue, static_cast<ColorRgb565>(0x194a));
26 }
27 
TEST(ColorsEndesga64Rgb565,EncodedRgb565)28 TEST(ColorsEndesga64Rgb565, EncodedRgb565) {
29   EXPECT_EQ(colors::rgb565::e64::kBlood, static_cast<ColorRgb565>(0xf808));
30   EXPECT_EQ(colors::rgb565::e64::kRed0, static_cast<ColorRgb565>(0x50e4));
31 }
32 
TEST(ColorToRGB565,FromRGB)33 TEST(ColorToRGB565, FromRGB) {
34   EXPECT_EQ(EncodeRgb565(0x1d, 0x2b, 0x53), colors::rgb565::pico8::kDarkBlue);
35   // Check each channel
36   EXPECT_EQ(EncodeRgb565(0xff, 0x00, 0x00),
37             static_cast<ColorRgb565>(0b1111100000000000));
38   EXPECT_EQ(EncodeRgb565(0x00, 0xff, 0x00),
39             static_cast<ColorRgb565>(0b0000011111100000));
40   EXPECT_EQ(EncodeRgb565(0x00, 0x00, 0xff),
41             static_cast<ColorRgb565>(0b0000000000011111));
42 }
43 
TEST(ColorToRGBA8888,FromRGB)44 TEST(ColorToRGBA8888, FromRGB) {
45   EXPECT_EQ(EncodeRgba8888(0xff, 0x00, 0x00, 0x00),
46             static_cast<ColorRgba8888>(0b00000000000000000000000011111111));
47   EXPECT_EQ(EncodeRgba8888(0x00, 0xff, 0x00, 0x00),
48             static_cast<ColorRgba8888>(0b00000000000000001111111100000000));
49   EXPECT_EQ(EncodeRgba8888(0x00, 0x00, 0xff, 0x00),
50             static_cast<ColorRgba8888>(0b00000000111111110000000000000000));
51   EXPECT_EQ(EncodeRgba8888(0x00, 0x00, 0x00, 0xff),
52             static_cast<ColorRgba8888>(0b11111111000000000000000000000000));
53 }
54 
TEST(ColorToRGB565,FromRGBA8888)55 TEST(ColorToRGB565, FromRGBA8888) {
56   EXPECT_EQ(EncodeRgb565(static_cast<ColorRgba8888>(0xff43143b)),
57             colors::rgb565::e64::kPurple0);
58 }
59 
60 }  // namespace
61 }  // namespace pw::display
62