OSDN Git Service

test: jpeg/enc: improve random YUV data initialization
authorU. Artie Eoff <ullysses.a.eoff@intel.com>
Wed, 28 Sep 2016 20:36:08 +0000 (13:36 -0700)
committerXiang, Haihao <haihao.xiang@intel.com>
Mon, 31 Oct 2016 02:00:08 +0000 (10:00 +0800)
Make initialization of YUV input for jpeg encode a
little faster, esp. for larger resolution.

Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
Reviewed-by: Sean V Kelley <seanvk@posteo.de>
(cherry picked from commit 6bf510f54b41dc9a4aca3d3ad921ec47d5fbfafe)

test/i965_jpeg_test_data.cpp
test/test_utils.h

index 0b0258a..c1ff627 100644 (file)
@@ -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;
     }
 
index ee84f7b..0076677 100644 (file)
@@ -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);
     }