blob: a2853211760c16b0a0849d13b4e19697ea5feac6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
// This code is in the public domain -- castanyo@yahoo.es
#pragma once
#ifndef NV_IMAGE_BITMAP_H
#define NV_IMAGE_BITMAP_H
#include "nvimage.h"
#include "nvcore/BitArray.h"
namespace nv
{
/// Bit map. This should probably be called BitImage.
class NVIMAGE_CLASS BitMap
{
public:
BitMap() : m_width(0), m_height(0) {}
BitMap(uint w, uint h) : m_width(w), m_height(h), m_bitArray(w*h) {}
uint width() const { return m_width; }
uint height() const { return m_height; }
void resize(uint w, uint h, bool initValue);
bool bitAt(uint x, uint y) const
{
nvDebugCheck(x < m_width && y < m_height);
return m_bitArray.bitAt(y * m_width + x);
}
bool bitAt(uint idx) const
{
return m_bitArray.bitAt(idx);
}
void setBitAt(uint x, uint y)
{
nvDebugCheck(x < m_width && y < m_height);
m_bitArray.setBitAt(y * m_width + x);
}
void setBitAt(uint idx)
{
m_bitArray.setBitAt(idx);
}
void clearBitAt(uint x, uint y)
{
nvDebugCheck(x < m_width && y < m_height);
m_bitArray.clearBitAt(y * m_width + x);
}
void clearBitAt(uint idx)
{
m_bitArray.clearBitAt(idx);
}
void clearAll()
{
m_bitArray.clearAll();
}
void setAll()
{
m_bitArray.setAll();
}
void toggleAll()
{
m_bitArray.toggleAll();
}
friend void swap(BitMap & a, BitMap & b)
{
nvCheck(a.m_width == b.m_width);
nvCheck(a.m_height == b.m_height);
swap(a.m_bitArray, b.m_bitArray);
}
private:
uint m_width;
uint m_height;
BitArray m_bitArray;
};
} // nv namespace
#endif // NV_IMAGE_BITMAP_H
|