# HG changeset patch # User Chris Cannam # Date 1457094162 0 # Node ID 19bb1744518eb4f4c679c536c4d2ec4b54d1abbf # Parent 44726e08859030892e97c3d1debfaf9ab0096979 Fix confusion between model columns and painted columns, and document the difference diff -r 44726e088590 -r 19bb1744518e layer/Colour3DPlotLayer.cpp --- a/layer/Colour3DPlotLayer.cpp Tue Feb 02 10:31:04 2016 +0000 +++ b/layer/Colour3DPlotLayer.cpp Fri Mar 04 12:22:42 2016 +0000 @@ -966,25 +966,27 @@ } void -Colour3DPlotLayer::fillCache(int firstBin, int lastBin) const +Colour3DPlotLayer::fillCache(int firstColumn, int lastColumn) const { + // This call requests a (perhaps partial) fill of the cache + // between model columns firstColumn and lastColumn inclusive. + // The cache itself always has size sufficient to contain the + // whole model, but its validity may be less, depending on which + // regions have been requested via calls to this function. Note + // that firstColumn and lastColumn are *model* column numbers. If + // the model starts at a frame > 0, a firstColumn of zero still + // corresponds to the first column in the model, not the first + // column on the resulting rendered layer. + Profiler profiler("Colour3DPlotLayer::fillCache", true); - sv_frame_t modelStart = m_model->getStartFrame(); - sv_frame_t modelEnd = m_model->getEndFrame(); - int modelResolution = m_model->getResolution(); - - int modelStartBin = int(modelStart / modelResolution); - int modelEndBin = int(modelEnd / modelResolution); + int cacheWidth = m_model->getWidth(); + int cacheHeight = m_model->getHeight(); #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT - cerr << "Colour3DPlotLayer::fillCache: range " << firstBin << " -> " << lastBin << " of model range " << modelStartBin << " -> " << modelEndBin << " (model resolution " << modelResolution << ")" << endl; + cerr << "Colour3DPlotLayer::fillCache: range " << firstColumn << " -> " << lastColumn << " (cache size will be " << cacheWidth << " x " << cacheHeight << ")" << endl; #endif - int cacheWidth = modelEndBin - modelStartBin + 1; - if (lastBin > modelEndBin) cacheWidth = lastBin - modelStartBin + 1; - int cacheHeight = m_model->getHeight(); - if (m_cache && m_cache->height() != cacheHeight) { // height has changed: delete everything rather than resizing #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT @@ -1018,8 +1020,7 @@ #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT cerr << "Colour3DPlotLayer::fillCache: Have no cache, making one" << endl; #endif - m_cache = new QImage - (cacheWidth, cacheHeight, QImage::Format_Indexed8); + m_cache = new QImage(cacheWidth, cacheHeight, QImage::Format_Indexed8); m_cache->setColorCount(256); m_cache->fill(0); if (!m_normalizeVisibleArea) { @@ -1041,20 +1042,21 @@ << " peaks cache size = " << m_peaksCache->width() << "x" << m_peaksCache->height() << endl; #endif - if (m_cacheValidStart <= firstBin && m_cacheValidEnd >= lastBin) { + if (m_cacheValidStart <= firstColumn && m_cacheValidEnd >= lastColumn) { #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT cerr << "Cache is valid in this region already" << endl; #endif return; } - int fillStart = firstBin; - int fillEnd = lastBin; + int fillStart = firstColumn; + int fillEnd = lastColumn; - if (fillStart < modelStartBin) fillStart = modelStartBin; - if (fillStart > modelEndBin) fillStart = modelEndBin; - if (fillEnd < modelStartBin) fillEnd = modelStartBin; - if (fillEnd > modelEndBin) fillEnd = modelEndBin; + if (fillStart >= cacheWidth) fillStart = cacheWidth-1; + if (fillStart < 0) fillStart = 0; + if (fillEnd >= cacheWidth) fillEnd = cacheWidth-1; + if (fillEnd < 0) fillEnd = 0; + if (fillEnd < fillStart) fillEnd = fillStart; bool normalizeVisible = (m_normalizeVisibleArea && !m_normalizeColumns);