annotate base/ResizeableBitmap.h @ 110:c1188c5a991d

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