// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
namespace test { staticinlinedouble alpha(int u) { return u == 0 ? 0.7071067811865475 : 1.0; }
// N-DCT on M columns, divided by sqrt(N). Matches the definition in the spec. template <size_t N, size_t M> void DCT1D(constdouble block[N * M], double out[N * M]) {
std::vector<double> matrix(N * N); constdouble scale = std::sqrt(2.0) / N; for (size_t y = 0; y < N; y++) { for (size_t u = 0; u < N; u++) {
matrix[N * u + y] = alpha(u) * cos((y + 0.5) * u * Pi(1.0 / N)) * scale;
}
} for (size_t x = 0; x < M; x++) { for (size_t u = 0; u < N; u++) {
out[M * u + x] = 0; for (size_t y = 0; y < N; y++) {
out[M * u + x] += matrix[N * u + y] * block[M * y + x];
}
}
}
}
// N-IDCT on M columns, multiplied by sqrt(N). Matches the definition in the // spec. template <size_t N, size_t M> void IDCT1D(constdouble block[N * M], double out[N * M]) {
std::vector<double> matrix(N * N); constdouble scale = std::sqrt(2.0); for (size_t y = 0; y < N; y++) { for (size_t u = 0; u < N; u++) { // Transpose of DCT matrix.
matrix[N * y + u] = alpha(u) * cos((y + 0.5) * u * Pi(1.0 / N)) * scale;
}
} for (size_t x = 0; x < M; x++) { for (size_t u = 0; u < N; u++) {
out[M * u + x] = 0; for (size_t y = 0; y < N; y++) {
out[M * u + x] += matrix[N * u + y] * block[M * y + x];
}
}
}
}
template <size_t N, size_t M> void TransposeBlock(constdouble in[N * M], double out[M * N]) { for (size_t x = 0; x < N; x++) { for (size_t y = 0; y < M; y++) {
out[y * N + x] = in[x * M + y];
}
}
}
} // namespace test
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.