From 47031a98eeb42eeb99d0fe0f7620d20d16d77ed1 Mon Sep 17 00:00:00 2001 From: Ramakrishnan Muthukrishnan Date: Sat, 29 Jul 2023 18:52:10 +0530 Subject: [PATCH] move entire waterfall to the left or right when changing vfo --- waterfall.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/waterfall.c b/waterfall.c index 11610df..03e133f 100644 --- a/waterfall.c +++ b/waterfall.c @@ -142,25 +142,28 @@ void waterfall_update(RECEIVER *rx) { // %lld to %lld // pixels=%d\n",rx->waterfall_frequency,vfo[rx->id].frequency,rotate_pixels); if (rotate_pixels < 0) { - memmove( - pixels, &pixels[-rotate_pixels * 3], - ((display_width * display_height) + rotate_pixels) * - 3); - // now clear the right hand side - for (i = 0; i < display_height; i++) { - memset(&pixels[((i * display_width) + - (width + rotate_pixels)) * - 3], - 0, -rotate_pixels * 3); + for (size_t h = 0; h < display_height; h++) { + // Move each line to the left by rotate_pixels * 3 bytes. + // Each pixel is 3 bytes, hence the 3. + // note: rotate_pixel is negative. + memmove(&pixels[h * rowstride], + &pixels[h * rowstride - (rotate_pixels * 3)], + rowstride + (rotate_pixels * 3)); + // clear the right side + memset(&pixels[h * rowstride + rowstride + (rotate_pixels * 3)], + 0, + -rotate_pixels * 3); } } else { - memmove( - &pixels[rotate_pixels * 3], pixels, - ((display_width * display_height) - rotate_pixels) * - 3); - // now clear the left hand side - for (i = 0; i < display_height; i++) { - memset(&pixels[(i * display_width) * 3], 0, + for (size_t h = 0; h < display_height; h++) { + // Move each line to the right, overwrite + // the last rotate_pixels * 3 bytes in each line. + memmove(&pixels[h * rowstride + (rotate_pixels * 3)], + &pixels[h * rowstride], + rowstride - (rotate_pixels * 3)); + // clear the left side + memset(&pixels[h * rowstride], + 0, rotate_pixels * 3); } } -- 2.45.2