Coverage Report

Created: 2025-06-12 06:11

/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
28.8M
int AdaptiveMedian(int w, int n, int nw) {
16
28.8M
  const int mx = (w > n) ? w : n;
17
28.8M
  const int mn = w + n - mx;
18
28.8M
  if (nw > mx) {
19
553k
    return mn;
20
28.2M
  } else if (nw < mn) {
21
1.18M
    return mx;
22
27.0M
  } else {
23
27.0M
    return n + w - nw;
24
27.0M
  }
25
28.8M
}
26
27
}  // namespace
28
29
30.1M
int PredictWithAdaptiveMedian(const coeff_t* coeffs, int x, int y, int stride) {
30
30.1M
  const int offset1 = -kDCTBlockSize;
31
30.1M
  const int offset2 = -stride;
32
30.1M
  const int offset3 = offset2 + offset1;
33
30.1M
  if (y != 0) {
34
29.1M
    if (x != 0) {
35
28.8M
      return AdaptiveMedian(coeffs[offset1], coeffs[offset2], coeffs[offset3]);
36
28.8M
    } else {
37
363k
      return coeffs[offset2];
38
363k
    }
39
29.1M
  } else {
40
975k
    return x ? coeffs[offset1] : 0;
41
975k
  }
42
30.1M
}
43
44
}  // namespace brunsli