/ *   
 
   *   P R O J E C T :   N y A R T o o l k i t C S 
 
   *   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
   *   T h i s   w o r k   i s   b a s e d   o n   t h e   o r i g i n a l   A R T o o l K i t   d e v e l o p e d   b y 
 
   *       H i r o k a z u   K a t o 
 
   *       M a r k   B i l l i n g h u r s t 
 
   *       H I T L a b ,   U n i v e r s i t y   o f   W a s h i n g t o n ,   S e a t t l e 
 
   *   h t t p : / / w w w . h i t l . w a s h i n g t o n . e d u / a r t o o l k i t / 
 
   * 
 
   *   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 1 2   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 ; 
 
 u s i n g   S y s t e m . I O ; 
 
 u s i n g   S y s t e m ; 
 
 u s i n g   S y s t e m . C o l l e c t i o n s . G e n e r i c ; 
 
 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 
 
 { 
 
         / * * 
 
           *   { @ l i n k   N y A R C o d e } 000n0/ec000g0Y00
 
           *   S0n0000o00{ @ l i n k   N y A R C o d e } n000000000S0_jn0F0a00I n p u t S t r e a m K00A R T o o l k i t b__n000000000Sc0f0MRk0<h
}Y00Kb0[ňW0~0Y00
 
           *   { @ l i n k   N y A R C o d e } NYK00O(uY00S0h0o0B00~0[000
 
           * / 
 
         c l a s s   N y A R C o d e F i l e R e a d e r 
 
         { 
 
 
 
                 / * * 
 
                   *   I m p u t S t r e a m K00A R T o o l K i t b__n0000000000o _ r a s t e r [ 4 ] k0<h
}W0~0Y00
 
                   *   @ p a r a m   i _ s t r e a m 
 
                   *   QW0CQn000000g0Y00
 
                   *   @ p a r a m   o _ r a s t e r 
 
                   *   QRHQn0000MRg0Y00
 
                   *   0000b__o0b__o0I N T 1 D _ X 8 R 8 G 8 B 8 _ 3 2 g0B0004  }0K0d0hQf0T Nj0000g0B00_L0B00~0Y00
 
                   *   @ 
 
                   * / 
 
                 p u b l i c   s t a t i c   v o i d   l o a d F r o m A R T o o l K i t F o r m F i l e ( S t r e a m R e a d e r   i _ s t r e a m ,   N y A R R a s t e r [ ]   o _ r a s t e r ) 
 
                 { 
 
                         D e b u g . A s s e r t ( o _ r a s t e r . L e n g t h   = =   4 ) ; 
 
                         / / 4 Pn0 }0000k0000Y000
 
                         t r y 
 
                         { 
 
                                 s t r i n g [ ]   d a t a   =   i _ s t r e a m . R e a d T o E n d ( ) . S p l i t ( n e w   C h a r [ ]   {   '   ' ,   ' \ r ' ,   ' \ n '   } ) ; 
 
                                 / / G B R A g0 N^0`0Y00
 
                                 i n t   i d x   =   0 ; 
 
                                 f o r   ( i n t   h   =   0 ;   h   <   4 ;   h + + ) 
 
                                 { 
 
                                         D e b u g . A s s e r t ( o _ r a s t e r [ h ] . i s E q u a l B u f f e r T y p e ( N y A R B u f f e r T y p e . I N T 1 D _ X 8 R 8 G 8 B 8 _ 3 2 ) ) ; 
 
                                         N y A R R a s t e r   r a   =   o _ r a s t e r [ h ] ; 
 
                                         i d x   =   r e a d B l o c k ( d a t a ,   i d x ,   r a . g e t W i d t h ( ) ,   r a . g e t H e i g h t ( ) ,   ( i n t [ ] ) r a . g e t B u f f e r ( ) ) ; 
 
                                 } 
 
                         } 
 
                         c a t c h   ( E x c e p t i o n   e ) 
 
                         { 
 
                                 t h r o w   n e w   N y A R E x c e p t i o n ( e ) ; 
 
                         } 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   I m p u t S t r e a m K00A R T o o l K i t b__n00000000000o _ c o d e 000000x0<h
}W0~0Y00
 
                   *   @ p a r a m   i _ s t r e a m 
 
                   *   QW0CQn000000g0Y00
 
                   *   @ p a r a m   o _ c o d e 
 
                   *   QRHQn0{ @ l i n k   N y A R C o d e } 000000g0Y00
 
                   *   @ 
 
                   * / 
 
                 p u b l i c   s t a t i c   v o i d   l o a d F r o m A R T o o l K i t F o r m F i l e ( S t r e a m R e a d e r   i _ s t r e a m ,   N y A R C o d e   o _ c o d e ) 
 
                 { 
 
                         i n t   w i d t h   =   o _ c o d e . g e t W i d t h ( ) ; 
 
                         i n t   h e i g h t   =   o _ c o d e . g e t H e i g h t ( ) ; 
 
                         N y A R R g b R a s t e r   t m p _ r a s t e r   =   n e w   N y A R R g b R a s t e r ( w i d t h ,   h e i g h t ,   N y A R B u f f e r T y p e . I N T 1 D _ X 8 R 8 G 8 B 8 _ 3 2 ) ; 
 
                         / / 4 Pn0 }0000k0000Y000
 
                         t r y 
 
                         { 
 
                                 i n t [ ]   b u f   =   ( i n t [ ] ) t m p _ r a s t e r . g e t B u f f e r ( ) ; 
 
                                 s t r i n g [ ]   d a t a   =   i _ s t r e a m . R e a d T o E n d ( ) . S p l i t ( n e w   C h a r [ ]   {   '   ' ,   ' \ r ' ,   ' \ n '   } ) ; 
 
                                 / / G B R A g0 N^0`0Y00
 
                                 i n t   i d x   =   0 ; 
 
                                 f o r   ( i n t   h   =   0 ;   h   <   4 ;   h + + ) 
 
                                 { 
 
                                         i d x   =   r e a d B l o c k ( d a t a ,   i d x ,   w i d t h ,   h e i g h t ,   b u f ) ; 
 
                                         / / A R C o d e k0000( 000) 
 
                                         o _ c o d e . g e t C o l o r D a t a ( h ) . s e t R a s t e r ( t m p _ r a s t e r ) ; 
 
                                         o _ c o d e . g e t B l a c k W h i t e D a t a ( h ) . s e t R a s t e r ( t m p _ r a s t e r ) ; 
 
                                 } 
 
                         } 
 
                         c a t c h   ( E x c e p t i o n   e ) 
 
                         { 
 
                                 t h r o w   n e w   N y A R E x c e p t i o n ( e ) ; 
 
                         } 
 
                         t m p _ r a s t e r   =   n u l l ; / / 00
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   00000i _ s t K0001 0000( 1 eMOR) n0X R G B 0000K00o _ b u f x00`0W0~0Y00
 
                   *   @ p a r a m   i _ d a t a 
 
                   *   eQRCQn0S t r e a m T o k e n i z e r 0c[W0~0Y00
 
                   *   i _ s t n00S0MOno0feU00~0Y00
 
                   *   @ p a r a m   i _ w i d t h 
 
                   *   0000n0*jP^( p i x e l ) g0Y00
 
                   *   @ p a r a m   i _ h e i g h t 
 
                   *   0000n0&~P^( p i x e l ) g0Y00
 
                   *   @ p a r a m   o _ b u f 
 
                   *   0Sc0_0$P0<h
}Y00MRg0Y00
 
                   *   @ 
 
                   * / 
 
                 p r i v a t e   s t a t i c   i n t   r e a d B l o c k ( s t r i n g [ ]   i _ d a t a ,   i n t   i _ i d x ,   i n t   i _ w i d t h ,   i n t   i _ h e i g h t ,   i n t [ ]   o _ b u f ) 
 
                 { 
 
                         i n t   i d x   =   i _ i d x ; 
 
                         t r y 
 
                         { 
 
                                 i n t   p i x e l s   =   i _ w i d t h   *   i _ h e i g h t ; 
 
                                 f o r   ( i n t   i 3   =   0 ;   i 3   <   3 ;   i 3 + + ) 
 
                                 { 
 
                                         f o r   ( i n t   i 2   =   0 ;   i 2   <   p i x e l s ;   i 2 + + ) 
 
                                         { 
 
                                                 / / pe$Pn000QY0( zzeW[o00ۘp0W0) 
 
                                                 f o r   ( ;   ;   ) 
 
                                                 { 
 
                                                         i f   ( i _ d a t a [ i d x ] . L e n g t h   >   0 ) 
 
                                                         { 
 
                                                                 b r e a k ; 
 
                                                         } 
 
                                                         i d x + + ; 
 
                                                 } 
 
                                                 o _ b u f [ i 2 ]   =   ( o _ b u f [ i 2 ]   < <   8 )   |   ( ( 0 x 0 0 0 0 0 0 f f   &   ( i n t ) i n t . P a r s e ( i _ d a t a [ i d x ] ) ) ) ; 
 
                                                 i d x + + ; 
 
                                         } 
 
                                 } 
 
                                 / / G B R !R G B 
 
                                 f o r   ( i n t   i 3   =   0 ;   i 3   <   p i x e l s ;   i 3 + + ) 
 
                                 { 
 
                                         o _ b u f [ i 3 ]   =   ( ( o _ b u f [ i 3 ]   < <   1 6 )   &   0 x f f 0 0 0 0 )   |   ( o _ b u f [ i 3 ]   &   0 x 0 0 f f 0 0 )   |   ( ( o _ b u f [ i 3 ]   > >   1 6 )   &   0 x 0 0 0 0 f f ) ; 
 
                                 } 
 
                         } 
 
                         c a t c h   ( E x c e p t i o n   e ) 
 
                         { 
 
                                 t h r o w   n e w   N y A R E x c e p t i o n ( e ) ; 
 
                         } 
 
                         r e t u r n   i d x ; 
 
                 } 
 
         } 
 
 
 
         / * * 
 
           *   S0n0000o00A R T o o l K i t n0000000001 Pn00000<h
}W0~0Y00
 
           *   00000000n000000h00000n0000_j0cOW0~0Y00
 
           * / 
 
         p u b l i c   c l a s s   N y A R C o d e 
 
         { 
 
                 p r i v a t e   N y A R M a t c h P a t t D e v i a t i o n C o l o r D a t a [ ]   _ c o l o r _ p a t   =   n e w   N y A R M a t c h P a t t D e v i a t i o n C o l o r D a t a [ 4 ] ; 
 
                 p r i v a t e   N y A R M a t c h P a t t D e v i a t i o n B l a c k W h i t e D a t a [ ]   _ b w _ p a t   =   n e w   N y A R M a t c h P a t t D e v i a t i o n B l a c k W h i t e D a t a [ 4 ] ; 
 
                 p r i v a t e   i n t   _ w i d t h ; 
 
                 p r i v a t e   i n t   _ h e i g h t ; 
 
 	         / * * 
 
 	           *   i n p u t S t r e a m K00A R T o o l K i t b__n000000000c[000g00QW0f00<h
}W0_00000000ubW0~0Y00
 
 	           *   000Y000000000n0&~*jP^o00S0n0000000n0$Ph0TX0g0B00_L0B00~0Y00
 
 	           *   @ p a r a m   i _ s t r e a m 
 
 	           *   QW0CQn0S t r e a m 000000
 
 	           *   @ p a r a m   i _ w i d t h 
 
 	           *   0000n0E^p i x e l pe0000n0Q[h0 NW0f0D00_L0B00~0Y00
 
 	           *   @ p a r a m   i _ h e i g h t 
 
 	           *   0000n0E^p i x e l pe0000n0Q[h0 NW0f0D00_L0B00~0Y00
 
 	           *   @ t h r o w s   N y A R E x c e p t i o n 
 
 	           * / 	 
 
 	         p u b l i c   s t a t i c   N y A R C o d e   c r e a t e F r o m A R P a t t F i l e ( S t r e a m R e a d e r   i _ s t r e a m , i n t   i _ w i d t h , i n t   i _ h e i g h t ) 
 
 	         { 
 
 	 	         / / 000k000000000Y000
 
 	 	         N y A R C o d e   r e t = n e w   N y A R C o d e ( i _ w i d t h , i _ h e i g h t ) ; 
 
 	 	         N y A R C o d e F i l e R e a d e r . l o a d F r o m A R T o o l K i t F o r m F i l e ( i _ s t r e a m , r e t ) ; 
 
 	 	         r e t u r n   r e t ; 
 
         	 	 
 
 	         } 
 
                 / * * 
 
                   *   c[W0_0d i r e c t i o n ( eMO) n0{ @ l i n k   N y A R M a t c h P a t t D e v i a t i o n C o l o r D a t a } 000000n0Sgq$P0ԏW0~0Y00
 
                   *   @ p a r a m   i _ i n d e x 
 
                   *   eMO00000n0$P0c[W0~0Y00
 
                   *   {Vo000 & l t ; = n & l t ; = 3 n0pe$Pg0Y00
 
                   *   @ r e t u r n 
 
                   *   c[W0_0eMOn0{ @ l i n k   N y A R M a t c h P a t t D e v i a t i o n C o l o r D a t a } 0000000ԏW0~0Y00
 
                   * / 
 
                 p u b l i c   N y A R M a t c h P a t t D e v i a t i o n C o l o r D a t a   g e t C o l o r D a t a ( i n t   i _ i n d e x ) 
 
                 { 
 
                         r e t u r n   t h i s . _ c o l o r _ p a t [ i _ i n d e x ] ; 
 
                 } 
 
                 / * * 
 
                   *   c[W0_0d i r e c t i o n ( eMO) n0{ @ l i n k   N y A R M a t c h P a t t D e v i a t i o n B l a c k W h i t e D a t a } 000000n0Sgq$P0ԏW0~0Y00
 
                   *   @ p a r a m   i _ i n d e x 
 
                   *   eMO00000n0$P0c[W0~0Y00
 
                   *   {Vo000 & l t ; = n & l t ; = 3 n0pe$Pg0Y00
 
                   *   @ r e t u r n 
 
                   *   c[W0_0eMOn0{ @ l i n k   N y A R M a t c h P a t t D e v i a t i o n B l a c k W h i t e D a t a } 0000000ԏW0~0Y00
 
                   * / 
 
                 p u b l i c   N y A R M a t c h P a t t D e v i a t i o n B l a c k W h i t e D a t a   g e t B l a c k W h i t e D a t a ( i n t   i _ i n d e x ) 
 
                 { 
 
                         r e t u r n   t h i s . _ b w _ p a t [ i _ i n d e x ] ; 
 
                 } 
 
                 / * * 
 
                   *   A R 000n0*jP^0ԏW0~0Y00
 
                   *   @ r e t u r n 
 
                   *   P^$P
 
                   * / 
 
                 p u b l i c   i n t   g e t W i d t h ( ) 
 
                 { 
 
                         r e t u r n   _ w i d t h ; 
 
                 } 
 
 
 
                 / * * 
 
                   *   A R 000n0&~P^0ԏW0~0Y00
 
                   *   @ r e t u r n 
 
                   *   P^$P
 
                   * / 
 
                 p u b l i c   i n t   g e t H e i g h t ( ) 
 
                 { 
 
                         r e t u r n   _ h e i g h t ; 
 
                 } 
 
 
 
 
 
                 / * * 
 
                   *   0000000g0Y00
 
                   *   zzn0N y A R C o d e 0000000\ObW0~0Y00
 
                   *   @ p a r a m   i _ w i d t h 
 
                   *   \ObY000000000n0*jP^
 
                   *   @ p a r a m   i _ h e i g h t 
 
                   *   \ObY000000000n0&~P^
 
                   *   @ 
 
                   * / 
 
                 p u b l i c   N y A R C o d e ( i n t   i _ w i d t h ,   i n t   i _ h e i g h t ) 
 
                 { 
 
                         t h i s . _ w i d t h   =   i _ w i d t h ; 
 
                         t h i s . _ h e i g h t   =   i _ h e i g h t ; 
 
                         / / zzn000004 P\Ob
 
                         f o r   ( i n t   i   =   0 ;   i   <   4 ;   i + + ) 
 
                         { 
 
                                 t h i s . _ c o l o r _ p a t [ i ]   =   n e w   N y A R M a t c h P a t t D e v i a t i o n C o l o r D a t a ( i _ w i d t h ,   i _ h e i g h t ) ; 
 
                                 t h i s . _ b w _ p a t [ i ]   =   n e w   N y A R M a t c h P a t t D e v i a t i o n B l a c k W h i t e D a t a ( i _ w i d t h ,   i _ h e i g h t ) ; 
 
                         } 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   4 gn0000000000K000000000000ubW0f0<h
}W0~0Y00
 
                   *   @ p a r a m   i _ r a s t e r 
 
                   *   00000000<h
}W0_0000000000MR0c[W0~0Y00
 
                   *   000o0T Nj0P^g0B000K0d0S0n0000000h0TX0P^g0B00_L0B00~0Y00
 
                   *   <h
}o000000n0S
NL001 , 2 , 3 , 4 aPk0j00jug0Y00
 
                   *   @ 
 
                   * / 
 
                 p u b l i c   v o i d   s e t R a s t e r ( I N y A R R g b R a s t e r [ ]   i _ r a s t e r ) 
 
                 { 
 
                         D e b u g . A s s e r t ( i _ r a s t e r . L e n g t h   ! =   4 ) ; 
 
                         / / 000k000000000Y000
 
                         f o r   ( i n t   i   =   0 ;   i   <   4 ;   i + + ) 
 
                         { 
 
                                 t h i s . _ c o l o r _ p a t [ i ] . s e t R a s t e r ( i _ r a s t e r [ i ] ) ; 
 
                         } 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   1 gn0000000000K000000000000ubW0f0<h
}W0~0Y00
 
                   *   k0n03 gn0000o00peL0i _ r a s t e r 0VU0[0f0Bl0~0Y00
 
                   *   @ p a r a m   i _ r a s t e r 
 
                   *   00000000<h
}W0_00000000000c[W0~0Y00
 
                   *   000o00S0n0000000h0TX0P^g0B00_L0B00~0Y00
 
                   *   @ 
 
                   * / 
 
                 p u b l i c   v o i d   s e t R a s t e r ( I N y A R R g b R a s t e r   i _ r a s t e r ) 
 
                 { 
 
                         / / 000k000000000Y000
 
                         f o r   ( i n t   i   =   0 ;   i   <   4 ;   i + + ) 
 
                         { 
 
                                 t h i s . _ c o l o r _ p a t [ i ] . s e t R a s t e r ( i _ r a s t e r ,   i ) ; 
 
                         } 
 
                         r e t u r n ; 
 
                 } 
 
         } 
 
 } 
 
 