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 / gprocs / imscanon.icn < prev    next >
Text File  |  2000-07-29  |  2KB  |  62 lines

  1. ############################################################################
  2. #
  3. #    File:     imscanon.icn
  4. #
  5. #    Subject:  Procedure to put bi-level image string in canonical form
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     August 6, 1994
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This procedure puts a bi-level image string in canonical form so
  18. #  that duplicates up to shifting can be eliminated.  It is intended to
  19. #  be used in imlreduc.icn, which handles the rotational case.
  20. #
  21. #  It presently only handles widths that are a multiple of four.
  22. #
  23. ############################################################################
  24. #
  25. #  Requires:  Large integers
  26. #
  27. ############################################################################
  28. #
  29. #  Links:  strings
  30. #
  31. ############################################################################
  32.  
  33. link strings
  34.  
  35. procedure imscanon(ims)
  36.    local head, spec, dspec, max, val, imax, i, width
  37.  
  38.    ims ? {
  39.       head := tab(upto('#~') + 1)
  40.       spec := tab(0)
  41.       }
  42.  
  43.    head ? {
  44.       width := tab(many(&digits))
  45.       }
  46.  
  47.    if (width % 4) ~= 0 then return ims        # one digit for 4 columns
  48.    width /:= 4
  49.    if (*spec % width) ~= 0 then return ims    # must be even number of digits
  50.  
  51.    dspec := spec || spec
  52.    max := -1
  53.    every i := 1 to (*spec / width) do {
  54.       val := integer("16r" || dspec[1 +: *spec])
  55.       if max <:= val then imax := (((i - 1) * width) + 1)
  56.       dspec := rotate(dspec, width)
  57.       }
  58.  
  59.    return head || dspec[imax +: *spec]
  60.  
  61. end
  62.