-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathImage.cc
More file actions
90 lines (77 loc) · 2.15 KB
/
Image.cc
File metadata and controls
90 lines (77 loc) · 2.15 KB
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
82
83
84
85
86
87
88
89
90
#include "Image.h"
#include <iostream>
namespace larcaffe {
Image::Image( int height, int width ) {
setSize( height, width );
}
Image::Image() {
}
Image::~Image() {
clear();
}
// // copy constructor
// Image::Image( Image& source ) {
// // deep copy
// setSize( source.height(), source.width() );
// for (int h=0; h<source.height(); h++) {
// for (int w=0; w<source.width(); w++) {
// setpixel( h, w, source.pixel(h,w) );
// }
// }
// }
// // assignment operator
// Image& Image::operator=( Image& source ) {
// // deep copy
// setSize( source.height(), source.width() );
// for (int h=0; h<source.height(); h++) {
// for (int w=0; w<source.width(); w++) {
// setpixel( h, w, source.pixel(h,w) );
// }
// }
// return *this;
// }
void Image::setSize( int height, int width ) {
clear();
fHeight = height;
fWidth = width;
alloc( fHeight, fWidth );
}
void Image::clear() {
fPixels.clear();
fWidth = 0;
fHeight = 0;
// if ( !fPixels )
// return;
// for (int h=0; h<fHeight; h++)
// delete [] fPixels[h];
// delete [] fPixels;
// fPixels = NULL;
std::cout << "[Image (" << this << ")] Cleared image memory " << std::endl;
}
void Image::alloc( int height, int width ) {
// fPixels = new float*[height];
fPixels.resize( height );
for (int h=0; h<height; h++)
fPixels.at(h).resize(width);
//fPixels[h] = new float[width];
std::cout << "[Image (" << this << ")] Allocated space for image H: " << height << " W: " << width << std::endl;
}
void Image::setpixel( int h, int w, float value ) {
if ( !isInBounds( h, w ) )
return;
fPixels.at(h).at(w) = value;
}
float Image::pixel( int h, int w ) {
if ( !isInBounds( h, w ) )
return 0;
return fPixels.at(h).at(w);
}
bool Image::isInBounds( int h, int w ) {
if ( (h<0 || h>=fHeight)
|| (w<0 || w>=fWidth) ) {
std::cout << "[Image] request pixel (" << h << ", " << w << ") is out of range of image (" << fHeight << ", " << fWidth << ")" << std::endl;
return false;
}
return true;
}
}