Coverage Report

Created: 2026-10-17 07:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/guetzli/guetzli/dct_double.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/dct_double.h"
18
19
#include <algorithm>
20
#include <cmath>
21
22
namespace guetzli {
23
24
namespace {
25
26
// kDCTMatrix[8*u+x] = 0.5*alpha(u)*cos((2*x+1)*u*M_PI/16),
27
// where alpha(0) = 1/sqrt(2) and alpha(u) = 1 for u > 0.
28
static const double kDCTMatrix[64] = {
29
  0.3535533906,  0.3535533906,  0.3535533906,  0.3535533906,
30
  0.3535533906,  0.3535533906,  0.3535533906,  0.3535533906,
31
  0.4903926402,  0.4157348062,  0.2777851165,  0.0975451610,
32
 -0.0975451610, -0.2777851165, -0.4157348062, -0.4903926402,
33
  0.4619397663,  0.1913417162, -0.1913417162, -0.4619397663,
34
 -0.4619397663, -0.1913417162,  0.1913417162,  0.4619397663,
35
  0.4157348062, -0.0975451610, -0.4903926402, -0.2777851165,
36
  0.2777851165,  0.4903926402,  0.0975451610, -0.4157348062,
37
  0.3535533906, -0.3535533906, -0.3535533906,  0.3535533906,
38
  0.3535533906, -0.3535533906, -0.3535533906,  0.3535533906,
39
  0.2777851165, -0.4903926402,  0.0975451610,  0.4157348062,
40
 -0.4157348062, -0.0975451610,  0.4903926402, -0.2777851165,
41
  0.1913417162, -0.4619397663,  0.4619397663, -0.1913417162,
42
 -0.1913417162,  0.4619397663, -0.4619397663,  0.1913417162,
43
  0.0975451610, -0.2777851165,  0.4157348062, -0.4903926402,
44
  0.4903926402, -0.4157348062,  0.2777851165, -0.0975451610,
45
};
46
47
0
void DCT1d(const double* in, int stride, double* out) {
48
0
  for (int x = 0; x < 8; ++x) {
49
0
    out[x * stride] = 0.0;
50
0
    for (int u = 0; u < 8; ++u) {
51
0
      out[x * stride] += kDCTMatrix[8 * x + u] * in[u * stride];
52
0
    }
53
0
  }
54
0
}
55
56
0
void IDCT1d(const double* in, int stride, double* out) {
57
0
  for (int x = 0; x < 8; ++x) {
58
0
    out[x * stride] = 0.0;
59
0
    for (int u = 0; u < 8; ++u) {
60
0
      out[x * stride] += kDCTMatrix[8 * u + x] * in[u * stride];
61
0
    }
62
0
  }
63
0
}
64
65
typedef void (*Transform1d)(const double* in, int stride, double* out);
66
67
0
void TransformBlock(double block[64], Transform1d f) {
68
0
  double tmp[64];
69
0
  for (int x = 0; x < 8; ++x) {
70
0
    f(&block[x], 8, &tmp[x]);
71
0
  }
72
0
  for (int y = 0; y < 8; ++y) {
73
0
    f(&tmp[8 * y], 1, &block[8 * y]);
74
0
  }
75
0
}
76
77
}  // namespace
78
79
0
void ComputeBlockDCTDouble(double block[64]) {
80
0
  TransformBlock(block, DCT1d);
81
0
}
82
83
0
void ComputeBlockIDCTDouble(double block[64]) {
84
0
  TransformBlock(block, IDCT1d);
85
0
}
86
87
}  // namespace guetzli