home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.graphics
- Path: sparky!uunet!world!mrob
- From: mrob@world.std.com (Robert P Munafo)
- Subject: Bitmap-to-text algorithm (ASCII graphics)
- Message-ID: <C0oEGo.yL@world.std.com>
- Summary: I have no program, but here's the algorithm
- Keywords: ASCII graphics picture bitmap conversion algorithm
- Organization: The World Public Access UNIX, Brookline, MA
- Date: Mon, 11 Jan 1993 06:09:59 GMT
- Lines: 70
-
- I have been getting quite a few responses to this by mail. Some of these
- folks cannot be reached by mail (the letters bounce -- anyone know what's
- the problem with greco-prog.fr and u-bordeaux.fr ?).
-
- People seem to think that I have a program that converts pictures to text.
- This is not the case! It is merely a subroutine in a crude and obfuscated
- Mandelbrot program that I have developed for my own use. The best I can do
- is to describe the algorithm.
-
- I wrote a bitmap-to-text converter and incorporated it into a Mandelbrot
- program that I am developing. Here is some sample output:
- -, \
- '-, \ ,
- ~. \ , [
- ` , \ ~ \ ]
- ^--.. '- ', \ - : : ,
- '^--,_ '`, '- \ .',i',,[,/
- `--.. -, -, `,-,~,\'\/b@mai`
- `^-._ `-, ~,*'\'\(d))d@F*@@[
- `--_ '-,~/\~._\_/@F**` ^*`
- ---__,:-`v//(@@@#@@*
- _____________________________~.Ldbb@@*` '*
- __.***F#T#@@,,__e
- ^`` ,.-:-\--/@F@@*@e, .
- .,-^` ,--',\~~\.((@b@mc:md[
- ..,--' ..- /~ '/`/`)~*\(@@d@)[
- _,,-^' ' .,- .- .*-~/`~/F^`,-
- .._--^` ., .' i~ . '. ``',
- --^' .,' ' a` i` ' i
- _- .` / c '
- .-` .` [
- .,~ .`
- '' `
- Figure 1. -1.999 985 881 278 +0.000 000 000 001 i @ .000 000 000 300
-
- A pixel grid (in this case containing a Distance-Estimator-Method Mandelbrot
- image) is broken up into character cells, each 5x12 pixels in size. Within
- each character cell, six _blocks_ are defined, each 2x4 pixels in size. (The
- rightmost column of pixels in each character cell is ignored.) A six-bit
- _pattern value_ is generated by doing a true-or-false test on each of the six
- blocks. For example, you could average the values of the 8 pixels in the
- block; or you could "OR" the values of the eight pixels, etc. Each of the
- six blocks generates one bit in the pattern value; the bit positions of the
- six blocks are shown in Table 1. So, for example, if the upper-left and
- lower-right blocks are both "1" and the rest are "0", the resulting pattern
- value would be 32 + 1, which is 33. Once a pattern value is achieved, a
- character is produced by looking up in a 64-entry table, Table 2.
-
- Tbl. 1 Table 2: Character corresponding to each pattern value
- 32 16 1 1 2 2 3 3 4 4 5 5 6
- 8 4 0 5 0 5 0 5 0 5 0 5 0 5 0
- 2 1 .,_-:/a-\ce-vrm':/d']//~(/("(/d`\;L~\))`\[L"\)b^7F%"T)$"(FC*#F@
-
- Characters for Table 2 were chosen carefully. In some cases (e.g. the '.'
- and ',') I assigned two different characters so that they could be
- distinguished. Ideally, 64 different ASCII characters would be used in the
- table, so that the entire 6 bits of information is always retained. I'm
- still making minor adjustments to it.
-
- In the Fig. 1 example above, a 256x256 image was converted into 22 lines of
- text, each containing 52 characters plus a newline. A total of 6592 bits of
- information is expressed in 1166 bytes of text.
-
- The 5:12 aspect ratio for the character cell was chosen because it is equal
- to (4/80):(3/25), i.e. 25x80 text on a 3x4 screen. The canonical 25x80
- text display uses a CRT originally designed for television, which uses a
- 3x4 screen shape.
- --
- mrob's .sig #1 |____ RF(1/3B1) -> '\-
- collect all 5! |\RM/ Robert P. Munafo _,_'F']_, ,
-