Coverage Report

Created: 2025-07-12 06:46

/src/brunsli/c/common/predict.cc
Line
Count
Source
1
// Copyright (c) Google LLC 2019
2
//
3
// Use of this source code is governed by an MIT-style
4
// license that can be found in the LICENSE file or at
5
// https://opensource.org/licenses/MIT.
6
7
#include "./predict.h"
8
9
#include <brunsli/jpeg_data.h>
10
11
namespace brunsli {
12
13
namespace {
14
15
33.2M
int AdaptiveMedian(int w, int n, int nw) {
16
33.2M
  const int mx = (w > n) ? w : n;
17
33.2M
  const int mn = w + n - mx;
18
33.2M
  if (nw > mx) {
19
1.05M
    return mn;
20
32.2M
  } else if (nw < mn) {
21
647k
    return mx;
22
31.5M
  } else {
23
31.5M
    return n + w - nw;
24
31.5M
  }
25
33.2M
}
26
27
}  // namespace
28
29
34.4M
int PredictWithAdaptiveMedian(const coeff_t* coeffs, int x, int y, int stride) {
30
34.4M
  const int offset1 = -kDCTBlockSize;
31
34.4M
  const int offset2 = -stride;
32
34.4M
  const int offset3 = offset2 + offset1;
33
34.4M
  if (y != 0) {
34
33.6M
    if (x != 0) {
35
33.2M
      return AdaptiveMedian(coeffs[offset1], coeffs[offset2], coeffs[offset3]);
36
33.2M
    } else {
37
339k
      return coeffs[offset2];
38
339k
    }
39
33.6M
  } else {
40
794k
    return x ? coeffs[offset1] : 0;
41
794k
  }
42
34.4M
}
43
44
}  // namespace brunsli