From 9751710eac4c4da6c4eb4f2840390298924e0806 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 18 Feb 2012 12:21:12 +0100 Subject: [PATCH 1/1] Fix the rotatescreen fading so subpixel LCD works again. Generally a lot fewer hacks here. --- bigscreen/rotatescreen.cpp | 50 +++++++++++++++----------------------- bigscreen/rotatescreen.h | 2 +- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/bigscreen/rotatescreen.cpp b/bigscreen/rotatescreen.cpp index 64e7269..655c7c3 100644 --- a/bigscreen/rotatescreen.cpp +++ b/bigscreen/rotatescreen.cpp @@ -40,6 +40,9 @@ void RotateScreen::draw(unsigned char *buf, unsigned width, unsigned height) fadefrom_buf = new unsigned char[width * height * 4]; } for (std::vector::iterator i = subscreens.begin(); i != subscreens.end(); ++i) { + if (i->redbuf == NULL) { + i->redbuf = new unsigned char[width * height * 4]; + } if (i->buf == NULL) { i->buf = new unsigned char[width * height * 4]; i->screen->draw(i->buf, width, height); @@ -71,50 +74,33 @@ void RotateScreen::draw(unsigned char *buf, unsigned width, unsigned height) if (elapsed_fade > 5.5 || (!fade_to_new_info && elapsed_fade > 0.5)) { in_fade = false; - // set G&B to be = R - unsigned char *ptr = subscreens[current_screen].buf; - for (unsigned i = 0; i < width * height; ++i) { - ptr[1] = ptr[2] = ptr[3] = ptr[0]; - ptr += 4; - } - memcpy(buf, subscreens[current_screen].buf, width * height * 4); } else { - // find the fade f + unsigned char *sptr1, *sptr2; + unsigned char *dptr = buf; int f; if (fade_to_new_info) { if (elapsed_fade < 0.5) { + sptr1 = fadefrom_buf; + sptr2 = subscreens[current_screen].redbuf; f = unsigned(elapsed_fade/0.5 * 256.0); } else { + sptr1 = subscreens[current_screen].redbuf; + sptr2 = subscreens[current_screen].buf; f = unsigned((elapsed_fade-0.5)/5.0 * 256.0); } } else { + sptr1 = fadefrom_buf; + sptr2 = subscreens[current_screen].buf; f = unsigned(elapsed_fade/0.5 * 256.0); } - unsigned char *sptr1 = fadefrom_buf; - unsigned char *sptr2 = subscreens[current_screen].buf; - unsigned char *dptr = buf; - - if (fade_to_new_info && elapsed_fade >= 0.5) { - // fade G&B to be = R - for (unsigned i = 0; i < width * height; ++i) { - dptr[0] = sptr2[0] + (((int(sptr2[2]) - int(sptr2[0])) * f) >> 8); - dptr[1] = dptr[0]; - dptr[2] = sptr2[2]; - dptr[3] = sptr2[3]; - - sptr1 += 4, sptr2 += 4, dptr += 4; - } - } else { - for (unsigned i = 0; i < width * height; ++i) { - dptr[0] = sptr1[0] + (((int(sptr2[0]) - int(sptr1[0])) * f) >> 8); - dptr[1] = dptr[0]; - dptr[2] = dptr[0]; - dptr[3] = dptr[0]; + for (unsigned i = 0; i < width * height; ++i) { + dptr[0] = sptr1[0] + (((int(sptr2[0]) - int(sptr1[0])) * f) >> 8); + dptr[1] = sptr1[1] + (((int(sptr2[1]) - int(sptr1[1])) * f) >> 8); + dptr[2] = sptr1[2] + (((int(sptr2[2]) - int(sptr1[2])) * f) >> 8); - sptr1 += 4, sptr2 += 4, dptr += 4; - } + sptr1 += 4, sptr2 += 4, dptr += 4; } } } else { @@ -147,6 +133,9 @@ void RotateScreen::draw(unsigned char *buf, unsigned width, unsigned height) memcpy(fadefrom_buf, subscreens[old_current_screen].buf, width * height * 4); if (subscreens[current_screen].screen->check_invalidated()) { + if (fade_to_new_info) { + subscreens[current_screen].screen->draw(subscreens[current_screen].redbuf, width, height); + } subscreens[current_screen].screen->draw(subscreens[current_screen].buf, width, height); } } @@ -196,6 +185,7 @@ bool RotateScreen::can_update() void RotateScreen::add_screen(GenericScreen *screen) { Subscreen ss; + ss.redbuf = NULL; ss.buf = NULL; ss.screen = screen; diff --git a/bigscreen/rotatescreen.h b/bigscreen/rotatescreen.h index 6f53e24..6499912 100644 --- a/bigscreen/rotatescreen.h +++ b/bigscreen/rotatescreen.h @@ -11,7 +11,7 @@ * one at a time). :-) */ struct Subscreen { - unsigned char *buf; + unsigned char *redbuf, *buf; GenericScreen *screen; }; -- 2.39.2