From 03cff2150aa4ca3b0b51c63016f0dfe915e6fc07 Mon Sep 17 00:00:00 2001 From: rdi Date: Sun, 24 Nov 2024 15:57:54 +0100 Subject: [PATCH] Add 180 degree rotate for context output to display --- include/erb/DisplayContext.h | 1 + include/erb/DisplayContext.hpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) 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