home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / image144.sit / User.p < prev    next >
Encoding:
Text File  |  1991-09-18  |  3.4 KB  |  144 lines

  1. unit User;
  2.  
  3. {This module is a good place to put user additions to Image. You will need }
  4. {to uncomment the call to InitUser in Image.p.}
  5.  
  6.  
  7. interface
  8.  
  9.     uses
  10.         QuickDraw, Palettes, PrintTraps, globals, Utilities, Graphics;
  11.  
  12.  
  13.     procedure InitUser;
  14.     procedure DoUserCommand1;
  15.     procedure DoUserCommand2;
  16.     procedure DoUserMenuEvent (MenuItem: integer);
  17.  
  18.  
  19. implementation
  20.  
  21. {User global variables go here.}
  22.     var
  23.         color: integer;
  24.  
  25.  
  26.     procedure InitUser;
  27.     begin
  28.         UserMenuH := GetMenu(UserMenu);
  29.         InsertMenu(UserMenuH, 0);
  30.         DrawMenuBar;
  31. {Additional user initialization code goes here.}
  32.     end;
  33.  
  34.  
  35.     procedure DrawDot (row, column, RowOffset, ColumnOffset: integer; big: boolean);
  36.         var
  37.             h, v: integer;
  38.     begin
  39.         if big then begin
  40.                 for h := -1 to 1 do
  41.                     for v := -1 to 1 do
  42.                         PutPixel(column * 16 + ColumnOffset * 4 + h + 16, row * 16 + RowOffset * 4 + v + 16, color)
  43.             end
  44.         else
  45.             PutPixel(column * 16 + ColumnOffset * 4 + 16, row * 16 + RowOffset * 4 + 16, color);
  46.     end;
  47.  
  48.     procedure DrawNeighborhood (i, row, column: integer);
  49.  
  50.     begin
  51.         DrawDot(row, column, 0, 0, BitAnd(i, 1) = 1);
  52.         DrawDot(row, column, 0, 1, BitAnd(i, 2) = 2);
  53.         DrawDot(row, column, 0, 2, BitAnd(i, 4) = 4);
  54.         DrawDot(row, column, 1, 2, BitAnd(i, 8) = 8);
  55.         DrawDot(row, column, 2, 2, BitAnd(i, 16) = 16);
  56.         DrawDot(row, column, 2, 1, BitAnd(i, 32) = 32);
  57.         DrawDot(row, column, 2, 0, BitAnd(i, 64) = 64);
  58.         DrawDot(row, column, 1, 0, BitAnd(i, 128) = 128);
  59.         DrawDot(row, column, 1, 1, true);
  60.     end;
  61.  
  62.  
  63.     procedure SetColor (i: integer);
  64. {Color neighborhoods to show which ones would be removed on the first pass(150), second pass(100),}
  65. {or either pass(200) when using the Zhang and Suen thinning algorithm(CACM, Mar. 1984,236-239).}
  66.         var
  67.             p2, p3, p4, p5, p6, p7, p8, p9, A, B: integer;
  68.     begin
  69.         p2 := bsr(band(i, 2), 1);
  70.         p3 := bsr(band(i, 4), 2);
  71.         p4 := bsr(band(i, 8), 3);
  72.         p5 := bsr(band(i, 16), 4);
  73.         p6 := bsr(band(i, 32), 5);
  74.         p7 := bsr(band(i, 64), 6);
  75.         p8 := bsr(band(i, 128), 7);
  76.         p9 := band(i, 1);
  77.         A := 0;
  78.         if (p2 = 0) and (p3 = 1) then
  79.             A := A + 1;
  80.         if (p3 = 0) and (p4 = 1) then
  81.             A := A + 1;
  82.         if (p4 = 0) and (p5 = 1) then
  83.             A := A + 1;
  84.         if (p5 = 0) and (p6 = 1) then
  85.             A := A + 1;
  86.         if (p6 = 0) and (p7 = 1) then
  87.             A := A + 1;
  88.         if (p7 = 0) and (p8 = 1) then
  89.             A := A + 1;
  90.         if (p8 = 0) and (p9 = 1) then
  91.             A := A + 1;
  92.         if (p9 = 0) and (p2 = 1) then
  93.             A := A + 1;
  94.         B := p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9;
  95.         color := 255;
  96.         if A = 1 then
  97.             if (B >= 2) and (B <= 6) then begin
  98.                     if ((p2 * p4 * p6 = 0) and (p4 * p6 * p8 = 0)) and ((p2 * p4 * p8 = 0) and (p2 * p6 * p8 = 0)) then
  99.                         color := 200
  100.                     else if (p2 * p4 * p6 = 0) and (p4 * p6 * p8 = 0) then
  101.                         color := 150
  102.                     else if (p2 * p4 * p8 = 0) and (p2 * p6 * p8 = 0) then
  103.                         color := 100;
  104.                 end;
  105.     end;
  106.  
  107.  
  108.     procedure DoUserCommand1;
  109. {Generates a table showing all possible 3x3 neighborhoods. This table is used}
  110. { for making up the "fate table" used by the Skeletonize command and the Wand tool.}
  111.         var
  112.             row, column, index: integer;
  113.     begin
  114.         row := 0;
  115.         column := 0;
  116.         if NewPicWindow('Fate Table', 600, 200) then
  117.             for index := 0 to 255 do begin
  118.                     SetColor(index);
  119.                     DrawNeighborhood(index, row, column);
  120.                     column := column + 1;
  121.                     if column = 32 then begin
  122.                             row := row + 1;
  123.                             column := 0;
  124.                         end;
  125.                 end;
  126.     end;
  127.  
  128.  
  129.     procedure DoUserCommand2;
  130.     begin
  131.         beep;
  132.     end;
  133.  
  134.     procedure DoUserMenuEvent (MenuItem: integer);
  135.     begin
  136.         case MenuItem of
  137.             1: 
  138.                 DoUserCommand1;
  139.             2: 
  140.                 DoUserCommand1;
  141.         end;
  142.     end;
  143.  
  144. end.