Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fftw3.h>
- #include "include/fft.h"
- #include <vector>
- #include <iostream>
- #include <cmath>
- class DctCalculator::Impl {
- public:
- fftw_plan plan;
- size_t width;
- std::vector<double>* input;
- std::vector<double>* output;
- Impl(size_t width, std::vector<double> *input, std::vector<double> *output)
- : input(input), output(output), width(width) {
- if (!(input->size() == output->size() && input->size() == width * width)) {
- throw std::invalid_argument("Wrong arrays");
- }
- plan = fftw_plan_r2r_2d(width, width, input->data(), output->data(), FFTW_REDFT01, FFTW_REDFT01, FFTW_ESTIMATE);
- }
- ~Impl() {
- fftw_destroy_plan(plan);
- }
- void Inverse() {
- double two_sqrt = std::sqrt(2);
- for (size_t i = 0; i < width * width; ++i) {
- (*input)[i] *= 4 * (i < width ? two_sqrt : 1) * (i % width == 0 ? two_sqrt : 1);
- }
- fftw_execute(plan);
- // for (size_t i = 0; i < output->size(); ++i) {
- // output->at(i) /= (width * width);
- // }
- }
- };
- DctCalculator::DctCalculator(size_t width, std::vector<double> *input, std::vector<double> *output)
- : impl_(new Impl(width, input, output)) {
- }
- void DctCalculator::Inverse() {
- impl_->Inverse();
- }
- DctCalculator::~DctCalculator() = default;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement