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 IGV_DEMOSAIC_H
31 #define IGV_DEMOSAIC_H
32 
33 #include <string>
34 
35 //#include <libraw/libraw.h>
36 
37 #include "../base/operation.hh"
38 #include "../rt/rtengine/rawimagesource.hh"
39 
40 
41 
42 namespace PF
43 {
44 
45   class IgvDemosaicPar: public OpParBase
46   {
47   public:
48     IgvDemosaicPar();
has_intensity()49     bool has_intensity() { return false; }
has_opacity()50     bool has_opacity() { return false; }
needs_input()51     bool needs_input() { return true; }
52 
set_image_hints(VipsImage * img)53     void set_image_hints( VipsImage* img )
54     {
55       if( !img ) return;
56       OpParBase::set_image_hints( img );
57       rgb_image( get_xsize(), get_ysize() );
58     }
59 
60     /* Function to derive the output area from the input area
61      */
transform(const VipsRect * rin,VipsRect * rout,int)62     virtual void transform(const VipsRect* rin, VipsRect* rout, int /*id*/)
63     {
64       rout->left = rin->left+16;
65       rout->top = rin->top+16;
66       rout->width = rin->width-32;
67       rout->height = rin->height-32;
68     }
69 
70     /* Function to derive the area to be read from input images,
71        based on the requested output area
72     */
transform_inv(const VipsRect * rout,VipsRect * rin,int)73     virtual void transform_inv(const VipsRect* rout, VipsRect* rin, int /*id*/)
74     {
75 			// Output region aligned to the Bayer pattern
76 			int raw_left = (rout->left/2)*2;
77 			int raw_top = (rout->top/2)*2;
78 			int raw_right = rout->left+rout->width-1;
79 			int raw_bottom = rout->top+rout->height-1;
80 			int raw_width = raw_right-raw_left+1;
81 			int raw_height = raw_bottom-raw_top+1;
82 
83       rin->left = raw_left-16;
84       rin->top = raw_top-16;
85       rin->width = raw_width+32;
86       rin->height = raw_height+32;
87     }
88 
89 
90 
91     VipsImage* build(std::vector<VipsImage*>& in, int first,
92 										 VipsImage* imap, VipsImage* omap,
93 										 unsigned int& level);
94   };
95 
96 
97 
98 
99   template < OP_TEMPLATE_DEF >
100   class IgvDemosaicProc
101   {
102   public:
render(VipsRegion ** in,int n,int in_first,VipsRegion * imap,VipsRegion * omap,VipsRegion * out,IgvDemosaicPar * par)103     void render(VipsRegion** in, int n, int in_first,
104 								VipsRegion* imap, VipsRegion* omap,
105 								VipsRegion* out, IgvDemosaicPar* par)
106     {
107       //fast_demosaic( in, n, in_first,
108       //	     imap, omap, out, par );
109     }
110   };
111 
112 
113   template < OP_TEMPLATE_DEF_TYPE_SPEC >
114   class IgvDemosaicProc< OP_TEMPLATE_IMP_TYPE_SPEC(float) >
115   {
116   public:
render(VipsRegion ** in,int n,int in_first,VipsRegion * imap,VipsRegion * omap,VipsRegion * out,IgvDemosaicPar * par)117     void render(VipsRegion** in, int n, int in_first,
118 								VipsRegion* imap, VipsRegion* omap,
119 								VipsRegion* out, IgvDemosaicPar* par)
120     {
121 			rtengine::RawImageSource rawimg;
122 			rawimg.igv_demosaic( in[0], out );
123     }
124   };
125 
126 
127   ProcessorBase* new_igv_demosaic();
128 }
129 
130 
131 #endif
132