comparison layer/SpectrogramLayer.h @ 31:fc802f7b112e

* Change SpectrogramLayer to use its own cache type instead of a QImage * Some gcc-4.0 compile fixes
author Chris Cannam
date Tue, 14 Feb 2006 17:43:14 +0000
parents ea6fe8cfcdd5
children 651e4e868bcc
comparison
equal deleted inserted replaced
30:ea6fe8cfcdd5 31:fc802f7b112e
32 * SpectrogramLayer represents waveform data (obtained from a 32 * SpectrogramLayer represents waveform data (obtained from a
33 * DenseTimeValueModel) in spectrogram form. 33 * DenseTimeValueModel) in spectrogram form.
34 */ 34 */
35 35
36 class SpectrogramLayer : public Layer, 36 class SpectrogramLayer : public Layer,
37 public PowerOfSqrtTwoZoomConstraint 37 public PowerOfSqrtTwoZoomConstraint
38 { 38 {
39 Q_OBJECT 39 Q_OBJECT
40 40
41 public: 41 public:
42 enum Configuration { FullRangeDb, MelodicRange }; 42 enum Configuration { FullRangeDb, MelodicRange };
160 size_t m_maxFrequency; 160 size_t m_maxFrequency;
161 ColourScale m_colourScale; 161 ColourScale m_colourScale;
162 ColourScheme m_colourScheme; 162 ColourScheme m_colourScheme;
163 FrequencyScale m_frequencyScale; 163 FrequencyScale m_frequencyScale;
164 164
165 // A QImage would do just as well here, and we originally used
166 // one: the problem is that we want to munlock() the memory it
167 // uses, and it's much easier to do that if we control it. This
168 // cache is hardwired to an effective 8-bit colour mapped layout.
169 class Cache {
170 public:
171 Cache(size_t width, size_t height);
172 ~Cache();
173
174 size_t getWidth() const;
175 size_t getHeight() const;
176
177 unsigned char getValueAt(size_t x, size_t y) const;
178 void setValueAt(size_t x, size_t y, unsigned char value);
179
180 QColor getColour(unsigned char index) const;
181 void setColour(unsigned char index, QColor colour);
182
183 void fill(unsigned char value);
184
185 protected:
186 size_t m_width;
187 size_t m_height;
188 unsigned char *m_values;
189 QColor m_colours[256];
190 };
191
192 Cache *m_cache;
193 bool m_cacheInvalid;
194
165 class CacheFillThread : public QThread 195 class CacheFillThread : public QThread
166 { 196 {
167 public: 197 public:
168 CacheFillThread(SpectrogramLayer &layer) : 198 CacheFillThread(SpectrogramLayer &layer) :
169 m_layer(layer), m_fillExtent(0) { } 199 m_layer(layer), m_fillExtent(0) { }
177 size_t m_fillExtent; 207 size_t m_fillExtent;
178 size_t m_fillCompletion; 208 size_t m_fillCompletion;
179 }; 209 };
180 210
181 void fillCache(); 211 void fillCache();
182
183 QImage *m_cache;
184 bool m_cacheInvalid;
185 212
186 mutable QPixmap *m_pixmapCache; 213 mutable QPixmap *m_pixmapCache;
187 mutable bool m_pixmapCacheInvalid; 214 mutable bool m_pixmapCacheInvalid;
188 mutable long m_pixmapCacheStartFrame; 215 mutable long m_pixmapCacheStartFrame;
189 mutable size_t m_pixmapCacheZoomLevel; 216 mutable size_t m_pixmapCacheZoomLevel;