[opengtl-commits] [452] add some examples

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 452
Author:   cyrille
Date:     2008-10-13 22:31:23 +0200 (Mon, 13 Oct 2008)

Log Message:
-----------
add some examples
add oilify to the test suite

Added Paths:
-----------
    trunk/OpenGTL/OpenShiva/examples/
    trunk/OpenGTL/OpenShiva/examples/AntiBullify.shiva
    trunk/OpenGTL/OpenShiva/examples/Bullify.shiva
    trunk/OpenGTL/OpenShiva/tests/convolution/oilify.shiva


Added: trunk/OpenGTL/OpenShiva/examples/AntiBullify.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/examples/AntiBullify.shiva	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/examples/AntiBullify.shiva	2008-10-13 20:31:23 UTC (rev 452)
@@ -0,0 +1,23 @@
+kernel AntiBullify
+{
+  const float2 center = { 400.0, 400.0 };
+  const float lightLength = 400.0;
+  
+  float length( float2 v)
+  {
+    v *= v;
+    return sqrt( v[0] + v[1] );
+  }
+  
+  void evaluatePixel(image4 img, out pixel4 result)
+  {
+    float2 vec = result.coord - center;
+    float factor = length( vec ) / lightLength;
+    factor = 1.0 / (factor * factor);
+    result = img.sampleNearest( vec * factor + center );
+  }
+  region changed(region changed_input_region, int input_index, region input_DOD[])
+  {
+    return changed_input_region;
+  }
+}

Added: trunk/OpenGTL/OpenShiva/examples/Bullify.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/examples/Bullify.shiva	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/examples/Bullify.shiva	2008-10-13 20:31:23 UTC (rev 452)
@@ -0,0 +1,23 @@
+kernel Bullify
+{
+  const float2 center = { 400.0, 400.0 };
+  const float lightLength = 400.0;
+  
+  float length( float2 v)
+  {
+    v *= v;
+    return sqrt( v[0] + v[1] );
+  }
+  
+  void evaluatePixel(image4 img, out pixel4 result)
+  {
+    float2 vec = result.coord - center;
+    float factor = length( vec ) / lightLength;
+    factor *= factor;
+    result = img.sampleNearest( vec * factor + center );
+  }
+  region changed(region changed_input_region, int input_index, region input_DOD[])
+  {
+    return changed_input_region;
+  }
+}

Added: trunk/OpenGTL/OpenShiva/tests/convolution/oilify.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/convolution/oilify.shiva	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/convolution/oilify.shiva	2008-10-13 20:31:23 UTC (rev 452)
@@ -0,0 +1,40 @@
+kernel Oilify
+{
+  int intensity( float4 px )
+  {
+     int v = (0.5 * px[1] + 0.3 * px[2] + 0.2 * px[0]) * 255;
+     if( v < 0 ) return 0;
+     if( v > 255) return 255;
+     return v;
+  }
+  void evaluatePixel(image4 img, out pixel4 result)
+  {
+    int xc = result.coord.x;
+    int yc = result.coord.y;
+    int histogram[256];
+    for(int i = 0; i < 255; ++i)
+    {
+      histogram[i] = 0;
+    }
+    float4 max_px;
+    int max = 0;
+    for( int y = yc - 4; y < yc + 4; ++y)
+    {
+      for( int x = xc - 4; x < xc + 4; ++x)
+       {
+          float4 px = img.sampleNearest( float2(x,y ) );
+          int hv = ++histogram[ intensity( px ) ];
+          if( hv > max )
+          {
+             max_px = px;
+             max = hv;
+          }
+       }
+    }
+    result = max_px;
+  }
+  region changed(region changed_input_region, int input_index, region input_DOD[])
+  {
+    return changed_input_region;
+  }
+}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/