home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / graphics / 13630 < prev    next >
Encoding:
Text File  |  1993-01-11  |  4.3 KB  |  82 lines

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