pw_framebuffer: Rename FramebufferRgb565 to Framebuffer.
Change-Id: Iafd7059fccfe5d9a0a043d7c48a5c716ca5d01b7
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/experimental/+/129550
Reviewed-by: Anthony DiGirolamo <tonymd@google.com>
Commit-Queue: Chris Mumford <cmumford@google.com>
diff --git a/pw_graphics/pw_display/display.cc b/pw_graphics/pw_display/display.cc
index 48d2ea9..84ea9c7 100644
--- a/pw_graphics/pw_display/display.cc
+++ b/pw_graphics/pw_display/display.cc
@@ -15,12 +15,12 @@
#include <utility>
-#include "pw_framebuffer/rgb565.h"
+#include "pw_framebuffer/framebuffer.h"
#include "pw_framebuffer_pool/framebuffer_pool.h"
#include "pw_status/try.h"
using pw::color::color_rgb565_t;
-using pw::framebuffer::FramebufferRgb565;
+using pw::framebuffer::Framebuffer;
namespace pw::display {
@@ -30,7 +30,7 @@
Display::~Display() = default;
-Status Display::UpdateNearestNeighbor(const FramebufferRgb565& framebuffer) {
+Status Display::UpdateNearestNeighbor(const Framebuffer& framebuffer) {
PW_ASSERT(framebuffer.IsValid());
if (!framebuffer.GetWidth() || !framebuffer.GetHeight())
return Status::Internal();
@@ -79,11 +79,11 @@
return OkStatus();
}
-FramebufferRgb565 Display::GetFramebuffer() {
+Framebuffer Display::GetFramebuffer() {
return display_driver_.GetFramebuffer();
}
-Status Display::ReleaseFramebuffer(FramebufferRgb565 framebuffer) {
+Status Display::ReleaseFramebuffer(Framebuffer framebuffer) {
if (!framebuffer.IsValid())
return Status::InvalidArgument();
if (framebuffer.GetWidth() != size_.width ||
diff --git a/pw_graphics/pw_display/display_test.cc b/pw_graphics/pw_display/display_test.cc
index 7f161ab..78a9cce 100644
--- a/pw_graphics/pw_display/display_test.cc
+++ b/pw_graphics/pw_display/display_test.cc
@@ -21,7 +21,7 @@
using pw::color::color_rgb565_t;
using pw::display_driver::DisplayDriver;
-using pw::framebuffer::FramebufferRgb565;
+using pw::framebuffer::Framebuffer;
using Size = pw::coordinates::Size<int>;
namespace pw::display {
@@ -51,19 +51,19 @@
class TestDisplayDriver : public DisplayDriver {
public:
- TestDisplayDriver(FramebufferRgb565 fb) : framebuffer_(std::move(fb)) {}
+ TestDisplayDriver(Framebuffer fb) : framebuffer_(std::move(fb)) {}
virtual ~TestDisplayDriver() = default;
Status Init() override { return OkStatus(); }
- FramebufferRgb565 GetFramebuffer() override {
- return FramebufferRgb565(framebuffer_.GetFramebufferData(),
- framebuffer_.GetWidth(),
- framebuffer_.GetHeight(),
- framebuffer_.GetRowBytes());
+ Framebuffer GetFramebuffer() override {
+ return Framebuffer(framebuffer_.GetFramebufferData(),
+ framebuffer_.GetWidth(),
+ framebuffer_.GetHeight(),
+ framebuffer_.GetRowBytes());
}
- Status ReleaseFramebuffer(FramebufferRgb565 framebuffer) override {
+ Status ReleaseFramebuffer(Framebuffer framebuffer) override {
if (next_call_param_idx_ < kMaxSavedParams) {
call_params_[next_call_param_idx_].call_func =
CallFunc::ReleaseFramebuffer;
@@ -111,7 +111,7 @@
private:
size_t next_call_param_idx_ = 0;
std::array<CallParams, kMaxSavedParams> call_params_;
- const FramebufferRgb565 framebuffer_;
+ const Framebuffer framebuffer_;
};
TEST(Display, ReleaseNoResize) {
@@ -123,10 +123,10 @@
sizeof(color_rgb565_t) * kFramebufferWidth;
color_rgb565_t pixel_data[kNumPixels];
- TestDisplayDriver test_driver(FramebufferRgb565(
+ TestDisplayDriver test_driver(Framebuffer(
pixel_data, kFramebufferWidth, kFramebufferHeight, kFramebufferRowBytes));
Display display(test_driver, kDisplaySize);
- FramebufferRgb565 fb = display.GetFramebuffer();
+ Framebuffer fb = display.GetFramebuffer();
EXPECT_TRUE(fb.IsValid());
EXPECT_EQ(kFramebufferWidth, fb.GetWidth());
EXPECT_EQ(kFramebufferHeight, fb.GetHeight());
@@ -148,10 +148,10 @@
sizeof(color_rgb565_t) * kFramebufferWidth;
color_rgb565_t pixel_data[kNumPixels];
- TestDisplayDriver test_driver(FramebufferRgb565(
+ TestDisplayDriver test_driver(Framebuffer(
pixel_data, kFramebufferWidth, kFramebufferHeight, kFramebufferRowBytes));
Display display(test_driver, kDisplaySize);
- FramebufferRgb565 fb = display.GetFramebuffer();
+ Framebuffer fb = display.GetFramebuffer();
EXPECT_TRUE(fb.IsValid());
EXPECT_EQ(kFramebufferWidth, fb.GetWidth());
EXPECT_EQ(kFramebufferHeight, fb.GetHeight());
@@ -194,10 +194,10 @@
sizeof(color_rgb565_t) * kFramebufferWidth;
color_rgb565_t pixel_data[kNumPixels];
- TestDisplayDriver test_driver(FramebufferRgb565(
+ TestDisplayDriver test_driver(Framebuffer(
pixel_data, kFramebufferWidth, kFramebufferHeight, kFramebufferRowBytes));
Display display(test_driver, kDisplaySize);
- FramebufferRgb565 fb = display.GetFramebuffer();
+ Framebuffer fb = display.GetFramebuffer();
EXPECT_TRUE(fb.IsValid());
EXPECT_EQ(kFramebufferWidth, fb.GetWidth());
EXPECT_EQ(kFramebufferHeight, fb.GetHeight());
diff --git a/pw_graphics/pw_display/public/pw_display/display.h b/pw_graphics/pw_display/public/pw_display/display.h
index 473184f..bf14d97 100644
--- a/pw_graphics/pw_display/public/pw_display/display.h
+++ b/pw_graphics/pw_display/public/pw_display/display.h
@@ -15,7 +15,7 @@
#include "pw_coordinates/vec_int.h"
#include "pw_display_driver/display_driver.h"
-#include "pw_framebuffer/rgb565.h"
+#include "pw_framebuffer/framebuffer.h"
#include "pw_framebuffer_pool/framebuffer_pool.h"
#include "pw_status/status.h"
@@ -35,7 +35,7 @@
// the framebuffer must be returned using ReleaseFramebuffer(). An invalid
// framebuffer may be returned, so the caller should verify it is valid
// before use.
- pw::framebuffer::FramebufferRgb565 GetFramebuffer();
+ pw::framebuffer::Framebuffer GetFramebuffer();
// Release the framebuffer back to the display. The display will
// send the framebuffer data to the screen. This function will block until
@@ -43,7 +43,7 @@
//
// This function should only be passed a valid framebuffer returned by
// a paired call to GetFramebuffer.
- Status ReleaseFramebuffer(pw::framebuffer::FramebufferRgb565 framebuffer);
+ Status ReleaseFramebuffer(pw::framebuffer::Framebuffer framebuffer);
// Return the width (in pixels) of the associated display.
int GetWidth() const { return size_.width; }
@@ -65,8 +65,7 @@
private:
// Update screen while scaling the framebuffer using nearest
// neighbor algorithm.
- Status UpdateNearestNeighbor(
- const pw::framebuffer::FramebufferRgb565& framebuffer);
+ Status UpdateNearestNeighbor(const pw::framebuffer::Framebuffer& framebuffer);
pw::display_driver::DisplayDriver& display_driver_;
const pw::coordinates::Size<int> size_;
diff --git a/pw_graphics/pw_draw/draw_test.cc b/pw_graphics/pw_draw/draw_test.cc
index 2c9076e..dd32c47 100644
--- a/pw_graphics/pw_draw/draw_test.cc
+++ b/pw_graphics/pw_draw/draw_test.cc
@@ -19,7 +19,7 @@
#include "pw_color/colors_pico8.h"
#include "pw_draw/font_set.h"
#include "pw_draw/text_area.h"
-#include "pw_framebuffer/rgb565.h"
+#include "pw_framebuffer/framebuffer.h"
#include "pw_log/log.h"
#include "pw_string/string_builder.h"
@@ -32,7 +32,7 @@
constexpr color_rgb565_t kBlack = 0x0;
-void PrintFramebufferAsANSI(const FramebufferRgb565& fb) {
+void PrintFramebufferAsANSI(const Framebuffer& fb) {
pw::StringBuffer<4096> line;
pw::StringBuffer<128> color_string;
@@ -67,7 +67,7 @@
TEST(DrawLine, Diagonal) {
uint16_t data[4 * 4];
- FramebufferRgb565 fb(data, 4, 4, 4 * sizeof(data[0]));
+ Framebuffer fb(data, 4, 4, 4 * sizeof(data[0]));
color_rgb565_t indigo = color::colors_pico8_rgb565[12];
fb.Fill(0);
@@ -92,7 +92,7 @@
TEST(DrawHLine, Top) {
uint16_t data[4 * 4];
- FramebufferRgb565 fb(data, 4, 4, 4 * sizeof(data[0]));
+ Framebuffer fb(data, 4, 4, 4 * sizeof(data[0]));
color_rgb565_t indigo = color::colors_pico8_rgb565[12];
fb.Fill(0);
@@ -114,7 +114,7 @@
TEST(DrawRect, Empty) {
uint16_t data[5 * 5];
- FramebufferRgb565 fb(data, 5, 5, 5 * sizeof(data[0]));
+ Framebuffer fb(data, 5, 5, 5 * sizeof(data[0]));
color_rgb565_t indigo = color::colors_pico8_rgb565[12];
fb.Fill(0);
@@ -206,7 +206,7 @@
TEST(DrawRect, Filled) {
uint16_t data[5 * 5];
- FramebufferRgb565 fb(data, 5, 5, 5 * sizeof(data[0]));
+ Framebuffer fb(data, 5, 5, 5 * sizeof(data[0]));
color_rgb565_t indigo = color::colors_pico8_rgb565[12];
fb.Fill(0);
@@ -293,7 +293,7 @@
TEST(DrawRectWH, WidthHeightCorrect) {
uint16_t data[5 * 5];
- FramebufferRgb565 fb(data, 5, 5, 5 * sizeof(data[0]));
+ Framebuffer fb(data, 5, 5, 5 * sizeof(data[0]));
color_rgb565_t indigo = color::colors_pico8_rgb565[12];
fb.Fill(0);
@@ -385,7 +385,7 @@
TEST(DrawCircle, Empty) {
uint16_t data[7 * 7];
- FramebufferRgb565 fb(data, 7, 7, 7 * sizeof(data[0]));
+ Framebuffer fb(data, 7, 7, 7 * sizeof(data[0]));
color_rgb565_t indigo = color::colors_pico8_rgb565[12];
fb.Fill(0);
@@ -559,7 +559,7 @@
TEST(DrawText, WithFgBg) {
uint16_t data[(5 * 6) * (3 * 8)];
- FramebufferRgb565 fb(data, 5 * 6, 3 * 8, (5 * 6) * sizeof(data[0]));
+ Framebuffer fb(data, 5 * 6, 3 * 8, (5 * 6) * sizeof(data[0]));
fb.Fill(0);
pw::draw::TextArea text_area(fb, &font6x8);
diff --git a/pw_graphics/pw_draw/public/pw_draw/draw.cc b/pw_graphics/pw_draw/public/pw_draw/draw.cc
index 4d5ff9b..94d0537 100644
--- a/pw_graphics/pw_draw/public/pw_draw/draw.cc
+++ b/pw_graphics/pw_draw/public/pw_draw/draw.cc
@@ -18,12 +18,12 @@
#include "pw_color/color.h"
#include "pw_draw/sprite_sheet.h"
-#include "pw_framebuffer/rgb565.h"
+#include "pw_framebuffer/framebuffer.h"
using pw::color::color_rgb565_t;
using pw::coordinates::Size;
using pw::coordinates::Vector2;
-using pw::framebuffer::FramebufferRgb565;
+using pw::framebuffer::Framebuffer;
namespace pw::draw {
@@ -33,7 +33,7 @@
Size<int> DrawSpace(Vector2<int> pos,
color_rgb565_t bg_color,
const FontSet& font,
- FramebufferRgb565& framebuffer) {
+ Framebuffer& framebuffer) {
for (int font_row = 0; font_row < font.height; font_row++) {
for (int font_column = 0; font_column < font.width; font_column++) {
framebuffer.SetPixel(pos.x + font_column, pos.y + font_row, bg_color);
@@ -44,12 +44,8 @@
} // namespace
-void DrawLine(FramebufferRgb565& fb,
- int x1,
- int y1,
- int x2,
- int y2,
- color_rgb565_t pen_color) {
+void DrawLine(
+ Framebuffer& fb, int x1, int y1, int x2, int y2, color_rgb565_t pen_color) {
// Bresenham's Line Algorithm
int16_t steep_gradient = abs(y2 - y1) > abs(x2 - x1);
// Swap values
@@ -92,7 +88,7 @@
// Draw a circle at center_x, center_y with given radius and color. Only a
// one-pixel outline is drawn if filled is false.
-void DrawCircle(FramebufferRgb565& fb,
+void DrawCircle(Framebuffer& fb,
int center_x,
int center_y,
int radius,
@@ -132,13 +128,13 @@
}
void DrawHLine(
- FramebufferRgb565& fb, int x1, int x2, int y, color_rgb565_t pen_color) {
+ Framebuffer& fb, int x1, int x2, int y, color_rgb565_t pen_color) {
for (int i = x1; i <= x2; i++) {
fb.SetPixel(i, y, pen_color);
}
}
-void DrawRect(FramebufferRgb565& fb,
+void DrawRect(Framebuffer& fb,
int x1,
int y1,
int x2,
@@ -160,7 +156,7 @@
}
}
-void DrawRectWH(FramebufferRgb565& fb,
+void DrawRectWH(Framebuffer& fb,
int x,
int y,
int w,
@@ -170,11 +166,9 @@
DrawRect(fb, x, y, x - 1 + w, y - 1 + h, pen_color, filled);
}
-void Fill(FramebufferRgb565& fb, color_rgb565_t pen_color) {
- fb.Fill(pen_color);
-}
+void Fill(Framebuffer& fb, color_rgb565_t pen_color) { fb.Fill(pen_color); }
-void DrawSprite(FramebufferRgb565& fb,
+void DrawSprite(Framebuffer& fb,
int x,
int y,
pw::draw::SpriteSheet* sprite_sheet,
@@ -201,7 +195,7 @@
}
}
-void DrawTestPattern(FramebufferRgb565& fb) {
+void DrawTestPattern(Framebuffer& fb) {
color_rgb565_t color = pw::color::ColorRGBA(0x00, 0xFF, 0xFF).ToRgb565();
// Create a Test Pattern
for (int x = 0; x < fb.GetWidth(); x++) {
@@ -218,7 +212,7 @@
color_rgb565_t fg_color,
color_rgb565_t bg_color,
const FontSet& font,
- FramebufferRgb565& framebuffer) {
+ Framebuffer& framebuffer) {
if (ch == ' ' || ch == '\0') {
// The font doesn't have a space glyph (why?), so special-case this.
return DrawSpace(pos, bg_color, font, framebuffer);
@@ -246,7 +240,7 @@
color_rgb565_t fg_color,
color_rgb565_t bg_color,
const FontSet& font,
- FramebufferRgb565& framebuffer) {
+ Framebuffer& framebuffer) {
Size<int> string_dimensions{0, font.height};
for (const wchar_t& ch : str) {
auto char_dimensions =
diff --git a/pw_graphics/pw_draw/public/pw_draw/draw.h b/pw_graphics/pw_draw/public/pw_draw/draw.h
index 5f8fc23..615fd03 100644
--- a/pw_graphics/pw_draw/public/pw_draw/draw.h
+++ b/pw_graphics/pw_draw/public/pw_draw/draw.h
@@ -19,11 +19,11 @@
#include "pw_coordinates/vec_int.h"
#include "pw_draw/font_set.h"
#include "pw_draw/sprite_sheet.h"
-#include "pw_framebuffer/rgb565.h"
+#include "pw_framebuffer/framebuffer.h"
namespace pw::draw {
-void DrawLine(pw::framebuffer::FramebufferRgb565& fb,
+void DrawLine(pw::framebuffer::Framebuffer& fb,
int x1,
int y1,
int x2,
@@ -32,20 +32,20 @@
// Draw a circle at center_x, center_y with given radius and color. Only a
// one-pixel outline is drawn if filled is false.
-void DrawCircle(pw::framebuffer::FramebufferRgb565& fb,
+void DrawCircle(pw::framebuffer::Framebuffer& fb,
int center_x,
int center_y,
int radius,
pw::color::color_rgb565_t pen_color,
bool filled);
-void DrawHLine(pw::framebuffer::FramebufferRgb565& fb,
+void DrawHLine(pw::framebuffer::Framebuffer& fb,
int x1,
int x2,
int y,
pw::color::color_rgb565_t pen_color);
-void DrawRect(pw::framebuffer::FramebufferRgb565& fb,
+void DrawRect(pw::framebuffer::Framebuffer& fb,
int x1,
int y1,
int x2,
@@ -53,7 +53,7 @@
pw::color::color_rgb565_t pen_color,
bool filled);
-void DrawRectWH(pw::framebuffer::FramebufferRgb565& fb,
+void DrawRectWH(pw::framebuffer::Framebuffer& fb,
int x,
int y,
int w,
@@ -61,10 +61,10 @@
pw::color::color_rgb565_t pen_color,
bool filled);
-void Fill(pw::framebuffer::FramebufferRgb565& fb,
+void Fill(pw::framebuffer::Framebuffer& fb,
pw::color::color_rgb565_t pen_color);
-void DrawSprite(pw::framebuffer::FramebufferRgb565& fb,
+void DrawSprite(pw::framebuffer::Framebuffer& fb,
int x,
int y,
pw::draw::SpriteSheet* sprite_sheet,
@@ -78,7 +78,7 @@
pw::color::color_rgb565_t fg_color,
pw::color::color_rgb565_t bg_color,
const FontSet& font,
- pw::framebuffer::FramebufferRgb565& framebuffer);
+ pw::framebuffer::Framebuffer& framebuffer);
pw::coordinates::Size<int> DrawString(
std::wstring_view str,
@@ -86,6 +86,6 @@
pw::color::color_rgb565_t fg_color,
pw::color::color_rgb565_t bg_color,
const FontSet& font,
- pw::framebuffer::FramebufferRgb565& framebuffer);
+ pw::framebuffer::Framebuffer& framebuffer);
} // namespace pw::draw
diff --git a/pw_graphics/pw_draw/public/pw_draw/sprite_sheet.h b/pw_graphics/pw_draw/public/pw_draw/sprite_sheet.h
index 1973688..d3a03b8 100644
--- a/pw_graphics/pw_draw/public/pw_draw/sprite_sheet.h
+++ b/pw_graphics/pw_draw/public/pw_draw/sprite_sheet.h
@@ -14,7 +14,7 @@
#pragma once
#include "pw_color/color.h"
-#include "pw_framebuffer/rgb565.h"
+#include "pw_framebuffer/framebuffer.h"
namespace pw::draw {
diff --git a/pw_graphics/pw_draw/public/pw_draw/text_area.cc b/pw_graphics/pw_draw/public/pw_draw/text_area.cc
index 5851f35..f05eede 100644
--- a/pw_graphics/pw_draw/public/pw_draw/text_area.cc
+++ b/pw_graphics/pw_draw/public/pw_draw/text_area.cc
@@ -17,14 +17,14 @@
#include "pw_color/color.h"
#include "pw_draw/draw.h"
#include "pw_draw/font_set.h"
-#include "pw_framebuffer/rgb565.h"
+#include "pw_framebuffer/framebuffer.h"
using pw::color::color_rgb565_t;
using pw::coordinates::Vector2;
namespace pw::draw {
-TextArea::TextArea(pw::framebuffer::FramebufferRgb565& fb, const FontSet* font)
+TextArea::TextArea(pw::framebuffer::Framebuffer& fb, const FontSet* font)
: framebuffer(fb) {
SetFont(font);
// Default colors: White on Black
diff --git a/pw_graphics/pw_draw/public/pw_draw/text_area.h b/pw_graphics/pw_draw/public/pw_draw/text_area.h
index 4e67bc8..db25d0c 100644
--- a/pw_graphics/pw_draw/public/pw_draw/text_area.h
+++ b/pw_graphics/pw_draw/public/pw_draw/text_area.h
@@ -15,7 +15,7 @@
#include "pw_color/color.h"
#include "pw_draw/font_set.h"
-#include "pw_framebuffer/rgb565.h"
+#include "pw_framebuffer/framebuffer.h"
namespace pw::draw {
@@ -28,9 +28,9 @@
const FontSet* current_font;
pw::color::color_rgb565_t foreground_color;
pw::color::color_rgb565_t background_color;
- pw::framebuffer::FramebufferRgb565& framebuffer;
+ pw::framebuffer::Framebuffer& framebuffer;
- TextArea(pw::framebuffer::FramebufferRgb565& fb, const FontSet* font);
+ TextArea(pw::framebuffer::Framebuffer& fb, const FontSet* font);
// Change the current font.
void SetFont(const FontSet* new_font);
diff --git a/pw_graphics/pw_framebuffer/BUILD.gn b/pw_graphics/pw_framebuffer/BUILD.gn
index b59d01d..a681838 100644
--- a/pw_graphics/pw_framebuffer/BUILD.gn
+++ b/pw_graphics/pw_framebuffer/BUILD.gn
@@ -29,8 +29,8 @@
"$dir_pw_color",
"$dir_pw_result",
]
- public = [ "public/pw_framebuffer/rgb565.h" ]
- sources = [ "rgb565.cc" ]
+ public = [ "public/pw_framebuffer/framebuffer.h" ]
+ sources = [ "framebuffer.cc" ]
}
pw_test("framebuffer_test") {
diff --git a/pw_graphics/pw_framebuffer/rgb565.cc b/pw_graphics/pw_framebuffer/framebuffer.cc
similarity index 75%
rename from pw_graphics/pw_framebuffer/rgb565.cc
rename to pw_graphics/pw_framebuffer/framebuffer.cc
index ec93b39..97a1441 100644
--- a/pw_graphics/pw_framebuffer/rgb565.cc
+++ b/pw_graphics/pw_framebuffer/framebuffer.cc
@@ -11,7 +11,7 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
-#include "public/pw_framebuffer/rgb565.h"
+#include "public/pw_framebuffer/framebuffer.h"
#include <cstddef>
@@ -21,19 +21,19 @@
namespace pw::framebuffer {
-FramebufferRgb565::FramebufferRgb565()
+Framebuffer::Framebuffer()
: pixel_data_(nullptr), width_(0), height_(0), row_bytes_(0) {}
-FramebufferRgb565::FramebufferRgb565(color_rgb565_t* data,
- int width,
- int height,
- int row_bytes)
+Framebuffer::Framebuffer(color_rgb565_t* data,
+ int width,
+ int height,
+ int row_bytes)
: pixel_data_(data),
width_(width),
height_(height),
row_bytes_(row_bytes) {}
-FramebufferRgb565::FramebufferRgb565(FramebufferRgb565&& other)
+Framebuffer::Framebuffer(Framebuffer&& other)
: pixel_data_(other.pixel_data_),
width_(other.width_),
height_(other.height_),
@@ -41,7 +41,7 @@
other.pixel_data_ = nullptr;
}
-FramebufferRgb565& FramebufferRgb565::operator=(FramebufferRgb565&& rhs) {
+Framebuffer& Framebuffer::operator=(Framebuffer&& rhs) {
pixel_data_ = rhs.pixel_data_;
width_ = rhs.width_;
height_ = rhs.height_;
@@ -51,7 +51,7 @@
}
// Return the RGB565 color at position x, y. Bounds are checked.
-Result<color_rgb565_t> FramebufferRgb565::GetPixel(int x, int y) const {
+Result<color_rgb565_t> Framebuffer::GetPixel(int x, int y) const {
PW_ASSERT(IsValid());
if (x >= 0 && x < width_ && y >= 0 && y < height_) {
return pixel_data_[y * width_ + x];
@@ -60,7 +60,7 @@
}
// Draw a color at (x, y) if it's a valid position.
-void FramebufferRgb565::SetPixel(int x, int y, color_rgb565_t rgb565_color) {
+void Framebuffer::SetPixel(int x, int y, color_rgb565_t rgb565_color) {
PW_ASSERT(IsValid());
if (x >= 0 && x < width_ && y >= 0 && y < height_) {
pixel_data_[y * width_ + x] = rgb565_color;
@@ -68,7 +68,7 @@
}
// Copy the colors from another framebuffer into this one at position x, y.
-void FramebufferRgb565::Blit(const FramebufferRgb565& fb, int x, int y) {
+void Framebuffer::Blit(const Framebuffer& fb, int x, int y) {
PW_ASSERT(fb.IsValid());
for (int current_x = 0; current_x < fb.width_; current_x++) {
for (int current_y = 0; current_y < fb.height_; current_y++) {
@@ -81,7 +81,7 @@
}
// Fill the entire buffer with a color.
-void FramebufferRgb565::Fill(color_rgb565_t color) {
+void Framebuffer::Fill(color_rgb565_t color) {
PW_ASSERT(IsValid());
for (int i = 0; i < width_ * height_; i++) {
pixel_data_[i] = color;
diff --git a/pw_graphics/pw_framebuffer/framebuffer_test.cc b/pw_graphics/pw_framebuffer/framebuffer_test.cc
index 178cfcd..8398e3d 100644
--- a/pw_graphics/pw_framebuffer/framebuffer_test.cc
+++ b/pw_graphics/pw_framebuffer/framebuffer_test.cc
@@ -12,13 +12,14 @@
// License for the specific language governing permissions and limitations under
// the License.
+#include "pw_framebuffer/framebuffer.h"
+
#include <cstdint>
#include "gtest/gtest.h"
#include "pw_color/color.h"
#include "pw_color/colors_endesga32.h"
#include "pw_color/colors_pico8.h"
-#include "pw_framebuffer/rgb565.h"
#include "pw_log/log.h"
using pw::color::color_rgb565_t;
@@ -26,16 +27,16 @@
namespace pw::framebuffer {
namespace {
-TEST(FramebufferRgb565, Init) {
+TEST(Framebuffer, Init) {
uint16_t data[32 * 32];
- FramebufferRgb565 fb(data, 32, 32, 32 * sizeof(data[0]));
+ Framebuffer fb(data, 32, 32, 32 * sizeof(data[0]));
EXPECT_EQ(fb.GetWidth(), 32);
EXPECT_EQ(fb.GetHeight(), 32);
}
-TEST(FramebufferRgb565, Fill) {
+TEST(Framebuffer, Fill) {
uint16_t data[8 * 8];
- FramebufferRgb565 fb(data, 8, 8, 8 * sizeof(data[0]));
+ Framebuffer fb(data, 8, 8, 8 * sizeof(data[0]));
color_rgb565_t* const pixel_data = fb.GetFramebufferData();
color_rgb565_t indigo = 0x83b3;
fb.Fill(indigo);
@@ -45,9 +46,9 @@
EXPECT_EQ(pixel_data[8 * 8 - 1], 0x83b3);
}
-TEST(FramebufferRgb565, SetPixelGetPixel) {
+TEST(Framebuffer, SetPixelGetPixel) {
uint16_t data[8 * 8];
- FramebufferRgb565 fb(data, 8, 8, 8 * sizeof(data[0]));
+ Framebuffer fb(data, 8, 8, 8 * sizeof(data[0]));
color_rgb565_t* const pixel_data = fb.GetFramebufferData();
color_rgb565_t indigo = 0x83b3;
fb.Fill(0);
@@ -74,9 +75,9 @@
EXPECT_EQ(c.value(), indigo);
}
-TEST(FramebufferRgb565, Blit) {
+TEST(Framebuffer, Blit) {
uint16_t data[8 * 8];
- FramebufferRgb565 fb(data, 8, 8, 8 * sizeof(data[0]));
+ Framebuffer fb(data, 8, 8, 8 * sizeof(data[0]));
color_rgb565_t indigo = color::colors_pico8_rgb565[12];
fb.Fill(indigo);
color_rgb565_t* const pixel_data = fb.GetFramebufferData();
@@ -86,7 +87,7 @@
EXPECT_EQ(pixel_data[8 * 8 - 1], indigo);
uint16_t data2[4 * 4];
- FramebufferRgb565 fb2(data2, 4, 4, 4 * sizeof(data2[0]));
+ Framebuffer fb2(data2, 4, 4, 4 * sizeof(data2[0]));
color_rgb565_t orange = 0xfd00;
fb2.Fill(orange);
diff --git a/pw_graphics/pw_framebuffer/public/pw_framebuffer/rgb565.h b/pw_graphics/pw_framebuffer/public/pw_framebuffer/framebuffer.h
similarity index 80%
rename from pw_graphics/pw_framebuffer/public/pw_framebuffer/rgb565.h
rename to pw_graphics/pw_framebuffer/public/pw_framebuffer/framebuffer.h
index 1954cff..e4edd74 100644
--- a/pw_graphics/pw_framebuffer/public/pw_framebuffer/rgb565.h
+++ b/pw_graphics/pw_framebuffer/public/pw_framebuffer/framebuffer.h
@@ -18,25 +18,25 @@
namespace pw::framebuffer {
-class FramebufferRgb565 {
+class Framebuffer {
public:
// Construct a default invalid framebuffer. Using an
// invalid framebuffer will result in a failed PW_CHECK.
- FramebufferRgb565();
+ Framebuffer();
// Construct a framebuffer of the specified dimensions which *does not* own
// the |data| - i.e. this instance may write to the data, but will never
// attempt to free it.
- FramebufferRgb565(pw::color::color_rgb565_t* data,
- int width,
- int height,
- int row_bytes);
+ Framebuffer(pw::color::color_rgb565_t* data,
+ int width,
+ int height,
+ int row_bytes);
- FramebufferRgb565(const FramebufferRgb565&) = delete;
- FramebufferRgb565(FramebufferRgb565&& other);
+ Framebuffer(const Framebuffer&) = delete;
+ Framebuffer(Framebuffer&& other);
- FramebufferRgb565& operator=(const FramebufferRgb565&) = delete;
- FramebufferRgb565& operator=(FramebufferRgb565&&);
+ Framebuffer& operator=(const Framebuffer&) = delete;
+ Framebuffer& operator=(Framebuffer&&);
// Has the framebuffer been properly initialized?
bool IsValid() const { return pixel_data_ != nullptr; };
@@ -50,7 +50,7 @@
void SetPixel(int x, int y, pw::color::color_rgb565_t rgb565_color);
// Copy the colors from another framebuffer into this one at position x, y.
- void Blit(const FramebufferRgb565& fb, int x, int y);
+ void Blit(const Framebuffer& fb, int x, int y);
// Fill the entire buffer with a color.
void Fill(pw::color::color_rgb565_t color);