whitebalance.c 2.82 KB
Newer Older
1 2 3 4 5
/* This file is an image processing operation for GEGL
 *
 * GEGL is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
6
 * version 3 of the License, or (at your option) any later version.
7 8 9 10 11 12 13
 *
 * GEGL is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
14
 * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
15 16 17 18
 *
 * Copyright 2006 Øyvind Kolås <pippin@gimp.org>
 */

19 20
#ifdef GEGL_CHANT_PROPERTIES

21 22 23 24 25
gegl_chant_double (high_a_delta, "High a delta", -2.0, 2.0, 0.0, "")
gegl_chant_double (high_b_delta, "High b delta", -2.0, 2.0, 0.0, "")
gegl_chant_double (low_a_delta,  "Low a delta",  -2.0, 2.0, 0.0, "")
gegl_chant_double (low_b_delta,  "Low b delta",  -2.0, 2.0, 0.0, "")
gegl_chant_double (saturation,   "Saturation",   -3.0, 3.0, 1.0, "")
26 27 28

#else

29 30
#define GEGL_CHANT_TYPE_POINT_FILTER
#define GEGL_CHANT_C_FILE       "whitebalance.c"
31

32
#include "gegl-chant.h"
33

34
static void prepare (GeglOperation *operation)
35
{
36 37 38
  Babl *format = babl_format ("Y'CbCrA float");
  gegl_operation_set_format (operation, "input", format);
  gegl_operation_set_format (operation, "output", format);
39 40 41 42 43 44 45 46 47 48 49
}

/* GeglOperationPointFilter gives us a linear buffer to operate on
 * in our requested pixel format
 */
static gboolean
process (GeglOperation *op,
         void          *in_buf,
         void          *out_buf,
         glong          n_pixels)
{
50 51 52 53 54 55 56 57
  GeglChantO *o = GEGL_CHANT_PROPERTIES (op);
  gfloat     *pixel;
  gfloat      a_base;
  gfloat      a_scale;
  gfloat      b_base;
  gfloat      b_scale;
  glong       i;

58 59
  pixel = in_buf;

60 61 62 63 64
  a_scale = (o->high_a_delta - o->low_a_delta);
  a_base = o->low_a_delta;
  b_scale = (o->high_b_delta - o->low_b_delta);
  b_base = o->low_b_delta;

65 66 67 68
  for (i=0; i<n_pixels; i++)
    {
      pixel[1] += pixel[0] * a_scale + a_base;
      pixel[2] += pixel[0] * b_scale + b_base;
69 70
      pixel[1] = pixel[1] * o->saturation;
      pixel[2] = pixel[2] * o->saturation;
71 72 73 74 75
      pixel += 4;
    }
  return TRUE;
}

76 77

static void
78
gegl_chant_class_init (GeglChantClass *klass)
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
{
  GeglOperationClass            *operation_class;
  GeglOperationPointFilterClass *point_filter_class;

  operation_class    = GEGL_OPERATION_CLASS (klass);
  point_filter_class = GEGL_OPERATION_POINT_FILTER_CLASS (klass);

  point_filter_class->process = process;
  operation_class->prepare = prepare;

  operation_class->name        = "whitebalance";
  operation_class->categories  = "color";
  operation_class->description =
        "Allows changing the whitepoint and blackpoint of an image.";
}

95
#endif