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 CA_CORRECT_H 31 #define CA_CORRECT_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 CACorrectPar: public OpParBase 46 { 47 Property<bool> enable_ca; 48 Property<bool> auto_ca; 49 50 // Manual CA correction parameters 51 Property<float> ca_red, ca_blue; 52 53 dcraw_data_t* image_data; 54 public: 55 CACorrectPar(); has_intensity()56 bool has_intensity() { return false; } has_opacity()57 bool has_opacity() { return false; } needs_input()58 bool needs_input() { return true; } 59 get_image_data()60 dcraw_data_t* get_image_data() { return image_data; } 61 set_enable_ca(bool flag)62 void set_enable_ca(bool flag) { enable_ca.update(flag); } get_auto_ca()63 bool get_auto_ca() { return auto_ca.get(); } set_auto_ca(bool flag)64 void set_auto_ca(bool flag) { auto_ca.update(flag); } get_ca_red()65 float get_ca_red() { return ca_red.get(); } get_ca_blue()66 float get_ca_blue() { return ca_blue.get(); } 67 68 /* Function to derive the output area from the input area 69 */ transform(const VipsRect * rin,VipsRect * rout,int)70 virtual void transform(const VipsRect* rin, VipsRect* rout, int /*id*/) 71 { 72 rout->left = rin->left+8; 73 rout->top = rin->top+8; 74 rout->width = rin->width-16; 75 rout->height = rin->height-16; 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 = 8; 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 119 template < OP_TEMPLATE_DEF > 120 class CACorrectProc 121 { 122 public: render(VipsRegion ** in,int n,int in_first,VipsRegion * imap,VipsRegion * omap,VipsRegion * out,CACorrectPar * par)123 void render(VipsRegion** in, int n, int in_first, 124 VipsRegion* imap, VipsRegion* omap, 125 VipsRegion* out, CACorrectPar* par) 126 { 127 //fast_demosaic( in, n, in_first, 128 // imap, omap, out, par ); 129 } 130 }; 131 132 133 template < OP_TEMPLATE_DEF_TYPE_SPEC > 134 class CACorrectProc< OP_TEMPLATE_IMP_TYPE_SPEC(float) > 135 { 136 public: render(VipsRegion ** in,int n,int in_first,VipsRegion * imap,VipsRegion * omap,VipsRegion * out,CACorrectPar * par)137 void render(VipsRegion** in, int n, int in_first, 138 VipsRegion* imap, VipsRegion* omap, 139 VipsRegion* out, CACorrectPar* par) 140 { 141 rtengine::RawImageSource rawimg; 142 rawimg.set_image_data( par->get_image_data() ); 143 rawimg.ca_correct( in[0], out, par->get_auto_ca(), par->get_ca_red(), par->get_ca_blue() ); 144 } 145 }; 146 147 148 ProcessorBase* new_ca_correct(); 149 } 150 151 152 #endif 153