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
31 #include "new_operation.hh"
32 #include "layer.hh"
33 #include "../operations/operations.hh"
34 #include "../operations/vips_operation.hh"
35
new_operation(std::string op_type,PF::Layer * current_layer)36 PF::ProcessorBase* PF::new_operation( std::string op_type, PF::Layer* current_layer )
37 {
38 PF::ProcessorBase* processor = NULL;
39
40 //std::cout<<"PF::new_operation: creating operation of type \""<<op_type<<"\""<<std::endl;
41
42 if( op_type == "imageread" ) {
43
44 //processor = new PF::Processor<PF::ImageReaderPar,PF::ImageReader>();
45 processor = new_image_reader();
46
47 } else if( op_type == "raw_loader" ) {
48
49 //processor = new PF::Processor<PF::BlenderPar,PF::BlenderProc>();
50 processor = new_raw_loader();
51
52 } else if( op_type == "raw_developer" ) {
53
54 //processor = new PF::Processor<PF::BlenderPar,PF::BlenderProc>();
55 processor = new_raw_developer_v1();
56
57 } else if( op_type == "raw_output" ) {
58
59 //processor = new PF::Processor<PF::BlenderPar,PF::BlenderProc>();
60 processor = new_raw_output_v1();
61
62 } else if( op_type == "raw_developer_v2" ) {
63
64 //processor = new PF::Processor<PF::BlenderPar,PF::BlenderProc>();
65 processor = new_raw_developer();
66
67 } else if( op_type == "raw_output_v2" ) {
68
69 //processor = new PF::Processor<PF::BlenderPar,PF::BlenderProc>();
70 processor = new_raw_output();
71
72 } else if( op_type == "buffer" ) {
73
74 //processor = new PF::Processor<PF::BlenderPar,PF::BlenderProc>();
75 processor = new_buffer();
76
77 } else if( op_type == "blender" ) {
78
79 //processor = new PF::Processor<PF::BlenderPar,PF::BlenderProc>();
80 processor = new_blender();
81
82 } else if( op_type == "white_balance" ) {
83
84 //processor = new PF::Processor<PF::ClonePar,PF::CloneProc>();
85 processor = new_white_balance();
86
87 } else if( op_type == "clip" ) {
88
89 //processor = new PF::Processor<PF::ClonePar,PF::CloneProc>();
90 processor = new_clip();
91
92 } else if( op_type == "clone" ) {
93
94 //processor = new PF::Processor<PF::ClonePar,PF::CloneProc>();
95 processor = new_clone();
96
97 } else if( op_type == "crop" ) {
98
99 //processor = new PF::Processor<PF::ClonePar,PF::CloneProc>();
100 processor = new_crop();
101
102 } else if( op_type == "scale" ) {
103
104 //processor = new PF::Processor<PF::ClonePar,PF::CloneProc>();
105 processor = new_scale();
106
107 } else if( op_type == "perspective" ) {
108
109 //processor = new PF::Processor<PF::ClonePar,PF::CloneProc>();
110 processor = new_perspective();
111
112 } else if( op_type == "invert" ) {
113
114 //processor = new PF::Processor<PF::InvertPar,PF::Invert>();
115 processor = new_invert();
116
117 } else if( op_type == "noise_generator" ) {
118
119 processor = new_noise_generator();
120
121 } else if( op_type == "threshold" ) {
122
123 //processor = new PF::Processor<PF::InvertPar,PF::Invert>();
124 processor = new_threshold();
125
126 } else if( op_type == "desaturate" ) {
127
128 //processor = new PF::Processor<PF::InvertPar,PF::Invert>();
129 processor = new_desaturate();
130
131 } else if( op_type == "guided_filter" ) {
132
133 //processor = new PF::Processor<PF::InvertPar,PF::Invert>();
134 processor = new_guided_filter();
135
136 } else if( op_type == "median_filter" ) {
137
138 //processor = new PF::Processor<PF::InvertPar,PF::Invert>();
139 processor = new_median_filter();
140
141 } else if( op_type == "uniform" ) {
142
143 //processor = new PF::Processor<PF::InvertPar,PF::Invert>();
144 processor = new_uniform();
145
146 } else if( op_type == "gradient" ) {
147
148 //processor = new PF::Processor<PF::GradientPar,PF::Gradient>();
149 processor = new_gradient();
150
151 } else if( op_type == "path_mask" ) {
152
153 //processor = new PF::Processor<PF::GradientPar,PF::Gradient>();
154 processor = new_path_mask();
155
156 } else if( op_type == "levels" ) {
157
158 //processor = new PF::Processor<PF::BrightnessContrastPar,PF::BrightnessContrast>();
159 processor = new_levels();
160
161 } else if( op_type == "basic_adjustments" ) {
162
163 //processor = new PF::Processor<PF::BrightnessContrastPar,PF::BrightnessContrast>();
164 processor = new_basic_adjustments();
165
166 } else if( op_type == "color_correction" ) {
167
168 //processor = new PF::Processor<PF::BrightnessContrastPar,PF::BrightnessContrast>();
169 processor = new_color_correction();
170
171 } else if( op_type == "brightness_contrast" ) {
172
173 //processor = new PF::Processor<PF::BrightnessContrastPar,PF::BrightnessContrast>();
174 processor = new_brightness_contrast();
175
176 } else if( op_type == "hue_saturation" ) {
177
178 processor = new_hue_saturation();
179
180 } else if( op_type == "hsl_mask" ) {
181
182 processor = new_hsl_mask();
183
184 } else if( op_type == "curves" ) {
185
186 //processor = new PF::Processor<PF::CurvesPar,PF::Curves>();
187 processor = new_curves();
188
189 } else if( op_type == "channel_mixer" ) {
190
191 //processor = new PF::Processor<PF::CurvesPar,PF::Curves>();
192 processor = new_channel_mixer();
193
194 } else if( op_type == "gaussblur" ) {
195
196 processor = new_gaussblur();
197
198 } else if( op_type == "blur_bilateral" ) {
199
200 processor = new_blur_bilateral();
201
202 } else if( op_type == "denoise" ) {
203
204 //processor = new PF::Processor<PF::CurvesPar,PF::Curves>();
205 processor = new_denoise();
206
207 } else if( op_type == "sharpen" ) {
208
209 //processor = new PF::Processor<PF::CurvesPar,PF::Curves>();
210 processor = new_sharpen();
211
212 } else if( op_type == "convert_colorspace" ) {
213
214 //processor = new PF::Processor<PF::Convert2LabPar,PF::Convert2LabProc>();
215 processor = new_convert_colorspace();
216
217 } else if( op_type == "dynamic_range_compressor" ) {
218
219 processor = new_dynamic_range_compressor();
220
221 } else if( op_type == "dynamic_range_compressor_v2" ) {
222
223 processor = new_dynamic_range_compressor_v2();
224
225 } else if( op_type == "draw" ) {
226
227 //processor = new PF::Processor<PF::Convert2LabPar,PF::Convert2LabProc>();
228 processor = new_draw();
229
230 } else if( op_type == "clone_stamp" ) {
231
232 //processor = new PF::Processor<PF::Convert2LabPar,PF::Convert2LabProc>();
233 processor = new_clone_stamp();
234
235 } else if( op_type == "lensfun" ) {
236 processor = new_lensfun();
237
238 } else if( op_type == "shadows_highlights" ) {
239 processor = new_shadows_highlights();
240
241 } else if( op_type == "shadows_highlights_v2" ) {
242 processor = new_shadows_highlights_v2();
243
244 } else if( op_type == "relight" ) {
245 processor = new_relight();
246 /*
247 processor = new_shadows_highlights_v2();
248 PF::OpParBase* par = processor ? processor->get_par() : NULL;
249 if( par ) {
250 PF::PropertyBase* prop;
251 par->set_type("relight");
252 par->set_default_name( _("relight") );
253
254 prop = par->get_property("shadows");
255 if(prop) {
256 prop->update(1.f);
257 prop->store_default();
258 }
259
260 prop = par->get_property("shadows_range");
261 if(prop) {
262 prop->update(5.0f);
263 prop->store_default();
264 }
265
266 prop = par->get_property("highlights");
267 if(prop) {
268 prop->update(1.0f);
269 prop->store_default();
270 }
271
272 prop = par->get_property("anchor");
273 if(prop) {
274 prop->update(0.75f);
275 prop->store_default();
276 }
277
278 prop = par->get_property("sh_radius");
279 if(prop) {
280 prop->update( static_cast<int>(128) );
281 prop->store_default();
282 }
283
284 prop = par->get_property("sh_threshold");
285 if(prop) {
286 prop->update( 0.1f );
287 prop->store_default();
288 }
289 }
290 */
291 } else if( op_type == "defringe" ) {
292 processor = new_defringe();
293
294 } else if( op_type == "split_details" ) {
295 processor = new_split_details();
296
297 } else if( op_type == "subtrimg" ) {
298 processor = new_subtrimg();
299
300 } else if( op_type == "tone_mapping" ) {
301 processor = new_tone_mapping();
302
303 } else if( op_type == "tone_mapping_v2" ) {
304 processor = new_tone_mapping_v2();
305
306 } else if( op_type == "tone_mapping_v3" ) {
307 processor = new_tone_mapping_v3();
308
309 } else if( op_type == "local_contrast" ) {
310 processor = new_local_contrast();
311
312 } else if( op_type == "local_contrast_v2" ) {
313 processor = new_local_contrast_v2();
314
315 } else if( op_type == "clahe" ) {
316 processor = new_clahe();
317
318 #ifdef HAVE_OCIO
319 } else if( op_type == "ocio_filmic" ) {
320 processor = new_ocio_view();
321
322 } else if( op_type == "ocio_aces" ) {
323 processor = new_ocio_aces();
324
325 } else if( op_type == "ocio_transform" ) {
326 processor = new_ocio_config();
327 #endif
328 } else if( op_type == "volume" ) {
329 processor = new_volume();
330 }
331
332 if( !processor ) {
333 // Try with G'MIC
334 std::cout<<"PF::new_operation: no tool of type \""<<op_type<<"\" found"<<std::endl;
335 std::cout<<"PF::new_gmic_operation( "<<op_type<<" );"<<std::endl;
336 processor = PF::new_gmic_operation( op_type );
337 }
338 /*
339 } else { // it must be a VIPS operation...
340
341 int pos = op_type.find( "vips-" );
342 if( pos != 0 ) return NULL;
343 std::string vips_op_type;
344 vips_op_type.append(op_type.begin()+5,op_type.end());
345
346 PF::Processor<PF::VipsOperationPar,PF::VipsOperationProc>* vips_op =
347 new PF::Processor<PF::VipsOperationPar,PF::VipsOperationProc>();
348 //ProcessorBase* vips_op = new_vips_operation();
349 vips_op->get_par()->set_op( vips_op_type.c_str() );
350 processor = vips_op;
351 }
352 */
353
354 if( processor && current_layer ) {
355 current_layer->set_processor( processor );
356 //if( processor->get_par() && processor->get_par()->has_opacity() )
357 current_layer->set_blender( new_blender() );
358 if( processor->get_par() )
359 current_layer->set_cached( processor->get_par()->needs_caching() );
360 }
361
362 return processor;
363 }
364