home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / gprogs / autotile.icn next >
Text File  |  2000-07-29  |  2KB  |  88 lines

  1. ############################################################################
  2. #
  3. #    File:     autotile.icn
  4. #
  5. #    Subject:  Program to produce tile from XBM image
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     January 3, 1994
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program creates a tile of a specified size by processing an
  18. #  XBM image file.  The tile grid is "laid over" the image to form squares.
  19. #
  20. #  The non-white pixels in each square of the image are counted. If the
  21. #  percentage of non-white pixels exceeds a specified threshold, the
  22. #  corresponding bit in the tile is set.
  23. #
  24. #  The supported options are:
  25. #
  26. #    -h i    tile height, default 32
  27. #    -w i    tile width, default 32
  28. #    -t r    threshold, default 0.50
  29. #
  30. ############################################################################
  31. #
  32. #  Links:  options, patutils
  33. #
  34. ############################################################################
  35.  
  36. link options
  37. link patutils
  38.  
  39. global pixmap
  40.  
  41. procedure main(args)
  42.    local x, y, pixels, i, j, size, rows, wcell, hcell
  43.    local opts, input, w, h, t, xoff, yoff
  44.  
  45.    opts := options(args, "t.h+w+")
  46.  
  47.    input := open(args[1]) | stop("*** cannot open input file")
  48.  
  49.    pixmap := []                    # image array
  50.  
  51.    every put(pixmap, xbm2rows(input))
  52.  
  53.    w := \opts["w"] | 32
  54.    h := \opts["h"] | 32
  55.    t := \opts["t"] | 0.50
  56.  
  57.    wcell := *pixmap[1] / w
  58.    hcell := *pixmap / h
  59.    
  60.    size := real(wcell * hcell)
  61.  
  62.    rows := list(h, repl("0", w))        # tile
  63.  
  64.    x :=  0
  65.  
  66.    every i := 1 to w do {
  67.       y := 0
  68.       every j := 1 to h do {
  69.          pixels := 0
  70.          xoff := x + 1
  71.          every 1 to wcell do {
  72.             yoff := y + 1
  73.             every 1 to hcell do {
  74.                every pixels +:=  pixmap[yoff, xoff]
  75.                yoff +:= 1
  76.                }
  77.             xoff +:= 1
  78.             }
  79.          if pixels / size > t then rows[j, i] := "1"
  80.          y +:= hcell
  81.          }
  82.       x +:= wcell
  83.       }
  84.  
  85.    write(rows2pat(rows))
  86.    
  87. end
  88.