changeset 1040:25b035362c44 spectrogram-minor-refactor

Truncate edges when about to paint beyond limits of cache
author Chris Cannam
date Wed, 03 Feb 2016 16:51:37 +0000
parents bfce7940c017
children fccee028a522 218be6cf2d4f
files layer/ScrollableImageCache.cpp layer/SpectrogramLayer.cpp
diffstat 2 files changed, 29 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/layer/ScrollableImageCache.cpp	Tue Feb 02 16:00:31 2016 +0000
+++ b/layer/ScrollableImageCache.cpp	Wed Feb 03 16:51:37 2016 +0000
@@ -17,7 +17,7 @@
 #include <iostream>
 using namespace std;
 
-#define DEBUG_SCROLLABLE_IMAGE_CACHE 1
+//#define DEBUG_SCROLLABLE_IMAGE_CACHE 1
 
 void
 ScrollableImageCache::scrollTo(sv_frame_t newStartFrame)
@@ -140,15 +140,15 @@
     }
     if (left < 0 || width < 0 || left + width > m_image.width()) {
 	cerr << "ScrollableImageCache::drawImage: ERROR: Target area (left = "
-	     << left << ", width = " << width << ") out of bounds for cache of "
-	     << "width " << m_image.width() << endl;
+	     << left << ", width = " << width << ", so right = " << left + width
+             << ") out of bounds for cache of width " << m_image.width() << endl;
 	throw std::logic_error("Target area out of bounds in ScrollableImageCache::drawImage");
     }
     if (imageLeft < 0 || imageWidth < 0 ||
 	imageLeft + imageWidth > image.width()) {
 	cerr << "ScrollableImageCache::drawImage: ERROR: Source area (left = "
-	     << imageLeft << ", width = " << imageWidth
-	     << ") out of bounds for image of "
+	     << imageLeft << ", width = " << imageWidth << ", so right = "
+             << imageLeft + imageWidth << ") out of bounds for image of "
 	     << "width " << image.width() << endl;
 	throw std::logic_error("Source area out of bounds in ScrollableImageCache::drawImage");
     }
--- a/layer/SpectrogramLayer.cpp	Tue Feb 02 16:00:31 2016 +0000
+++ b/layer/SpectrogramLayer.cpp	Wed Feb 03 16:51:37 2016 +0000
@@ -2063,14 +2063,31 @@
                  << scaledLeftCrop << " from " << scaledLeftCrop - scaledLeft << endl;
 #endif
 
-            //!!! Update this for failedToRepaint logic
+            int targetLeft = scaledLeftCrop;
+            if (targetLeft < 0) {
+                targetLeft = 0;
+            }
+
+            int targetWidth = scaledRightCrop - targetLeft;
+            if (targetLeft + targetWidth > cache.getSize().width()) {
+                targetWidth = cache.getSize().width() - targetLeft;
+            }
             
-            cache.drawImage
-                (scaledLeftCrop,
-                 scaledRightCrop - scaledLeftCrop,
-                 scaled,
-                 scaledLeftCrop - scaledLeft,
-                 scaledRightCrop - scaledLeftCrop);
+            int sourceLeft = targetLeft - scaledLeft;
+            if (sourceLeft < 0) {
+                sourceLeft = 0;
+            }
+            
+            int sourceWidth = targetWidth;
+
+            if (targetWidth > 0) {
+                cache.drawImage
+                    (targetLeft,
+                     targetWidth,
+                     scaled,
+                     sourceLeft,
+                     sourceWidth);
+            }
 
         } else {