-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.h
81 lines (62 loc) · 2.02 KB
/
image.h
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
#pragma once
#include <stdio.h>
#include <inttypes.h>
#include "common.h"
#ifdef BOOST
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/array.hpp>
#include <boost/serialization/split_member.hpp>
#include <fstream>
using namespace boost::archive;
#endif
class Image {
public:
uint8_t * rgb_;
int32_t x_, y_, n_;
int32_t id_;
Image(int32_t x, int32_t y, uint8_t *rgb);
Image() = default;
#ifdef BOOST
friend class boost::serialization::access;
#endif
void interlaced(uint8_t *rgb );
static void write_to_file(uint8_t *rgb, char * filename, int x, int y, int n);
inline size_t imageSize(void) const {
#ifdef DEBUG
if (x_ * y_ * n_== 0)
printf("ERROR ALLOCATING NO MEMORY\n");
#endif
return (n_*x_*y_ * sizeof(uint8_t));
}
inline void getPixel(int32_t *x, int32_t *y, PixelP *r) {
r->r = &rgb_[(0*(y_*x_) + *x*(y_) + *y)];
r->g = &rgb_[(1*(y_*x_) + *x*(y_) + *y)];
r->b = &rgb_[(2*(y_*x_) + *x*(y_) + *y)];
}
inline void getPixelFromVector(Vector2 *v, PixelP *r) {
r->r = &rgb_[(0*(y_*x_) + v->x*(y_) + v->y)]; r->g = &rgb_[(1*(y_*x_) + v->x*(y_) + v->y)];
r->b = &rgb_[(2*(y_*x_) + v->x*(y_) + v->y)];
}
private:
#ifdef BOOST
template <typename Archive>
void load(Archive &ar, const unsigned int version) {
ar & id_;
ar & x_;
ar & y_;
ar & n_;
rgb_ =(unsigned char *) malloc(imageSize());
ar & boost::serialization::make_array(rgb_, (size_t)imageSize());
}
template <typename Archive>
void save (Archive &ar, const unsigned int version) const {
ar & id_;
ar & x_;
ar & y_;
ar & n_;
ar & boost::serialization::make_array(rgb_, imageSize());
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
#endif
};