c++ - 492 454 386
my first code golf ;)
#include
#define B(i,j)(b[i][j]=='X')
int main(int i,char**v){for(int n=0;n3))?g<<'.':(!B(i,j)&&k==3)?g<<'X':g<
A somewhat revised version, replacing some of the logic with a table lookup+a few other minor tricks:
#include
#define B(x,y)(b[i+x][j+y]=='X')
int main(int i,char**v){for(int n=0;n>b[i];std::ofstream g(*v);g<