Flutter Engine
 
Loading...
Searching...
No Matches
rmse.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <cmath>
9
10namespace flutter {
11namespace testing {
12namespace {
13double CalculateDistance(const uint8_t* left, const uint8_t* right) {
14 double diff[4] = {
15 static_cast<double>(left[0]) - right[0], //
16 static_cast<double>(left[1]) - right[1], //
17 static_cast<double>(left[2]) - right[2], //
18 static_cast<double>(left[3]) - right[3] //
19 };
20 return sqrt((diff[0] * diff[0]) + //
21 (diff[1] * diff[1]) + //
22 (diff[2] * diff[2]) + //
23 (diff[3] * diff[3]));
24}
25} // namespace
26
28 const impeller::testing::Screenshot* right) {
29 FML_CHECK(left);
30 FML_CHECK(right);
31 FML_CHECK(left->GetWidth() == right->GetWidth());
32 FML_CHECK(left->GetHeight() == right->GetHeight());
33
34 int64_t samples = left->GetWidth() * left->GetHeight();
35 double tally = 0;
36
37 const uint8_t* left_ptr = left->GetBytes();
38 const uint8_t* right_ptr = right->GetBytes();
39 for (int64_t i = 0; i < samples; ++i, left_ptr += 4, right_ptr += 4) {
40 double distance = CalculateDistance(left_ptr, right_ptr);
41 tally += distance * distance;
42 }
43
44 return sqrt(tally / static_cast<double>(samples));
45}
46
47} // namespace testing
48} // namespace flutter
#define FML_CHECK(condition)
Definition logging.h:104
double RMSE(const impeller::testing::Screenshot *left, const impeller::testing::Screenshot *right)
Definition rmse.cc:27