diff layer/Colour3DPlotRenderer.cpp @ 1095:ba62684a4512 spectrogram-minor-refactor

Fix draw buffer sizing problem in scaled rendering
author Chris Cannam
date Mon, 11 Jul 2016 10:38:23 +0100
parents 8a815776151c
children 6288f1b5f49b
line wrap: on
line diff
--- a/layer/Colour3DPlotRenderer.cpp	Thu Jul 07 19:18:31 2016 +0100
+++ b/layer/Colour3DPlotRenderer.cpp	Mon Jul 11 10:38:23 2016 +0100
@@ -344,7 +344,10 @@
     
     int h = v->getPaintHeight();
 
-    clearDrawBuffer(drawBufferWidth, h);
+    // For our purposes here, the draw buffer needs to be exactly our
+    // target size (so we recreate always rather than just clear it)
+    
+    recreateDrawBuffer(drawBufferWidth, h);
 
     vector<int> binforx(drawBufferWidth);
     vector<double> binfory(h);
@@ -372,6 +375,10 @@
 
     int scaledLeft = v->getXForFrame(leftBoundaryFrame);
     int scaledRight = v->getXForFrame(rightBoundaryFrame);
+
+    cerr << "scaling draw buffer from width " << m_drawBuffer.width()
+         << " to " << (scaledRight - scaledLeft) << " (nb drawBufferWidth = "
+         << drawBufferWidth << ")" << endl;
     
     QImage scaled = m_drawBuffer.scaled
         (scaledRight - scaledLeft, h,
@@ -556,21 +563,28 @@
 }
 
 void
-Colour3DPlotRenderer::clearDrawBuffer(int w, int h)
+Colour3DPlotRenderer::recreateDrawBuffer(int w, int h)
 {
-    if (m_drawBuffer.width() < w || m_drawBuffer.height() != h) {
+    m_drawBuffer = QImage(w, h, QImage::Format_Indexed8);
 
-        m_drawBuffer = QImage(w, h, QImage::Format_Indexed8);
-
-        for (int pixel = 0; pixel < 256; ++pixel) {
-            //!!! todo: colour rotation (here 0)
-            m_drawBuffer.setColor
-                ((unsigned char)pixel,
-                 m_params.colourScale.getColourForPixel(pixel, 0).rgb());
-        }
+    for (int pixel = 0; pixel < 256; ++pixel) {
+        //!!! todo: colour rotation (here 0)
+        m_drawBuffer.setColor
+            ((unsigned char)pixel,
+             m_params.colourScale.getColourForPixel(pixel, 0).rgb());
     }
 
     m_drawBuffer.fill(0);
 }
 
+void
+Colour3DPlotRenderer::clearDrawBuffer(int w, int h)
+{
+    if (m_drawBuffer.width() < w || m_drawBuffer.height() != h) {
+        recreateDrawBuffer(w, h);
+    } else {
+        m_drawBuffer.fill(0);
+    }
+}
 
+