Coverage Report

Created: 2026-12-01 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/guetzli/guetzli/butteraugli_comparator.h
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
#ifndef GUETZLI_BUTTERAUGLI_COMPARATOR_H_
18
#define GUETZLI_BUTTERAUGLI_COMPARATOR_H_
19
20
#include <vector>
21
22
#include "butteraugli/butteraugli.h"
23
#include "guetzli/comparator.h"
24
#include "guetzli/jpeg_data.h"
25
#include "guetzli/output_image.h"
26
#include "guetzli/stats.h"
27
28
namespace guetzli {
29
30
constexpr int kButteraugliStep = 3;
31
32
class ButteraugliComparator : public Comparator {
33
 public:
34
  ButteraugliComparator(const int width, const int height,
35
                        const std::vector<uint8_t>* rgb,
36
                        const float target_distance, ProcessStats* stats);
37
38
  void Compare(const OutputImage& img) override;
39
40
  void StartBlockComparisons() override;
41
  void FinishBlockComparisons() override;
42
43
  void SwitchBlock(int block_x, int block_y,
44
                   int factor_x, int factor_y) override;
45
46
  double CompareBlock(const OutputImage& img,
47
                      int off_x, int off_y) const override;
48
49
  double ScoreOutputSize(int size) const override;
50
51
49.3k
  bool DistanceOK(double target_mul) const override {
52
49.3k
    return distance_ <= target_mul * target_distance_;
53
49.3k
  }
54
55
158k
  const std::vector<float> distmap() const override { return distmap_; }
56
0
  float distmap_aggregate() const override { return distance_; }
57
58
  float BlockErrorLimit() const override;
59
60
  void ComputeBlockErrorAdjustmentWeights(
61
      int direction, int max_block_dist, double target_mul, int factor_x,
62
      int factor_y, const std::vector<float>& distmap,
63
      std::vector<float>* block_weight) override;
64
65
 private:
66
  const int width_;
67
  const int height_;
68
  const float target_distance_;
69
  const std::vector<uint8_t>& rgb_orig_;
70
  int block_x_;
71
  int block_y_;
72
  int factor_x_;
73
  int factor_y_;
74
  std::vector<::butteraugli::ImageF> mask_xyz_;
75
  std::vector<std::vector<std::vector<float>>> per_block_pregamma_;
76
  ::butteraugli::ButteraugliComparator comparator_;
77
  float distance_;
78
  std::vector<float> distmap_;
79
  ProcessStats* stats_;
80
};
81
82
}  // namespace guetzli
83
84
#endif  // GUETZLI_BUTTERAUGLI_COMPARATOR_H_