title: How can I find all rectangles that bound regions in a bitmap?
body: <p>I have a problem: I need an algorithm for my tile engine.</p>
  
  <p>I have an 2d-array which stores my un-walkable tiles.</p>
  
  <p>Now I want to implement a light engine, but this engine need shadow-hulls.</p>
  
  <p>So I need an algorithm which will create these shadow-hulls. </p>
  
  <p>I need a set of rectangles that bound the un-walkable portions of the array (the cells that have <code>1</code>s)<br>
  For example:</p>
  
  <p><img src="https://i.stack.imgur.com/rQ1eK.png" alt="http://makerland.de/Zerlegt.png"></p>
  
  <p>The black tile are <code>1</code>s; I need to find the set of red rectangles that fully enclose them.</p>