ASCII art is the practice of creating images by using ASCII text to form shapes.
Aliasing is the effect created by the large "pixels" of ASCII art, which are the size of characters. The image becomes blocky and hard to see. Anti-aliasing removes this effect by creating a gradient and by softening the hard edges of the ASCII art.
Your challenge is to write the shortest program possible that will take a piece of ASCII art and will output a version that has been anti-aliased.
What sort of anti-aliasing?
All of the ASCII art will consist of two types of symbols: Spaces and non-whitespace. For each non-whitespace character, your program must determine whether it is in a position where it need to be anti-aliased. If it is, then you need to replace it with the correct character. If it isn't, then the character stays the same.
How do you know if a character needs to be anti-aliased? The answer depends on the characters that are immediately above, below, left, and right of the character (not the diagonals). Here is a chart of when anti-aliasing is required, where
x can stand for any non-whitespace character.
x? -> d? ? ? ?x -> ?b ? ? ? ? ?x -> ?F ? ? x? -> Y? x -> ; Note: This character has been changed from _ to ; ? ? ? ? x -> V ?x -> ?> x? -> <? x -> @
Input (and example pre-anti-aliasing ASCII art)
First, there will be two lines of input (to STDIN), a number H followed by a number W. There will then be H lines of exactly W characters each (excluding the newline). These following lines will be the ASCII art that needs to be anti-aliased. Here is an example input (not beautiful, but a test):
7 9 888888 888888 999 98 7 666666 666666 6666 6
Output (and example anti-aliased art)
Your program should output to STDOUT the ASCII art (of the same dimensions), which has been anti-aliased. Here is the output for the above input. Notice how the the border characters are treated as bordering whitespace.
d8888> d8888F <99 98 @ Y6666b Y6666> Y66F V
This might not look that good (due to the space between lines in the code block), it looks better with larger ASCII art, and the quality depends on the exact font used.
12 18 xx xxx xxx xxxx xxx xxx xxxxxx xxx xxx xxx xxx xxx xxx xxxx xxx xxx xxx xxxxxx xxx xxx xxxx xxx xxx x xx xxx xxx x xx xxx xxx xx xxx xxx xxx xxx xxxx xxx xxx xx xxxxx xxx xxx x
db <xb <xb dxxb Yxb Yxb dxxxxb Yxb Yxb dxx xxb xxb xxb Yxxb xxF xxF xxF YxxxxF dxF dxF YxxF dxF dxF ; YF dxF dxF ; xb dxF dxF dx xxb <xF <xF <xx xxxb Yxb Yxb Yx Yxxx> Yx> Yx> V
Rules, Restrictions, and Notes
Your program should be written in printable ASCII characters only, so that we can make art out of the programs. Other than that, the standard code-golf rules apply.
;because it works better. \$\endgroup\$