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_UNSHARP_MASK_H 31 #define PF_UNSHARP_MASK_H 32 33 #include "../base/format_info.hh" 34 #include "../base/pixel_processor.hh" 35 #include "gaussblur.hh" 36 37 #define CLIP_T(T,VAL) (T)( MIN(MAX(VAL,FormatInfo<T>::MIN),FormatInfo<T>::MAX) ) 38 39 namespace PF 40 { 41 42 class UnsharpMaskPar: public PixelProcessorPar 43 { 44 Property<float> radius, amount; 45 ProcessorBase* blur; 46 public: 47 UnsharpMaskPar(); 48 ~UnsharpMaskPar(); set_radius(float r)49 void set_radius( float r ) { radius.set( r ); } get_radius()50 float get_radius() { return radius.get(); } get_amount()51 float get_amount() { return amount.get(); } 52 53 //bool needs_caching() { return true; } 54 void propagate_settings(); compute_padding(VipsImage * full_res,unsigned int id,unsigned int level)55 void compute_padding( VipsImage* full_res, unsigned int id, unsigned int level ) 56 { 57 g_assert(blur->get_par() != NULL); 58 blur->get_par()->compute_padding(full_res, id, level); 59 set_padding( blur->get_par()->get_padding(id), id ); 60 } 61 62 VipsImage* build(std::vector<VipsImage*>& in, int first, 63 VipsImage* imap, VipsImage* omap, 64 unsigned int& level); 65 }; 66 67 68 69 70 71 template < typename T, colorspace_t CS, int CHMIN, int CHMAX, bool PREVIEW, class OP_PAR > 72 class UnsharpMaskProc 73 { 74 UnsharpMaskPar* par; 75 float amount; 76 public: UnsharpMaskProc(UnsharpMaskPar * p)77 UnsharpMaskProc(UnsharpMaskPar* p): par(p) { 78 amount = 1; 79 if(par) amount = 0.01f*par->get_amount(); 80 } 81 process(T ** p,const int & n,const int & first,const int & nch,const int & x,const double & intensity,T * & pout)82 void process(T**p, const int& n, const int& first, const int& nch, const int& x, const double& intensity, T*& pout) 83 { 84 for( int ch = CHMIN; ch <= CHMAX; ch++ ) { 85 typename FormatInfo<T>::SIGNED diff = ((typename FormatInfo<T>::SIGNED)p[first+1][x+ch]) - ((typename FormatInfo<T>::SIGNED)p[first][x+ch]); 86 double val = amount*intensity*diff + p[first+1][x+ch]; 87 //if( val < FormatInfo<T>::MIN ) val = FormatInfo<T>::MIN; 88 //else if( val > FormatInfo<T>::MAX ) val = FormatInfo<T>::MAX; 89 pout[x+ch] = (T)(val); 90 } 91 } 92 }; 93 94 95 template < OP_TEMPLATE_DEF > 96 class UnsharpMask: public PixelProcessor< OP_TEMPLATE_IMP, UnsharpMaskPar, UnsharpMaskProc > 97 { 98 }; 99 100 101 ProcessorBase* new_unsharp_mask(); 102 103 } 104 105 #endif 106 107 108