-
Notifications
You must be signed in to change notification settings - Fork 9
/
demoutils.cpp
50 lines (41 loc) · 1.08 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
//
// Created by Gabriele Facciolo on 10/04/17.
//
#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;
namespace imgutils {
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_split(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_split(const_cast<char *>(filename.c_str()),
const_cast<float *>(image.data()),
image.columns(), image.rows(), image.channels());
}
} // namespace imgutils