comparison layer/SpectrogramLayer.cpp @ 479:0033dbfb92e3

* smooth x-scaling for images in spectrogram -- needs an overlap to avoid discontinuity
author Chris Cannam
date Tue, 03 Feb 2009 12:55:09 +0000
parents 0990b95140e3
children 567b94e627b8
comparison
equal deleted inserted replaced
478:0990b95140e3 479:0033dbfb92e3
1803 bool recreateWholeImageCache = true; 1803 bool recreateWholeImageCache = true;
1804 1804
1805 x0 = rect.left(); 1805 x0 = rect.left();
1806 x1 = rect.right() + 1; 1806 x1 = rect.right() + 1;
1807 1807
1808 float xPixelRatio = float(fft->getResolution()) / float(zoomLevel);
1809 std::cerr << "xPixelRatio = " << xPixelRatio << std::endl;
1810 if (xPixelRatio < 1.f) xPixelRatio = 1.f;
1811
1808 if (cache.validArea.width() > 0) { 1812 if (cache.validArea.width() > 0) {
1809 1813
1810 if (int(cache.zoomLevel) == zoomLevel && 1814 if (int(cache.zoomLevel) == zoomLevel &&
1811 cache.image.width() == v->width() && 1815 cache.image.width() == v->width() &&
1812 cache.image.height() == v->height()) { 1816 cache.image.height() == v->height()) {
1819 #ifdef DEBUG_SPECTROGRAM_REPAINT 1823 #ifdef DEBUG_SPECTROGRAM_REPAINT
1820 std::cerr << "SpectrogramLayer: image cache good" << std::endl; 1824 std::cerr << "SpectrogramLayer: image cache good" << std::endl;
1821 #endif 1825 #endif
1822 1826
1823 paint.drawImage(rect, cache.image, rect); 1827 paint.drawImage(rect, cache.image, rect);
1828 //!!!
1829 // paint.drawImage(v->rect(), cache.image,
1830 // QRect(QPoint(0, 0), cache.image.size()));
1831
1824 illuminateLocalFeatures(v, paint); 1832 illuminateLocalFeatures(v, paint);
1825 return; 1833 return;
1826 1834
1827 } else { 1835 } else {
1828 1836
1895 std::cerr << "valid area now " 1903 std::cerr << "valid area now "
1896 << px << "," << cache.validArea.y() 1904 << px << "," << cache.validArea.y()
1897 << " " << pw << "x" << cache.validArea.height() 1905 << " " << pw << "x" << cache.validArea.height()
1898 << std::endl; 1906 << std::endl;
1899 #endif 1907 #endif
1900 1908 /*
1901 paint.drawImage(rect & cache.validArea, 1909 paint.drawImage(rect & cache.validArea,
1902 cache.image, 1910 cache.image,
1903 rect & cache.validArea); 1911 rect & cache.validArea);
1912 */
1904 1913
1905 } else if (dx != 0) { 1914 } else if (dx != 0) {
1906 1915
1907 // we scrolled too far to be of use 1916 // we scrolled too far to be of use
1908 1917
2068 2077
2069 #ifdef DEBUG_SPECTROGRAM_REPAINT 2078 #ifdef DEBUG_SPECTROGRAM_REPAINT
2070 std::cerr << "x0 " << x0 << ", x1 " << x1 << ", w " << w << ", h " << h << std::endl; 2079 std::cerr << "x0 " << x0 << ", x1 " << x1 << ", w " << w << ", h " << h << std::endl;
2071 #endif 2080 #endif
2072 2081
2073 if (m_drawBuffer.width() < w || m_drawBuffer.height() < h) { 2082 if (m_drawBuffer.width() < w / xPixelRatio + 1 ||
2074 m_drawBuffer = QImage(w, h, QImage::Format_Indexed8); 2083 m_drawBuffer.height() < h) {
2084 m_drawBuffer = QImage(w / xPixelRatio + 1, h, QImage::Format_Indexed8);
2075 m_drawBuffer.setNumColors(256); 2085 m_drawBuffer.setNumColors(256);
2076 for (int pixel = 0; pixel < 256; ++pixel) { 2086 for (int pixel = 0; pixel < 256; ++pixel) {
2077 m_drawBuffer.setColor(pixel, m_palette.getColour(pixel).rgb()); 2087 m_drawBuffer.setColor(pixel, m_palette.getColour(pixel).rgb());
2078 } 2088 }
2079 } 2089 }
2157 size_t pixels = 0; 2167 size_t pixels = 0;
2158 #endif 2168 #endif
2159 2169
2160 Profiler outerprof("SpectrogramLayer::paint: all cols"); 2170 Profiler outerprof("SpectrogramLayer::paint: all cols");
2161 2171
2162 for (int x = 0; x < w; ++x) { 2172 for (int x = 0; x < w / xPixelRatio; ++x) {
2163 2173
2164 Profiler innerprof("SpectrogramLayer::paint: 1 pixel column"); 2174 Profiler innerprof("SpectrogramLayer::paint: 1 pixel column");
2165 2175
2166 runOutOfData = !paintColumnValues(v, fft, x0, x, 2176 runOutOfData = !paintColumnValues(v, fft, x0, x,
2167 minbin, maxbin, 2177 minbin, maxbin,
2168 displayMinFreq, displayMaxFreq, 2178 displayMinFreq, displayMaxFreq,
2179 xPixelRatio,
2169 h, yforbin); 2180 h, yforbin);
2170 2181
2171 if (runOutOfData) { 2182 if (runOutOfData) {
2172 #ifdef DEBUG_SPECTROGRAM_REPAINT 2183 #ifdef DEBUG_SPECTROGRAM_REPAINT
2173 std::cerr << "Run out of data -- dropping out of loop" << std::endl; 2184 std::cerr << "Run out of data -- dropping out of loop" << std::endl;
2209 << " from draw buffer at " << 0 << "," << 0 2220 << " from draw buffer at " << 0 << "," << 0
2210 << " to cache at " << x0 << "," << 0 << std::endl; 2221 << " to cache at " << x0 << "," << 0 << std::endl;
2211 #endif 2222 #endif
2212 2223
2213 QPainter cachePainter(&cache.image); 2224 QPainter cachePainter(&cache.image);
2214 cachePainter.drawImage(x0, 0, m_drawBuffer, 0, 0, w, h); 2225 cachePainter.setRenderHint(QPainter::SmoothPixmapTransform, true);
2226 cachePainter.drawImage(QRect(x0, 0, w, h),
2227 m_drawBuffer,
2228 QRect(0, 0, w / xPixelRatio, h));
2215 cachePainter.end(); 2229 cachePainter.end();
2216 } 2230 }
2217 2231
2218 QRect pr = rect & cache.validArea; 2232 QRect pr = rect & cache.validArea;
2219 2233
2222 << " from cache at " << pr.x() << "," << pr.y() 2236 << " from cache at " << pr.x() << "," << pr.y()
2223 << " to window" << std::endl; 2237 << " to window" << std::endl;
2224 #endif 2238 #endif
2225 2239
2226 paint.drawImage(pr.x(), pr.y(), cache.image, 2240 paint.drawImage(pr.x(), pr.y(), cache.image,
2227 pr.x(), pr.y(), pr.width(), pr.height()); 2241 pr.x(), pr.y(), pr.width(), pr.height());
2242 //!!!
2243 // paint.drawImage(v->rect(), cache.image,
2244 // QRect(QPoint(0, 0), cache.image.size()));
2228 2245
2229 cache.startFrame = startFrame; 2246 cache.startFrame = startFrame;
2230 cache.zoomLevel = zoomLevel; 2247 cache.zoomLevel = zoomLevel;
2231 2248
2232 if (!m_synchronous) { 2249 if (!m_synchronous) {
2288 int x, 2305 int x,
2289 int minbin, 2306 int minbin,
2290 int maxbin, 2307 int maxbin,
2291 float displayMinFreq, 2308 float displayMinFreq,
2292 float displayMaxFreq, 2309 float displayMaxFreq,
2310 float xPixelRatio,
2293 const int h, 2311 const int h,
2294 const float *yforbin) const 2312 const float *yforbin) const
2295 { 2313 {
2296 float ymag[h]; 2314 float ymag[h];
2297 float ydiv[h]; 2315 float ydiv[h];
2315 ydiv[y] = 0.f; 2333 ydiv[y] = 0.f;
2316 } 2334 }
2317 2335
2318 float s0 = 0, s1 = 0; 2336 float s0 = 0, s1 = 0;
2319 2337
2320 if (!getXBinRange(v, x0 + x, s0, s1)) { 2338 if (!getXBinRange(v, x0 + x * xPixelRatio, s0, s1)) {
2321 #ifdef DEBUG_SPECTROGRAM_REPAINT 2339 #ifdef DEBUG_SPECTROGRAM_REPAINT
2322 std::cerr << "Out of range at " << x0 + x << std::endl; 2340 std::cerr << "Out of range at " << x0 + x << std::endl;
2323 #endif 2341 #endif
2324 assert(x <= m_drawBuffer.width()); 2342 assert(x <= m_drawBuffer.width());
2325 return true; 2343 return true;