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 DEMOSAIC_XTRANS_RT_H 31 #define DEMOSAIC_XTRANS_RT_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 #include <cstring> 42 43 namespace PF 44 { 45 46 class XTransDemosaicPar: public OpParBase 47 { 48 bool normalize; 49 50 public: 51 XTransDemosaicPar(); has_intensity()52 bool has_intensity() { return false; } has_opacity()53 bool has_opacity() { return false; } needs_input()54 bool needs_input() { return true; } 55 do_normalize()56 bool do_normalize() { return normalize; } set_normalize(bool n)57 void set_normalize( bool n ) { normalize = n; } 58 set_image_hints(VipsImage * img)59 void set_image_hints( VipsImage* img ) 60 { 61 if( !img ) return; 62 OpParBase::set_image_hints( img ); 63 rgb_image( get_xsize(), get_ysize() ); 64 set_demand_hint( VIPS_DEMAND_STYLE_FATSTRIP ); 65 } 66 67 /* Function to derive the output area from the input area 68 */ transform(const VipsRect * rin,VipsRect * rout,int)69 virtual void transform(const VipsRect* rin, VipsRect* rout, int /*id*/) 70 { 71 int border = 12; 72 rout->left = rin->left+border; 73 rout->top = rin->top+border; 74 rout->width = rin->width-border*2; 75 rout->height = rin->height-border*2; 76 } 77 78 /* Function to derive the area to be read from input images, 79 based on the requested output area 80 */ transform_inv(const VipsRect * rout,VipsRect * rin,int)81 virtual void transform_inv(const VipsRect* rout, VipsRect* rin, int /*id*/) 82 { 83 int border = 12; 84 // Output region aligned to the Bayer pattern 85 int raw_left = (rout->left/2)*2; 86 //if( raw_left < border ) raw_left = 0; 87 88 int raw_top = (rout->top/2)*2; 89 //if( raw_top < border ) raw_top = 0; 90 91 int raw_right = rout->left+rout->width-1; 92 //if( raw_right > (in->Xsize-border-1) ) raw_right = in->Xsize-1; 93 94 int raw_bottom = rout->top+rout->height-1; 95 //if( raw_bottom > (in->Ysize-border-1) ) raw_bottom = in->Ysize-1; 96 97 int raw_width = raw_right-raw_left+1; 98 int raw_height = raw_bottom-raw_top+1; 99 100 rin->left = raw_left-border; 101 rin->top = raw_top-border; 102 rin->width = raw_width+border*2; 103 rin->height = raw_height+border*2; 104 105 if( (rin->width%2) ) rin->width += 1; 106 if( (rin->height%2) ) rin->height += 1; 107 } 108 109 110 111 VipsImage* build(std::vector<VipsImage*>& in, int first, 112 VipsImage* imap, VipsImage* omap, 113 unsigned int& level); 114 }; 115 116 117 118 template < OP_TEMPLATE_DEF > 119 class XTransDemosaicProc 120 { 121 public: render(VipsRegion ** in,int n,int in_first,VipsRegion * imap,VipsRegion * omap,VipsRegion * out,XTransDemosaicPar * par)122 void render(VipsRegion** in, int n, int in_first, 123 VipsRegion* imap, VipsRegion* omap, 124 VipsRegion* out, XTransDemosaicPar* par) 125 { 126 //fast_demosaic( in, n, in_first, 127 // imap, omap, out, par ); 128 } 129 }; 130 131 132 #define fcol(r,c) ((int)(rawData[r].color(c))) 133 134 135 template < OP_TEMPLATE_DEF_TYPE_SPEC > 136 class XTransDemosaicProc< OP_TEMPLATE_IMP_TYPE_SPEC(float) > 137 { 138 public: render(VipsRegion ** ir,int n,int in_first,VipsRegion * imap,VipsRegion * omap,VipsRegion * oreg,XTransDemosaicPar * par)139 void render(VipsRegion** ir, int n, int in_first, 140 VipsRegion* imap, VipsRegion* omap, 141 VipsRegion* oreg, XTransDemosaicPar* par) 142 { 143 rtengine::RawImageSource rawimg; 144 rawimg.xtrans_demosaic( ir[0], oreg ); 145 } 146 }; 147 148 149 ProcessorBase* new_xtrans_demosaic(); 150 } 151 152 153 #endif 154