summaryrefslogtreecommitdiff
path: root/ipl/gprocs/imscanon.icn
blob: 2c1c16fd08e2ab98c271dbb9b820170b415fc8b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
############################################################################
#
#	File:     imscanon.icn
#
#	Subject:  Procedure to put bi-level image string in canonical form
#
#	Author:   Ralph E. Griswold
#
#	Date:     August 6, 1994
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  This procedure puts a bi-level image string in canonical form so
#  that duplicates up to shifting can be eliminated.  It is intended to
#  be used in imlreduc.icn, which handles the rotational case.
#
#  It presently only handles widths that are a multiple of four.
#
############################################################################
#
#  Requires:  Large integers
#
############################################################################
#
#  Links:  strings
#
############################################################################

link strings

procedure imscanon(ims)
   local head, spec, dspec, max, val, imax, i, width

   ims ? {
      head := tab(upto('#~') + 1)
      spec := tab(0)
      }

   head ? {
      width := tab(many(&digits))
      }

   if (width % 4) ~= 0 then return ims		# one digit for 4 columns
   width /:= 4
   if (*spec % width) ~= 0 then return ims	# must be even number of digits

   dspec := spec || spec
   max := -1
   every i := 1 to (*spec / width) do {
      val := integer("16r" || dspec[1 +: *spec])
      if max <:= val then imax := (((i - 1) * width) + 1)
      dspec := rotate(dspec, width)
      }
 
   return head || dspec[imax +: *spec]

end