From 3a136f2d9803d5b293f6221cc7e3dec03a138648 Mon Sep 17 00:00:00 2001 From: Phillip Burgess Date: Thu, 9 Nov 2017 23:07:31 -0800 Subject: [PATCH] Clean up a little, do XOR w/32-bit ops --- main.c | 57 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/main.c b/main.c index e683bf1..934a591 100644 --- a/main.c +++ b/main.c @@ -64,6 +64,7 @@ int process() { return -1; } + // Allocate 3 screen buffers (current, prior, delta) screenbuf[0] = (uint16_t *)malloc(vinfo.xres * vinfo.yres * 2 * 3); if(!screenbuf[0]) { printf("malloc fail"); @@ -89,37 +90,41 @@ int process() { // Transfer snamshot to screenbuf vc_dispmanx_resource_read_data(screen_resource, &rect1, (char *)screenbuf[bufNum], vinfo.xres * vinfo.bits_per_pixel / 8); - // Calculate delta between two screenbufs - for(int i=0; i first) && - !screenbuf[2][last]; last--); + if(first < (vinfo.xres * vinfo.yres / 2)) { // ANY change? + // Find last nonzero lword + for(last=(vinfo.xres * vinfo.yres / 2) - 1; (last > first) && + !p2[last]; last--); - int firstRow = first / vinfo.xres; - int lastRow = last / vinfo.xres; - // printf("%d %d\n", firstRow, lastRow); + int firstRow = first / (vinfo.xres / 2); + int lastRow = last / (vinfo.xres / 2); #if 0 -// Try a full-width copy (single operation) -memcpy( - (uint16_t *)&fbp[(firstRow * vinfo.xres) * 2], - &screenbuf[bufNum][firstRow * vinfo.xres], - vinfo.xres * (lastRow - firstRow + 1) * 2); + // Let's try a full-width copy (single memcpy operation) + memcpy( + (uint16_t *)&fbp[firstRow * vinfo.xres * 2], + &screenbuf[bufNum][firstRow * vinfo.xres], + vinfo.xres * (lastRow - firstRow + 1) * 2); #else -// Try rect bounds (multiple memcpy's) + // Find actual rect bounds and use memcpy-per-row int firstCol = vinfo.xres - 1, lastCol = 0; for(int row=firstRow; row <= lastRow; row++) { - uint16_t *s = &screenbuf[2][row * vinfo.xres]; + uint16_t *s = (uint16_t *)&p2[row * vinfo.xres / 2]; for(int col=0; col