changeset 1084:db976e9f385a spectrogram-minor-refactor

Scale and copy
author Chris Cannam
date Fri, 01 Jul 2016 11:37:46 +0100
parents 7122aae95a88
children 179ea8a2f650
files layer/Colour3DPlotRenderer.cpp
diffstat 1 files changed, 51 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Colour3DPlotRenderer.cpp	Fri Jul 01 11:21:09 2016 +0100
+++ b/layer/Colour3DPlotRenderer.cpp	Fri Jul 01 11:37:46 2016 +0100
@@ -282,6 +282,57 @@
                                          timeConstrained);
 
     //!!! now scale-copy to cache
+
+    if (attainedWidth == 0) return;
+    
+    int paintedLeft = x0;
+    if (rightToLeft) {
+        paintedLeft += (repaintWidth - attainedWidth);
+    }
+
+    if (bufferIsBinResolution) {
+
+        int scaledLeft = v->getXForFrame(leftBoundaryFrame);
+        int scaledRight = v->getXForFrame(rightBoundaryFrame);
+
+        QImage scaled = m_drawBuffer.scaled
+            (scaledRight - scaledLeft, h,
+             Qt::IgnoreAspectRatio, (m_params.interpolate ?
+                                     Qt::SmoothTransformation :
+                                     Qt::FastTransformation));
+            
+        int scaledLeftCrop = v->getXForFrame(leftCropFrame);
+        int scaledRightCrop = v->getXForFrame(rightCropFrame);
+
+        int targetLeft = scaledLeftCrop;
+        if (targetLeft < 0) {
+            targetLeft = 0;
+        }
+
+        int targetWidth = scaledRightCrop - targetLeft;
+        if (targetLeft + targetWidth > m_cache.getSize().width()) {
+            targetWidth = m_cache.getSize().width() - targetLeft;
+        }
+            
+        int sourceLeft = targetLeft - scaledLeft;
+        if (sourceLeft < 0) {
+            sourceLeft = 0;
+        }
+            
+        int sourceWidth = targetWidth;
+
+        if (targetWidth > 0) {
+            m_cache.drawImage(targetLeft, targetWidth,
+                              scaled,
+                              sourceLeft, sourceWidth);
+        }
+
+    } else {
+
+        m_cache.drawImage(paintedLeft, attainedWidth,
+                          m_drawBuffer,
+                          paintedLeft - x0, attainedWidth);
+    }
 }