# HG changeset patch # User Chris Cannam # Date 1454518297 0 # Node ID 25b035362c44a4a402db1cc28fee137966cba326 # Parent bfce7940c0177649c3869b2b0b15070d24de6ee5 Truncate edges when about to paint beyond limits of cache diff -r bfce7940c017 -r 25b035362c44 layer/ScrollableImageCache.cpp --- 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 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"); } diff -r bfce7940c017 -r 25b035362c44 layer/SpectrogramLayer.cpp --- 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 {