"Fossies" - the Fresh Open Source Software Archive

Member "darktable-3.6.1/data/kernels/atrous.cl" (10 Sep 2021, 2824 Bytes) of package /linux/misc/darktable-3.6.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lisp source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2     This file is part of darktable,
    3     copyright (c) 2009--2010 johannes hanika.
    4 
    5     darktable is free software: you can redistribute it and/or modify
    6     it under the terms of the GNU General Public License as published by
    7     the Free Software Foundation, either version 3 of the License, or
    8     (at your option) any later version.
    9 
   10     darktable is distributed in the hope that it will be useful,
   11     but WITHOUT ANY WARRANTY; without even the implied warranty of
   12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13     GNU General Public License for more details.
   14 
   15     You should have received a copy of the GNU General Public License
   16     along with darktable.  If not, see <http://www.gnu.org/licenses/>.
   17 */
   18 
   19 #include "common.h"
   20 
   21 
   22 
   23 float4
   24 weight(const float4 c1, const float4 c2, const float sharpen)
   25 {
   26   // native_exp is faster than the cpu floating point aliasing hack:
   27   const float wc = native_exp(-((c1.y - c2.y)*(c1.y - c2.y) + (c1.z - c2.z)*(c1.z - c2.z)) * sharpen);
   28   const float wl = native_exp(- (c1.x - c2.x)*(c1.x - c2.x) * sharpen);
   29   return (float4)(wl, wc, wc, 1.0f);
   30 }
   31 
   32 
   33 __kernel void
   34 eaw_decompose (__read_only image2d_t in, __write_only image2d_t coarse, __write_only image2d_t detail,
   35      const int width, const int height, const int scale, const float sharpen, global const float *filter)
   36 {
   37   const int x = get_global_id(0);
   38   const int y = get_global_id(1);
   39 
   40   if(x >= width || y >= height) return;
   41 
   42   const int mult = 1<<scale;
   43 
   44   float4 pixel = read_imagef(in, sampleri, (int2)(x, y));
   45   float4 sum = (float4)(0.0f);
   46   float4 wgt = (float4)(0.0f);
   47   for(int j=0;j<5;j++) for(int i=0;i<5;i++)
   48   {
   49     int xx = mad24(mult, i - 2, x);
   50     int yy = mad24(mult, j - 2, y);
   51     int k  = mad24(j, 5, i);
   52 
   53     float4 px = read_imagef(in, sampleri, (int2)(xx, yy));
   54     float4 w = filter[k]*weight(pixel, px, sharpen);
   55 
   56     sum += w*px;
   57     wgt += w;
   58   }
   59   sum /= wgt;
   60   sum.w = pixel.w;
   61 
   62   write_imagef (detail, (int2)(x, y), pixel - sum);
   63   write_imagef (coarse, (int2)(x, y), sum);
   64 }
   65 
   66 
   67 __kernel void
   68 eaw_synthesize (__write_only image2d_t out, __read_only image2d_t coarse, __read_only image2d_t detail,
   69      const int width, const int height,
   70      const float t0, const float t1, const float t2, const float t3,
   71      const float b0, const float b1, const float b2, const float b3)
   72 {
   73   const int x = get_global_id(0);
   74   const int y = get_global_id(1);
   75 
   76   if(x >= width || y >= height) return;
   77 
   78   const float4 threshold = (float4)(t0, t1, t2, t3);
   79   const float4 boost     = (float4)(b0, b1, b2, b3);
   80   float4 c = read_imagef(coarse, sampleri, (int2)(x, y));
   81   float4 d = read_imagef(detail, sampleri, (int2)(x, y));
   82   float4 amount = copysign(max((float4)(0.0f), fabs(d) - threshold), d);
   83   float4 sum = c + boost*amount;
   84   sum.w = c.w;
   85   write_imagef (out, (int2)(x, y), sum);
   86 }
   87