Hi,
On 14/12/17 01:10, Kieran Bingham wrote:
From: Kieran Bingham <kieran.bingham@xxxxxxxxxxxxxxxx>
Provide a util module to provide helpers involved in validation and verification
of data frames.
The first addition is a raw frame binary output with bindings to python modelled
on Tomi's implementation in wbcap.
I don't think verification.cpp is a good name for this. A function to
save the fb sounds like a generic fb utility.
In fact, I'd like to have a helper utility function to save as png, as
converting a raw image to png is a bit of a hassle. Then again, we'd
need a png library for that, and possibly bigger pieces of code to
handle all the different pixel formats...
So, a function to save the raw bits is fine, but how about "fbutils.cpp"
or such?
Signed-off-by: Kieran Bingham <kieran.bingham@xxxxxxxxxxxxxxxx>
---
kms++util/inc/kms++util/kms++util.h | 2 ++
kms++util/src/verification.cpp | 21 +++++++++++++++++++++
py/pykms/pykmsutil.cpp | 5 +++++
3 files changed, 28 insertions(+)
create mode 100644 kms++util/src/verification.cpp
diff --git a/kms++util/inc/kms++util/kms++util.h b/kms++util/inc/kms++util/kms++util.h
index 8e45b0df3cde..431de0bb159a 100644
--- a/kms++util/inc/kms++util/kms++util.h
+++ b/kms++util/inc/kms++util/kms++util.h
@@ -27,6 +27,8 @@ void draw_text(IFramebuffer& buf, uint32_t x, uint32_t y, const std::string& str
void draw_color_bar(IFramebuffer& buf, int old_xpos, int xpos, int width);
void draw_test_pattern(IFramebuffer &fb, YUVType yuvt = YUVType::BT601_Lim);
+
+void save_raw_frame(IFramebuffer& fb, const char *filename);
}
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
diff --git a/kms++util/src/verification.cpp b/kms++util/src/verification.cpp
new file mode 100644
index 000000000000..3210bb144d2b
--- /dev/null
+++ b/kms++util/src/verification.cpp
@@ -0,0 +1,21 @@
+
+#include <kms++/kms++.h>
+#include <kms++util/kms++util.h>
+
+#include <fstream>
+
+using namespace std;
+
+namespace kms
+{
+
+void save_raw_frame(IFramebuffer& fb, const char *filename)
+{
+ unique_ptr<ofstream> os;
+ os = unique_ptr<ofstream>(new ofstream(filename, ofstream::binary));
+
+ for (unsigned i = 0; i < fb.num_planes(); ++i)
+ os->write((char*)fb.map(i), fb.size(i));
+}
You don't need any of that unique_ptr stuff here. I needed it as the
code needed to handle the case where we don't save, i.e. os = null.
And I'm not fond of the function name, "frame" doesn't sound good. Maybe
rather save_raw_fb(). Or save_fb_raw(), so in the future we might have
also save_fb_png().
+
+}
diff --git a/py/pykms/pykmsutil.cpp b/py/pykms/pykmsutil.cpp
index 518d5eaa88f0..2d741751ba75 100644
--- a/py/pykms/pykmsutil.cpp
+++ b/py/pykms/pykmsutil.cpp
@@ -59,4 +59,9 @@ void init_pykmstest(py::module &m)
} );
m.def("draw_text", [](Framebuffer& fb, uint32_t x, uint32_t y, const string& str, RGB color) {
draw_text(fb, x, y, str, color); } );
+
+ // Verification and Validation
+ m.def("save_raw_frame", [](Framebuffer& fb, const char * filename) {
+ save_raw_frame(fb, filename);
+ });
}
--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki