-
Notifications
You must be signed in to change notification settings - Fork 20
/
img.h
61 lines (50 loc) · 1.86 KB
/
img.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
/* Copyright (C) 2015, Gabriele Facciolo <facciolo@cmla.ens-cachan.fr>,
* Carlo de Franchis <carlo.de-franchis@ens-cachan.fr>,
* Enric Meinhardt <enric.meinhardt@cmla.ens-cachan.fr>*/
#ifndef IMG_H_
#define IMG_H_
#include <vector>
#include <assert.h>
struct Img
{
std::vector<float > data;
union{
int sz[3];
struct{
union { int ncol; int nx; };
union { int nrow; int ny; };
int nch;
};
};
// int nx;
// int ny;
// int nch;
int npix;
Img(int nx, int ny, int nch=1);
Img(float *copydata, int nx, int ny, int nch=1);
inline Img() {nx=0;ny=0;nch=0;npix=0;}
inline float operator[](int i) const { assert(i>=0 && i < npix*nch); return data[i];}
inline float& operator[](int i) { assert(i>=0 && i < npix*nch); return data[i];}
inline float operator()(int i) const { assert(i>=0 && i < npix*nch); return data[i];}
inline float& operator()(int i) { assert(i>=0 && i < npix*nch); return data[i];}
inline float operator()(int x, int y, int c = 0) const { int i=x+y*nx+c*npix; assert(i>=0 && i < npix*nch); return data[i];}
inline float& operator()(int x, int y, int c = 0) { int i=x+y*nx+c*npix; assert(i>=0 && i < npix*nch); return data[i];}
inline float& val(int i, int j, int c) {
assert(i >= 0 && i < nx &&
j >= 0 && j < ny &&
c >= 0 && c < nch );
return data[i + j*nx + c*nx*ny];
}
//inline float val(int x, int y, int c) const { return data[x+y*nx+c*nx*ny];}
inline float val(int i, int j, int c) const {
assert(i >= 0 && i < nx &&
j >= 0 && j < ny &&
c >= 0 && c < nch );
return data[i + j*nx + c*nx*ny];
}
// private:
// Img(const Img&); // disable copy constructor
// void operator=(const Img&);
// Img& operator= (const Img&p);
};
#endif /* IMG_H_ */