comparison layer/Colour3DPlotRenderer.cpp @ 1080:2e5945b87aca spectrogram-minor-refactor

Minor adjustments
author Chris Cannam
date Thu, 30 Jun 2016 16:28:32 +0100
parents 7ebfb61b1701
children cbc7c8675706
comparison
equal deleted inserted replaced
1079:7ebfb61b1701 1080:2e5945b87aca
45 if (!v) { 45 if (!v) {
46 throw std::logic_error("no LayerGeometryProvider provided"); 46 throw std::logic_error("no LayerGeometryProvider provided");
47 } 47 }
48 48
49 sv_frame_t startFrame = v->getStartFrame(); 49 sv_frame_t startFrame = v->getStartFrame();
50 int zoomLevel = v->getZoomLevel();
51 50
52 int x0 = v->getXForViewX(rect.x()); 51 int x0 = v->getXForViewX(rect.x());
53 int x1 = v->getXForViewX(rect.x() + rect.width()); 52 int x1 = v->getXForViewX(rect.x() + rect.width());
54 if (x0 < 0) x0 = 0; 53 if (x0 < 0) x0 = 0;
55 if (x1 > v->getPaintWidth()) x1 = v->getPaintWidth(); 54 if (x1 > v->getPaintWidth()) x1 = v->getPaintWidth();
124 // sub-regions of our target region in right-to-left order in 123 // sub-regions of our target region in right-to-left order in
125 // order to ensure contiguity 124 // order to ensure contiguity
126 rightToLeft = isLeftOfValidArea; 125 rightToLeft = isLeftOfValidArea;
127 } 126 }
128 127
129 int repaintWidth = x1 - x0; 128 renderToCache(x0, x1 - x0, rightToLeft, timeConstrained);
130
131 QRect rendered = renderToCache(x0, repaintWidth, timeConstrained);
132 129
133 QRect pr = rect & m_cache.getValidArea(); 130 QRect pr = rect & m_cache.getValidArea();
134 paint.drawImage(pr.x(), pr.y(), m_cache.getImage(), 131 paint.drawImage(pr.x(), pr.y(), m_cache.getImage(),
135 pr.x(), pr.y(), pr.width(), pr.height()); 132 pr.x(), pr.y(), pr.width(), pr.height());
136 133
161 //!!! fft model scaling? 158 //!!! fft model scaling?
162 159
163 //!!! should we own the Dense3DModelPeakCache here? or should it persist 160 //!!! should we own the Dense3DModelPeakCache here? or should it persist
164 } 161 }
165 162
166 QRect 163 void
167 Colour3DPlotRenderer::renderToCache(int x0, int repaintWidth, bool timeConstrained) 164 Colour3DPlotRenderer::renderToCache(int x0, int repaintWidth,
165 bool rightToLeft, bool timeConstrained)
168 { 166 {
169 // Draw to the draw buffer, and then scale-copy from there. 167 // Draw to the draw buffer, and then scale-copy from there.
170 168
171 DenseThreeDimensionalModel *model = m_sources.source; 169 DenseThreeDimensionalModel *model = m_sources.source;
172 if (!model || !model->isOK() || !model->isReady()) { 170 if (!model || !model->isOK() || !model->isReady()) {
239 237
240 bool usePeaksCache = false; 238 bool usePeaksCache = false;
241 int binsPerPeak = 1; 239 int binsPerPeak = 1;
242 240
243 if (bufferIsBinResolution) { 241 if (bufferIsBinResolution) {
242
244 for (int x = 0; x < drawWidth; ++x) { 243 for (int x = 0; x < drawWidth; ++x) {
245 binforx[x] = int(leftBoundaryFrame / binResolution) + x; 244 binforx[x] = int(leftBoundaryFrame / binResolution) + x;
246 } 245 }
246
247 // calculating boundaries later will be too fiddly for partial
248 // paints, and painting should be fast anyway when this is the
249 // case because it means we're well zoomed in
250 timeConstrained = false;
251
247 } else { 252 } else {
248 for (int x = 0; x < drawWidth; ++x) { 253 for (int x = 0; x < drawWidth; ++x) {
249 sv_frame_t f0 = v->getFrameForX(x); 254 sv_frame_t f0 = v->getFrameForX(x);
250 double s0 = double(f0 - model->getStartFrame()) / binResolution; 255 double s0 = double(f0 - model->getStartFrame()) / binResolution;
251 binforx[x] = int(s0 + 0.0001); 256 binforx[x] = int(s0 + 0.0001);
260 ColourScale::PhaseColourScale) { 265 ColourScale::PhaseColourScale) {
261 usePeaksCache = false; 266 usePeaksCache = false;
262 } 267 }
263 } 268 }
264 } 269 }
265 270 /*!!!
266 int attainedDrawWidth = drawWidth; 271 for (int y = 0; y < h; ++y) {
267 272 double q0 = 0, q1 = 0;
268 //!!! todo: all 273 if (!getSmoothedYBinRange(v, h-y-1, q0, q1)) {
269 274 binfory[y] = -1;
275 } else {
276 binfory[y] = q0;
277 }
278 }
279
280 int attainedWidth = renderDrawBuffer(v,
281 repaintWidth,
282 h,
283 binforx,
284 binfory,
285 usePeaksCache,
286 rightToLeft,
287 timeConstrained);
288 */
270 } 289 }
271 290
272 void 291 void
273 Colour3DPlotRenderer::clearDrawBuffer(int w, int h) 292 Colour3DPlotRenderer::clearDrawBuffer(int w, int h)
274 { 293 {