-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.cpp
74 lines (63 loc) · 1.96 KB
/
image.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "image.hpp"
#ifndef IMG_NO_IIO
extern "C" {
#include "iio.h"
}
template <>
img_t<uint8_t> img_t<uint8_t>::load(const std::string& filename)
{
int w, h, d;
uint8_t* data = iio_read_image_uint8_vec(filename.c_str(), &w, &h, &d);
img_t<uint8_t> img(w, h, d, data);
free(data);
return img;
}
template <>
img_t<float> img_t<float>::load(const std::string& filename)
{
int w, h, d;
float* data = iio_read_image_float_vec(filename.c_str(), &w, &h, &d);
img_t<float> img(w, h, d, data);
free(data);
return img;
}
template <>
img_t<double> img_t<double>::load(const std::string& filename)
{
int w, h, d;
double* data = iio_read_image_double_vec(filename.c_str(), &w, &h, &d);
img_t<double> img(w, h, d, data);
free(data);
return img;
}
template <>
void img_t<uint8_t>::save(const std::string& filename) const
{
iio_write_image_uint8_vec(const_cast<char*>(filename.c_str()), const_cast<uint8_t*>(&data[0]), w, h, d);
}
template <>
void img_t<int>::save(const std::string& filename) const
{
iio_write_image_int_vec(const_cast<char*>(filename.c_str()), const_cast<int*>(&data[0]), w, h, d);
}
template <>
void img_t<float>::save(const std::string& filename) const
{
iio_write_image_float_vec(const_cast<char*>(filename.c_str()), const_cast<float*>(&data[0]), w, h, d);
}
template <>
void img_t<double>::save(const std::string& filename) const
{
iio_write_image_double_vec(const_cast<char*>(filename.c_str()), const_cast<double*>(&data[0]), w, h, d);
}
template <>
void img_t<std::complex<float>>::save(const std::string& filename) const
{
iio_write_image_float_vec(const_cast<char*>(filename.c_str()), const_cast<float*>(reinterpret_cast<const float*>(&data[0])), w, h, 2 * d);
}
template <>
void img_t<std::complex<double>>::save(const std::string& filename) const
{
iio_write_image_double_vec(const_cast<char*>(filename.c_str()), const_cast<double*>(reinterpret_cast<const double*>(&data[0])), w, h, 2 * d);
}
#endif