forked from edrosten/libcvd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubimage_test.cc
89 lines (60 loc) · 1.53 KB
/
subimage_test.cc
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
#include <iostream>
#include <algorithm>
#include <tag/stdpp.h>
#include <cvd/image_io.h>
#include <cvd/videodisplay.h>
#include <cvd/gl_helpers.h>
#include <cvd/timer.h>
using namespace std;
using namespace CVD;
using namespace tag;
void clear_area(BasicImage<byte> im, ImageRef start, ImageRef size)
{
int ye = start.y + size.y;
int xe = start.x + size.x;
for(int y=start.y; y < ye; y++)
for(int x=start.x; x < xe; x++)
im[y][x] = 0;
}
template<class A, class B> void clear(A a, B b)
{
for(; a != b; ++a)
*a=128;
}
int main()
{
Image<byte> in;
img_load(in, "lab.pgm");
VideoDisplay d(in.size());
glDrawPixels(in);
glFlush();
SubImage<byte> s = in.sub_image(ImageRef(10,10), ImageRef(100,100));
VideoDisplay e(0,0,90,90);
glDrawPixels(s);
cin.get();
d.make_current();
clear(s.begin(), s.end());
glDrawPixels(in);
glFlush();
clear_area(in, ImageRef(220, 10), ImageRef(100,100));
glDrawPixels(in);
glFlush();
cin.get();
s = in;
cvd_timer t;
for(int i=0; i < 10000; i++)
clear(in.begin(), in.end());
cout << "Using T* as iterator: " << t.get_time() << endl;
t.reset();
for(int i=0; i < 10000; i++)
clear(s.begin(), s.fastend());
cout << "Using SubImageIterator and SubImageIteratorEnd: " << t.get_time() << endl;
t.reset();
for(int i=0; i < 10000; i++)
clear(s.begin(), s.end());
cout << "Using SubImageIterator only: " << t.get_time() << endl;
t.reset();
for(int i=0; i < 10000; i++)
clear_area(in, ImageRef_zero, in.size());
cout << "Using double for loop: " << t.get_time() << endl;
}