Coverage Report

Created: 2026-08-14 06:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/guetzli/guetzli/score.cc
Line
Count
Source
1
/*
2
 * Copyright 2016 Google Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#include "guetzli/score.h"
18
19
#include <cmath>
20
21
namespace guetzli {
22
23
double ScoreJPEG(double butteraugli_distance, int size,
24
145k
                 double butteraugli_target) {
25
145k
  constexpr double kScale = 50;
26
145k
  constexpr double kMaxExponent = 10;
27
145k
  constexpr double kLargeSize = 1e30;
28
  // TODO(user): The score should also depend on distance below target (and be
29
  // smooth).
30
145k
  double diff = butteraugli_distance - butteraugli_target;
31
145k
  if (diff <= 0.0) {
32
35.0k
    return size;
33
110k
  } else {
34
110k
    double exponent = kScale * diff;
35
110k
    if (exponent > kMaxExponent) {
36
95.1k
      return kLargeSize * std::exp(kMaxExponent) * diff + size;
37
95.1k
    } else {
38
15.2k
      return std::exp(exponent) * size;
39
15.2k
    }
40
110k
  }
41
145k
}
42
43
}  // namespace guetzli