comparison layer/SpectrogramLayer.cpp @ 337:813170c57b13

* Spectrogram paint-from-cache fix
author Chris Cannam
date Thu, 29 Nov 2007 10:43:54 +0000
parents 2f83b6e3b8ca
children e1a9e478b7f2
comparison
equal deleted inserted replaced
336:4a542ba875c2 337:813170c57b13
1850 std::cerr << "(cache height " << cache.pixmap.height() 1850 std::cerr << "(cache height " << cache.pixmap.height()
1851 << " != " << v->height(); 1851 << " != " << v->height();
1852 } 1852 }
1853 #endif 1853 #endif
1854 cache.validArea = QRect(); 1854 cache.validArea = QRect();
1855 // recreateWholePixmapCache = true;
1855 } 1856 }
1856 } 1857 }
1857 1858
1858 if (updateViewMagnitudes(v)) { 1859 if (updateViewMagnitudes(v)) {
1859 #ifdef DEBUG_SPECTROGRAM_REPAINT 1860 #ifdef DEBUG_SPECTROGRAM_REPAINT
1945 } 1946 }
1946 1947
1947 cache.validArea = QRect 1948 cache.validArea = QRect
1948 (std::min(vx0, x0), cache.validArea.y(), 1949 (std::min(vx0, x0), cache.validArea.y(),
1949 std::max(vx1 - std::min(vx0, x0), 1950 std::max(vx1 - std::min(vx0, x0),
1950 x1 - std::min(vx0, x0)), 1951 x1 - std::min(vx0, x0)),
1951 cache.validArea.height()); 1952 cache.validArea.height());
1953
1954 #ifdef DEBUG_SPECTROGRAM_REPAINT
1955 std::cerr << "Valid area becomes " << cache.validArea.x()
1956 << ", " << cache.validArea.y() << ", "
1957 << cache.validArea.width() << "x"
1958 << cache.validArea.height() << std::endl;
1959 #endif
1952 1960
1953 } else { 1961 } else {
1954 if (x1 > x0 + paintBlockWidth) { 1962 if (x1 > x0 + paintBlockWidth) {
1955 int sfx = x1; 1963 int sfx = x1;
1956 if (startFrame < 0) sfx = v->getXForFrame(0); 1964 if (startFrame < 0) sfx = v->getXForFrame(0);
1961 int mid = (x1 + x0) / 2; 1969 int mid = (x1 + x0) / 2;
1962 x0 = mid - paintBlockWidth/2; 1970 x0 = mid - paintBlockWidth/2;
1963 x1 = x0 + paintBlockWidth; 1971 x1 = x0 + paintBlockWidth;
1964 } 1972 }
1965 } 1973 }
1974 #ifdef DEBUG_SPECTROGRAM_REPAINT
1975 std::cerr << "Valid area becomes " << x0 << ", 0, " << (x1-x0)
1976 << "x" << h << std::endl;
1977 #endif
1966 cache.validArea = QRect(x0, 0, x1 - x0, h); 1978 cache.validArea = QRect(x0, 0, x1 - x0, h);
1967 } 1979 }
1968 1980
1969 int w = x1 - x0; 1981 int w = x1 - x0;
1970 1982
2082 } 2094 }
2083 2095
2084 float s0 = 0, s1 = 0; 2096 float s0 = 0, s1 = 0;
2085 2097
2086 if (!getXBinRange(v, x0 + x, s0, s1)) { 2098 if (!getXBinRange(v, x0 + x, s0, s1)) {
2099 #ifdef DEBUG_SPECTROGRAM_REPAINT
2100 std::cerr << "Out of range at " << x0 + x << std::endl;
2101 #endif
2087 assert(x <= m_drawBuffer.width()); 2102 assert(x <= m_drawBuffer.width());
2088 continue; 2103 continue;
2089 } 2104 }
2090 2105
2091 int s0i = int(s0 + 0.001); 2106 int s0i = int(s0 + 0.001);
2286 #endif 2301 #endif
2287 } 2302 }
2288 2303
2289 Profiler profiler2("SpectrogramLayer::paint: draw image", true); 2304 Profiler profiler2("SpectrogramLayer::paint: draw image", true);
2290 2305
2291 if (w > 0) {
2292 #ifdef DEBUG_SPECTROGRAM_REPAINT
2293 std::cerr << "Painting " << w << "x" << rect.height()
2294 << " from draw buffer at " << 0 << "," << rect.y()
2295 << " to window at " << x0 << "," << rect.y() << std::endl;
2296 #endif
2297
2298 paint.drawImage(x0, rect.y(), m_drawBuffer,
2299 0, rect.y(), w, rect.height());
2300 }
2301
2302 if (recreateWholePixmapCache) { 2306 if (recreateWholePixmapCache) {
2303 std::cerr << "Recreating pixmap cache: width = " << v->width() 2307 std::cerr << "Recreating pixmap cache: width = " << v->width()
2304 << ", height = " << h << std::endl; 2308 << ", height = " << h << std::endl;
2305 cache.pixmap = QPixmap(v->width(), h); 2309 cache.pixmap = QPixmap(v->width(), h);
2306 } 2310 }
2314 2318
2315 QPainter cachePainter(&cache.pixmap); 2319 QPainter cachePainter(&cache.pixmap);
2316 cachePainter.drawImage(x0, 0, m_drawBuffer, 0, 0, w, h); 2320 cachePainter.drawImage(x0, 0, m_drawBuffer, 0, 0, w, h);
2317 cachePainter.end(); 2321 cachePainter.end();
2318 } 2322 }
2323
2324 QRect pr = rect & cache.validArea;
2325
2326 #ifdef DEBUG_SPECTROGRAM_REPAINT
2327 std::cerr << "Painting " << pr.width() << "x" << pr.height()
2328 << " from cache at " << pr.x() << "," << pr.y()
2329 << " to window" << std::endl;
2330 #endif
2331
2332 paint.drawPixmap(pr.x(), pr.y(), cache.pixmap,
2333 pr.x(), pr.y(), pr.width(), pr.height());
2319 2334
2320 cache.startFrame = startFrame; 2335 cache.startFrame = startFrame;
2321 cache.zoomLevel = zoomLevel; 2336 cache.zoomLevel = zoomLevel;
2322 2337
2323 if (!m_normalizeVisibleArea || !overallMagChanged) { 2338 if (!m_normalizeVisibleArea || !overallMagChanged) {