2 #include "splitscreen.h"
4 SplitScreen::SplitScreen(GenericScreen *s1, GenericScreen *s2, GenericScreen *s3, GenericScreen *s4)
12 memset(subbufs[0], 0, 800*600*4);
13 memset(subbufs[1], 0, 800*600*4);
14 memset(subbufs[2], 0, 800*600*4);
15 memset(subbufs[3], 0, 800*600*4);
18 SplitScreen::~SplitScreen()
22 bool SplitScreen::check_invalidated()
27 for (unsigned i = 0; i < 4; ++i) {
28 if (subscreens[i] && subscreens[i]->check_invalidated())
35 void SplitScreen::draw(unsigned char *buf)
37 for (unsigned i = 0; i < 4; ++i) {
38 if (subscreens[i] && subscreens[i]->check_invalidated()) {
39 subscreens[i]->draw(subbufs[i]);
43 downscale_2x2(buf, subbufs[0]);
44 downscale_2x2(buf + 400 * 4, subbufs[1]);
45 downscale_2x2(buf + 800 * 300 * 4, subbufs[2]);
46 downscale_2x2(buf + 800 * 300 * 4 + 400 * 4, subbufs[3]);
49 unsigned char *ptr = buf + 300 * 800 * 4;
50 for (unsigned x = 0; x < 800; ++x) {
58 for (unsigned y = 0; y < 600; ++y) {
70 // simple box filter (blah)
71 void SplitScreen::downscale_2x2(unsigned char *dst, unsigned char *src)
73 for (unsigned y = 0; y < 300; ++y) {
74 unsigned char *sptr1 = src + (y*2) * 800 * 4;
75 unsigned char *sptr2 = src + (y*2+1) * 800 * 4;
76 unsigned char *dptr = dst + y * 800 * 4;
78 for (unsigned x = 0; x < 400; ++x) {
79 *dptr++ = (sptr1[0] + sptr1[4] + sptr2[0] + sptr2[4]) >> 2; // red
80 *dptr++ = (sptr1[1] + sptr1[5] + sptr2[1] + sptr2[5]) >> 2; // green
81 *dptr++ = (sptr1[2] + sptr1[6] + sptr2[2] + sptr2[6]) >> 2; // blue
82 *dptr++ = (sptr1[3] + sptr1[7] + sptr2[3] + sptr2[7]) >> 2; // alpha