Blame docs/brightness-contrast.c.html

Packit bc1512
Packit bc1512
<HTML>
Packit bc1512
<HEAD>
Packit bc1512
<TITLE>Enscript Output</TITLE>
Packit bc1512
</HEAD>
Packit bc1512
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#1F00FF" ALINK="#FF0000" VLINK="#9900DD">
Packit bc1512
Packit bc1512
Packit bc1512

../operations/common/brightness-contrast.c

Packit bc1512
Packit bc1512
Packit bc1512
<FONT COLOR="#B22222">/* This file is an image processing operation for GEGL
Packit bc1512
 *
Packit bc1512
 * GEGL is free software; you can redistribute it and/or
Packit bc1512
 * modify it under the terms of the GNU Lesser General Public
Packit bc1512
 * License as published by the Free Software Foundation; either
Packit bc1512
 * version 3 of the License, or (at your option) any later version.
Packit bc1512
 *
Packit bc1512
 * GEGL is distributed in the hope that it will be useful,
Packit bc1512
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit bc1512
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit bc1512
 * Lesser General Public License for more details.
Packit bc1512
 *
Packit bc1512
 * You should have received a copy of the GNU Lesser General Public
Packit bc1512
 * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
Packit bc1512
 *
Packit bc1512
 * Copyright 2006 Øyvind Kolås <pippin@gimp.org>
Packit bc1512
 */</FONT>
Packit bc1512
Packit bc1512
#<FONT COLOR="#5F9EA0">include</FONT> <FONT COLOR="#BC8F8F">"config.h"</FONT>
Packit bc1512
#<FONT COLOR="#5F9EA0">include</FONT> <FONT COLOR="#BC8F8F"><glib/gi18n-lib.h></FONT>
Packit bc1512
Packit bc1512
<FONT COLOR="#B22222">/* Followed by this #if ... */</FONT>
Packit bc1512
#<FONT COLOR="#5F9EA0">ifdef</FONT> <FONT COLOR="#B8860B">GEGL_CHANT_PROPERTIES</FONT>
Packit bc1512
<FONT COLOR="#B22222">/* ... are the properties of the filter, these are all scalar values
Packit bc1512
 * (doubles), the the parameters are:
Packit bc1512
 *       property name,   min,   max, default, "description of property"
Packit bc1512
 */</FONT>
Packit bc1512
Packit bc1512
<FONT COLOR="#0000FF">gegl_chant_double_ui</FONT> (contrast, _(<FONT COLOR="#BC8F8F">"Contrast"</FONT>), -5.0, 5.0, 1.0, 0.0, 2.0, 1.0,
Packit bc1512
                   _(<FONT COLOR="#BC8F8F">"Range scale factor"</FONT>))
Packit bc1512
<FONT COLOR="#0000FF">gegl_chant_double_ui</FONT> (brightness, _(<FONT COLOR="#BC8F8F">"Brightness"</FONT>), -3.0, 3.0, 0.0, -1.0, 1.0, 1.0,
Packit bc1512
                   _(<FONT COLOR="#BC8F8F">"Amount to increase brightness"</FONT>))
Packit bc1512
Packit bc1512
<FONT COLOR="#B22222">/* this will create the instance structure for our use, and register the
Packit bc1512
 * property with the given ranges, default values and a comment for the
Packit bc1512
 * documentation/tooltip.
Packit bc1512
 */</FONT>
Packit bc1512
#<FONT COLOR="#5F9EA0">else</FONT>
Packit bc1512
Packit bc1512
<FONT COLOR="#B22222">/* Specify the base class we're building our operation on, the base
Packit bc1512
 * class provides a lot of the legwork so we do not have to. For
Packit bc1512
 * brightness contrast the best base class is the POINT_FILTER base
Packit bc1512
 * class.
Packit bc1512
 */</FONT>
Packit bc1512
#<FONT COLOR="#5F9EA0">define</FONT> <FONT COLOR="#B8860B">GEGL_CHANT_TYPE_POINT_FILTER</FONT>
Packit bc1512
Packit bc1512
<FONT COLOR="#B22222">/* We specify the file we're in, this is needed to make the code
Packit bc1512
 * generation for the properties work.
Packit bc1512
 */</FONT>
Packit bc1512
#<FONT COLOR="#5F9EA0">define</FONT> <FONT COLOR="#B8860B">GEGL_CHANT_C_FILE</FONT>       <FONT COLOR="#BC8F8F">"brightness-contrast.c"</FONT>
Packit bc1512
Packit bc1512
<FONT COLOR="#B22222">/* Including gegl-chant.h creates most of the GObject boiler plate
Packit bc1512
 * needed, creating a GeglChant instance structure a GeglChantClass
Packit bc1512
 * structure for our operation, as well as the needed code to register
Packit bc1512
 * our new gobject with GEGL.
Packit bc1512
 */</FONT>
Packit bc1512
#<FONT COLOR="#5F9EA0">include</FONT> <FONT COLOR="#BC8F8F">"gegl-chant.h"</FONT>
Packit bc1512
Packit bc1512
<FONT COLOR="#B22222">/* prepare() is called on each operation providing data to a node that
Packit bc1512
 * is requested to provide a rendered result. When prepare is called
Packit bc1512
 * all properties are known. For brightness contrast we use this
Packit bc1512
 * opportunity to dictate the formats of the input and output buffers.
Packit bc1512
 */</FONT>
Packit bc1512
<FONT COLOR="#228B22">static</FONT> <FONT COLOR="#228B22">void</FONT> <FONT COLOR="#0000FF">prepare</FONT> (GeglOperation *operation)
Packit bc1512
{
Packit bc1512
  gegl_operation_set_format (operation, <FONT COLOR="#BC8F8F">"input"</FONT>, babl_format (<FONT COLOR="#BC8F8F">"RGBA float"</FONT>));
Packit bc1512
  gegl_operation_set_format (operation, <FONT COLOR="#BC8F8F">"output"</FONT>, babl_format (<FONT COLOR="#BC8F8F">"RGBA float"</FONT>));
Packit bc1512
}
Packit bc1512
Packit bc1512
<FONT COLOR="#B22222">/* For GeglOperationPointFilter subclasses, we operate on linear
Packit bc1512
 * buffers with a pixel count.
Packit bc1512
 */</FONT>
Packit bc1512
<FONT COLOR="#228B22">static</FONT> gboolean
Packit bc1512
<FONT COLOR="#0000FF">process</FONT> (GeglOperation       *op,
Packit bc1512
         <FONT COLOR="#228B22">void</FONT>                *in_buf,
Packit bc1512
         <FONT COLOR="#228B22">void</FONT>                *out_buf,
Packit bc1512
         glong                n_pixels,
Packit bc1512
         <FONT COLOR="#228B22">const</FONT> GeglRectangle *roi,
Packit bc1512
         gint                 level)
Packit bc1512
{
Packit bc1512
  <FONT COLOR="#B22222">/* Retrieve a pointer to GeglChantO structure which contains all the
Packit bc1512
   * chanted properties
Packit bc1512
   */</FONT>
Packit bc1512
  GeglChantO *o = GEGL_CHANT_PROPERTIES (op);
Packit bc1512
  gfloat     * GEGL_ALIGNED in_pixel;
Packit bc1512
  gfloat     * GEGL_ALIGNED out_pixel;
Packit bc1512
  gfloat      brightness, contrast;
Packit bc1512
  glong       i;
Packit bc1512
Packit bc1512
  in_pixel   = in_buf;
Packit bc1512
  out_pixel  = out_buf;
Packit bc1512
Packit bc1512
  brightness = o->brightness;
Packit bc1512
  contrast   = o->contrast;
Packit bc1512
Packit bc1512
  <FONT COLOR="#A020F0">for</FONT> (i=0; i<n_pixels; i++)
Packit bc1512
    {
Packit bc1512
      out_pixel[0] = (in_pixel[0] - 0.5f) * contrast + brightness + 0.5;
Packit bc1512
      out_pixel[1] = (in_pixel[1] - 0.5f) * contrast + brightness + 0.5;
Packit bc1512
      out_pixel[2] = (in_pixel[2] - 0.5f) * contrast + brightness + 0.5;
Packit bc1512
      out_pixel[3] = in_pixel[3]; <FONT COLOR="#B22222">/* copy the alpha */</FONT>
Packit bc1512
      in_pixel  += 4;
Packit bc1512
      out_pixel += 4;
Packit bc1512
    }
Packit bc1512
  <FONT COLOR="#A020F0">return</FONT> TRUE;
Packit bc1512
}
Packit bc1512
Packit bc1512
#<FONT COLOR="#5F9EA0">include</FONT> <FONT COLOR="#BC8F8F">"opencl/gegl-cl.h"</FONT>
Packit bc1512
Packit bc1512
<FONT COLOR="#228B22">static</FONT> <FONT COLOR="#228B22">const</FONT> <FONT COLOR="#228B22">char</FONT>* kernel_source =
Packit bc1512
<FONT COLOR="#BC8F8F">"__kernel void kernel_bc(__global const float4     *in,         \n"</FONT>
Packit bc1512
<FONT COLOR="#BC8F8F">"                        __global       float4     *out,        \n"</FONT>
Packit bc1512
<FONT COLOR="#BC8F8F">"                        float brightness,                      \n"</FONT>
Packit bc1512
<FONT COLOR="#BC8F8F">"                        float contrast)                        \n"</FONT>
Packit bc1512
<FONT COLOR="#BC8F8F">"{                                                              \n"</FONT>
Packit bc1512
<FONT COLOR="#BC8F8F">"  int gid = get_global_id(0);                                  \n"</FONT>
Packit bc1512
<FONT COLOR="#BC8F8F">"  float4 in_v  = in[gid];                                      \n"</FONT>
Packit bc1512
<FONT COLOR="#BC8F8F">"  float4 out_v;                                                \n"</FONT>
Packit bc1512
<FONT COLOR="#BC8F8F">"  out_v.xyz = (in_v.xyz - 0.5f) * contrast + brightness + 0.5f;\n"</FONT>
Packit bc1512
<FONT COLOR="#BC8F8F">"  out_v.w   =  in_v.w;                                         \n"</FONT>
Packit bc1512
<FONT COLOR="#BC8F8F">"  out[gid]  =  out_v;                                          \n"</FONT>
Packit bc1512
<FONT COLOR="#BC8F8F">"}                                                              \n"</FONT>;
Packit bc1512
Packit bc1512
<FONT COLOR="#228B22">static</FONT> gegl_cl_run_data *cl_data = NULL;
Packit bc1512
Packit bc1512
<FONT COLOR="#B22222">/* OpenCL processing function */</FONT>
Packit bc1512
<FONT COLOR="#228B22">static</FONT> cl_int
Packit bc1512
<FONT COLOR="#0000FF">cl_process</FONT> (GeglOperation       *op,
Packit bc1512
            cl_mem               in_tex,
Packit bc1512
            cl_mem               out_tex,
Packit bc1512
            size_t               global_worksize,
Packit bc1512
            <FONT COLOR="#228B22">const</FONT> GeglRectangle *roi,
Packit bc1512
            <FONT COLOR="#228B22">int</FONT>                  level)
Packit bc1512
{
Packit bc1512
  <FONT COLOR="#B22222">/* Retrieve a pointer to GeglChantO structure which contains all the
Packit bc1512
   * chanted properties
Packit bc1512
   */</FONT>
Packit bc1512
Packit bc1512
  GeglChantO *o = GEGL_CHANT_PROPERTIES (op);
Packit bc1512
Packit bc1512
  gfloat brightness = o->brightness;
Packit bc1512
  gfloat contrast   = o->contrast;
Packit bc1512
Packit bc1512
  cl_int cl_err = 0;
Packit bc1512
Packit bc1512
  <FONT COLOR="#A020F0">if</FONT> (!cl_data)
Packit bc1512
    {
Packit bc1512
      <FONT COLOR="#228B22">const</FONT> <FONT COLOR="#228B22">char</FONT> *kernel_name[] = {<FONT COLOR="#BC8F8F">"kernel_bc"</FONT>, NULL};
Packit bc1512
      cl_data = gegl_cl_compile_and_build (kernel_source, kernel_name);
Packit bc1512
    }
Packit bc1512
Packit bc1512
  <FONT COLOR="#A020F0">if</FONT> (!cl_data) <FONT COLOR="#A020F0">return</FONT> 1;
Packit bc1512
Packit bc1512
  cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 0, <FONT COLOR="#A020F0">sizeof</FONT>(cl_mem),   (<FONT COLOR="#228B22">void</FONT>*)&in_tex);
Packit bc1512
  cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 1, <FONT COLOR="#A020F0">sizeof</FONT>(cl_mem),   (<FONT COLOR="#228B22">void</FONT>*)&out_tex);
Packit bc1512
  cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 2, <FONT COLOR="#A020F0">sizeof</FONT>(cl_float), (<FONT COLOR="#228B22">void</FONT>*)&brightness);
Packit bc1512
  cl_err |= gegl_clSetKernelArg(cl_data->kernel[0], 3, <FONT COLOR="#A020F0">sizeof</FONT>(cl_float), (<FONT COLOR="#228B22">void</FONT>*)&contrast);
Packit bc1512
  <FONT COLOR="#A020F0">if</FONT> (cl_err != CL_SUCCESS) <FONT COLOR="#A020F0">return</FONT> cl_err;
Packit bc1512
Packit bc1512
  cl_err = gegl_clEnqueueNDRangeKernel(gegl_cl_get_command_queue (),
Packit bc1512
                                        cl_data->kernel[0], 1,
Packit bc1512
                                        NULL, &global_worksize, NULL,
Packit bc1512
                                        0, NULL, NULL);
Packit bc1512
  <FONT COLOR="#A020F0">if</FONT> (cl_err != CL_SUCCESS) <FONT COLOR="#A020F0">return</FONT> cl_err;
Packit bc1512
Packit bc1512
  <FONT COLOR="#A020F0">return</FONT> cl_err;
Packit bc1512
}
Packit bc1512
Packit bc1512
<FONT COLOR="#B22222">/*
Packit bc1512
 * The class init function sets up information needed for this operations class
Packit bc1512
 * (template) in the GObject OO framework.
Packit bc1512
 */</FONT>
Packit bc1512
<FONT COLOR="#228B22">static</FONT> <FONT COLOR="#228B22">void</FONT>
Packit bc1512
<FONT COLOR="#0000FF">gegl_chant_class_init</FONT> (GeglChantClass *klass)
Packit bc1512
{
Packit bc1512
  GeglOperationClass            *operation_class;
Packit bc1512
  GeglOperationPointFilterClass *point_filter_class;
Packit bc1512
Packit bc1512
  operation_class    = GEGL_OPERATION_CLASS (klass);
Packit bc1512
  point_filter_class = GEGL_OPERATION_POINT_FILTER_CLASS (klass);
Packit bc1512
Packit bc1512
  <FONT COLOR="#B22222">/* override the prepare methods of the GeglOperation class */</FONT>
Packit bc1512
  operation_class->prepare = prepare;
Packit bc1512
  <FONT COLOR="#B22222">/* override the process method of the point filter class (the process methods
Packit bc1512
   * of our superclasses deal with the handling on their level of abstraction)
Packit bc1512
   */</FONT>
Packit bc1512
  point_filter_class->process = process;
Packit bc1512
  point_filter_class->cl_process = cl_process;
Packit bc1512
Packit bc1512
  <FONT COLOR="#B22222">/* specify the name this operation is found under in the GUI/when
Packit bc1512
   * programming/in XML
Packit bc1512
   */</FONT>
Packit bc1512
  operation_class->opencl_support = TRUE;
Packit bc1512
Packit bc1512
  gegl_operation_class_set_keys (operation_class,
Packit bc1512
      <FONT COLOR="#BC8F8F">"name"</FONT>,       <FONT COLOR="#BC8F8F">"gegl:brightness-contrast"</FONT>,
Packit bc1512
      <FONT COLOR="#BC8F8F">"categories"</FONT>, <FONT COLOR="#BC8F8F">"color"</FONT>, 
Packit bc1512
      <FONT COLOR="#BC8F8F">"description"</FONT>, _(<FONT COLOR="#BC8F8F">"Changes the light level and contrast."</FONT>),
Packit bc1512
      NULL);
Packit bc1512
}
Packit bc1512
Packit bc1512
#<FONT COLOR="#5F9EA0">endif</FONT> <FONT COLOR="#B22222">/* closing #ifdef GEGL_CHANT_PROPERTIES ... else ... */</FONT>
Packit bc1512
Packit bc1512

Packit bc1512
<ADDRESS>Generated by GNU Enscript 1.6.5.90.</ADDRESS>
Packit bc1512
</BODY>
Packit bc1512
</HTML>