brightness-contrast.c 1.76 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* 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
 * version 2 of the License, or (at your option) any later version.
 *
 * 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
 * License along with GEGL; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * Copyright 2006 Øyvind Kolås <pippin@gimp.org>
 */
20
#ifdef GEGL_CHANT_SELF
21
 
22 23
gegl_chant_double (contrast,   -100.0, 100.0, 1.0, "Range scale factor")
gegl_chant_double (brightness,  -10.0,  10.0, 0.0, "Amount to increase brightness")
24 25 26

#else

27 28 29 30 31
#define GEGL_CHANT_POINT_FILTER
#define GEGL_CHANT_NAME         brightness_contrast
#define GEGL_CHANT_DESCRIPTION  "Changes the light level and contrast."
#define GEGL_CHANT_SELF         "brightness-contrast.c"
#define GEGL_CHANT_CATEGORIES   "color"
32 33 34 35 36 37 38 39
#include "gegl-chant.h"

static gboolean
evaluate (GeglOperation *op,
          void          *in_buf,
          void          *out_buf,
          glong          n_pixels)
{
40
  ChantInstance *self = GEGL_CHANT_INSTANCE (op);
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
  gint o;
  gfloat *p = in_buf;  /* it is inplace anyways, and out_but==in_buf) */

  g_assert (in_buf == out_buf);

  for (o=0; o<n_pixels; o++)
    {
      gint i;
      for (i=0;i<3;i++)
        p[i] = (p[i] - 0.5) * self->contrast + self->brightness + 0.5;
      p+=4;
    }
  return TRUE;
}
#endif