Chris Mumford | 23c47b8 | 2023-03-08 19:18:33 +0000 | [diff] [blame] | 1 | // Copyright 2023 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_framebuffer/reader.h" |
| 16 | |
| 17 | #include <cstdint> |
| 18 | |
| 19 | #include "gtest/gtest.h" |
| 20 | #include "pw_color/color.h" |
| 21 | #include "pw_color/colors_endesga32.h" |
| 22 | #include "pw_color/colors_pico8.h" |
| 23 | #include "pw_framebuffer/framebuffer.h" |
| 24 | #include "pw_framebuffer/reader.h" |
| 25 | #include "pw_framebuffer/writer.h" |
| 26 | |
| 27 | using pw::color::color_rgb565_t; |
| 28 | |
| 29 | namespace pw::framebuffer { |
| 30 | namespace { |
| 31 | |
| 32 | TEST(FramebufferReader, SetPixelGetPixel) { |
Chris Mumford | aa694fe | 2023-03-10 16:26:50 +0000 | [diff] [blame] | 33 | color_rgb565_t data[8 * 8]; |
| 34 | Framebuffer fb(data, PixelFormat::RGB565, {8, 8}, 8 * sizeof(data[0])); |
Chris Mumford | 23c47b8 | 2023-03-08 19:18:33 +0000 | [diff] [blame] | 35 | const color_rgb565_t* pixel_data = |
Chris Mumford | 69c69cc | 2023-03-10 17:08:31 +0000 | [diff] [blame] | 36 | static_cast<const color_rgb565_t*>(fb.data()); |
Chris Mumford | 23c47b8 | 2023-03-08 19:18:33 +0000 | [diff] [blame] | 37 | color_rgb565_t indigo = 0x83b3; |
| 38 | { |
| 39 | FramebufferWriter writer(fb); |
| 40 | writer.Fill(0); |
| 41 | for (uint16_t i = 0; i < 8; i++) { |
| 42 | writer.SetPixel(i, i, indigo); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | FramebufferReader reader(fb); |
| 47 | EXPECT_EQ(pixel_data[0], indigo); |
| 48 | EXPECT_EQ(pixel_data[1], 0); |
| 49 | EXPECT_EQ(pixel_data[8 * 8 - 2], 0); |
| 50 | EXPECT_EQ(pixel_data[8 * 8 - 1], indigo); |
| 51 | |
| 52 | Result<color_rgb565_t> c; |
| 53 | c = reader.GetPixel(0, 0); |
| 54 | ASSERT_TRUE(c.ok()); |
| 55 | EXPECT_EQ(c.value(), indigo); |
| 56 | c = reader.GetPixel(0, 1); |
| 57 | ASSERT_TRUE(c.ok()); |
| 58 | EXPECT_EQ(c.value(), 0); |
| 59 | c = reader.GetPixel(6, 7); |
| 60 | ASSERT_TRUE(c.ok()); |
| 61 | EXPECT_EQ(c.value(), 0); |
| 62 | c = reader.GetPixel(7, 7); |
| 63 | ASSERT_TRUE(c.ok()); |
| 64 | EXPECT_EQ(c.value(), indigo); |
| 65 | } |
| 66 | |
| 67 | } // namespace |
| 68 | } // namespace pw::framebuffer |