/ *   
 
   *   P R O J E C T :   N y A R T o o l k i t C S ( E x t e n s i o n ) 
 
   *   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
   *   T h e   N y A R T o o l k i t C S   i s   J a v a   e d i t i o n   A R T o o l K i t   c l a s s   l i b r a r y . 
 
   *   C o p y r i g h t   ( C ) 2 0 0 8 - 2 0 0 9   R y o   I i z u k a 
 
   * 
 
   *   T h i s   p r o g r a m   i s   f r e e   s o f t w a r e :   y o u   c a n   r e d i s t r i b u t e   i t   a n d / o r   m o d i f y 
 
   *   i t   u n d e r   t h e   t e r m s   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e   a s   p u b l i s h e d   b y 
 
   *   t h e   F r e e   S o f t w a r e   F o u n d a t i o n ,   e i t h e r   v e r s i o n   3   o f   t h e   L i c e n s e ,   o r 
 
   *   ( a t   y o u r   o p t i o n )   a n y   l a t e r   v e r s i o n . 
 
   *   
 
   *   T h i s   p r o g r a m   i s   d i s t r i b u t e d   i n   t h e   h o p e   t h a t   i t   w i l l   b e   u s e f u l , 
 
   *   b u t   W I T H O U T   A N Y   W A R R A N T Y ;   w i t h o u t   e v e n   t h e   i m p l i e d   w a r r a n t y   o f 
 
   *   M E R C H A N T A B I L I T Y   o r   F I T N E S S   F O R   A   P A R T I C U L A R   P U R P O S E .     S e e   t h e 
 
   *   G N U   G e n e r a l   P u b l i c   L i c e n s e   f o r   m o r e   d e t a i l s . 
 
   * 
 
   *   Y o u   s h o u l d   h a v e   r e c e i v e d   a   c o p y   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e 
 
   *   a l o n g   w i t h   t h i s   p r o g r a m .     I f   n o t ,   s e e   < h t t p : / / w w w . g n u . o r g / l i c e n s e s / > . 
 
   *   
 
   *   F o r   f u r t h e r   i n f o r m a t i o n   p l e a s e   c o n t a c t . 
 
   * 	 h t t p : / / n y a t l a . j p / n y a t o o l k i t / 
 
   * 	 < a i r m a i l ( a t ) e b o n y . p l a l a . o r . j p >   o r   < n y a t l a ( a t ) n y a t l a . j p > 
 
   *   
 
   * / 
 
 u s i n g   S y s t e m . D i a g n o s t i c s ; 
 
 n a m e s p a c e   j p . n y a t l a . n y a r t o o l k i t . c s . c o r e 
 
 { 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
         / * * 
 
           *   S0n0000o00R L E 'W.~0)R(uW0_0*}00000000iQ(un00y0000000g0Y00
 
           *   0y0000;uP0ub[0Z0k00000*x0n0000000000n0 N0\O0S0h0k0laW0f0O0`0U0D00
 
           *   < p > 000000pe
 
           *   S0n0000o0D0O0d0K0n0]000000pe0cd0ba000g0Y00}b000g0000000pe0[ňW0f0OD0~0Y00
 
           *   < u l > 
 
           *   < l i > { @ l i n k   # o n L a b e l F o u n d } -   { @ l i n k   # l a b e l i n g } peL0iQW0_00000wY00000000peg0Y00
 
           *   S0S0k00zvW0_00000QtY000000fM0~0Y00
 
           *   < / u l > 
 
           *   < / p > 
 
           *   < p > 000*n0000000000  - 
 
           *   S0n000000000o000000ibY00JXn0*퐒0cY0pg0Y00S0S0K00eMO*iQ0[LY00h00
 
           *   000n0*퐒0 NhTY00S0h0L0g0M0~0Y00
 
           *   < / p > 
 
           *   < p > eQRg0M00;u }b__  - 
 
           *   < p > { @ l i n k   N y A R B i n R a s t e r } 0eQRY004XT
 
           *   < u l > 
 
           *   < l i > { @ l i n k   N y A R B u f f e r T y p e # I N T 1 D _ B I N _ 8 } 
 
           *   < / u l > 
 
           *   < / p > 
 
           *   < p > { @ l i n k   N y A R G r a y s c a l e R a s t e r } 0eQRY004XT
 
           *   < u l > 
 
           *   < l i > { @ l i n k   N y A R B u f f e r T y p e # I N T 1 D _ G R A Y _ 8 } 
 
           *   < / u l > 
 
           *   < / p > 
 
           *   < / p > 
 
           * / 
 
         p u b l i c   a b s t r a c t   c l a s s   N y A R L a b e l i n g _ R l e 
 
         { 
 
                 / * * 
 
                   *   N y A R L a b e l i n g _ R l e 000L0O(uY00000000000000000g0Y00
 
                   * / 
 
                 p u b l i c   i n t e r f a c e   I R a s t e r D r i v e r 
 
                 { 
 
                         / * * 
 
                           *   s(Wn0000n0c[p( x , y ) K000E^i _ l e n n0W0R L E 'W.~W0f0ԏW0~0Y00
 
                           *   @ p a r a m   i _ x 
 
                           *   @ p a r a m   i _ y 
 
                           *   @ p a r a m   i _ l e n 
 
                           *   @ p a r a m   i _ o u t 
 
                           *   @ r e t u r n 
 
                           * / 
 
                         i n t   x L i n e T o R l e ( i n t   i _ x ,   i n t   i _ y ,   i n t   i _ l e n ,   i n t   i _ t h ,   R l e E l e m e n t [ ]   i _ o u t ) ; 
 
                 } 
 
                 / * * 
 
                   *   L a b e l i n g (un0;uP00000i{W0~0Y00
 
                   * / 
 
                 p u b l i c   c l a s s   R a s t e r D r i v e r F a c t o r y 
 
                 { 
 
                         / * * 
 
                           *   S0n0peo0000K00|Tp0000
 
                           *   @ p a r a m   i _ r a s t e r 
 
                           *   @ r e t u r n 
 
                           * / 
 
                         p u b l i c   s t a t i c   N y A R L a b e l i n g _ R l e . I R a s t e r D r i v e r   c r e a t e D r i v e r ( I N y A R G r a y s c a l e R a s t e r   i _ r a s t e r ) 
 
                         { 
 
                                 s w i t c h   ( i _ r a s t e r . g e t B u f f e r T y p e ( ) ) 
 
                                 { 
 
                                         c a s e   N y A R B u f f e r T y p e . I N T 1 D _ G R A Y _ 8 : 
 
                                         c a s e   N y A R B u f f e r T y p e . I N T 1 D _ B I N _ 8 : 
 
                                                 r e t u r n   n e w   N y A R R l e P i x e l D r i v e r _ B I N _ G S 8 ( i _ r a s t e r ) ; 
 
                                         d e f a u l t : 
 
                                                 i f   ( i _ r a s t e r   i s   I N y A R G r a y s c a l e R a s t e r ) 
 
                                                 { 
 
                                                         r e t u r n   n e w   N y A R R l e P i x e l D r i v e r _ G S R e a d e r ( ( I N y A R G r a y s c a l e R a s t e r ) i _ r a s t e r ) ; 
 
                                                 } 
 
                                                 t h r o w   n e w   N y A R E x c e p t i o n ( ) ; 
 
                                 } 
 
                         } 
 
                 } 
 
                 / * * 
 
                   *   S0n0000o00{ @ l i n k   R l e I n f o S t a c k } n0 }g0Y00
 
                   *   R L E 000000n0000000OcW0~0Y00
 
                   *   000L0OF0S0h0o0B00~0[000
 
                   * / 
 
                 p u b l i c   c l a s s   R l e E l e m e n t 
 
                 { 
 
                         p u b l i c   i n t   l ; 
 
                         p u b l i c   i n t   r ; 
 
                         p u b l i c   i n t   f i d ; 
 
                         p u b l i c   s t a t i c   R l e E l e m e n t [ ]   c r e a t e A r r a y ( i n t   i _ l e n g t h ) 
 
                         { 
 
                                 R l e E l e m e n t [ ]   r e t   =   n e w   R l e E l e m e n t [ i _ l e n g t h ] ; 
 
                                 f o r   ( i n t   i   =   0 ;   i   <   i _ l e n g t h ;   i + + ) 
 
                                 { 
 
                                         r e t [ i ]   =   n e w   R l e E l e m e n t ( ) ; 
 
                                 } 
 
                                 r e t u r n   r e t ; 
 
                         } 
 
                 } 
 
                 p r i v a t e   c o n s t   i n t   A R _ A R E A _ M A X   =   1 0 0 0 0 0 ; / /   # d e f i n e   A R _ A R E A _ M A X   1 0 0 0 0 0 
 
                 p r i v a t e   c o n s t   i n t   A R _ A R E A _ M I N   =   7 0 ; / /   # d e f i n e   A R _ A R E A _ M I N   7 0 
 
                 p r i v a t e   R l e I n f o S t a c k   _ r l e s t a c k ; 
 
                 p r i v a t e   R l e E l e m e n t [ ]   _ r l e 1 ; 
 
                 p r i v a t e   R l e E l e m e n t [ ]   _ r l e 2 ; 
 
                 p r i v a t e   i n t   _ m a x _ a r e a ; 
 
                 p r i v a t e   i n t   _ m i n _ a r e a ; 
 
                 / * *   eQR000n0000* / 
 
                 p r o t e c t e d   N y A R I n t S i z e   _ r a s t e r _ s i z e   =   n e w   N y A R I n t S i z e ( ) ; 
 
                 / * * 
 
                   *   0000000g0Y00{ @ l i n k   # l a b e l i n g } k0eQRY00000n00000c[W0f000000000ubW0~0Y00
 
                   *   @ p a r a m   i _ w i d t h 
 
                   *   eQR;uPn0E^
 
                   *   @ p a r a m   i _ h e i g h t 
 
                   *   eQR;uPn0ؚU0
 
                   *   @ 
 
                   * / 
 
                 p u b l i c   N y A R L a b e l i n g _ R l e ( i n t   i _ w i d t h ,   i n t   i _ h e i g h t ) 
 
                 { 
 
                         t h i s . i n i t I n s t a n c e ( i _ w i d t h ,   i _ h e i g h t ) ; 
 
                 } 
 
 
 
                 p r o t e c t e d   v o i d   i n i t I n s t a n c e ( i n t   i _ w i d t h ,   i n t   i _ h e i g h t ) 
 
                 { 
 
                         t h i s . _ r a s t e r _ s i z e . s e t V a l u e ( i _ w i d t h ,   i _ h e i g h t ) ; 
 
                         / / 1 2 0 K B / Q V G A   + 4 K 
 
                         l o n g   t   =   ( l o n g ) i _ w i d t h   *   i _ h e i g h t   *   3 0 0 0   /   ( 3 2 0   *   2 4 0 )   +   1 0 0 ; / / f u l l   H D   s u p p o r t 
 
                         t h i s . _ r l e s t a c k   =   n e w   R l e I n f o S t a c k ( ( i n t ) t ) ; 
 
                         t h i s . _ r l e 1   =   R l e E l e m e n t . c r e a t e A r r a y ( i _ w i d t h   /   2   +   1 ) ; 
 
                         t h i s . _ r l e 2   =   R l e E l e m e n t . c r e a t e A r r a y ( i _ w i d t h   /   2   +   1 ) ; 
 
                         t h i s . _ m a x _ a r e a   =   A R _ A R E A _ M A X ; 
 
                         t h i s . _ m i n _ a r e a   =   A R _ A R E A _ M I N ; 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   iQY00000n0000;u }pe	{V0-[W0~0Y00
 
                   *   S0n0{Vk0B00000n00L00P}gk0ԏU00~0Y00
 
                   *   Rg$Po00{ @ l i n k   # A R _ A R E A _ M A X } , { @ l i n k   # A R _ A R E A _ M I N } g0Y00
 
                   *   @ p a r a m   i _ m a x 
 
                   *   000n0 g'Y$P0c[W0~0Y00
 
                   *   @ p a r a m   i _ m i n 
 
                   *   000n0 g\$P0c[W0~0Y00
 
                   * / 
 
                 p u b l i c   v o i d   s e t A r e a R a n g e ( i n t   i _ m a x ,   i n t   i _ m i n ) 
 
                 { 
 
                         D e b u g . A s s e r t ( i _ m i n   >   0   & &   i _ m a x   >   i _ m i n ) ; 
 
                         t h i s . _ m a x _ a r e a   =   i _ m a x ; 
 
                         t h i s . _ m i n _ a r e a   =   i _ m i n ; 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   0000000R L E 0000x0RY000
 
                   *   @ p a r a m   i _ r e l _ i m g 
 
                   *   @ p a r a m   i _ n o f 
 
                   *   @ p a r a m   i _ r o w _ i n d e x 
 
                   *   @ p a r a m   o _ s t a c k 
 
                   *   @ r e t u r n 
 
                   *   @ 
 
                   * / 
 
                 p r i v a t e   b o o l   a d d F r a g m e n t ( R l e E l e m e n t   i _ r e l _ i m g ,   i n t   i _ n o f ,   i n t   i _ r o w _ i n d e x ,   R l e I n f o S t a c k   o _ s t a c k ) 
 
                 { 
 
                         i n t   l   =   i _ r e l _ i m g . l ; 
 
                         i n t   l e n   =   i _ r e l _ i m g . r   -   l ; 
 
                         i _ r e l _ i m g . f i d   =   i _ n o f ; / /   R E L kn0V	gI D 
 
                         N y A R R l e L a b e l F r a g m e n t I n f o   v   =   o _ s t a c k . p r e P u s h ( ) ; 
 
                         i f   ( v   = =   n u l l ) 
 
                         { 
 
                                 r e t u r n   f a l s e ; 
 
                         } 
 
                         v . e n t r y _ x   =   l ; 
 
                         v . a r e a   =   l e n ; 
 
                         v . c l i p _ l   =   l ; 
 
                         v . c l i p _ r   =   i _ r e l _ i m g . r   -   1 ; 
 
                         v . c l i p _ t   =   i _ r o w _ i n d e x ; 
 
                         v . c l i p _ b   =   i _ r o w _ i n d e x ; 
 
                         v . p o s _ x   =   ( l e n   *   ( 2   *   l   +   ( l e n   -   1 ) ) )   /   2 ; 
 
                         v . p o s _ y   =   i _ r o w _ i n d e x   *   l e n ; 
 
 
 
                         r e t u r n   t r u e ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo000000weE\$Pi _ t h g02 $PSW0f0000000W0~0Y00
 
                   *   iQW0_0000o00]000000pe{ @ l i n k   # o n L a b e l F o u n d } g0wW0~0Y00
 
                   *   @ p a r a m   i _ b i n _ r a s t e r 
 
                   *   eQR;uP0[_Y00b__o00000n0f0SgqW0f0O0`0U0D00
 
                   *   @ p a r a m   i _ t h 
 
                   *   weE\$P0c[W0~0Y002 $P;uPn04XTo000 0c[W0f0O0`0U0D00
 
                   *   @ 
 
                   * / 
 
                 p u b l i c   v i r t u a l   b o o l   l a b e l i n g ( I N y A R G r a y s c a l e R a s t e r   i _ r a s t e r ,   i n t   i _ t h ) 
 
                 { 
 
                         N y A R I n t S i z e   s i z e   =   i _ r a s t e r . g e t S i z e ( ) ; 
 
                         r e t u r n   t h i s . i m p l e _ l a b e l i n g ( i _ r a s t e r ,   i _ t h ,   0 ,   0 ,   s i z e . w ,   s i z e . h ) ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo000000weE\$Pi _ t h g02 $PSW0f0000000W0~0Y00
 
                   *   iQW0_0000o00]000000pe{ @ l i n k   # o n L a b e l F o u n d } g0wW0~0Y00
 
                   *   @ p a r a m   i _ b i n _ r a s t e r 
 
                   *   eQR;uP0[_Y00b__o00000n0f0SgqW0f0O0`0U0D00
 
                   *   @ p a r a m   i _ a r e a 
 
                   *   0y0000Y00;uPQn0{V
 
                   *   @ p a r a m   i _ t h 
 
                   *   weE\$P
 
                   *   @ 
 
                   * / 
 
                 p u b l i c   v i r t u a l   b o o l   l a b e l i n g ( I N y A R G r a y s c a l e R a s t e r   i _ r a s t e r ,   N y A R I n t R e c t   i _ a r e a ,   i n t   i _ t h ) 
 
                 { 
 
                         r e t u r n   t h i s . i m p l e _ l a b e l i n g ( i _ r a s t e r ,   0 ,   i _ a r e a . x ,   i _ a r e a . y ,   i _ a r e a . w ,   i _ a r e a . h ) ; 
 
                 } 
 
                 p r i v a t e   I N y A R R a s t e r   _ l a s t _ i n p u t _ r a s t e r   =   n u l l ; 
 
                 p r i v a t e   I R a s t e r D r i v e r   _ i m a g e _ d r i v e r ; 
 
 
 
   	         / * * 
 
 	           *   
 
 	           *   00000n0[SO0
 
 	           *   @ r e t u r n 
 
 	           *   000peL0
NPk0TW0_0h0M0o0f a l s e 
 
 	           * / 
 
 	         p r i v a t e   b o o l   i m p l e _ l a b e l i n g ( I N y A R R a s t e r   i _ r a s t e r , i n t   i _ t h , i n t   i _ l e f t , i n t   i _ t o p , i n t   i _ w i d t h ,   i n t   i _ h e i g h t ) 
 
 	         { 
 
 	 	 / / 000n00000x
 
 	 	 D e b u g . A s s e r t ( i _ r a s t e r . g e t S i z e ( ) . i s E q u a l S i z e ( t h i s . _ r a s t e r _ s i z e ) ) ; 
 
 	 	 / / 0000000n00000
 
 	 	 i f ( _ l a s t _ i n p u t _ r a s t e r ! = i _ r a s t e r ) { 
 
 	 	 	 t h i s . _ i m a g e _ d r i v e r = ( I R a s t e r D r i v e r ) i _ r a s t e r . c r e a t e I n t e r f a c e ( t y p e o f ( I R a s t e r D r i v e r ) ) ; 
 
 	 	 } 
 
 	 	 I R a s t e r D r i v e r   p i x d r v = t h i s . _ i m a g e _ d r i v e r ; 
 
 	 	 R l e E l e m e n t [ ]   r l e _ p r e v   =   t h i s . _ r l e 1 ; 
 
 	 	 R l e E l e m e n t [ ]   r l e _ c u r r e n t   =   t h i s . _ r l e 2 ; 
 
 	 	 / /   0000Qt
 
 	 	   R l e I n f o S t a c k   r l e s t a c k = t h i s . _ r l e s t a c k ; 
 
 	 	 r l e s t a c k . c l e a r ( ) ; 
 
 
 
 	 	 / / 
 
 	 	 i n t   l e n _ p r e v   =   0 ; 
 
 	 	 i n t   l e n _ c u r r e n t   =   0 ; 
 
 	 	 i n t   b o t t o m = i _ t o p + i _ h e i g h t ; 
 
 	 	 i n t   i d _ m a x   =   0 ; 
 
 	 	 i n t   y p o s = i _ t o p ; 
 
 	 	 / /   Rk{v2
 
 	 	 l e n _ p r e v   =   p i x d r v . x L i n e T o R l e ( i _ l e f t , y p o s , i _ w i d t h , i _ t h , r l e _ p r e v ) ; 
 
 	 	 f o r   ( i n t   i   =   0 ;   i   <   l e n _ p r e v ;   i + + )   { 
 
 	 	 	 / /   000000I D = 000000Rg$P0P O S = Y $P0R E L 00000= L
 
                         i f   ( a d d F r a g m e n t ( r l e _ p r e v [ i ] ,   i d _ m a x ,   y p o s ,   r l e s t a c k ) ) 
 
                         { 
 
                                 i d _ m a x + + ; 
 
 	 	 	 } e l s e { 
 
 	 	 	 	 r e t u r n   f a l s e ; 
 
                         } 
 
 	 	 } 
 
 	 	 N y A R R l e L a b e l F r a g m e n t I n f o [ ]   f _ a r r a y   =   r l e s t a c k . g e t A r r a y ( ) ; 
 
 	 	 / /   !kkP}T
 
 	 	 f o r   ( i n t   y   =   i _ t o p   +   1 ;   y   <   b o t t o m ;   y + + )   { 
 
 	 	 	 / /   0000Ln0
 
 	 	 	 
 
 	 	 	 y p o s + + ; 
 
 	 	 	 l e n _ c u r r e n t   =   p i x d r v . x L i n e T o R l e ( i _ l e f t , y p o s , i _ w i d t h , i _ t h ,   r l e _ c u r r e n t ) ; 
 
 	 	 	 i n t   i n d e x _ p r e v   =   0 ; 
 
 
 
 	 	 	 f o r   ( i n t   i   =   0 ;   i   <   l e n _ c u r r e n t ;   i + + )   { 
 
 	 	 	 	 / /   i n d e x _ p r e v , l e n _ p r e v n0MOn0teY00
 
 	 	 	 	 i n t   i d   =   - 1 ; 
 
 	 	 	 	 / /   0000Y0y0M0p r e v L0B00p0x
 
 	 	 	 	 w h i l e   ( i n d e x _ p r e v   <   l e n _ p r e v )   { 
 
 	 	 	 	 	 i f   ( r l e _ c u r r e n t [ i ] . l   -   r l e _ p r e v [ i n d e x _ p r e v ] . r   >   0 )   { / /   0 j008 eMO00000
 
 	 	 	 	 	 	 / /   p r e v L0c u r n0]ek0B00!!kn00000000c"}
 
 	 	 	 	 	 	 i n d e x _ p r e v + + ; 
 
 	 	 	 	 	 	 c o n t i n u e ; 
 
 	 	 	 	 	 }   e l s e   i f   ( r l e _ p r e v [ i n d e x _ p r e v ] . l   -   r l e _ c u r r e n t [ i ] . r   >   0 )   { / /   0 j008 eMO00000k0j00
 
 	 	 	 	 	 	 / /   p r e v L0c u r Sek0B00!rz000000
 
 	 	 	 	 	 	 i f ( a d d F r a g m e n t ( r l e _ c u r r e n t [ i ] ,   i d _ m a x ,   y , r l e s t a c k ) ) { 
 
 	 	 	 	 	 	 	 i d _ m a x + + ; 
 
                                                 } e l s e { 
 
                                                         r e t u r n   f a l s e ; 
 
                                                 } 
 
 	 	 	 	 	 	 / /   !kn0i n d e x 0W00y00
 
 	 	 	 	 	 	 g o t o   S C A N _ C U R ; 
 
 	 	 	 	 	 } 
 
 	 	 	 	 	 i d = r l e _ p r e v [ i n d e x _ p r e v ] . f i d ; / / 000000000i d 
 
 	 	 	 	 	 N y A R R l e L a b e l F r a g m e n t I n f o   i d _ p t r   =   f _ a r r a y [ i d ] ; 
 
 	 	 	 	 	 / / P}T[a( RV) - > p r e v n0I D 0000W0f00000000000n0`1X0fe
 
 	 	 	 	 	 r l e _ c u r r e n t [ i ] . f i d   =   i d ; / / 000000I D 0OX[
 
 	 	 	 	 	 / / 
 
 	 	 	 	 	   i n t   l =   r l e _ c u r r e n t [ i ] . l ; 
 
 	 	 	 	 	   i n t   r =   r l e _ c u r r e n t [ i ] . r ; 
 
 	 	 	 	 	   i n t   l e n = r - l ; 
 
 	 	 	 	 	 / / P}THQ000000n0`1X0feY000
 
 	 	 	 	 	 i d _ p t r . a r e a   + =   l e n ; 
 
 	 	 	 	 	 / / t h0e n t r y _ x o00P}THQn00OF0n0g0feW0j0D00
 
 	 	 	 	 	 i d _ p t r . c l i p _ l = l < i d _ p t r . c l i p _ l ? l : i d _ p t r . c l i p _ l ; 
 
 	 	 	 	 	 i d _ p t r . c l i p _ r = r > i d _ p t r . c l i p _ r ? r - 1 : i d _ p t r . c l i p _ r ; 
 
 	 	 	 	 	 i d _ p t r . c l i p _ b = y ; 
 
 	 	 	 	 	 i d _ p t r . p o s _ x + = ( l e n * ( 2 * l + ( l e n - 1 ) ) ) / 2 ; 
 
 	 	 	 	 	 i d _ p t r . p o s _ y + = y * l e n ; 
 
 	 	 	 	 	 / / Y͑P}Tn0xPvNM	
 
 	 	 	 	 	 i n d e x _ p r e v + + ; 
 
 	 	 	 	 	 w h i l e   ( i n d e x _ p r e v   <   l e n _ p r e v )   { 
 
 	 	 	 	 	 	 i f   ( r l e _ c u r r e n t [ i ] . l   -   r l e _ p r e v [ i n d e x _ p r e v ] . r   >   0 )   { / /   0 j008 eMO00000
 
 	 	 	 	 	 	 	 / /   p r e v L0c u r n0]ek0B00!p r e v o0c u r k0#P}W0f0D0j0D00
 
 	 	 	 	 	 	 	 g o t o   S C A N _ P R E V ; 
 
 	 	 	 	 	 	 }   e l s e   i f   ( r l e _ p r e v [ i n d e x _ p r e v ] . l   -   r l e _ c u r r e n t [ i ] . r   >   0 )   { / /   0 j008 eMO00000k0j00
 
 	 	 	 	 	 	 	 / /   p r e v L0c u r n0Sek0B00!p r e v o0c u r k0#P}W0f0D0j0D00
 
 	 	 	 	 	 	 	 i n d e x _ p r e v - - ; 
 
 	 	 	 	 	 	 	 g o t o   S C A N _ C U R ; 
 
 	 	 	 	 	 	 } 
 
 	 	 	 	 	 	 / /   p r e v h0c u r o0#P}W0f0D00!000000000n0q}T
 
 	 	 	 	 	 	 
 
 	 	 	 	 	 	 / / P}TY000000000000S_
 
 	 	 	 	 	 	   i n t   p r e v _ i d   = r l e _ p r e v [ i n d e x _ p r e v ] . f i d ; 
 
 	 	 	 	 	 	 N y A R R l e L a b e l F r a g m e n t I n f o   p r e v _ p t r   =   f _ a r r a y [ p r e v _ i d ] ; 
 
 	 	 	 	 	 	 i f   ( i d   ! =   p r e v _ i d ) { 
 
 	 	 	 	 	 	 	 / / p r e v h0c u r r e n t n0000000i d 0fM0cH000
 
 	 	 	 	 	 	 	 f o r ( i n t   i 2 = i n d e x _ p r e v ; i 2 < l e n _ p r e v ; i 2 + + ) { 
 
 	 	 	 	 	 	 	 	 / / p r e v o0s(Wn0i d K00 g_~0g0
 
 	 	 	 	 	 	 	 	 i f ( r l e _ p r e v [ i 2 ] . f i d = = p r e v _ i d ) { 
 
 	 	 	 	 	 	 	 	 	 r l e _ p r e v [ i 2 ] . f i d = i d ; 
 
 	 	 	 	 	 	 	 	 } 
 
 	 	 	 	 	 	 	 } 
 
 	 	 	 	 	 	 	 f o r ( i n t   i 2 = 0 ; i 2 < i ; i 2 + + ) { 
 
 	 	 	 	 	 	 	 	 / / c u r r e n t o00 K00s(W- 1 ~0g0
 
 	 	 	 	 	 	 	 	 i f ( r l e _ c u r r e n t [ i 2 ] . f i d = = p r e v _ i d ) { 
 
 	 	 	 	 	 	 	 	 	 r l e _ c u r r e n t [ i 2 ] . f i d = i d ; 
 
 	 	 	 	 	 	 	 	 } 
 
 	 	 	 	 	 	 	 } 
 
 	 	 	 	 	 	 	 
 
 	 	 	 	 	 	 	 / / s(Wn0000000000k0`1X0Ɩ}
 
 	 	 	 	 	 	 	 i d _ p t r . a r e a   + = p r e v _ p t r . a r e a ; 
 
 	 	 	 	 	 	 	 i d _ p t r . p o s _ x + = p r e v _ p t r . p o s _ x ; 
 
 	 	 	 	 	 	 	 i d _ p t r . p o s _ y + = p r e v _ p t r . p o s _ y ; 
 
 	 	 	 	 	 	 	 / / t h0e n t r y _ x n0zl[
 
 	 	 	 	 	 	 	 i f   ( i d _ p t r . c l i p _ t   >   p r e v _ p t r . c l i p _ t )   { 
 
 	 	 	 	 	 	 	 	 / /   s(Wn0eL0Nk0B000
 
 	 	 	 	 	 	 	 	 i d _ p t r . c l i p _ t   =   p r e v _ p t r . c l i p _ t ; 
 
 	 	 	 	 	 	 	 	 i d _ p t r . e n t r y _ x   =   p r e v _ p t r . e n t r y _ x ; 
 
 	 	 	 	 	 	 	 } e l s e   i f   ( i d _ p t r . c l i p _ t   <   p r e v _ p t r . c l i p _ t )   { 
 
 	 	 	 	 	 	 	 	 / /   s(Wn0eL0
Nk0B000p r e v k00000000
 
 	 	 	 	 	 	 	 }   e l s e   { 
 
 	 	 	 	 	 	 	 	 / /   4ls^eTg0\U0D0eL0000000000
 
 	 	 	 	 	 	 	 	 i f   ( i d _ p t r . e n t r y _ x   >   p r e v _ p t r . e n t r y _ x )   { 
 
 	 	 	 	 	 	 	 	 	 i d _ p t r . e n t r y _ x   =   p r e v _ p t r . e n t r y _ x ; 
 
 	 	 	 	 	 	 	 	 } e l s e { 
 
 	 	 	 	 	 	 	 	 } 
 
 	 	 	 	 	 	 	 } 
 
 	 	 	 	 	 	 	 / / l n0zl[
 
 	 	 	 	 	 	 	 i f   ( i d _ p t r . c l i p _ l   >   p r e v _ p t r . c l i p _ l )   { 
 
 	 	 	 	 	 	 	 	 i d _ p t r . c l i p _ l = p r e v _ p t r . c l i p _ l ; 
 
 	 	 	 	 	 	 	 } e l s e { 
 
 	 	 	 	 	 	 	 } 
 
 	 	 	 	 	 	 	 / / r n0zl[
 
 	 	 	 	 	 	 	 i f   ( i d _ p t r . c l i p _ r   <   p r e v _ p t r . c l i p _ r )   { 
 
 	 	 	 	 	 	 	 	 i d _ p t r . c l i p _ r = p r e v _ p t r . c l i p _ r ; 
 
 	 	 	 	 	 	 	 } e l s e { 
 
 	 	 	 	 	 	 	 } 
 
 	 	 	 	 	 	 	 / / b n0zl[
 
 
 
 	 	 	 	 	 	 	 / / P}Tnn00000000000!qRSY000
 
 	 	 	 	 	 	 	 p r e v _ p t r . a r e a = 0 ; 
 
 	 	 	 	 	 	 } 
 
 
 
 
 
 	 	 	 	 	 	 i n d e x _ p r e v + + ; 
 
 	 	 	 	 	 } 
 
 	 	 	 	 	 i n d e x _ p r e v - - ; 
 
 	 	 	 	 	 b r e a k ; 
 
                                 S C A N _ P R E V :   ; 
 
 	 	 	 	 } 
 
 	 	 	 	 / /   c u r k0i d L0rR0S_f000_0K00x
 
 	 	 	 	 / /   Szrz0000000R
 
 	 	 	 	 i f   ( i d   <   0 ) { 
 
 	 	 	 	 	 i f ( a d d F r a g m e n t ( r l e _ c u r r e n t [ i ] ,   i d _ m a x ,   y , r l e s t a c k ) ) { 
 
 	 	 	 	 	 	 i d _ m a x + + ; 
 
                                         } e l s e { 
 
                                                 r e t u r n   f a l s e ; 
 
                                         } 
 
 	 	 	 	 } 
 
                         S C A N _ C U R :   ; 
 
                         } 
 
 	 	 	 / /   p r e v h0r e l n0Nc
 
 	 	 	 R l e E l e m e n t [ ]   t m p   =   r l e _ p r e v ; 
 
 	 	 	 r l e _ p r e v   =   r l e _ c u r r e n t ; 
 
 	 	 	 l e n _ p r e v   =   l e n _ c u r r e n t ; 
 
 	 	 	 r l e _ c u r r e n t   =   t m p ; 
 
 	 	 } 
 
 	 	 / / [an0000`0Q00
 
 	 	   i n t   m a x = t h i s . _ m a x _ a r e a ; 
 
 	 	   i n t   m i n = t h i s . _ m i n _ a r e a ; 
 
 	 	 f o r ( i n t   i = i d _ m a x - 1 ; i > = 0 ; i - - ) { 
 
 	 	 	   N y A R R l e L a b e l F r a g m e n t I n f o   s r c _ i n f o = f _ a r r a y [ i ] ; 
 
 	 	 	   i n t   a r e a = s r c _ i n f o . a r e a ; 
 
 	 	 	 i f ( a r e a < m i n   | |   a r e a > m a x ) { / / [aYn00000 n00m i n g0o0X0O0
 
 	 	 	 	 c o n t i n u e ; 
 
 	 	 	 } 
 
 	 	 	 / / $P0v[MOnk0܈ck
 
 	 	 	 s r c _ i n f o . c l i p _ l + = i _ l e f t ; 
 
 	 	 	 s r c _ i n f o . c l i p _ r + = i _ l e f t ; 
 
 	 	 	 s r c _ i n f o . e n t r y _ x + = i _ l e f t ; 
 
 	 	 	 s r c _ i n f o . p o s _ x / = a r e a ; 
 
 	 	 	 s r c _ i n f o . p o s _ y / = a r e a ; 
 
 	 	 	 / / 000000pe000
 
 	 	 	 t h i s . o n L a b e l F o u n d ( s r c _ i n f o ) ; 
 
 	 	 } 
 
                 r e t u r n   t r u e ; 
 
 	 } 
 
                 / * * 
 
                   *   S0n0N`peo0]000000peg0Y00
 
                   *   { @ l i n k   # l a b e l i n g } peL00iQW0_00000wY00_00k0OD0~0Y00
 
                   *   @ p a r a m   i _ r e f _ l a b e l 
 
                   *   iQW0_00000<h
}W0_00000000$Pn0	gRgo00!kn0{ @ l i n k   # l a b e l i n g } L0[LU000~0g0g0Y00
 
                   *   ( l) S0n0Nio0	Y00K00W00~0[000
 
                   *   @ 
 
                   * / 
 
 
 
                 p r o t e c t e d   a b s t r a c t   v o i d   o n L a b e l F o u n d ( N y A R R l e L a b e l F r a g m e n t I n f o   i _ r e f _ l a b e l ) ; 
 
 
 
                 / * * 
 
                   *   000n0Nix000g0Y00000MRn0Sgq0000L0SK00ԏW0~0Y00
 
                   *   S0n0000g0o00t r u e V[g0Y00
 
                   * / 
 
                 p u b l i c   c o n s t   b o o l   _ s f _ l a b e l _ a r r a y _ s a f e _ r e f e r e n c e   =   t r u e ; 
 
         } 
 
 
 
         / * * 
 
           *   S0n0000o00{ @ l i n k   N y A R L a b e l i n g _ R l e _ o l d } L0Q萄vk0OF0R L E 0000g0Y00
 
           *   000L0OF0S0h0o0B00~0[000
 
           * / 
 
         c l a s s   R l e I n f o S t a c k   :   N y A R O b j e c t S t a c k < N y A R R l e L a b e l F r a g m e n t I n f o > 
 
         { 
 
                 p u b l i c   R l e I n f o S t a c k ( i n t   i _ l e n g t h ) : b a s e ( ) 
 
                 { 
 
                         b a s e . i n i t I n s t a n c e ( i _ l e n g t h ) ; 
 
                         r e t u r n ; 
 
                 } 
 
 
 
                 p r o t e c t e d   o v e r r i d e   N y A R R l e L a b e l F r a g m e n t I n f o   c r e a t e E l e m e n t ( ) 
 
                 { 
 
                         r e t u r n   n e w   N y A R R l e L a b e l F r a g m e n t I n f o ( ) ; 
 
                 } 
 
         } 
 
 
 
         / / 
 
         / / ;uP0000
 
         / / 
 
 
 
         c l a s s   N y A R R l e P i x e l D r i v e r _ B I N _ G S 8   :   N y A R L a b e l i n g _ R l e . I R a s t e r D r i v e r 
 
         { 
 
                 p r i v a t e   I N y A R R a s t e r   _ r e f _ r a s t e r ; 
 
                 p u b l i c   N y A R R l e P i x e l D r i v e r _ B I N _ G S 8 ( I N y A R R a s t e r   i _ r e f _ r a s t e r ) 
 
                 { 
 
                         t h i s . _ r e f _ r a s t e r   =   i _ r e f _ r a s t e r ; 
 
                 } 
 
                 p u b l i c   i n t   x L i n e T o R l e ( i n t   i _ x ,   i n t   i _ y ,   i n t   i _ l e n ,   i n t   i _ t h ,   N y A R L a b e l i n g _ R l e . R l e E l e m e n t [ ]   i _ o u t ) 
 
                 { 
 
                         i n t [ ]   b u f   =   ( i n t [ ] ) t h i s . _ r e f _ r a s t e r . g e t B u f f e r ( ) ; 
 
                         i n t   c u r r e n t   =   0 ; 
 
                         i n t   r   =   - 1 ; 
 
                         / /   Lx[Y
 
                         i n t   s t   =   i _ x   +   t h i s . _ r e f _ r a s t e r . g e t W i d t h ( )   *   i _ y ; 
 
                         i n t   x   =   s t ; 
 
                         i n t   r i g h t _ e d g e   =   s t   +   i _ l e n   -   1 ; 
 
                         w h i l e   ( x   <   r i g h t _ e d g e ) 
 
                         { 
 
                                 / /   fp( 0 ) 0000
 
                                 i f   ( b u f [ x ]   >   i _ t h ) 
 
                                 { 
 
                                         x + + ; / / fp
 
                                         c o n t i n u e ; 
 
                                 } 
 
                                 / /   fpzv!fpw0y00
 
                                 r   =   ( x   -   s t ) ; 
 
                                 i _ o u t [ c u r r e n t ] . l   =   r ; 
 
                                 r + + ; / /   fp+ 1 
 
                                 x + + ; 
 
                                 w h i l e   ( x   <   r i g h t _ e d g e ) 
 
                                 { 
 
                                         i f   ( b u f [ x ]   >   i _ t h ) 
 
                                         { 
 
                                                 / /   fp( 1 ) !fp( 0 ) MRB}N> {v2
 
                                                 i _ o u t [ c u r r e n t ] . r   =   r ; 
 
                                                 c u r r e n t + + ; 
 
                                                 x + + ; / /   !kpn0x0
 
                                                 r   =   - 1 ; / /   Szn0MOn00 k00
 
                                                 b r e a k ; 
 
                                         } 
 
                                         e l s e 
 
                                         { 
 
                                                 / /   fp( 0 ) wR
 
                                                 r + + ; 
 
                                                 x + + ; 
 
                                         } 
 
                                 } 
 
                         } 
 
                         / /    g_n01 p`0Q0$R[elL0\W0UF0n00
 
                         i f   ( b u f [ x ]   >   i _ t h ) 
 
                         { 
 
                                 / /   fp!r 0000-Nj00fpMRB}N> {v2
 
                                 i f   ( r   > =   0 ) 
 
                                 { 
 
                                         i _ o u t [ c u r r e n t ] . r   =   r ; 
 
                                         c u r r e n t + + ; 
 
                                 } 
 
                         } 
 
                         e l s e 
 
                         { 
 
                                 / /   fp!0000-Ng0j0Q00p0l 1 g0R
 
                                 i f   ( r   > =   0 ) 
 
                                 { 
 
                                         i _ o u t [ c u r r e n t ] . r   =   ( r   +   1 ) ; 
 
                                 } 
 
                                 e l s e 
 
                                 { 
 
                                         / /    g_n01 pn04XT
 
                                         i _ o u t [ c u r r e n t ] . l   =   ( i _ l e n   -   1 ) ; 
 
                                         i _ o u t [ c u r r e n t ] . r   =   ( i _ l e n ) ; 
 
                                 } 
 
                                 c u r r e n t + + ; 
 
                         } 
 
                         / /   Lx[
 
                         r e t u r n   c u r r e n t ; 
 
                 } 
 
         } 
 
 
 
         / * * 
 
           *   G S P i x e l D r i v e r 0Oc0_0000
 
           * / 
 
         c l a s s   N y A R R l e P i x e l D r i v e r _ G S R e a d e r   :   N y A R L a b e l i n g _ R l e . I R a s t e r D r i v e r 
 
         { 
 
                 p r i v a t e   I N y A R G s P i x e l D r i v e r   _ r e f _ d r i v e r ; 
 
                 p u b l i c   N y A R R l e P i x e l D r i v e r _ G S R e a d e r ( I N y A R G r a y s c a l e R a s t e r   i _ r a s t e r ) 
 
                 { 
 
                         t h i s . _ r e f _ d r i v e r   =   i _ r a s t e r . g e t G s P i x e l D r i v e r ( ) ; 
 
                 } 
 
                 p u b l i c   i n t   x L i n e T o R l e ( i n t   i _ x ,   i n t   i _ y ,   i n t   i _ l e n ,   i n t   i _ t h ,   N y A R L a b e l i n g _ R l e . R l e E l e m e n t [ ]   i _ o u t ) 
 
                 { 
 
                         i n t   c u r r e n t   =   0 ; 
 
                         i n t   r   =   - 1 ; 
 
                         / /   Lx[Y
 
                         i n t   s t   =   i _ x ; 
 
                         i n t   x   =   s t ; 
 
                         i n t   r i g h t _ e d g e   =   s t   +   i _ l e n   -   1 ; 
 
                         w h i l e   ( x   <   r i g h t _ e d g e ) 
 
                         { 
 
                                 / /   fp( 0 ) 0000
 
                                 i f   ( t h i s . _ r e f _ d r i v e r . g e t P i x e l ( x ,   i _ y )   >   i _ t h ) 
 
                                 { 
 
                                         x + + ; / / fp
 
                                         c o n t i n u e ; 
 
                                 } 
 
                                 / /   fpzv!fpw0y00
 
                                 r   =   ( x   -   s t ) ; 
 
                                 i _ o u t [ c u r r e n t ] . l   =   r ; 
 
                                 r + + ; / /   fp+ 1 
 
                                 x + + ; 
 
                                 w h i l e   ( x   <   r i g h t _ e d g e ) 
 
                                 { 
 
                                         i f   ( t h i s . _ r e f _ d r i v e r . g e t P i x e l ( x ,   i _ y )   >   i _ t h ) 
 
                                         { 
 
                                                 / /   fp( 1 ) !fp( 0 ) MRB}N> {v2
 
                                                 i _ o u t [ c u r r e n t ] . r   =   r ; 
 
                                                 c u r r e n t + + ; 
 
                                                 x + + ; / /   !kpn0x0
 
                                                 r   =   - 1 ; / /   Szn0MOn00 k00
 
                                                 b r e a k ; 
 
                                         } 
 
                                         e l s e 
 
                                         { 
 
                                                 / /   fp( 0 ) wR
 
                                                 r + + ; 
 
                                                 x + + ; 
 
                                         } 
 
                                 } 
 
                         } 
 
                         / /    g_n01 p`0Q0$R[elL0\W0UF0n00
 
                         i f   ( t h i s . _ r e f _ d r i v e r . g e t P i x e l ( x ,   i _ y )   >   i _ t h ) 
 
                         { 
 
                                 / /   fp!r 0000-Nj00fpMRB}N> {v2
 
                                 i f   ( r   > =   0 ) 
 
                                 { 
 
                                         i _ o u t [ c u r r e n t ] . r   =   r ; 
 
                                         c u r r e n t + + ; 
 
                                 } 
 
                         } 
 
                         e l s e 
 
                         { 
 
                                 / /   fp!0000-Ng0j0Q00p0l 1 g0R
 
                                 i f   ( r   > =   0 ) 
 
                                 { 
 
                                         i _ o u t [ c u r r e n t ] . r   =   ( r   +   1 ) ; 
 
                                 } 
 
                                 e l s e 
 
                                 { 
 
                                         / /    g_n01 pn04XT
 
                                         i _ o u t [ c u r r e n t ] . l   =   ( i _ l e n   -   1 ) ; 
 
                                         i _ o u t [ c u r r e n t ] . r   =   ( i _ l e n ) ; 
 
                                 } 
 
                                 c u r r e n t + + ; 
 
                         } 
 
                         / /   Lx[
 
                         r e t u r n   c u r r e n t ; 
 
                 } 
 
         } 
 
 } 