"Fossies" - the Fresh Open Source Software Archive

Member "rawtherapee-5.7/rtengine/iplocalcontrast.cc" (10 Sep 2019, 2137 Bytes) of package /linux/misc/rawtherapee-5.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "iplocalcontrast.cc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.6_vs_5.7.

    1 /* -*- C++ -*-
    2  *
    3  *  This file is part of RawTherapee.
    4  *
    5  *  Ported from G'MIC by Alberto Griggio <alberto.griggio@gmail.com>
    6  *
    7  *  The original implementation in G'MIC was authored by Arto Huotari, and was
    8  *  released under the CeCILL free software license (see
    9  *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.html)
   10  *
   11  *  RawTherapee is free software: you can redistribute it and/or modify
   12  *  it under the terms of the GNU General Public License as published by
   13  *  the Free Software Foundation, either version 3 of the License, or
   14  *  (at your option) any later version.
   15  *
   16  *  RawTherapee is distributed in the hope that it will be useful,
   17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19  *  GNU General Public License for more details.
   20  *
   21  *  You should have received a copy of the GNU General Public License
   22  *  along with RawTherapee.  If not, see <https://www.gnu.org/licenses/>.
   23  */
   24 
   25 #ifdef _OPENMP
   26 #include <omp.h>
   27 #endif
   28 
   29 #include "array2D.h"
   30 #include "gauss.h"
   31 #include "improcfun.h"
   32 #include "procparams.h"
   33 
   34 namespace rtengine {
   35 
   36 void ImProcFunctions::localContrast(LabImage *lab)
   37 {
   38     if (!params->localContrast.enabled) {
   39         return;
   40     }
   41 
   42     const int width = lab->W;
   43     const int height = lab->H;
   44     const float a = params->localContrast.amount;
   45     const float dark = params->localContrast.darkness;
   46     const float light = params->localContrast.lightness;
   47     array2D<float> buf(width, height);
   48     const float sigma = params->localContrast.radius / scale;
   49 
   50 #ifdef _OPENMP
   51     #pragma omp parallel if(multiThread)
   52 #endif
   53     gaussianBlur(lab->L, buf, width, height, sigma);
   54 
   55 #ifdef _OPENMP
   56     #pragma omp parallel for if(multiThread)
   57 #endif
   58     for (int y = 0; y < height; ++y) {
   59         for (int x = 0; x < width; ++x) {
   60             float bufval = (lab->L[y][x] - buf[y][x]) * a;
   61 
   62             if (dark != 1 || light != 1) {
   63                 bufval *= (bufval > 0.f) ? light : dark;
   64             }
   65 
   66             lab->L[y][x] = std::max(0.0001f, lab->L[y][x] + bufval);
   67         }
   68     }
   69 }
   70 
   71 } // namespace rtengine