ResponseTransform.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 #ifndef _PHOTOMETRIC_VIGNETTING_CORRECTION_H
00025 #define _PHOTOMETRIC_VIGNETTING_CORRECTION_H
00026 
00027 #include <vector>
00028 #include <functional>
00029 #include "hugin_config.h"
00030 #include <random>
00031 
00032 #include <vigra/stdimage.hxx>
00033 #include <vigra/numerictraits.hxx>
00034 #include <vigra/array_vector.hxx>
00035 
00036 #include <hugin_math/hugin_math.h>
00037 #include <vigra_ext/lut.h>
00038 #include <vigra_ext/utils.h>
00039 #include <panodata/SrcPanoImage.h>
00040 
00041 
00042 namespace HuginBase { namespace Photometric {
00043     
00044 
00050 template <class VTIn>
00051 class ResponseTransform
00052 {
00053         
00054     public:
00056         typedef typename vigra_ext::ValueTypeTraits<VTIn>::value_type VT1;
00057         
00059         typedef std::vector<double> LUT;
00060 
00061         
00062     public:
00064         ResponseTransform();
00065         
00067         ResponseTransform(const HuginBase::SrcPanoImage & src);
00068         
00070         virtual ~ResponseTransform() {};
00071         
00072     private:
00074         void initWithSrcImg(const HuginBase::SrcPanoImage & src);
00075         
00076         
00077     public:
00079         void setFlatfield(const vigra::FImage * flat)
00080         { m_flatfield = flat; }
00081 
00083         double calcVigFactor(hugin_utils::FDiff2D d) const;
00084 
00085                 void enforceMonotonicity()
00086                 {
00087                         vigra_ext::enforceMonotonicity(m_lutR);
00088                 }
00089 
00091         typename vigra::NumericTraits<VT1>::RealPromote
00092             apply(VT1 v, const hugin_utils::FDiff2D & pos, vigra::VigraTrueType) const;
00093         
00095         typename vigra::NumericTraits<VT1>::RealPromote
00096             apply(VT1 v, const hugin_utils::FDiff2D & pos) const;
00097 
00099         typename vigra::NumericTraits<vigra::RGBValue<VT1> >::RealPromote
00100             apply(vigra::RGBValue<VT1> v, const hugin_utils::FDiff2D & pos, vigra::VigraFalseType) const;
00101         
00103         typename vigra::NumericTraits<vigra::RGBValue<VT1> >::RealPromote
00104             apply(vigra::RGBValue<VT1> v, const hugin_utils::FDiff2D & pos) const;
00105         
00106         
00108         template <class T>
00109         typename vigra::NumericTraits<T>::RealPromote
00110             operator()(T v, const hugin_utils::FDiff2D & pos) const { return apply(v, pos); }
00111 
00112         
00113         
00114     public:
00115             
00116         LUT m_lutR;
00117         double m_radiusScale;
00118         vigra_ext::LUTFunctor<VT1, LUT> m_lutRFunc;
00119         const vigra::FImage * m_flatfield;
00120         double m_srcExposure;
00121         std::vector<double> m_RadialVigCorrCoeff;
00122         hugin_utils::FDiff2D m_RadialVigCorrCenter;
00123         int m_VigCorrMode;
00124         double m_WhiteBalanceRed;
00125         double m_WhiteBalanceBlue;
00126 
00127         HuginBase::SrcPanoImage m_src;
00128 };
00129 
00130 
00136 template <class VTIn, class VTOut>
00137 class InvResponseTransform : public ResponseTransform<VTIn>
00138 {
00139 
00140         typedef ResponseTransform<VTIn> Base;
00141      
00142     public:
00143         typedef typename vigra_ext::ValueTypeTraits<VTIn>::value_type VT1;
00144         typedef typename vigra::NumericTraits<VT1>::RealPromote VTInCompReal;
00145         typedef typename vigra_ext::ValueTypeTraits<VTOut>::value_type dest_type;
00146 
00147         typedef std::vector<double> LUT;
00148         typedef std::vector<dest_type> LUTD;
00149 
00150 
00151     public:
00153         InvResponseTransform();
00154 
00156         InvResponseTransform(const HuginBase::SrcPanoImage & src);
00157         
00159         virtual ~InvResponseTransform() {};
00160         
00161     private:
00163         void init(const HuginBase::SrcPanoImage & src);
00164 
00165         
00166     public:
00168         void setHDROutput(bool hdrMode, double destExposure);
00169         
00171         void setOutput(double destExposure, const LUTD & destLut, double scale);
00172         
00173                 void enforceMonotonicity()
00174                 {
00175                     if (!Base::m_lutR.empty()) {
00176                                 vigra_ext::enforceMonotonicity(Base::m_lutR);
00177                 invertLUT();
00178                         m_lutRInvFunc = vigra_ext::LUTFunctor<VT1, LUT>(m_lutRInv);
00179                         }
00180                 }
00181 
00188         double dither(const double &v) const;
00189         
00191         typename vigra::NumericTraits<dest_type>::RealPromote
00192             apply(VT1 v, const hugin_utils::FDiff2D & pos, vigra::VigraTrueType) const;
00193         
00195         typename vigra::NumericTraits<dest_type>::RealPromote
00196             apply(VT1 v, const hugin_utils::FDiff2D & pos) const;
00197         
00199         typename vigra::NumericTraits<vigra::RGBValue<VT1> >::RealPromote
00200             apply(vigra::RGBValue<VT1> v, const hugin_utils::FDiff2D & pos, vigra::VigraFalseType) const;
00201         
00203         typename vigra::NumericTraits<vigra::RGBValue<VT1> >::RealPromote
00204             apply(vigra::RGBValue<VT1> v, const hugin_utils::FDiff2D & pos) const;
00205         
00206         
00208         template <class T>
00209         typename vigra::NumericTraits<T>::RealPromote 
00210             operator()(T v, const hugin_utils::FDiff2D & pos) const
00211         {
00212             return apply(v, pos);
00213         }
00214         
00216         template <class T, class A>
00217         A hdrWeight(T v, A a) const
00218         {
00219             if (m_hdrMode && a > 0) {
00220                 return vigra::NumericTraits<A>::fromRealPromote(vigra_ext::getMaxComponent(v)/(double)vigra_ext::LUTTraits<T>::max()*vigra_ext::LUTTraits<A>::max());
00221             } else {
00222                 return a;
00223             }
00224         }
00225         
00226         void emitGLSL(std::ostringstream& oss, std::vector<double>& invLut, std::vector<double>& destLut) const;
00227 
00228     private:
00229         void invertLUT()
00230         {
00231             m_lutRInv.clear();
00232             if (!Base::m_lutR.empty())
00233             {
00234                 m_lutRInv.reserve(Base::m_lutR.size());
00235                 vigra_ext::InvLUTFunctor<VT1, LUT> slowRInvFunc = vigra_ext::InvLUTFunctor<VT1, LUT>(Base::m_lutR);
00236                 for (int i = 0; i < Base::m_lutR.size(); i++)
00237                 {
00238                     const double f = static_cast<double>(i) / (Base::m_lutR.size() - 1);
00239                     m_lutRInv.push_back(slowRInvFunc(f));
00240                 };
00241             };
00242         };
00243     protected: // needs be public?
00244         LUT m_lutRInv;
00245         vigra_ext::LUTFunctor<VT1, LUT> m_lutRInvFunc;
00246         LUTD m_destLut;
00247         vigra_ext::LUTFunctor<VTInCompReal, LUTD> m_destLutFunc;
00248         double m_destExposure;
00249         bool m_hdrMode;
00250         double m_intScale;
00251         
00252     private:
00253         std::mt19937 Twister;
00254 };
00255 
00256 
00257 }} // namespace
00258 
00259 
00260 
00261 
00262 // templated implementation ----------------------------------------------------
00263 
00264 
00265 namespace HuginBase { namespace Photometric {
00266 
00267 
00268 template <class VTIn>
00269 ResponseTransform<VTIn>::ResponseTransform()
00270 {
00271     m_radiusScale=0;
00272     m_flatfield = 0;
00273 }
00274 
00275 template <class VTIn>
00276 ResponseTransform<VTIn>::ResponseTransform(const HuginBase::SrcPanoImage & src)
00277 {
00278     initWithSrcImg(src);
00279 }
00280 
00281 
00282 template <class VTIn>
00283 void ResponseTransform<VTIn>::initWithSrcImg(const HuginBase::SrcPanoImage & src)
00284 {
00285 //        DEBUG_DEBUG(" " << src.getFilename() << ": resp type:" <<   src.getResponseType() << " expo: " << src.getExposure());
00286     m_flatfield = 0;
00287     m_src = src;
00288     m_radiusScale = 1.0/sqrt(m_src.getSize().x/2.0*m_src.getSize().x/2.0 + m_src.getSize().y/2.0*m_src.getSize().y/2.0);
00289     m_srcExposure = m_src.getExposure();
00290     //save some variables, direct access is slower since merging of layout mode
00291     m_RadialVigCorrCoeff = m_src.getRadialVigCorrCoeff();
00292     m_RadialVigCorrCenter = m_src.getRadialVigCorrCenter();
00293     m_VigCorrMode = m_src.getVigCorrMode();
00294     m_WhiteBalanceRed = m_src.getWhiteBalanceRed();
00295     m_WhiteBalanceBlue = m_src.getWhiteBalanceBlue();
00296 
00297     // build response function lookup table, if required
00298     if (m_src.getResponseType() != HuginBase::SrcPanoImage::RESPONSE_LINEAR) {
00299         // scale lut to right byte size..
00300         double lutLenD = vigra_ext::LUTTraits<VT1>::max();
00301         // maximum lut size: 10 bits. Should be enought for most purposes.
00302         // and fit into the L1 cache.
00303         size_t lutLen=0;
00304         if (lutLenD == 1.0 || (lutLenD > ((1<<10)-1))) {
00305             lutLen = (1<<10);
00306         } else {
00307             lutLen = size_t(lutLenD) + 1;
00308         }
00309         switch (m_src.getResponseType()) 
00310         {
00311             case HuginBase::SrcPanoImage::RESPONSE_EMOR:
00312                 {
00313                 if (lutLen == 1<<10) {
00314                     vigra_ext::EMoR::createEMoRLUT(m_src.getEMoRParams(), m_lutR);
00315                 } else {
00316                     // resize lut, if size doesn't fit
00317                     LUT tmp;
00318                     vigra_ext::EMoR::createEMoRLUT(m_src.getEMoRParams(), tmp);
00319                     m_lutR.resize(lutLen);
00320                     vigra_ext::resizeLUT(tmp, m_lutR);
00321                 }
00322                 }
00323                 break;
00324             case HuginBase::SrcPanoImage::RESPONSE_GAMMA:
00325                 m_lutR.resize(lutLen);
00326                 vigra_ext::createGammaLUT(m_src.getGamma(), m_lutR);
00327                 break;
00328             default:
00329                 // response curve is stored in src image
00330                 vigra_fail("ResponseTransform: unknown response function type");
00331                 break;
00332         }
00333         m_lutRFunc = vigra_ext::LUTFunctor<VT1, LUT>(m_lutR);
00334     }
00335 }
00336 
00337 
00338 template <class VTIn>
00339 double ResponseTransform<VTIn>::calcVigFactor(hugin_utils::FDiff2D d) const
00340 {
00341     if (m_VigCorrMode & HuginBase::SrcPanoImage::VIGCORR_RADIAL) {
00342         d = d - m_RadialVigCorrCenter;
00343         // scale according to 
00344         d *= m_radiusScale;
00345         double vig = m_RadialVigCorrCoeff[0];
00346         double r2 = d.x*d.x + d.y*d.y;
00347         double r = r2;
00348         for (unsigned int i = 1; i < 4; i++) {
00349             vig += m_RadialVigCorrCoeff[i] * r;
00350             r *= r2;
00351         }
00352         return vig;
00353     } else if (m_VigCorrMode & HuginBase::SrcPanoImage::VIGCORR_FLATFIELD) {
00354         // TODO: implement flatfield
00355         if (m_flatfield) {
00356             int x = std::min(std::max(hugin_utils::roundi(d.x),0), static_cast<int>(m_flatfield->width()-1));
00357             int y = std::min(std::max(hugin_utils::roundi(d.y),0), static_cast<int>(m_flatfield->height()-1));
00358             return (*m_flatfield)(x,y);
00359         } else {
00360             return 1;
00361         }
00362     } else {
00363         return 1;
00364     }
00365 }
00366 
00367 
00368 template <class VTIn>
00369 typename vigra::NumericTraits<typename ResponseTransform<VTIn>::VT1>::RealPromote
00370 ResponseTransform<VTIn>::apply(typename ResponseTransform<VTIn>::VT1 v, const hugin_utils::FDiff2D & pos, vigra::VigraTrueType) const
00371 {
00372     typename vigra::NumericTraits<VT1>::RealPromote ret = v;
00373     // first, apply vignetting
00374 
00375     ret = ret*calcVigFactor(pos)*m_srcExposure;
00376     if (!m_lutR.empty()) {
00377         return m_lutRFunc(ret);
00378     } else {
00379         return ret;
00380     }
00381 }
00382 
00383 template <class VTIn>
00384 typename vigra::NumericTraits<vigra::RGBValue<typename ResponseTransform<VTIn>::VT1> >::RealPromote
00385 ResponseTransform<VTIn>::apply(vigra::RGBValue<typename ResponseTransform<VTIn>::VT1> v, const hugin_utils::FDiff2D & pos, vigra::VigraFalseType) const
00386 {
00387     typename vigra::NumericTraits<vigra::RGBValue<VT1> >::RealPromote ret = v;
00388     // first, apply vignetting
00389     double common = calcVigFactor(pos)*m_srcExposure;
00390     ret = ret*common;
00391     // apply white balance factors
00392     ret.red() = ret.red() * m_WhiteBalanceRed;
00393     ret.blue() = ret.blue() * m_WhiteBalanceBlue;
00394     // apply response curve
00395     if (!m_lutR.empty()) {
00396         return m_lutRFunc(ret);
00397     } else {
00398         return ret;
00399     }
00400 }
00401 
00402 template <class VTIn>
00403 typename vigra::NumericTraits<typename ResponseTransform<VTIn>::VT1>::RealPromote
00404 ResponseTransform<VTIn>::apply(typename ResponseTransform<VTIn>::VT1 v, const hugin_utils::FDiff2D & pos) const
00405 {
00406     typedef typename vigra::NumericTraits<VT1>::isScalar is_scalar;
00407     return apply(v, pos, is_scalar());
00408 }
00409 
00410 template <class VTIn>
00411 typename vigra::NumericTraits<vigra::RGBValue<typename ResponseTransform<VTIn>::VT1> >::RealPromote
00412 ResponseTransform<VTIn>::apply(vigra::RGBValue<typename ResponseTransform<VTIn>::VT1> v, const hugin_utils::FDiff2D & pos) const
00413 {
00414     typedef typename vigra::NumericTraits<vigra::RGBValue<VT1> >::isScalar is_scalar;
00415     return apply(v, pos, is_scalar());
00416 }
00417 
00418 template <class VTIn, class VTOut>
00419 InvResponseTransform<VTIn,VTOut>::InvResponseTransform()
00420 {
00421     m_destExposure = 1.0;
00422     m_hdrMode = false;
00423     m_intScale = 1;
00424 }
00425 
00426 template <class VTIn, class VTOut>
00427 InvResponseTransform<VTIn,VTOut>::InvResponseTransform(const HuginBase::SrcPanoImage & src)
00428 : Base(src), m_hdrMode(false)
00429 {
00430     m_destExposure = 1.0;
00431     m_intScale = 1;
00432     if (!Base::m_lutR.empty()) {
00433         invertLUT();
00434         m_lutRInvFunc = vigra_ext::LUTFunctor<VT1, LUT>(m_lutRInv);
00435     }
00436 }
00437 
00438 template <class VTIn, class VTOut>
00439 void InvResponseTransform<VTIn,VTOut>::init(const HuginBase::SrcPanoImage & src)
00440 {
00441     m_destExposure = 1.0;
00442     m_intScale = 1;
00443     Base::init(src);
00444     if (!Base::m_lutR.empty()) {
00445         invertLUT();
00446         m_lutRInvFunc = vigra_ext::LUTFunctor<VT1, LUT>(m_lutRInv);
00447     }
00448 }
00449 
00450 template <class VTIn, class VTOut>
00451 void InvResponseTransform<VTIn,VTOut>::setHDROutput(bool hdrMode, double destExposure)
00452 {
00453     m_hdrMode = hdrMode;
00454     m_intScale = 1;
00455     m_destExposure = destExposure;
00456     m_destLut.clear();
00457 }
00458 
00459 template <class VTIn, class VTOut>
00460 void InvResponseTransform<VTIn,VTOut>::setOutput(double destExposure, const LUTD & destLut, double scale)
00461 {
00462     m_hdrMode = false;
00463     m_destLut = destLut;
00464     if (!m_destLut.empty()) {
00465         m_destLutFunc = vigra_ext::LUTFunctor<VTInCompReal, LUTD>(m_destLut);
00466     }
00467     m_destExposure = destExposure;
00468     m_intScale = scale;
00469 }
00470 
00471 
00472 template <class VTIn, class VTOut>
00473 double InvResponseTransform<VTIn,VTOut>::dither(const double &v) const
00474 {
00475     std::mt19937 &mt = const_cast<std::mt19937 &>(Twister);
00476     double vFraction = v - floor(v);
00477     // Only dither values within a certain range of the rounding cutoff point.
00478     if (vFraction > 0.25 && vFraction <= 0.75) {
00479         // Generate a random number between 0 and 0.5.
00480         double random = 0.5 * (double)mt() / UINT_MAX;
00481         if ((vFraction - 0.25) >= random) {
00482             return ceil(v);
00483         } else {
00484             return floor(v);
00485         }
00486     } else {
00487         return v;
00488     }
00489 }
00490 
00491 
00492 template <class VTIn, class VTOut>
00493 typename vigra::NumericTraits<typename InvResponseTransform<VTIn,VTOut>::dest_type>::RealPromote
00494 InvResponseTransform<VTIn,VTOut>::apply(VT1 v, const hugin_utils::FDiff2D & pos, vigra::VigraTrueType) const
00495 {
00496     // inverse response
00497     typename vigra::NumericTraits<VT1>::RealPromote ret(v);
00498     if (!Base::m_lutR.empty()) {
00499         ret = m_lutRInvFunc(v);
00500     } else {
00501         ret /= vigra_ext::LUTTraits<VT1>::max();
00502     }
00503     // inverse vignetting and exposure
00504     ret *= m_destExposure / (Base::calcVigFactor(pos) * Base::m_srcExposure);
00505     // apply output transform if required
00506     if (!m_destLut.empty()) {
00507         ret = m_destLutFunc(ret);
00508     }
00509     // dither all integer images
00510     if ( m_intScale > 1) {
00511         return dither(ret * m_intScale);
00512     }
00513     return ret;
00514 }
00515 
00516 
00517 template <class VTIn, class VTOut>
00518 typename vigra::NumericTraits<vigra::RGBValue<typename InvResponseTransform<VTIn,VTOut>::VT1> >::RealPromote
00519 InvResponseTransform<VTIn,VTOut>::apply(vigra::RGBValue<VT1> v, const hugin_utils::FDiff2D & pos, vigra::VigraFalseType) const
00520 {
00521     typename vigra::NumericTraits<vigra::RGBValue<VT1> >::RealPromote ret(v);
00522     if (!Base::m_lutR.empty()) {
00523         ret = m_lutRInvFunc(v);
00524     } else {
00525         ret /= vigra_ext::LUTTraits<VT1>::max();
00526     }
00527 
00528     // inverse vignetting and exposure
00529     ret *= m_destExposure/(Base::calcVigFactor(pos)*Base::m_srcExposure);
00530     ret.red() /= Base::m_WhiteBalanceRed;
00531     ret.blue() /= Base::m_WhiteBalanceBlue;
00532     // apply output transform if required
00533     if (!m_destLut.empty()) {
00534         ret = m_destLutFunc(ret);
00535     }
00536     // dither 8 bit images.
00537     if (m_intScale > 1) {
00538         for (size_t i=0; i < 3; i++) {
00539             ret[i] = dither(ret[i] * m_intScale);
00540         }
00541     }
00542     return ret;
00543 }
00544 
00545 
00546 template <class VTIn, class VTOut>
00547 typename vigra::NumericTraits<typename InvResponseTransform<VTIn,VTOut>::dest_type>::RealPromote
00548 InvResponseTransform<VTIn,VTOut>::apply(VT1 v, const hugin_utils::FDiff2D & pos) const
00549 {
00550     typedef typename vigra::NumericTraits<VT1>::isScalar is_scalar;
00551     return apply(v, pos, is_scalar());
00552 }
00553 
00554 template <class VTIn, class VTOut>
00555 typename vigra::NumericTraits<vigra::RGBValue<typename InvResponseTransform<VTIn,VTOut>::VT1> >::RealPromote
00556 InvResponseTransform<VTIn,VTOut>::apply(vigra::RGBValue<VT1> v, const hugin_utils::FDiff2D & pos) const
00557 {
00558     typedef typename vigra::NumericTraits<vigra::RGBValue<VT1> >::isScalar is_scalar;
00559     return apply(v, pos, is_scalar());
00560 }
00561 
00562 template <class VTIn, class VTOut>
00563 void
00564 InvResponseTransform<VTIn,VTOut>::emitGLSL(std::ostringstream& oss, std::vector<double>& invLut, std::vector<double>& destLut) const
00565 {
00566     invLut = m_lutRInv;
00567     destLut = m_destLut;
00568 
00569     const double invLutSize = Base::m_lutR.size();
00570     const double pixelMax = vigra_ext::LUTTraits<VT1>::max();
00571     const double destLutSize = m_destLut.size();
00572 
00573     oss << "    // invLutSize = " << invLutSize << endl
00574         << "    // pixelMax = " << pixelMax << endl
00575         << "    // destLutSize = " << destLutSize << endl
00576         << "    // destExposure = " << m_destExposure << endl
00577         << "    // srcExposure = " << Base::m_srcExposure << endl
00578         << "    // whiteBalanceRed = " << Base::m_src.getWhiteBalanceRed() << endl
00579         << "    // whiteBalanceBlue = " << Base::m_src.getWhiteBalanceBlue() << endl;
00580 
00581     if (!Base::m_lutR.empty()) {
00582         oss << "    p.rgb = p.rgb * " << (invLutSize - 1.0) << ";" << endl
00583             << "    vec2 invR = texture2DRect(InvLutTexture, vec2(p.r, 0.0)).sq;" << endl
00584             << "    vec2 invG = texture2DRect(InvLutTexture, vec2(p.g, 0.0)).sq;" << endl
00585             << "    vec2 invB = texture2DRect(InvLutTexture, vec2(p.b, 0.0)).sq;" << endl
00586             << "    vec3 invX = vec3(invR.x, invG.x, invB.x);" << endl
00587             << "    vec3 invY = vec3(invR.y, invG.y, invB.y);" << endl
00588             << "    vec3 invA = fract(p.rgb);" << endl
00589             << "    p.rgb = mix(invX, invY, invA);" << endl;
00590     }
00591 
00592     if (Base::m_src.getVigCorrMode() & HuginBase::SrcPanoImage::VIGCORR_RADIAL) {
00593         oss << "    // VigCorrMode=VIGCORR_RADIAL" << endl
00594             << "    float vig = 1.0;" << endl
00595             << "    {" << endl
00596             << "        vec2 vigCorrCenter = vec2(" << Base::m_src.getRadialVigCorrCenter().x << ", "
00597             << Base::m_src.getRadialVigCorrCenter().y << ");" << endl
00598             << "        float radiusScale=" << Base::m_radiusScale << ";" << endl
00599             << "        float radialVigCorrCoeff0 = " << Base::m_src.getRadialVigCorrCoeff()[0] << ";" << endl
00600             << "        float radialVigCorrCoeff1 = " << Base::m_src.getRadialVigCorrCoeff()[1] << ";" << endl
00601             << "        float radialVigCorrCoeff2 = " << Base::m_src.getRadialVigCorrCoeff()[2] << ";" << endl
00602             << "        float radialVigCorrCoeff3 = " << Base::m_src.getRadialVigCorrCoeff()[3] << ";" << endl
00603             << "        vec2 src = texture2DRect(CoordTexture, gl_TexCoord[0].st).sq;" << endl
00604             << "        vec2 d = src - vigCorrCenter;" << endl
00605             << "        d *= radiusScale;" << endl
00606             << "        vig = radialVigCorrCoeff0;" << endl
00607             << "        float r2 = dot(d, d);" << endl
00608             << "        float r = r2;" << endl
00609             << "        vig += radialVigCorrCoeff1 * r;" << endl
00610             << "        r *= r2;" << endl
00611             << "        vig += radialVigCorrCoeff2 * r;" << endl
00612             << "        r *= r2;" << endl
00613             << "        vig += radialVigCorrCoeff3 * r;" << endl
00614             << "    }" << endl;
00615     } else if (Base::m_src.getVigCorrMode() & HuginBase::SrcPanoImage::VIGCORR_FLATFIELD) {
00616         oss << "    // VigCorrMode=VIGCORR_FLATFIELD" << endl
00617             << "    float vig = 1.0;" << endl;
00618     } else {
00619         oss << "    // VigCorrMode=none" << endl
00620             << "    float vig = 1.0;" << endl;
00621     }
00622 
00623     oss << "    vec3 exposure_whitebalance = vec3("
00624         << (m_destExposure / (Base::m_srcExposure * Base::m_src.getWhiteBalanceRed())) << ", "
00625         << (m_destExposure / (Base::m_srcExposure)) << ", "
00626         << (m_destExposure / (Base::m_srcExposure * Base::m_src.getWhiteBalanceBlue())) << ");" << endl
00627         << "    p.rgb = (p.rgb * exposure_whitebalance) / vig;" << endl;
00628 
00629     if (!m_destLut.empty()) {
00630         oss << "    p.rgb = p.rgb * " << (destLutSize - 1.0) << ";" << endl
00631             << "    vec2 destR = texture2DRect(DestLutTexture, vec2(p.r, 0.0)).sq;" << endl
00632             << "    vec2 destG = texture2DRect(DestLutTexture, vec2(p.g, 0.0)).sq;" << endl
00633             << "    vec2 destB = texture2DRect(DestLutTexture, vec2(p.b, 0.0)).sq;" << endl
00634             << "    vec3 destX = vec3(destR.x, destG.x, destB.x);" << endl
00635             << "    vec3 destY = vec3(destR.y, destG.y, destB.y);" << endl
00636             << "    vec3 destA = fract(p.rgb);" << endl
00637             << "    p.rgb = mix(destX, destY, destA);" << endl;
00638     }
00639 
00640     // alpha hdrWeight
00641     if (m_hdrMode) {
00642         oss << "    p.a = max(p.r, max(p.g, p.b));" << endl;
00643     }
00644 }
00645 
00646 }} // namespace
00647 
00648 #endif // _H

Generated on 26 Jun 2017 for Hugintrunk by  doxygen 1.4.7