X-Git-Url: https://git.sesse.net/?p=ccbs;a=blobdiff_plain;f=bigscreen%2Frotatescreen.cpp;h=a1a9f59118e2982e5780862c338f6ea4b74a3ce9;hp=78a0e783693ceb3b1ff8fcbeb7964f7c49b6c6af;hb=7b8b747f037d2244ffd080e97d9d5e5c0e9114a7;hpb=9c22e166f4d25f2d80766de9baab56efd9d952b0 diff --git a/bigscreen/rotatescreen.cpp b/bigscreen/rotatescreen.cpp index 78a0e78..a1a9f59 100644 --- a/bigscreen/rotatescreen.cpp +++ b/bigscreen/rotatescreen.cpp @@ -1,15 +1,21 @@ +/* NOTE: this class will _NOT_ handle resolution changes cleanly. You have been warned. :-) */ + +#include #include #include "rotatescreen.h" RotateScreen::RotateScreen() - : valid(false), current_screen(0), in_fade(false) + : fadefrom_buf(NULL), valid(false), current_screen(0), in_fade(false), fade_to_new_info(false) { - fadefrom_buf = new unsigned char[SCREEN_WIDTH * SCREEN_HEIGHT * 4]; } RotateScreen::~RotateScreen() { - delete fadefrom_buf; + delete[] fadefrom_buf; + for (unsigned i = 0; i < subscreens.size(); ++i) { + delete[] subscreens[i].redbuf; + delete[] subscreens[i].buf; + } } bool RotateScreen::check_invalidated() @@ -24,15 +30,30 @@ bool RotateScreen::check_invalidated() return false; for (unsigned i = 0; i < subscreens.size(); ++i) { - if (subscreens[i].screen->check_invalidated()) + if (subscreens[i].buf == NULL || subscreens[i].screen->check_invalidated()) return true; } return false; } -void RotateScreen::draw(unsigned char *buf) +void RotateScreen::draw(unsigned char *buf, unsigned width, unsigned height) { + // see line 1 for all of this + if (fadefrom_buf == NULL) { + 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); + } + } + // end of "line 1"-code :-) + bool force = false; if (subscreens.size() == 0) { @@ -57,46 +78,33 @@ void RotateScreen::draw(unsigned char *buf) if (elapsed_fade > 5.5 || (!fade_to_new_info && elapsed_fade > 0.5)) { in_fade = false; - // ugly hack here? :-) - subscreens[current_screen].screen->draw(subscreens[current_screen].buf); - - memcpy(buf, subscreens[current_screen].buf, SCREEN_WIDTH * SCREEN_HEIGHT * 4); + memcpy(buf, subscreens[current_screen].buf, width * height * 4); } else { - // find the fade factors - int fr, fg, fb, fa; + unsigned char *sptr1, *sptr2; + unsigned char *dptr = buf; + int f; if (fade_to_new_info) { if (elapsed_fade < 0.5) { - fr = fg = fb = fa = unsigned(elapsed_fade/0.5 * 256.0); + sptr1 = fadefrom_buf; + sptr2 = subscreens[current_screen].redbuf; + f = unsigned(elapsed_fade/0.5 * 256.0); } else { - fr = fg = fb = fa = unsigned((elapsed_fade-0.5)/5.0 * 256.0); + sptr1 = subscreens[current_screen].redbuf; + sptr2 = subscreens[current_screen].buf; + f = unsigned((elapsed_fade-0.5)/5.0 * 256.0); } } else { - fr = fg = fb = fa = unsigned(elapsed_fade/0.5 * 256.0); + 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 < SCREEN_WIDTH * SCREEN_HEIGHT; ++i) { - dptr[0] = sptr2[0] + (((int(sptr2[2]) - int(sptr2[0])) * fb) >> 8); - dptr[1] = sptr2[1] + (((int(sptr2[2]) - int(sptr2[1])) * fg) >> 8); - dptr[2] = sptr2[2]; - dptr[3] = sptr2[3]; - - sptr1 += 4, sptr2 += 4, dptr += 4; - } - } else { - for (unsigned i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; ++i) { - dptr[0] = sptr1[0] + (((int(sptr2[0]) - int(sptr1[0])) * fb) >> 8); - dptr[1] = sptr1[1] + (((int(sptr2[1]) - int(sptr1[1])) * fg) >> 8); - dptr[2] = sptr1[2] + (((int(sptr2[2]) - int(sptr1[2])) * fr) >> 8); - dptr[3] = sptr1[3] + (((int(sptr2[3]) - int(sptr1[3])) * fa) >> 8); + 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 { @@ -126,10 +134,14 @@ void RotateScreen::draw(unsigned char *buf) fade_found_start_time = false; fade_to_new_info = force; - memcpy(fadefrom_buf, subscreens[old_current_screen].buf, SCREEN_WIDTH * SCREEN_HEIGHT * 4); + memcpy(fadefrom_buf, subscreens[old_current_screen].buf, width * height * 4); - if (subscreens[current_screen].screen->check_invalidated()) - subscreens[current_screen].screen->draw(subscreens[current_screen].buf); + 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); + } } } @@ -151,7 +163,14 @@ bool RotateScreen::needs_update() return (since >= 10.0); } -// hold all screens for minimum three seconds, hold all screens with new info for at minimum eight seconds +/* + * Hold all screens for minimum three seconds, hold all screens with new info + * for at minimum eight seconds. There's a slight hack here; a screen with new + * info _might_ already be outdated (for instance, if we do an update to a group + * with a mistake, then correct it quick afterwards). If it's already outdated, + * we ignore the "eight second" rule; the results will be somewhat ugly, though, + * but it's hard to do much better without too much special code. + */ bool RotateScreen::can_update() { struct timeval now; @@ -162,7 +181,7 @@ bool RotateScreen::can_update() if (since < 3.0) return false; - if (fade_to_new_info && since < 8.0) + if (fade_to_new_info && subscreens.size() > 0 && !subscreens[current_screen].screen->check_invalidated() && since < 8.0) return false; return true; } @@ -170,11 +189,10 @@ bool RotateScreen::can_update() void RotateScreen::add_screen(GenericScreen *screen) { Subscreen ss; - ss.buf = new unsigned char[SCREEN_WIDTH * SCREEN_HEIGHT * 4]; + ss.redbuf = NULL; + ss.buf = NULL; ss.screen = screen; - screen->draw(ss.buf); - subscreens.push_back(ss); }