]> git.sesse.net Git - ccbs/blobdiff - bigscreen/splitscreen.cpp
Let each screen get width and height in as a parameter on draw() instead of hardcodin...
[ccbs] / bigscreen / splitscreen.cpp
index 9d569b1665eff783ff1012f232caa65db904f011..e4bb4c441155ec962ee92a0ec2366f3607c04c4b 100644 (file)
@@ -1,3 +1,5 @@
+/* NOTE: this class will _NOT_ handle resolution changes cleanly. You have been warned. :-) */
+
 #include <cstring>
 #include "splitscreen.h"
 
 #include <cstring>
 #include "splitscreen.h"
 
@@ -9,10 +11,8 @@ SplitScreen::SplitScreen(GenericScreen *s1, GenericScreen *s2, GenericScreen *s3
        subscreens[2] = s3;
        subscreens[3] = s4;
 
        subscreens[2] = s3;
        subscreens[3] = s4;
 
-       memset(subbufs[0], 0, SCREEN_WIDTH*SCREEN_HEIGHT*4);
-       memset(subbufs[1], 0, SCREEN_WIDTH*SCREEN_HEIGHT*4);
-       memset(subbufs[2], 0, SCREEN_WIDTH*SCREEN_HEIGHT*4);
-       memset(subbufs[3], 0, SCREEN_WIDTH*SCREEN_HEIGHT*4);
+       for (unsigned i = 0; i < 4; ++i)
+               subbufs[i] = NULL;
 }
 
 SplitScreen::~SplitScreen()
 }
 
 SplitScreen::~SplitScreen()
@@ -32,58 +32,52 @@ bool SplitScreen::check_invalidated()
        return false;
 }
 
        return false;
 }
 
-void SplitScreen::draw(unsigned char *buf)
+void SplitScreen::draw(unsigned char *buf, unsigned width, unsigned height)
 {
        for (unsigned i = 0; i < 4; ++i) {
 {
        for (unsigned i = 0; i < 4; ++i) {
+               if (subbufs[i] == NULL) {  // see line 1
+                       subbufs[i] = new unsigned char[width/2 * height/2 * 4];
+                       memset(subbufs[i], 0, width/2 * height/2 * 4);
+               }
                if (subscreens[i] && subscreens[i]->check_invalidated()) {
                if (subscreens[i] && subscreens[i]->check_invalidated()) {
-                       subscreens[i]->draw(subbufs[i]);
+                       subscreens[i]->draw(subbufs[i], width/2, height/2);
                }
        }
        
                }
        }
        
-       downscale_2x2(buf, subbufs[0]);
-       downscale_2x2(buf + (SCREEN_WIDTH/2) * 4, subbufs[1]);
-       downscale_2x2(buf + SCREEN_WIDTH * (SCREEN_HEIGHT/2) * 4, subbufs[2]);
-       downscale_2x2(buf + SCREEN_WIDTH * (SCREEN_HEIGHT/2) * 4 + (SCREEN_WIDTH/2) * 4, subbufs[3]); 
-
+       copy_subscreen(buf, subbufs[0], width, height);
+       copy_subscreen(buf + (width/2) * 4, subbufs[1], width, height);
+       copy_subscreen(buf + width * (height/2) * 4, subbufs[2], width, height);
+       copy_subscreen(buf + width * (height/2) * 4 + (width/2) * 4, subbufs[3], width, height); 
+       
        // make divider lines
        // make divider lines
-       unsigned char *ptr = buf + (SCREEN_HEIGHT/2) * SCREEN_WIDTH * 4;
-       for (unsigned x = 0; x < SCREEN_WIDTH; ++x) {
+       unsigned char *ptr = buf + (height/2) * width * 4;
+       for (unsigned x = 0; x < width; ++x) {
                *ptr++ = 255;
                *ptr++ = 255;
                *ptr++ = 255;
                *ptr++ = 0;
        }
        
                *ptr++ = 255;
                *ptr++ = 255;
                *ptr++ = 255;
                *ptr++ = 0;
        }
        
-       ptr = buf + (SCREEN_WIDTH/2) * 4;
-       for (unsigned y = 0; y < SCREEN_HEIGHT; ++y) {
+       ptr = buf + (width/2) * 4;
+       for (unsigned y = 0; y < height; ++y) {
                ptr[0] = 255;
                ptr[1] = 255;
                ptr[2] = 255;
                ptr[3] = 0;
 
                ptr[0] = 255;
                ptr[1] = 255;
                ptr[2] = 255;
                ptr[3] = 0;
 
-               ptr += SCREEN_WIDTH * 4;
+               ptr += width * 4;
        }
        
        valid = true;
 }
        }
        
        valid = true;
 }
-       
-// simple box filter (blah)
-void SplitScreen::downscale_2x2(unsigned char *dst, unsigned char *src)
+
+void SplitScreen::copy_subscreen(unsigned char *dst, unsigned char *src, unsigned width, unsigned height)
 {
 {
-       for (unsigned y = 0; y < (SCREEN_HEIGHT/2); ++y) {
-               unsigned char *sptr1 = src + (y*2) * SCREEN_WIDTH * 4;
-               unsigned char *sptr2 = src + (y*2+1) * SCREEN_WIDTH * 4;
-               unsigned char *dptr = dst + y * SCREEN_WIDTH * 4;
-               
-               for (unsigned x = 0; x < (SCREEN_WIDTH/2); ++x) {
-                       *dptr++ = (sptr1[0] + sptr1[4] + sptr2[0] + sptr2[4]) >> 2;  // red
-                       *dptr++ = (sptr1[1] + sptr1[5] + sptr2[1] + sptr2[5]) >> 2;  // green
-                       *dptr++ = (sptr1[2] + sptr1[6] + sptr2[2] + sptr2[6]) >> 2;  // blue
-                       *dptr++ = (sptr1[3] + sptr1[7] + sptr2[3] + sptr2[7]) >> 2;  // alpha
+       for (unsigned y = 0; y < height/2; ++y) {
+               unsigned char *sptr = src + y * width/2 * 4;
+               unsigned char *dptr = dst + y * width * 4;
 
 
-                       sptr1 += 8;
-                       sptr2 += 8;
-               }
+               memcpy(dptr, sptr, width/2 * 4);
        }
 }
        }
 }
-
+