"Fossies" - the Fresh Open Source Software Archive

Member "darktable-2.6.3/src/common/interpolation.h" (20 Oct 2019, 8334 Bytes) of package /linux/misc/darktable-2.6.3.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 "interpolation.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.6.3_vs_3.0.0.rc0.

    1 /* --------------------------------------------------------------------------
    2     This file is part of darktable,
    3     copyright (c) 2012 Edouard Gomez <ed.gomez@free.fr>
    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 #pragma once
   20 
   21 #include "common/opencl.h"
   22 #include "develop/pixelpipe_hb.h"
   23 
   24 #if defined(__SSE__)
   25 #include <xmmintrin.h>
   26 #endif
   27 
   28 /** Available interpolations */
   29 enum dt_interpolation_type
   30 {
   31   DT_INTERPOLATION_FIRST = 0,                         /**< Helper for easy iteration on interpolators */
   32   DT_INTERPOLATION_BILINEAR = DT_INTERPOLATION_FIRST, /**< Bilinear interpolation (aka tent filter) */
   33   DT_INTERPOLATION_BICUBIC,                           /**< Bicubic interpolation (with -0.5 parameter) */
   34   DT_INTERPOLATION_LANCZOS2,                          /**< Lanczos interpolation (with 2 lobes) */
   35   DT_INTERPOLATION_LANCZOS3,                          /**< Lanczos interpolation (with 3 lobes) */
   36   DT_INTERPOLATION_LAST,                              /**< Helper for easy iteration on interpolators */
   37   DT_INTERPOLATION_DEFAULT = DT_INTERPOLATION_BILINEAR,
   38   DT_INTERPOLATION_USERPREF /**< can be specified so that user setting is chosen */
   39 };
   40 
   41 /** Interpolation function */
   42 typedef float (*dt_interpolation_func)(float width, float t);
   43 
   44 #if defined(__SSE2__)
   45 /** Interpolation function (SSE) */
   46 typedef __m128 (*dt_interpolation_sse_func)(__m128 width, __m128 t);
   47 #endif
   48 
   49 /** Interpolation structure */
   50 struct dt_interpolation
   51 {
   52   enum dt_interpolation_type id;     /**< Id such as defined by the dt_interpolation_type */
   53   const char *name;                  /**< internal name  */
   54   int width;                         /**< Half width of its kernel support */
   55   dt_interpolation_func func;        /**< Kernel function */
   56 #if defined(__SSE2__)
   57   dt_interpolation_sse_func funcsse; /**< Kernel function (four params a time) */
   58 #endif
   59 };
   60 
   61 /** Compute a single interpolated sample.
   62  *
   63  * This function computes a single interpolated sample. Implied costs are:
   64  * <ul>
   65  * <li>Horizontal filtering kernel computation</li>
   66  * <li>Vertical filtering kernel computation</li>
   67  * <li>Sample computation</li>
   68  * </ul>
   69  *
   70  * @param in Input image
   71  * @param itor interpolator to be used
   72  * @param x X-Coordinate of the requested sample
   73  * @param y Y-Coordinate of the requested sample
   74  * @param width Width of the input image
   75  * @param height Width of the input image
   76  * @param samplestride Stride in bytes for a sample
   77  * @param linestride Stride in bytes for complete line
   78  *
   79  * @return computed sample
   80  */
   81 float dt_interpolation_compute_sample(const struct dt_interpolation *itor, const float *in, const float x,
   82                                       const float y, const int width, const int height,
   83                                       const int samplestride, const int linestride);
   84 
   85 /** Compute an interpolated 4 component pixel.
   86  *
   87  * This function computes a full 4 component pixel. This helps a bit speedwise
   88  * as interpolation coordinates are supposed to be the same for all components.
   89  * Thus we can share horizontal and vertical interpolation kernels across all
   90  * components
   91  *
   92  * NB: a pixel is to be four floats big in stride
   93  *
   94  * @param in Pointer to the input image
   95  * @param out Pointer to the output sample
   96  * @param itor interpolator to be used
   97  * @param x X-Coordinate of the requested sample
   98  * @param y Y-Coordinate of the requested sample
   99  * @param width Width of the input image
  100  * @param height Width of the input image
  101  * @param linestride Stride in bytes for complete line
  102  *
  103  */
  104 void dt_interpolation_compute_pixel4c(const struct dt_interpolation *itor, const float *in, float *out,
  105                                       const float x, const float y, const int width, const int height,
  106                                       const int linestride);
  107 
  108 /** Get an interpolator from type
  109  * @param type Interpolator to search for
  110  * @return requested interpolator or default if not found (this function can't fail)
  111  */
  112 const struct dt_interpolation *dt_interpolation_new(enum dt_interpolation_type type);
  113 
  114 /** Image resampler.
  115  *
  116  * Resamples the image "in" to "out" according to roi values. Here is the
  117  * exact contract:
  118  * <ul>
  119  * <li>The resampling is isotropic (same for both x and y directions),
  120  * represented by roi_out->scale</li>
  121  * <li>It generates roi_out->width samples horizontally whose positions span
  122  * from roi_out->x to roi_out->x + roi_out->width</li>
  123  * <li>It generates roi_out->height samples vertically whose positions span
  124  * from roi_out->y to roi_out->y + roi_out->height</li>
  125  * </ul>
  126  *
  127  * @param itor [in] Interpolator to use
  128  * @param out [out] Will hold the resampled image
  129  * @param roi_out [in] Region of interest of the resampled image
  130  * @param out_stride [in] Output line stride in <strong>bytes</strong>
  131  * @param in [in] Will hold the resampled image
  132  * @param roi_in [in] Region of interest of the original image
  133  * @param in_stride [in] Input line stride in <strong>bytes</strong>
  134  */
  135 void dt_interpolation_resample(const struct dt_interpolation *itor, float *out,
  136                                const dt_iop_roi_t *const roi_out, const int32_t out_stride,
  137                                const float *const in, const dt_iop_roi_t *const roi_in,
  138                                const int32_t in_stride);
  139 
  140 void dt_interpolation_resample_roi(const struct dt_interpolation *itor, float *out,
  141                                    const dt_iop_roi_t *const roi_out, const int32_t out_stride,
  142                                    const float *const in, const dt_iop_roi_t *const roi_in,
  143                                    const int32_t in_stride);
  144 
  145 #ifdef HAVE_OPENCL
  146 typedef struct dt_interpolation_cl_global_t
  147 {
  148   int kernel_interpolation_resample;
  149 } dt_interpolation_cl_global_t;
  150 
  151 dt_interpolation_cl_global_t *dt_interpolation_init_cl_global(void);
  152 
  153 void dt_interpolation_free_cl_global(dt_interpolation_cl_global_t *g);
  154 
  155 
  156 /** Image resampler OpenCL version.
  157  *
  158  * Resamples the image "in" to "out" according to roi values. Here is the
  159  * exact contract:
  160  * <ul>
  161  * <li>The resampling is isotropic (same for both x and y directions),
  162  * represented by roi_out->scale</li>
  163  * <li>It generates roi_out->width samples horizontally whose positions span
  164  * from roi_out->x to roi_out->x + roi_out->width</li>
  165  * <li>It generates roi_out->height samples vertically whose positions span
  166  * from roi_out->y to roi_out->y + roi_out->height</li>
  167  * </ul>
  168  *
  169  * @param itor [in] Interpolator to use
  170  * @param devid [in] The device to run on
  171  * @param dev_out [out] Will hold the resampled image
  172  * @param roi_out [in] Region of interest of the resampled image
  173  * @param out_stride [in] Output line stride in <strong>bytes</strong>
  174  * @param dev_in [in] Will hold the resampled image
  175  * @param roi_in [in] Region of interest of the original image
  176  * @param in_stride [in] Input line stride in <strong>bytes</strong>
  177  */
  178 int dt_interpolation_resample_cl(const struct dt_interpolation *itor, int devid, cl_mem dev_out,
  179                                  const dt_iop_roi_t *const roi_out, cl_mem dev_in,
  180                                  const dt_iop_roi_t *const roi_in);
  181 
  182 int dt_interpolation_resample_roi_cl(const struct dt_interpolation *itor, int devid, cl_mem dev_out,
  183                                      const dt_iop_roi_t *const roi_out, cl_mem dev_in,
  184                                      const dt_iop_roi_t *const roi_in);
  185 #endif
  186 
  187 // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
  188 // vim: shiftwidth=2 expandtab tabstop=2 cindent
  189 // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;