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 "unsharp_mask.hh"
31
32
UnsharpMaskPar()33 PF::UnsharpMaskPar::UnsharpMaskPar():
34 PixelProcessorPar(),
35 radius("radius",this,1),
36 amount("amount",this,100)
37 {
38 blur = new_gaussblur();
39
40 set_type( "unsharp_mask" );
41 }
42
43
~UnsharpMaskPar()44 PF::UnsharpMaskPar::~UnsharpMaskPar()
45 {
46 delete blur;
47 }
48
49
propagate_settings()50 void PF::UnsharpMaskPar::propagate_settings()
51 {
52 PropertyBase* pradius = blur->get_par()->get_property("radius");
53 if(!pradius) {
54 std::cout<<"UnsharpMaskPar::propagate_settings(): could not find property \"radius\""<<std::endl;
55 return;
56 }
57 pradius->import( &radius );
58 blur->get_par()->propagate_settings();
59 }
60
61
62
63
build(std::vector<VipsImage * > & in,int first,VipsImage * imap,VipsImage * omap,unsigned int & level)64 VipsImage* PF::UnsharpMaskPar::build(std::vector<VipsImage*>& in, int first,
65 VipsImage* imap, VipsImage* omap,
66 unsigned int& level)
67 {
68 VipsImage* srcimg = NULL;
69 if( (int)in.size() > first ) srcimg = in[first];
70
71 if( !srcimg )
72 return NULL;
73
74 double radius2 = radius.get();
75 for( unsigned int l = 1; l < level; l++ )
76 radius2 /= 2;
77
78 blur->get_par()->set_image_hints( this );
79
80 VipsImage* blurred = blur->get_par()->build( in, first, NULL, NULL, level );
81 if( !blurred )
82 return NULL;
83
84 std::vector<VipsImage*> in2;
85 in2.push_back(blurred);
86 in2.push_back(srcimg);
87 VipsImage* out = PF::OpParBase::build( in2, 0, imap, omap, level );
88 PF_UNREF( blurred, "PF::GaussBlurPar::build(): blurred unref" );
89
90 return out;
91 }
92