forked from jart/hiptext
-
Notifications
You must be signed in to change notification settings - Fork 2
/
charquantizer.h
45 lines (36 loc) · 961 Bytes
/
charquantizer.h
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
// hiptext - Image to Text Converter
// By Justine Tunney
#ifndef HIPTEXT_CHARQUANTIZER_H_
#define HIPTEXT_CHARQUANTIZER_H_
#include <string>
#include <vector>
#include <glog/logging.h>
class CharQuantizer {
public:
CharQuantizer(const std::wstring& chars, int size) : map_(size) {
const int segment_size = size / chars.size() + 1;
for (int n = 0; n < size; ++n) {
map_[n] = chars[n / segment_size];
}
}
inline wchar_t Quantize(int color) const {
DCHECK_GE(color, 0);
DCHECK_LT(color, map_.size());
return map_[color];
}
CharQuantizer(const CharQuantizer& other) = delete;
void operator=(const CharQuantizer& other) = delete;
private:
std::vector<wchar_t> map_;
};
#endif // HIPTEXT_CHARQUANTIZER_H_
// For Emacs:
// Local Variables:
// mode:c++
// indent-tabs-mode:nil
// tab-width:2
// c-basic-offset:2
// c-file-style: nil
// End:
// For VIM:
// vim:set expandtab softtabstop=2 shiftwidth=2 tabstop=2: