Skip to content

Commit

Permalink
Add 180 degree rotate for context output to display
Browse files Browse the repository at this point in the history
  • Loading branch information
ohmtech-rdi committed Dec 6, 2024
1 parent 5249209 commit 03cff21
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/erb/DisplayContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class DisplayContext

operator Storage () const;
Storage rotate_ccw (std::size_t width, std::size_t height) const;
Storage rotate_180 (std::size_t width, std::size_t height) const;

void set (Color color);

Expand Down
32 changes: 32 additions & 0 deletions include/erb/DisplayContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,38 @@ typename DisplayContext <Format>::Storage DisplayContext <Format>::rotate_ccw (s



/*
==============================================================================
Name : rotate_180
==============================================================================
*/

template <typename Format>
typename DisplayContext <Format>::Storage DisplayContext <Format>::rotate_180 (std::size_t width, std::size_t height) const
{
Storage ret;

for (std::size_t x = 0 ; x < width ; ++x)
for (std::size_t y = 0 ; y < height ; ++y)
{
auto & d = ret [x + (y / 8) * width];
const auto s = _data [(width - 1 - x) + ((height - 1 - y) / 8) * width];
const auto b = (s & (1 << (height - 1 - y) % 8)) != 0;
if (b)
{
d |= 1 << y % 8;
}
else
{
d &= ~(1 << y % 8);
}
}

return ret;
}



/*
==============================================================================
Name : set
Expand Down

0 comments on commit 03cff21

Please sign in to comment.