<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Drakoniis's Techblog</title>
	<atom:link href="http://drakoniis.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://drakoniis.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Sat, 19 Jul 2008 07:50:22 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='drakoniis.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/979437a5ffe0fcee4635de7290577eca?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Drakoniis's Techblog</title>
		<link>http://drakoniis.wordpress.com</link>
	</image>
			<item>
		<title>DrosteSharp: Yet Another Thing You Shouldn&#8217;t Do With .NET&#8217;s JIT</title>
		<link>http://drakoniis.wordpress.com/2008/07/19/drostesharp/</link>
		<comments>http://drakoniis.wordpress.com/2008/07/19/drostesharp/#comments</comments>
		<pubDate>Sat, 19 Jul 2008 07:40:53 +0000</pubDate>
		<dc:creator>drakoniis</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[codeprovider]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[recursion]]></category>

		<guid isPermaLink="false">http://drakoniis.wordpress.com/2008/07/19/drostesharp-yet-another-thing-you-shouldnt-do-with-nets-jit/</guid>
		<description><![CDATA[There are some very interesting features in .NET with little in the way of clear documentation. One of these is the CodeProvider: a way to use .NET compilers from within .NET. While this may seem a bit odd, it allows for some very advanced reflection, and things like scripting to be implemented without using any [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drakoniis.wordpress.com&blog=4205264&post=12&subd=drakoniis&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>There are some very interesting features in .NET with little in the way of clear documentation. One of these is the CodeProvider: a way to use .NET compilers from within .NET. While this may seem a bit odd, it allows for some very advanced reflection, and things like scripting to be implemented without using any weird hacks (though the concept of including an entire set of compilers in the redistributable runtime is a bit&#8230; questionable).</p>
<p>Here is a hack I came up with, which uses &#8220;assembly recursion&#8221;. It&#8217;s actually quite efficient, since assemblies are cached, even if generated by CodeProvider (which saves dll&#8217;s of the compiled assemblies in your temp folder with a hash for a name).</p>
<p>I have two projects, once I call DrosteSharp, the other I call RecurseLib. DrosteSharp is a console application, RecurseLib is a class library referenced by DrosteSharp. To get this to work, under the properties for Recurse.cs, I set &#8220;Copy To Output Directory&#8221; to &#8220;Copy If Newer&#8221;.</p>
<p>The effect of this program is that it compiles a copy of itself, then accesses an object in the copy of itself through a shared interface, then calls a virtual function through the interface which starts the cycle again in the newly generated assembly.</p>
<p>Recurse.cs (in the DrosteSharp project):</p>
<pre class="brush: csharp;">

using System;
using System.IO;
using System.Collections.Generic;
using System.CodeDom.Compiler;
using Microsoft.CSharp;

namespace DrosteSharp
{
  public class Recurse : RecurseLib.IRecurse
  {
    public override void Do()
    {
      Console.WriteLine(&quot;Do() called&quot;);

      string code;
      using (StreamReader reader = new StreamReader(&quot;Recurse.cs&quot;))
      {
        code = reader.ReadToEnd();
      }

      CSharpCodeProvider compiler = new CSharpCodeProvider();
      CompilerParameters compilerParams = new CompilerParameters(
        new string[] { &quot;System.dll&quot;, &quot;RecurseLib.dll&quot; });
      CompilerResults compilerResults = compiler.CompileAssemblyFromSource(
        compilerParams, new string[] { code });

      object inst = compilerResults.CompiledAssembly.CreateInstance(&quot;DrosteSharp.Recurse&quot;);
      ((RecurseLib.IRecurse)inst).Do();
    }
  }

  public class Program
  {
    static void Main(string[] args)
    {
      Recurse recurse = new Recurse();
      recurse.Do();
    }
  }
}
</pre>
<p>IRecurse.cs (in the RecurseLib project):</p>
<pre class="brush: csharp;">

namespace RecurseLib
{
  public abstract class IRecurse
  {
    public abstract void Do();
  }
}
</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/drakoniis.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/drakoniis.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/drakoniis.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/drakoniis.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/drakoniis.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/drakoniis.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/drakoniis.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/drakoniis.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/drakoniis.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/drakoniis.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/drakoniis.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/drakoniis.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drakoniis.wordpress.com&blog=4205264&post=12&subd=drakoniis&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://drakoniis.wordpress.com/2008/07/19/drostesharp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bebbd2e56b9e653a5761a47dcd23f40a?s=96&#38;d=identicon" medium="image">
			<media:title type="html">drakoniis</media:title>
		</media:content>
	</item>
		<item>
		<title>Box Filters</title>
		<link>http://drakoniis.wordpress.com/2008/07/14/box-filters/</link>
		<comments>http://drakoniis.wordpress.com/2008/07/14/box-filters/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 05:25:53 +0000</pubDate>
		<dc:creator>drakoniis</dc:creator>
				<category><![CDATA[math]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[box filter]]></category>
		<category><![CDATA[graphics]]></category>

		<guid isPermaLink="false">http://drakoniis.wordpress.com/?p=6</guid>
		<description><![CDATA[I&#8217;ve been needing to get a tech blog for a while, so here it is finally. For my first entry I&#8217;m going to explain box filters (convolution matrices). It&#8217;s a pretty simple topic, but it has come up lately a few times, so I&#8217;m going to give a brief explanation and a possible implementation in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drakoniis.wordpress.com&blog=4205264&post=6&subd=drakoniis&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve been needing to get a tech blog for a while, so here it is finally. For my first entry I&#8217;m going to explain box filters (convolution matrices). It&#8217;s a pretty simple topic, but it has come up lately a few times, so I&#8217;m going to give a brief explanation and a possible implementation in C.</p>
<p>Box filters as mathematical objects take the form of square matrices.</p>
<p>Let <img src='http://s2.wordpress.com/latex.php?latex=%5Cmathcal%7BB%7D+_%7Bk%7D+&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\mathcal{B} _{k} ' title='\mathcal{B} _{k} ' class='latex' /> (where k is and odd integer greater than 0) be a vector space of matrices over <img src='http://s3.wordpress.com/latex.php?latex=%5Cmathbb%7BR%7D%5E%7Bn%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\mathbb{R}^{n}' title='\mathbb{R}^{n}' class='latex' /> representing the set of all square convolution matrices (box filters) with kernel action size k and dimension n. Normally, box filters are 2-dimensional, since their (current) primary use is image processing. Blurs, edge-detection, etc can be implemented using these filters. To keep this short, I&#8217;m going to cover a simple box filter that operates on a 1-dimensional data set.</p>
<p>Let <img src='http://s1.wordpress.com/latex.php?latex=%5Cmathcal%7BB%7D+_%7B3%7D+%28+%5Cmathbb%7BR%7D%5E%7B1%7D+%29+&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\mathcal{B} _{3} ( \mathbb{R}^{1} ) ' title='\mathcal{B} _{3} ( \mathbb{R}^{1} ) ' class='latex' /> be a 1-dimensional box filter with kernel action size 3. A box filter of this type takes the form <img src='http://s2.wordpress.com/latex.php?latex=%5Cbegin%7Bbmatrix%7D+a+%26%26+b+%26%26+c+%5Cend%7Bbmatrix%7D+&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\begin{bmatrix} a &amp;&amp; b &amp;&amp; c \end{bmatrix} ' title='\begin{bmatrix} a &amp;&amp; b &amp;&amp; c \end{bmatrix} ' class='latex' />. Each element resulting from the box filter will be combination of the old element in the same position and its adjacent elements:</p>
<p><img src='http://s3.wordpress.com/latex.php?latex=v%27_%7Bn%7D+%3D+a+v_%7Bn+-+1%7D+%5C%2C+%2B+%5C%2C+b+v_%7Bn%7D+%5C%2C+%2B+%5C%2C+c+v_%7Bn+%2B+1%7D+&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='v&#039;_{n} = a v_{n - 1} \, + \, b v_{n} \, + \, c v_{n + 1} ' title='v&#039;_{n} = a v_{n - 1} \, + \, b v_{n} \, + \, c v_{n + 1} ' class='latex' /></p>
<p>Say I&#8217;m given a 1-dimensional scalar array:</p>
<p><img src='http://s1.wordpress.com/latex.php?latex=%5Cbegin%7BBmatrix%7D+3+%26+2+%26+0+%26+4+%26+1+%26+5+%26+2+%26+3+%26+1+%26+4++%5Cend%7BBmatrix%7D+&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\begin{Bmatrix} 3 &amp; 2 &amp; 0 &amp; 4 &amp; 1 &amp; 5 &amp; 2 &amp; 3 &amp; 1 &amp; 4  \end{Bmatrix} ' title='\begin{Bmatrix} 3 &amp; 2 &amp; 0 &amp; 4 &amp; 1 &amp; 5 &amp; 2 &amp; 3 &amp; 1 &amp; 4  \end{Bmatrix} ' class='latex' /></p>
<p>Which, when graphed, looks like this:</p>
<p><img src="http://drakoniis.files.wordpress.com/2008/07/box_source.png" alt="" /></p>
<p>If I wanted to smooth this uniformly, I could use the box filter: <img src='http://s2.wordpress.com/latex.php?latex=%5Cfrac%7B1%7D%7B3%7D+%5Cbegin%7Bbmatrix%7D+1+%26+1+%26+1++%5Cend%7Bbmatrix%7D+&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\frac{1}{3} \begin{bmatrix} 1 &amp; 1 &amp; 1  \end{bmatrix} ' title='\frac{1}{3} \begin{bmatrix} 1 &amp; 1 &amp; 1  \end{bmatrix} ' class='latex' /> In the cases where the kernel action area overlaps the edge, there are a few ways of applying the filter. One is to extend the edge value past the edge, another is to wrap the action area around to the other edge. Here are both results when the smoothing filter is applied:</p>
<p>Extended:<br />
<img src="http://drakoniis.files.wordpress.com/2008/07/box_extend.png" alt="" /><br />
Wrapped:<br />
<img src="http://drakoniis.files.wordpress.com/2008/07/box_wrap.png" alt="" /></p>
<p>For a less computational, more mathematical definition (for example, how these relate to general signal processing), google &#8220;convolution matrix&#8221;.</p>
<p>References:</p>
<p><a href="http://docs.gimp.org/en/plug-in-convmatrix.html">http://docs.gimp.org/en/plug-in-convmatrix.html</a></p>
<pre class="brush: cpp;">
#include &lt;stdio.h&gt; /* fprintf, printf */

enum Mode
{
  WRAP = 0,
  EXTEND = 1
};

/* filter assumed to be of kernel action area 3 */
void ApplyFilter(double *target, const double *source,
                 const double *filter, unsigned len, int mode)
{
  unsigned i;
  for(i = 1; i &lt; (len - 1); i++)
  {
    target[i] = (filter[0] * source[i-1]) +
                (filter[1] * source[i])   +
                (filter[2] * source[i+1]);
  }

  switch(mode)
  {
    case WRAP:
      target[0]       = (filter[0] * source[len - 1]) +
                        (filter[1] * source[0])       +
                        (filter[2] * source[1]);
      target[len - 1] = (filter[0] * source[len - 2]) +
                        (filter[1] * source[len - 1]) +
                        (filter[2] * source[0]);
      break;

    case EXTEND:
      target[0]       = (filter[0] * source[0])       +
                        (filter[1] * source[0])       +
                        (filter[2] * source[1]);
      target[len - 1] = (filter[0] * source[len - 2]) +
                        (filter[1] * source[len - 1]) +
                        (filter[2] * source[len - 1]);
      break;

    default:
      fprintf(stderr, &quot;Invalid mode specified!&quot;);
  }
}

void PrintSvgPath(const double *arr, unsigned len)
{
  unsigned i;

  printf(&quot;M %f, %f  &quot;, 10.0, 100.0);

  for(i = 0; i &lt; len; i++)
  {
    printf(&quot;L %f, %f  &quot;, 10.0 + (i * 10.0), 10.0*(10.0 - arr[i]));
    printf(&quot;L %f, %f  &quot;, 10.0 + ((i + 1) * 10.0), 10.0*(10.0 - arr[i]));
  }

  printf(&quot;L %f, %f&quot;, 10.0 + (len * 10.0), 100.0);
}

void PrintDoubleArr(const double *arr, unsigned len)
{
  unsigned i;

  printf(&quot;{ &quot;);

  for(i = 0; i &lt; len; i++)
  {
    printf(&quot;%.2f &quot;, arr[i]);
  }

  printf(&quot;}\n&quot;);
}

int main()
{
  double source[]   = {3, 2, 0, 4, 1, 5, 2, 3, 1, 4};
  double filter[]   = {(1.0/3.0), (1.0/3.0), (1.0/3.0)};
  double wrap[10]   = {0};
  double extend[10] = {0};

  ApplyFilter(wrap,   source, filter, 10, WRAP);
  ApplyFilter(extend, source, filter, 10, EXTEND);

  PrintDoubleArr(source, 10);
  PrintDoubleArr(wrap, 10);
  PrintDoubleArr(extend, 10);

  puts(&quot;\n&quot;);
  PrintSvgPath(source, 10);
  puts(&quot;\n&quot;);
  PrintSvgPath(wrap, 10);
  puts(&quot;\n&quot;);
  PrintSvgPath(extend, 10);

  return 0;
}
</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/drakoniis.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/drakoniis.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/drakoniis.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/drakoniis.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/drakoniis.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/drakoniis.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/drakoniis.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/drakoniis.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/drakoniis.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/drakoniis.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/drakoniis.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/drakoniis.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=drakoniis.wordpress.com&blog=4205264&post=6&subd=drakoniis&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://drakoniis.wordpress.com/2008/07/14/box-filters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/bebbd2e56b9e653a5761a47dcd23f40a?s=96&#38;d=identicon" medium="image">
			<media:title type="html">drakoniis</media:title>
		</media:content>

		<media:content url="http://drakoniis.files.wordpress.com/2008/07/box_source.png" medium="image" />

		<media:content url="http://drakoniis.files.wordpress.com/2008/07/box_extend.png" medium="image" />

		<media:content url="http://drakoniis.files.wordpress.com/2008/07/box_wrap.png" medium="image" />
	</item>
	</channel>
</rss>