[Libva] [PATCH intel-driver 08/11] test: jpeg/enc: improve random YUV data initialization

U. Artie Eoff ullysses.a.eoff at intel.com
Wed Sep 28 20:36:08 UTC 2016


Make initialization of YUV input for jpeg encode a
little faster, esp. for larger resolution.

Signed-off-by: U. Artie Eoff <ullysses.a.eoff at intel.com>
---
 test/i965_jpeg_test_data.cpp | 17 +++++++++--------
 test/test_utils.h            |  2 +-
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/test/i965_jpeg_test_data.cpp b/test/i965_jpeg_test_data.cpp
index 0b0258a49689..c1ff6276323a 100644
--- a/test/i965_jpeg_test_data.cpp
+++ b/test/i965_jpeg_test_data.cpp
@@ -28,6 +28,7 @@
 #include "test_utils.h"
 
 #include <algorithm>
+#include <numeric>
 
 namespace JPEG {
 namespace Decode {
@@ -822,6 +823,10 @@ namespace Encode {
 
         for (size_t i(1); i < planes; ++i)
             offsets[i] = sizes[i - 1] + offsets[i - 1];
+
+        // Allocate bytes. Values are arbitrary.
+        bytes.resize(
+            std::accumulate(std::begin(sizes), std::end(sizes), 0u));
     }
 
     const unsigned TestInput::width() const
@@ -849,7 +854,7 @@ namespace Encode {
                 result = create(VA_FOURCC_I420, width(), height());
                 std::copy(
                     std::begin(bytes), std::end(bytes),
-                    std::back_inserter(result->bytes));
+                    std::begin(result->bytes));
                 size_t i(0);
                 auto predicate = [&i](const ByteData::value_type&) {
                     bool isu = ((i % 2) == 0) or (i == 0);
@@ -890,13 +895,9 @@ namespace Encode {
         const std::array<unsigned, 2> res = getResolution();
 
         TestInput::Shared input(TestInput::create(fourcc, res[0], res[1]));
-        ByteData& bytes = input->bytes;
-
-        RandomValueGenerator<uint8_t> rg(0x00, 0xff);
-        for (size_t i(0); i < input->planes; ++i)
-            std::generate_n(
-                std::back_inserter(bytes), input->sizes[i],
-                [&rg]{ return rg(); });
+        std::generate_n(
+            std::begin(input->bytes), input->bytes.size(),
+            RandomValueGenerator<uint8_t>(0x00, 0xff));
         return input;
     }
 
diff --git a/test/test_utils.h b/test/test_utils.h
index ee84f7bf45a4..007667708adb 100644
--- a/test/test_utils.h
+++ b/test/test_utils.h
@@ -38,7 +38,7 @@ public:
     const T operator()()
     {
         static std::random_device rd;
-        static std::mt19937 gen(rd());
+        static std::default_random_engine gen(rd());
         return dis(gen);
     }
 
-- 
2.4.11



More information about the Libva mailing list