Do some funky channel magic on fading between different versions of the same screen...
authorSteinar H. Gunderson <sesse@samfundet.no>
Sun, 20 Feb 2005 13:59:08 +0000 (13:59 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Sun, 20 Feb 2005 13:59:08 +0000 (13:59 +0000)
bigscreen/rotatescreen.cpp
bigscreen/rotatescreen.h

index 8e216cf..47f9095 100644 (file)
@@ -42,28 +42,53 @@ void RotateScreen::draw(unsigned char *buf)
                        double(now.tv_usec - fade_started.tv_usec) * 1.0e-6;
                printf("fade: %f\n", elapsed_fade);
                
-               if (elapsed_fade > 0.5) {
+               if (elapsed_fade > 5.0 || (!same_fade && elapsed_fade > 0.5)) {
                        in_fade = false;
                        memcpy(buf, subscreens[current_screen].buf, 800 * 600 * 4);
                        printf("fade done\n");
                } else {
                        // find the fade factors
-                       int fr = unsigned(elapsed_fade/0.5 * 256.0);
-                       int fg = unsigned(elapsed_fade/0.5 * 256.0);
-                       int fb = unsigned(elapsed_fade/0.5 * 256.0);
-                       int fa = unsigned(elapsed_fade/0.5 * 256.0);
+                       int fr, fg, fb, fa;
+                       if (same_fade) {
+                               fr = unsigned(elapsed_fade/0.5 * 256.0);
+                               if (elapsed_fade < 0.5) {
+                                       fg = fb = fa = 0;
+                               } else {
+                                       fr = 256;
+                                       fg = fb = fa = unsigned((elapsed_fade-0.5)/4.5 * 256.0);
+                               }
+                       } else {
+                               fr = fg = fb = fa = unsigned(elapsed_fade/0.5 * 256.0);
+                       }
+                       printf("%u %u %u %u\n", fr, fg, fb, fa);
 
                        unsigned char *sptr1 = fadefrom_buf;
                        unsigned char *sptr2 = subscreens[current_screen].buf;
                        unsigned char *dptr = buf;
 
-                       for (unsigned i = 0; i < 800 * 600; ++i) {
-                               dptr[0] = sptr1[0] + (((int(sptr2[0]) - int(sptr1[0])) * fr) >> 8);
-                               dptr[1] = sptr1[1] + (((int(sptr2[1]) - int(sptr1[1])) * fg) >> 8);
-                               dptr[2] = sptr1[2] + (((int(sptr2[2]) - int(sptr1[2])) * fb) >> 8);
-                               dptr[3] = sptr1[3] + (((int(sptr2[3]) - int(sptr1[3])) * fa) >> 8); 
-
-                               sptr1 += 4, sptr2 += 4, dptr += 4;
+                       if (same_fade) {
+                               for (unsigned i = 0; i < 800 * 600; ++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);
+
+                                       if (dptr[0] > dptr[2])
+                                               dptr[0] = dptr[2];
+                                       if (dptr[1] > dptr[2])
+                                               dptr[1] = dptr[2];
+
+                                       sptr1 += 4, sptr2 += 4, dptr += 4;
+                               }
+                       } else {
+                               for (unsigned i = 0; i < 800 * 600; ++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); 
+
+                                       sptr1 += 4, sptr2 += 4, dptr += 4;
+                               }
                        }
                }
        } else {
@@ -88,13 +113,14 @@ void RotateScreen::draw(unsigned char *buf)
                if (current_screen != old_current_screen || subscreens[current_screen].screen->check_invalidated()) {
                        // initialize a fade
                        in_fade = true;
+                       same_fade = (current_screen == old_current_screen);
                        gettimeofday(&fade_started, NULL);
-                       printf("starting fade\n");
+                       printf("starting fade (same=%u)\n", same_fade);
                        
+                       memcpy(fadefrom_buf, subscreens[old_current_screen].buf, 800 * 600 * 4);
+
                        if (subscreens[current_screen].screen->check_invalidated())
                                subscreens[current_screen].screen->draw(subscreens[current_screen].buf);
-               
-                       memcpy(fadefrom_buf, subscreens[old_current_screen].buf, 800 * 600 * 4);
                }
        }
 
index 35931b5..d2c69f7 100644 (file)
@@ -23,7 +23,7 @@ private:
        unsigned current_screen;
 
        struct timeval last_update, fade_started;
-       bool in_fade;
+       bool in_fade, same_fade;
 
        bool needs_update();