F#, 672 646 643 634 629 628 chars (incl newlines)
EDIT: priceless: this post triggered Stackoverflow's human verification system. I bet it's because of the code.
EDIT2: more filthy tricks knocked off 36 chars. Reversing an if in the second line shaved off 5 more.
Writing this code made my eyes bleed and my brain melt.
- The good: it's short(ish).
- The bad: it'll crash on any input square larger than 4x4 (it's an O(be stupid and try everything) algorithm, O(n*2^(n^2)) to be more precise). Much of the ugliness comes from padding the input square with zeroes on all sides to avoid edge and corner cases.
- The ugly: just look at it. It's code only a parent could love. Liberal uses of >>> and <<< made F# look like brainfuck.
The program accepts rows of input until you enter a blank line.
This code doesn't work in F# interactive. It has to be compiled inside a project.
open System
let rec i()=[let l=Console.ReadLine()in if l<>""then yield!l::i()]
let a=i()
let m=a.[0].Length
let M=m+2
let q=Seq.sum[for k in 1..m->(1L<<Convert.ToInt64(String.collect(function|'.'->"0"|_->"1")s,2)<<B&&&q|n->f(if n%2L=1L then B^^^(x*7L/2L+(x<<>>M))else B)(x*2L)(n/2L)
let z=fst<|Seq.find(snd>>(=)0L)[for k in 0L..1L<<let n=Seq.sum[for j in 0..m->k+1L&&&(((1L<<