1 /* -*- C++ -*-
2  *
3  *  This file is part of RawTherapee.
4  *
5  *  Copyright (c) 2019 Alberto Griggio <alberto.griggio@gmail.com>
6  *
7  *  RawTherapee is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  RawTherapee is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with RawTherapee.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #pragma once
22 
23 #include "coord2d.h"
24 #include "procparams.h"
25 #include "imagesource.h"
26 
27 namespace rtengine {
28 
29 class ControlLine {
30 public:
31     enum Type {
32         HORIZONTAL,
33         VERTICAL
34     };
35     float x1, y1, x2, y2;
36     Type type;
37 };
38 
39 
40 class PerspectiveCorrection {
41 public:
42     PerspectiveCorrection();
43     void init(int width, int height, const procparams::PerspectiveParams &params, bool fill, const FramesMetaData *meta);
44     void operator()(double &x, double &y);
45 
46     enum Direction {
47         HORIZONTAL,
48         VERTICAL,
49         BOTH
50     };
51     static procparams::PerspectiveParams autocompute(ImageSource *src, Direction dir, const procparams::ProcParams *pparams, const FramesMetaData *metadata, const std::vector<ControlLine> *control_lines=nullptr);
52 
53     static void autocrop(int width, int height, bool fixratio, const procparams::PerspectiveParams &params, const FramesMetaData *metadata, int &x, int &y, int &w, int &h);
54 
55 private:
56     void correct(double &x, double &y, double scale, double offx, double offy);
57     void calc_scale(int w, int h, const procparams::PerspectiveParams &params, bool fill);
58 
59     bool ok_;
60     double scale_;
61     double offx_;
62     double offy_;
63     float ihomograph_[3][3];
64 };
65 
66 } // namespace rtengine
67