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 31 template < typename T, colorspace_t CS, int CHMIN, int CHMAX, bool PREVIEW, class OP_PAR > 32 class DesaturateLightnessProc 33 { 34 PixelProcessorPar* par; 35 public: DesaturateLightnessProc(PixelProcessorPar * p)36 DesaturateLightnessProc(PixelProcessorPar* p): par(p) {} 37 process(T ** p,const int & n,const int & first,const int & nch,int & x,const double & intensity,T * pout)38 void process(T**p, const int& n, const int& first, const int& nch, int& x, const double& intensity, T* pout) {} 39 }; 40 41 42 template < typename T, int CHMIN, int CHMAX, bool PREVIEW, class OP_PAR > 43 class DesaturateLightnessProc<T, PF_COLORSPACE_RGB, CHMIN, CHMAX, PREVIEW, OP_PAR> 44 { 45 PixelProcessorPar* par; 46 public: DesaturateLightnessProc(PixelProcessorPar * p)47 DesaturateLightnessProc(PixelProcessorPar* p): par(p) {} 48 process(T ** p,const int & n,const int & first,const int & nch,const int & x,const double & intensity,T * pout)49 void process(T**p, const int& n, const int& first, const int& nch, const int& x, const double& intensity, T* pout) 50 { 51 T* pp = p[first]; 52 T val = static_cast<T>( ( static_cast< typename FormatInfo<T>::PROMOTED >(MAX3(pp[x], pp[x+1], pp[x+2])) + 53 static_cast< typename FormatInfo<T>::PROMOTED >(MIN3(pp[x], pp[x+1], pp[x+2])) )/2 ); 54 for(int i = CHMIN; i <= CHMAX; i++) { 55 pout[x+i] = val; 56 } 57 } 58 }; 59 60 61 template < typename T, int CHMIN, int CHMAX, bool PREVIEW, class OP_PAR > 62 class DesaturateLightnessProc<T, PF_COLORSPACE_LAB, CHMIN, CHMAX, PREVIEW, OP_PAR> 63 { 64 PixelProcessorPar* par; 65 public: DesaturateLightnessProc(PixelProcessorPar * p)66 DesaturateLightnessProc(PixelProcessorPar* p): par(p) {} 67 process(T ** p,const int & n,const int & first,const int & nch,const int & x,const double & intensity,T * pout)68 void process(T**p, const int& n, const int& first, const int& nch, const int& x, const double& intensity, T* pout) 69 { 70 T* pp = p[first]; 71 for(int i = CHMIN; i <= CHMAX; i++) { 72 pout[x+i] = ( (i==0) ? pp[x] : FormatInfo<T>::HALF ); 73 } 74 } 75 }; 76 77 78 79 template < OP_TEMPLATE_DEF > 80 class DesaturateLightness: public PixelProcessor< OP_TEMPLATE_IMP, PixelProcessorPar, DesaturateLightnessProc > 81 { 82 }; 83 84 85 ProcessorBase* new_desaturate_lightness(); 86