1 /*
2  */
3 
4 /*
5 
6     Copyright (C) 2014 Ferrero Andrea
7 
8     This program is free software: you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12 
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     GNU General Public License for more details.
17 
18     You should have received a copy of the GNU General Public License
19     along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21 
22  */
23 
24 /*
25 
26     These files are distributed with PhotoFlow - http://aferrero2707.github.io/PhotoFlow/
27 
28  */
29 
30 #include "perspective.hh"
31 
32 int vips_perspective( VipsImage* in, VipsImage **out, PF::ProcessorBase* proc, VipsInterpolate* interpolate, ... );
33 
34 
PerspectivePar()35 PF::PerspectivePar::PerspectivePar():
36       OpParBase(),
37       keystones("keystones",this)
38 {
39   set_type( "perspective" );
40 
41   keystones.get().push_back( std::make_pair(0.2f, 0.2f) );
42   keystones.get().push_back( std::make_pair(0.8f, 0.2f) );
43   keystones.get().push_back( std::make_pair(0.8f, 0.8f) );
44   keystones.get().push_back( std::make_pair(0.2f, 0.8f) );
45   //keystones.get().push_back( std::make_pair(0.29f, 0.15f) );
46   //keystones.get().push_back( std::make_pair(0.77f, 0.25f) );
47   //keystones.get().push_back( std::make_pair(0.84f, 0.84f) );
48   //keystones.get().push_back( std::make_pair(0.27f, 0.88f) );
49 
50   set_default_name( _("perspective correction") );
51 }
52 
53 
54 
build(std::vector<VipsImage * > & in,int first,VipsImage * imap,VipsImage * omap,unsigned int & level)55 VipsImage* PF::PerspectivePar::build(std::vector<VipsImage*>& in, int first,
56     VipsImage* imap, VipsImage* omap,
57     unsigned int& level)
58 {
59   VipsImage* srcimg = NULL;
60   if( in.size() > 0 ) srcimg = in[0];
61   if( srcimg == NULL ) return NULL;
62   VipsImage* out, *rotated;
63 
64 #ifndef NDEBUG
65   std::cout<<"PerspectivePar::build(): is_editing()="<<is_editing()<<std::endl;
66 #endif
67   if( (get_render_mode() == PF_RENDER_PREVIEW) && is_editing() ) {
68     //std::cout<<"PerspectivePar::build(): editing, returning source image"<<std::endl;
69     PF_REF( srcimg, "PerspectivePar::build(): srcimg ref (editing mode)" );
70     return srcimg;
71   }
72 
73   VipsInterpolate* interpolate = NULL; //vips_interpolate_new( "nohalo" );
74   if( !interpolate )
75     interpolate = vips_interpolate_new( "bicubic" );
76   if( !interpolate )
77     interpolate = vips_interpolate_new( "bilinear" );
78 
79   if( vips_perspective(in[0], &out, get_processor(), interpolate, NULL) ) {
80     std::cout<<"vips_perspective() failed."<<std::endl;
81     PF_REF( in[0], "PerspectivePar::build(): in[0] ref after viprs_perspective() failed")
82     return in[0];
83   }
84 
85   PF_UNREF( interpolate, "vips_perspective(): interpolate unref" );
86 
87   return out;
88 
89 }
90