Mercurial > hg > svgui
comparison 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 |
comparison
equal
deleted
inserted
replaced
1094:8a815776151c | 1095:ba62684a4512 |
---|---|
342 drawBufferWidth = int | 342 drawBufferWidth = int |
343 ((rightBoundaryFrame - leftBoundaryFrame) / binResolution); | 343 ((rightBoundaryFrame - leftBoundaryFrame) / binResolution); |
344 | 344 |
345 int h = v->getPaintHeight(); | 345 int h = v->getPaintHeight(); |
346 | 346 |
347 clearDrawBuffer(drawBufferWidth, h); | 347 // For our purposes here, the draw buffer needs to be exactly our |
348 // target size (so we recreate always rather than just clear it) | |
349 | |
350 recreateDrawBuffer(drawBufferWidth, h); | |
348 | 351 |
349 vector<int> binforx(drawBufferWidth); | 352 vector<int> binforx(drawBufferWidth); |
350 vector<double> binfory(h); | 353 vector<double> binfory(h); |
351 | 354 |
352 for (int x = 0; x < drawBufferWidth; ++x) { | 355 for (int x = 0; x < drawBufferWidth; ++x) { |
370 | 373 |
371 if (attainedWidth == 0) return; | 374 if (attainedWidth == 0) return; |
372 | 375 |
373 int scaledLeft = v->getXForFrame(leftBoundaryFrame); | 376 int scaledLeft = v->getXForFrame(leftBoundaryFrame); |
374 int scaledRight = v->getXForFrame(rightBoundaryFrame); | 377 int scaledRight = v->getXForFrame(rightBoundaryFrame); |
378 | |
379 cerr << "scaling draw buffer from width " << m_drawBuffer.width() | |
380 << " to " << (scaledRight - scaledLeft) << " (nb drawBufferWidth = " | |
381 << drawBufferWidth << ")" << endl; | |
375 | 382 |
376 QImage scaled = m_drawBuffer.scaled | 383 QImage scaled = m_drawBuffer.scaled |
377 (scaledRight - scaledLeft, h, | 384 (scaledRight - scaledLeft, h, |
378 Qt::IgnoreAspectRatio, (m_params.interpolate ? | 385 Qt::IgnoreAspectRatio, (m_params.interpolate ? |
379 Qt::SmoothTransformation : | 386 Qt::SmoothTransformation : |
554 | 561 |
555 return columnCount; | 562 return columnCount; |
556 } | 563 } |
557 | 564 |
558 void | 565 void |
566 Colour3DPlotRenderer::recreateDrawBuffer(int w, int h) | |
567 { | |
568 m_drawBuffer = QImage(w, h, QImage::Format_Indexed8); | |
569 | |
570 for (int pixel = 0; pixel < 256; ++pixel) { | |
571 //!!! todo: colour rotation (here 0) | |
572 m_drawBuffer.setColor | |
573 ((unsigned char)pixel, | |
574 m_params.colourScale.getColourForPixel(pixel, 0).rgb()); | |
575 } | |
576 | |
577 m_drawBuffer.fill(0); | |
578 } | |
579 | |
580 void | |
559 Colour3DPlotRenderer::clearDrawBuffer(int w, int h) | 581 Colour3DPlotRenderer::clearDrawBuffer(int w, int h) |
560 { | 582 { |
561 if (m_drawBuffer.width() < w || m_drawBuffer.height() != h) { | 583 if (m_drawBuffer.width() < w || m_drawBuffer.height() != h) { |
562 | 584 recreateDrawBuffer(w, h); |
563 m_drawBuffer = QImage(w, h, QImage::Format_Indexed8); | 585 } else { |
564 | 586 m_drawBuffer.fill(0); |
565 for (int pixel = 0; pixel < 256; ++pixel) { | 587 } |
566 //!!! todo: colour rotation (here 0) | 588 } |
567 m_drawBuffer.setColor | 589 |
568 ((unsigned char)pixel, | 590 |
569 m_params.colourScale.getColourForPixel(pixel, 0).rgb()); | |
570 } | |
571 } | |
572 | |
573 m_drawBuffer.fill(0); | |
574 } | |
575 | |
576 |