# HG changeset patch # User Chris Cannam # Date 1468229903 -3600 # Node ID ba62684a4512ea3ee544e5d2f9e91ab827ea2f71 # Parent 8a815776151c9aeb0c663b900d19c1cc7620e67f Fix draw buffer sizing problem in scaled rendering diff -r 8a815776151c -r ba62684a4512 layer/Colour3DPlotRenderer.cpp --- 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 binforx(drawBufferWidth); vector 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); + } +} + diff -r 8a815776151c -r ba62684a4512 layer/Colour3DPlotRenderer.h --- a/layer/Colour3DPlotRenderer.h Thu Jul 07 19:18:31 2016 +0100 +++ b/layer/Colour3DPlotRenderer.h Mon Jul 11 10:38:23 2016 +0100 @@ -182,6 +182,7 @@ bool usePeaksCache, bool rightToLeft, bool timeConstrained); + void recreateDrawBuffer(int w, int h); void clearDrawBuffer(int w, int h); };