diff --git a/include/erb/DisplayContext.h b/include/erb/DisplayContext.h index 77795a8f..996ceff9 100755 --- a/include/erb/DisplayContext.h +++ b/include/erb/DisplayContext.h @@ -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); diff --git a/include/erb/DisplayContext.hpp b/include/erb/DisplayContext.hpp index e9633a01..fc1abc8a 100755 --- a/include/erb/DisplayContext.hpp +++ b/include/erb/DisplayContext.hpp @@ -82,6 +82,38 @@ typename DisplayContext ::Storage DisplayContext ::rotate_ccw (s +/* +============================================================================== +Name : rotate_180 +============================================================================== +*/ + +template +typename DisplayContext ::Storage DisplayContext ::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