1
1
#include < iostream>
2
2
#include " Vid2Ascii.h"
3
3
#include < windows.h>
4
+ #include < cmath>
4
5
5
6
#define NOMINMAX
6
7
#define WIN32_LEAN_AND_MEAN
@@ -14,19 +15,42 @@ void Vid2Ascii::setCursorPosition(int x, int y)
14
15
15
16
void Vid2Ascii::progressBar (int idx, int total_frames)
16
17
{
17
- float barWidth = 40 ;
18
- float progress = idx * 1.0 / total_frames;
19
- float pos = barWidth * progress;
18
+ /*
19
+ [#] - Current
20
+ [=] - Processed
21
+ [ ] - Unprocessed
22
+ */
23
+ int num_ths;
24
+ (use_n_threads == 0 ) ? num_ths = 1 : num_ths = use_n_threads;
25
+
26
+ float max_frames = total_frames / num_ths;
20
27
21
- std::cout << " [" << (int )(idx * 100 ) / total_frames << " %]" ;
28
+ int barWidth = 40 ;
29
+ float sub_section = barWidth / num_ths;
22
30
23
31
std::string bar;
24
- bar += " [" ;
32
+ for (int i = 0 ; i < num_ths; i++) {
33
+ float processed_frames = (frames_processed[i] * 1.0 / max_frames) * sub_section;
34
+ processed_frames = round (processed_frames);
35
+ float unprocessed_frames = ((max_frames - frames_processed[i]) * 1.0 / max_frames) * sub_section;
36
+ unprocessed_frames = round (unprocessed_frames);
37
+
38
+ std::string processed (processed_frames, ' =' );
39
+ std::string unprocessed (unprocessed_frames, ' ' );
40
+
41
+ bar += processed;
42
+ bar += unprocessed;
43
+ }
44
+
45
+ float progress = idx * 1.0 / total_frames;
46
+ int pos = barWidth * progress;
25
47
for (int i = 0 ; i < barWidth; i++) {
26
- (i <= pos ? bar += " #" : bar += " =" );
48
+ if (i <= pos)
49
+ bar[i] = ' #' ;
27
50
}
28
- bar += " ]" ;
29
- std::cout << bar << " " << idx << " /" << total_frames << " " ;
51
+ bar = ' [' + std::to_string ((int )(idx * 100 ) / total_frames) + " %][" + bar + " ] " ;
52
+ bar += std::to_string (idx) + ' /' + std::to_string (total_frames) + " " ;
53
+ std::cout << bar;
30
54
}
31
55
32
56
void Vid2Ascii::display_adjustedOutputSize (int ascii_height, int ascii_width)
@@ -41,7 +65,7 @@ void Vid2Ascii::display_adjustedOutputSize(int ascii_height, int ascii_width)
41
65
}
42
66
}
43
67
44
- void Vid2Ascii::adjustOutputSize (float _resize_ratio, float _cell_height, float _cell_width)
68
+ void Vid2Ascii::adjustOutput (float _resize_ratio, float _cell_height, float _cell_width, unsigned _use_n_threads )
45
69
{
46
70
system (" CLS" );
47
71
output_vid.resize_ratio = _resize_ratio;
@@ -55,13 +79,15 @@ void Vid2Ascii::adjustOutputSize(float _resize_ratio, float _cell_height, float
55
79
output_vid.ascii_height = output_vid.height / _cell_height;
56
80
output_vid.ascii_width = output_vid.width / _cell_width;
57
81
82
+ use_n_threads = _use_n_threads;
83
+
58
84
int ascii_height = output_vid.ascii_height ;
59
85
int ascii_width = output_vid.ascii_width ;
60
86
display_adjustedOutputSize (ascii_height, ascii_width);
61
87
62
88
setCursorPosition (0 , ascii_height + 1 );
63
89
char res;
64
- std::cout << " Resize output size ? y/n -> " ;
90
+ std::cout << " Resize output? y/n -> " ;
65
91
std::cin >> res;
66
92
res = std::tolower (res);
67
93
@@ -78,6 +104,22 @@ void Vid2Ascii::adjustOutputSize(float _resize_ratio, float _cell_height, float
78
104
std::cout << " New cell height: " ;
79
105
std::cin >> _cell_height;
80
106
81
- adjustOutputSize (_resize_ratio, _cell_height, _cell_width);
107
+ if (max_threads != 0 ) {
108
+ std::cout << " ---" << std::endl;
109
+ std::cout << " Current number of threads used: " << _use_n_threads << std::endl;
110
+ std::cout << " Max number of threads supported by your hardware: " << max_threads << std::endl;
111
+ std::cout << " Recommended number of threads to use: 1" << std::endl;
112
+ std::cout << " Use: " ;
113
+ unsigned int num_ths;
114
+ std::cin >> num_ths;
115
+ if (num_ths > max_threads) {
116
+ std::cout << " Cannot have " << num_ths << " threads" << std::endl;
117
+ }
118
+ else {
119
+ _use_n_threads = num_ths;
120
+ }
121
+ std::cout << " ---" << std::endl;
122
+ }
123
+ adjustOutput (_resize_ratio, _cell_height, _cell_width, _use_n_threads);
82
124
}
83
125
}
0 commit comments