svg-blend.rb 2.05 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#!/usr/bin/env ruby

copyright = '
/* !!!! AUTOGENERATED FILE generated by svg.rb !!!!! 
 *
 *  Copyright 2006 Øyvind Kolås <pippin@gimp.org>
 *
 * !!!! AUTOGENERATED FILE !!!!!
 *
 */'

a = [
      ['normal',       '(1.0 - qa) * cb + ca'],
      ['svg_multiply', '(1-qa)*cb + (1-qb)*ca + ca*cb'],
      ['screen',       'cb + ca - ca * cb'],
      ['darken',       'MIN ((1 - qa) * cb + ca, (1 - qb) * ca + cb)'],
      ['lighten',      'MAX ((1 - qa) * cb + ca, (1 - qb) * ca + cb)']
    ]

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 "
36
#ifdef GEGL_CHANT_PROPERTIES
37 38 39
/* no properties */
#else

40 41 42 43 44
#define GEGL_CHANT_POINT_COMPOSER
#define GEGL_CHANT_NAME          #{name}
#define GEGL_CHANT_DESCRIPTION   \"SVG blend operation #{name} (c = #{formula})\"
#define GEGL_CHANT_CATEGORIES    \"compositors:svgfilter\"
#define GEGL_CHANT_SELF          \"#{filename}\"
Øyvind Kolås's avatar
Øyvind Kolås committed
45
#define GEGL_CHANT_INIT
46 47
#include \"gegl-chant.h\"

48
static void init (GeglChantOperation *self)
49 50 51 52 53 54 55
{
  GEGL_OPERATION_POINT_COMPOSER (self)->format = babl_format (\"RaGaBaA float\");
  GEGL_OPERATION_POINT_COMPOSER (self)->aux_format = babl_format (\"RaGaBaA float\");

}

static gboolean
Øyvind Kolås's avatar
Øyvind Kolås committed
56
process (GeglOperation *op,
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
          void          *in_buf,
          void          *aux_buf,
          void          *out_buf,
          glong          n_pixels)
{
  gint i;
  gfloat *in = in_buf;
  gfloat *aux = aux_buf;
  gfloat *out = out_buf;

  if (aux==NULL)
    return TRUE;

  for (i=0; i<n_pixels; i++)
    {
      int  j;
      gfloat qa, qb;

      qb=in[3];
      qa=aux[3];
      for (j=0; j<3; j++)
          {
              gfloat ca, cb;

              cb=in[j];
              ca=aux[j];
              out[j] = #{formula};
          }
      out[3] = 1 - (1-qa)*(1-qb);
      in  += 4;
      aux += 4;
      out += 4;
    }
  return TRUE;
}

#endif
"

  file.close
end