Mercurial > hg > svcore
comparison base/ResizeableBitmap.h @ 109:61a2ac1241b3
* Make a single base Thread class for RT and non-RT threads
* Pull ResizeableBitmap out from the MatrixFile's ColumnBitmap
* Reorder SpectrogramLayer::paint somewhat so as to improve cache hit ratio
in the FFT file cache
author | Chris Cannam |
---|---|
date | Mon, 08 May 2006 16:44:47 +0000 |
parents | |
children | 7648e8502822 |
comparison
equal
deleted
inserted
replaced
108:0c19e50bad7c | 109:61a2ac1241b3 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006 Chris Cannam. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #ifndef _RESIZEABLE_BITMAP_H_ | |
17 #define _RESIZEABLE_BITMAP_H_ | |
18 | |
19 #include <vector> | |
20 #include <stdint.h> | |
21 | |
22 class ResizeableBitmap { | |
23 | |
24 public: | |
25 ResizeableBitmap() : m_bits(0) { | |
26 } | |
27 ResizeableBitmap(size_t size) : m_bits(new std::vector<uint8_t>) { | |
28 m_bits->assign(size / 8 + 1, 0); | |
29 } | |
30 ResizeableBitmap(const ResizeableBitmap &b) { | |
31 m_bits = new std::vector<uint8_t>(*b.m_bits); | |
32 } | |
33 ResizeableBitmap &operator=(const ResizeableBitmap &b) { | |
34 if (&b != this) return *this; | |
35 delete m_bits; | |
36 m_bits = new std::vector<uint8_t>(*b.m_bits); | |
37 return *this; | |
38 } | |
39 ~ResizeableBitmap() { | |
40 delete m_bits; | |
41 } | |
42 | |
43 void resize(size_t bits) { // losing all data | |
44 if (!m_bits || bits < m_bits->size()) { | |
45 delete m_bits; | |
46 m_bits = new std::vector<uint8_t>; | |
47 } | |
48 m_bits->assign(bits / 8, 0); | |
49 } | |
50 | |
51 bool get(size_t column) const { | |
52 return ((*m_bits)[column / 8]) & (1u << (column % 8)); | |
53 } | |
54 | |
55 void set(size_t column, bool state) { | |
56 if (state) { | |
57 ((*m_bits)[column / 8]) |= (uint8_t(1) << (column % 8)); | |
58 } else { | |
59 ((*m_bits)[column / 8]) &= ~(uint8_t(1) << (column % 8)); | |
60 } | |
61 } | |
62 | |
63 private: | |
64 std::vector<uint8_t> *m_bits; | |
65 }; | |
66 | |
67 | |
68 #endif | |
69 |