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 
32 template<typename T, colorspace_t colorspace, int CHMIN, int CHMAX, bool has_omap>
33 class BlendGrainExtract: public BlendBase<T, colorspace, CHMIN, CHMAX, has_omap>
34 {
35 public:
blend(const float &,T *,T *,T *,const int &,int &)36   void blend(const float& /*opacity*/, T* /*bottom*/, T* /*top*/,
37       T* /*out*/, const int& /*x*/, int& /*xomap*/) {}
38 };
39 
40 
41 
42 template<typename T, colorspace_t CS, int CHMIN, int CHMAX>
43 class BlendGrainExtract<T, CS, CHMIN, CHMAX, false>:
44   public BlendBase<T, CS, CHMIN, CHMAX, false>
45 {
46   int ch, pos;
47   typename FormatInfo<T>::PROMOTED ptop;
48 public:
blend(const float & opacity,T * bottom,T * top,T * out,const int & x,int &)49   void blend(const float& opacity, T* bottom, T* top, T* out, const int& x, int& /*xomap*/)
50   {
51     pos = x;
52     for( ch=CHMIN; ch<=CHMAX; ch++, pos++ ) {
53       ptop = ( (((typename FormatInfo<T>::PROMOTED)bottom[pos])-((typename FormatInfo<T>::PROMOTED)top[pos]))/2 + FormatInfo<T>::HALF );
54       clip( opacity*ptop + (1.0f-opacity)*bottom[pos], out[pos] );
55       //std::cout<<"  out="<<(int)out[pos]<<std::endl;
56     }
57   }
58 };
59 
60 
61 
62 template<typename T, colorspace_t CS, int CHMIN, int CHMAX>
63 class BlendGrainExtract<T, CS, CHMIN, CHMAX, true>:
64   public BlendBase<T, CS, CHMIN, CHMAX, true>
65 {
66   int ch, pos;
67   typename FormatInfo<T>::PROMOTED ptop;
68   float opacity_real;
69 public:
blend(const float & opacity,T * bottom,T * top,T * out,const int & x,int & xomap)70   void blend(const float& opacity, T* bottom, T* top, T* out, const int& x, int& xomap)
71   {
72     opacity_real = opacity*(this->pmap[xomap]+FormatInfo<T>::MIN)/(FormatInfo<T>::RANGE);
73     xomap += 1;
74 
75     pos = x;
76     for( ch=CHMIN; ch<=CHMAX; ch++, pos++ ) {
77       ptop = ( (((typename FormatInfo<T>::PROMOTED)bottom[pos])-((typename FormatInfo<T>::PROMOTED)top[pos]))/2+FormatInfo<T>::HALF );
78       clip( opacity_real*ptop + (1.0f-opacity_real)*bottom[pos], out[pos] );
79       //std::cout<<"  out="<<(int)out[pos]<<std::endl;
80     }
81   }
82 };
83 
84 
85 
86