-
Notifications
You must be signed in to change notification settings - Fork 1
/
DemoUtils.cpp
54 lines (45 loc) · 1.16 KB
/
DemoUtils.cpp
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
/*
* DemoUtils.cpp
*
* Created on: 10/apr/2017
* Author: gabriele facciolo <facciolo@cmla.ens-cachan.fr>
*/
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include "DemoUtils.hpp"
extern "C" {
#include "iio.h"
}
using std::string;
using std::free;
using std::strcmp;
using da3d::Image;
namespace utils {
const char *pick_option(int *c, char **v, const char *o, const char *d) {
int id = d ? 1 : 0;
for (int i = 0; i < *c - id; i++) {
if (v[i][0] == '-' && 0 == strcmp(v[i] + 1, o)) {
char *r = v[i + id] + 1 - id;
for (int j = i; j < *c - id; j++)
v[j] = v[j + id + 1];
*c -= id + 1;
return r;
}
}
return d;
}
Image read_image(const string &filename) {
int w, h, c;
float *data = iio_read_image_float_vec(filename.c_str(), &w, &h, &c);
Image im(data, h, w, c);
free(data);
return im;
}
void save_image(const Image &image, const string &filename) {
iio_save_image_float_vec(const_cast<char *>(filename.c_str()),
const_cast<float *>(image.data()),
image.columns(), image.rows(), image.channels());
}
} // namespace utils