-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgress.h
More file actions
86 lines (78 loc) · 1.99 KB
/
Progress.h
File metadata and controls
86 lines (78 loc) · 1.99 KB
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
/*
* Progress.h
* Morph
*
* Created by Christian Brunschen on 27/11/2011.
* Copyright 2011 Christian Brunschen. All rights reserved.
*
*/
#ifndef __Progress_h__
#define __Progress_h__
#include <iostream>
#include <iomanip>
#include "Primitives.h"
#include "Bitmap.h"
#include "ColorImage.h"
using namespace std;
using namespace Primitives;
using namespace Images;
namespace Progress {
#if 0
}
#endif
class Stepper {
int step_;
string prefix_;
string pen_;
public:
Stepper(const string &prefix, const string &pen = "no pen", int step = 1) : step_(step), prefix_(prefix), pen_(pen) { }
void setPen(const char *s) { pen_ = s; }
void setPen(const string &s) { pen_ = s; }
void clearPen() { pen_ = "no_pen"; }
const string &pen() { return pen_; }
void clearStep() { step_ = 1; }
int step() { return step_; }
const string makeName(const char *s, const char *pen = NULL) {
ostringstream os;
os << prefix_ << "_";
os << setw(3) << setfill('0') << step_++ << "_";
if (pen) {
os << pen << "_";
} else {
os << pen_ << "_";
}
os << s;
os << flush;
return os.str();
}
};
class Approximator {
ColorImage<uint8_t> approximation_;
double cFraction, mFraction, yFraction;
public:
Approximator(int w, int h) : approximation_(w, h, true) { }
template<typename C> void setPenColor(const PenColor<C> &color) {
cFraction = color.cFraction();
mFraction = color.mFraction();
yFraction = color.yFraction();
}
void addToApproximation(shared_ptr<Bitmap> covered) {
for (int y = 0; y < covered->height(); y++) {
for (int x = 0; x < covered->width(); x++) {
if (covered->at(x, y)) {
RGBPixel<uint8_t> &p = approximation_.at(x, y);
p.rFraction() -= cFraction;
p.gFraction() -= mFraction;
p.bFraction() -= yFraction;
// approximation_.at(x, y) = p;
}
}
}
}
ColorImage<uint8_t> &approximation() { return approximation_; }
};
#if 0
{
#endif
}
#endif // __Progress_h__