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 #ifndef PF_CROP_H
31 #define PF_CROP_H
32 
33 #include <string>
34 
35 #include "../base/property.hh"
36 #include "../base/operation.hh"
37 #include "../base/processor.hh"
38 
39 namespace PF
40 {
41 
42 enum crop_ar_t
43 {
44   CROP_AR_NONE,
45   CROP_AR_INPUT,
46   CROP_AR_CUSTOM,
47   CROP_AR_1_1,
48   CROP_AR_3_2,
49   CROP_AR_2_3,
50   CROP_AR_4_3,
51   CROP_AR_3_4,
52   CROP_AR_A4,
53   CROP_AR_A4R,
54   CROP_AR_A3,
55   CROP_AR_A3R,
56   CROP_AR_16_9,
57   CROP_AR_16_10
58 };
59 
60   class CropPar: public OpParBase
61   {
62     Property<int> crop_left, crop_top, crop_width, crop_height;
63     Property<bool> keep_ar;
64     PropertyBase ar_mode;
65     Property<float> ar_width, ar_height;
66 
67   public:
68     CropPar();
69 
has_opacity()70     bool has_opacity() { return false; }
has_intensity()71     bool has_intensity() { return false; }
72 
73     /* Function to derive the output area from the input area
74     */
transform(const VipsRect * rin,VipsRect * rout,int)75     virtual void transform(const VipsRect* rin, VipsRect* rout, int /*id*/)
76     {
77       rout->left = (is_editing()==true) ? rin->left : rin->left - crop_left.get();
78       rout->top = (is_editing()==true) ? rin->top : rin->top - crop_top.get();
79       rout->width = rin->width;
80       rout->height = rin->height;
81     }
82 
83     /* Function to derive the area to be read from input images,
84        based on the requested output area
85     */
transform_inv(const VipsRect * rout,VipsRect * rin,int)86     virtual void transform_inv(const VipsRect* rout, VipsRect* rin, int /*id*/)
87     {
88       rin->left = (is_editing()==true) ? rout->left : rout->left + crop_left.get();
89       rin->top = (is_editing()==true) ? rout->top : rout->top + crop_top.get();
90       rin->width = rout->width;
91       rin->height = rout->height;
92     }
93 
94 
95     VipsImage* build(std::vector<VipsImage*>& in, int first,
96 										 VipsImage* imap, VipsImage* omap,
97 										 unsigned int& level);
98   };
99 
100 
101 
102   template < OP_TEMPLATE_DEF >
103   class CropProc
104   {
105   public:
render(VipsRegion ** ireg,int n,int in_first,VipsRegion * imap,VipsRegion * omap,VipsRegion * oreg,OpParBase * par)106     void render(VipsRegion** ireg, int n, int in_first,
107 		VipsRegion* imap, VipsRegion* omap,
108 		VipsRegion* oreg, OpParBase* par)
109     {
110     }
111   };
112 
113   ProcessorBase* new_crop();
114 }
115 
116 #endif
117 
118 
119