-
Notifications
You must be signed in to change notification settings - Fork 860
/
Copy pathtest.cpp
128 lines (109 loc) · 3.71 KB
/
test.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* This file is part of the Pangolin Project.
* http://github.com/stevenlovegrove/Pangolin
*
* Copyright (c) 2013 Steven Lovegrove
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include <pangolin/video/drivers/test.h>
#include <pangolin/factory/factory_registry.h>
#include <pangolin/video/iostream_operators.h>
namespace pangolin
{
void setRandomData(unsigned char * arr, size_t size){
for(size_t i = 0 ; i < size;i++) {
// arr[i] = (unsigned char)(i * 255.0 / size);
arr[i] = (unsigned char)(rand()/(RAND_MAX/255.0));
}
}
TestVideo::TestVideo(size_t w, size_t h, size_t n, std::string pix_fmt)
{
const PixelFormat pfmt = PixelFormatFromString(pix_fmt);
size_bytes = 0;
for(size_t c=0; c < n; ++c) {
const StreamInfo stream_info(pfmt, w, h, (w*pfmt.bpp)/8, 0);
streams.push_back(stream_info);
size_bytes += w*h*(pfmt.bpp)/8;
}
}
TestVideo::~TestVideo()
{
}
//! Implement VideoInput::Start()
void TestVideo::Start()
{
}
//! Implement VideoInput::Stop()
void TestVideo::Stop()
{
}
//! Implement VideoInput::SizeBytes()
size_t TestVideo::SizeBytes() const
{
return size_bytes;
}
//! Implement VideoInput::Streams()
const std::vector<StreamInfo>& TestVideo::Streams() const
{
return streams;
}
//! Implement VideoInput::GrabNext()
bool TestVideo::GrabNext( unsigned char* image, bool /*wait*/ )
{
setRandomData(image, size_bytes);
return true;
}
//! Implement VideoInput::GrabNewest()
bool TestVideo::GrabNewest( unsigned char* image, bool wait )
{
return GrabNext(image,wait);
}
PANGOLIN_REGISTER_FACTORY(TestVideo)
{
struct TestVideoFactory final : public TypedFactoryInterface<VideoInterface> {
std::map<std::string,Precedence> Schemes() const override
{
return {{"test",10}};
}
const char* Description() const override
{
return "A test video feed with pixel-wise white noise.";
}
ParamSet Params() const override
{
return {{
{"size","640x480","Image dimension"},
{"n","1","Number of streams"},
{"fmt","RGB24","Pixel format: see pixel format help for all possible values"}
}};
}
std::unique_ptr<VideoInterface> Open(const Uri& uri) override {
ParamReader reader(Params(), uri);
const ImageDim dim = reader.Get<ImageDim>("size");
const int n = reader.Get<int>("n");
std::string fmt = reader.Get<std::string>("fmt");
return std::unique_ptr<VideoInterface>(new TestVideo(dim.x,dim.y,n,fmt));
}
};
return FactoryRegistry::I()->RegisterFactory<VideoInterface>(std::make_shared<TestVideoFactory>());
}
}