]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
move entire waterfall to the left or right when changing vfo
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Sat, 29 Jul 2023 13:22:10 +0000 (18:52 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Sat, 29 Jul 2023 13:22:10 +0000 (18:52 +0530)
waterfall.c

index 11610df47ae29be6cc96c1706665aa125475ccb3..03e133fc489415642b14e09b9f2cc3fbdf3796ad 100644 (file)
@@ -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);
                         }
                     }