#!/usr/bin/env ruby copyright = ' /* !!!! AUTOGENERATED FILE generated by math.rb !!!!! * * 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 3 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, see . * * Copyright 2006 Øyvind Kolås * * !!!! AUTOGENERATED FILE !!!!! */' a = [ ['add', 'c = c + value', 0.0], ['subtract', 'c = c - value', 0.0], ['multiply', 'c = c * value', 1.0], ['divide', 'c = value==0.0f?0.0f:c/value', 1.0], ['gamma', 'c = powf (c, value)', 1.0], # ['threshold', 'c = c>=value?1.0f:0.0f', 0.5], # ['invert', 'c = 1.0-c'] ] a.each do |item| name = item[0] + '' filename = name + '.c' puts "generating #{filename}" file = File.open(filename, 'w') name = item[0] capitalized = name.capitalize swapcased = name.swapcase formula = item[1] file.write copyright file.write " #include \"config.h\" #include #ifdef GEGL_CHANT_PROPERTIES gegl_chant_double (value, _(\"Value\"), -G_MAXDOUBLE, G_MAXDOUBLE, #{item[2]}, _(\"global value used if aux doesn't contain data\")) #else #define GEGL_CHANT_TYPE_POINT_COMPOSER #define GEGL_CHANT_C_FILE \"#{filename}\" #include \"gegl-chant.h\" #include #ifdef _MSC_VER #define powf(a,b) ((gfloat)pow(a,b)) #endif static void prepare (GeglOperation *operation) { const Babl *format = babl_format (\"RGBA float\"); gegl_operation_set_format (operation, \"input\", format); gegl_operation_set_format (operation, \"aux\", babl_format (\"RGB float\")); gegl_operation_set_format (operation, \"output\", format); } static gboolean process (GeglOperation *op, void *in_buf, void *aux_buf, void *out_buf, glong n_pixels, const GeglRectangle *roi, gint level) { gfloat * GEGL_ALIGNED in = in_buf; gfloat * GEGL_ALIGNED out = out_buf; gfloat * GEGL_ALIGNED aux = aux_buf; gint i; if (aux == NULL) { gfloat value = GEGL_CHANT_PROPERTIES (op)->value; for (i=0; iprocess = process; operation_class->prepare = prepare; gegl_operation_class_set_keys (operation_class, \"name\" , \"gegl:#{name}\", \"categories\" , \"compositors:math\", \"description\" , _(\"Math operation #{name} (#{formula})\"), NULL); } #endif " file.close end