/ *   
 
   *   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 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 ; 
 
 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 G B ;uP0H S V ;uPk0	YcY000000g0Y00
 
           *   [_W0f0D00eQR;u }b__o0NNn00g0Y00
 
           *   < p > eQR;u }b__
 
           *   < u l > 
 
           *   < l i > N y A R B u f f e r T y p e . B Y T E 1 D _ B 8 G 8 R 8 _ 2 4 
 
           *   < / u l > 
 
           *   < / p > 
 
           *   QR;u }b__o00{ @ l i n k   N y A R B u f f e r T y p e # I N T 1 D _ X 7 H 9 S 8 V 8 _ 3 2 } b__n0H S V 000k0P00~0Y00
 
           * 
 
           * / 
 
         p u b l i c   c l a s s   N y A R R a s t e r F i l t e r _ R g b 2 H s v 
 
         { 
 
                 / * *   	Yc(u0000n00000000* / 
 
                 p u b l i c   i n t e r f a c e   I F i l t e r 
 
                 { 
 
                         b o o l   i s S u p p o r t ( I N y A R R a s t e r   i _ i n ,   I N y A R R a s t e r   i _ o u t ) ; 
 
                         v o i d   d o F i l t e r ( I N y A R R a s t e r   i _ i n p u t ,   I N y A R R a s t e r   i _ o u t p u t ,   N y A R I n t S i z e   i _ s i z e ) ; 
 
                 } 
 
 
 
                 p r i v a t e   I F i l t e r   _ d o _ f i l t e r _ i m p l ; 
 
                 / * * 
 
                   *   0000000g0Y00
 
                   *   @ 
 
                   * / 
 
                 p u b l i c   N y A R R a s t e r F i l t e r _ R g b 2 H s v ( ) 
 
                 { 
 
                         t h i s . _ d o _ f i l t e r _ i m p l   =   n e w   R g b 2 H s v F i l t e r _ B l a n k ( ) ; 
 
                 } 
 
                 p r o t e c t e d   I F i l t e r   c r e a t e F i l t e r ( I N y A R R a s t e r   i _ i n ,   I N y A R R a s t e r   i _ o u t ) 
 
                 { 
 
                         i f   ( i _ i n . g e t 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 _ G R A Y _ 8 ) 
 
                         { 
 
                                 s w i t c h   ( i _ o u t . 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 . B Y T E 1 D _ B 8 G 8 R 8 _ 2 4 : 
 
                                                 r e t u r n   n e w   R g b 2 H s v F i l t e r _ B Y T E 1 D _ B 8 G 8 R 8 _ 2 4 ( ) ; 
 
                                         d e f a u l t : 
 
                                                 b r e a k ; 
 
                                 } 
 
                         } 
 
                         t h r o w   n e w   N y A R E x c e p t i o n ( ) ; 
 
                 } 
 
                 / * * 
 
                   *   eQR0000H S V b__k0	YcW0f00QR000x0f0~0Y00
 
                   *   ;u }b__o000000000k0c[W0_0b__k0T[0f0O0`0U0D00
 
                   * / 
 
                 p u b l i c   v o i d   d o F i l t e r ( I N y A R R g b R a s t e r   i _ i n p u t ,   I N y A R R a s t e r   i _ o u t p u t ) 
 
                 { 
 
                         D e b u g . A s s e r t ( i _ i n p u t . g e t S i z e ( ) . i s E q u a l S i z e ( i _ o u t p u t . g e t S i z e ( ) )   = =   t r u e ) ; 
 
                         i f   ( ! t h i s . _ d o _ f i l t e r _ i m p l . i s S u p p o r t ( i _ i n p u t ,   i _ o u t p u t ) ) 
 
                         { 
 
                                 t h i s . _ d o _ f i l t e r _ i m p l   =   t h i s . c r e a t e F i l t e r ( i _ i n p u t ,   i _ o u t p u t ) ; 
 
                         } 
 
                         t h i s . _ d o _ f i l t e r _ i m p l . d o F i l t e r ( i _ i n p u t ,   i _ o u t p u t ,   i _ i n p u t . g e t S i z e ( ) ) ; 
 
                 } 
 
         } 
 
 
 
         / / 
 
         / / 0000000
 
         / / 
 
 
 
         c l a s s   R g b 2 H s v F i l t e r _ B l a n k   :   N y A R R a s t e r F i l t e r _ R g b 2 H s v . I F i l t e r 
 
         { 
 
                 p u b l i c   b o o l   i s S u p p o r t ( I N y A R R a s t e r   i _ i n ,   I N y A R R a s t e r   i _ o u t ) 
 
                 { 
 
                         r e t u r n   f a l s e ; 
 
                 } 
 
                 p u b l i c   v o i d   d o F i l t e r ( I N y A R R a s t e r   i _ i n p u t ,   I N y A R R a s t e r   i _ o u t p u t ,   N y A R I n t S i z e   i _ s i z e ) 
 
                 { 
 
                         t h r o w   n e w   N y A R E x c e p t i o n ( ) ; 
 
                 } 
 
 
 
         } 
 
 
 
         c l a s s   R g b 2 H s v F i l t e r _ B Y T E 1 D _ B 8 G 8 R 8 _ 2 4   :   N y A R R a s t e r F i l t e r _ R g b 2 H s v . I F i l t e r 
 
         { 
 
                 p u b l i c   b o o l   i s S u p p o r t ( I N y A R R a s t e r   i _ i n ,   I N y A R R a s t e r   i _ o u t ) 
 
                 { 
 
                         r e t u r n   i _ i n . 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 . B Y T E 1 D _ B 8 G 8 R 8 _ 2 4 )   & &   i _ o u t . 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 7 H 9 S 8 V 8 _ 3 2 ) ; 
 
                 } 
 
                 p u b l i c   v o i d   d o F i l t e r ( I N y A R R a s t e r   i _ i n p u t ,   I N y A R R a s t e r   i _ o u t p u t ,   N y A R I n t S i z e   i _ s i z e ) 
 
                 { 
 
                         D e b u g . A s s e r t ( i _ i n p u t . 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 7 H 9 S 8 V 8 _ 3 2 ) ) ; 
 
 
 
                         i n t [ ]   o u t _ b u f   =   ( i n t [ ] ) i _ o u t p u t . g e t B u f f e r ( ) ; 
 
                         b y t e [ ]   i n _ b u f   =   ( b y t e [ ] ) i _ i n p u t . g e t B u f f e r ( ) ; 
 
                         i n t   s ; 
 
                         f o r   ( i n t   i   =   i _ s i z e . h   *   i _ s i z e . w   -   1 ;   i   > =   0 ;   i - - ) 
 
                         { 
 
                                 i n t   r   =   ( i n _ b u f [ i   *   3   +   2 ]   &   0 x f f ) ; 
 
                                 i n t   g   =   ( i n _ b u f [ i   *   3   +   1 ]   &   0 x f f ) ; 
 
                                 i n t   b   =   ( i n _ b u f [ i   *   3   +   0 ]   &   0 x f f ) ; 
 
                                 i n t   c m a x ,   c m i n ; 
 
                                 / /  g'Y$Ph0 g\$P0{
 
                                 i f   ( r   >   g ) 
 
                                 { 
 
                                         c m a x   =   r ; 
 
                                         c m i n   =   g ; 
 
                                 } 
 
                                 e l s e 
 
                                 { 
 
                                         c m a x   =   g ; 
 
                                         c m i n   =   r ; 
 
                                 } 
 
                                 i f   ( b   >   c m a x ) 
 
                                 { 
 
                                         c m a x   =   b ; 
 
                                 } 
 
                                 i f   ( b   <   c m i n ) 
 
                                 { 
 
                                         c m i n   =   b ; 
 
                                 } 
 
                                 i n t   h ; 
 
                                 i f   ( c m a x   = =   0 ) 
 
                                 { 
 
                                         s   =   0 ; 
 
                                         h   =   0 ; 
 
                                 } 
 
                                 e l s e 
 
                                 { 
 
                                         s   =   ( c m a x   -   c m i n )   *   2 5 5   /   c m a x ; 
 
                                         i n t   c d e s   =   c m a x   -   c m i n ; 
 
                                         / / H bR0{
 
                                         i f   ( c d e s   ! =   0 ) 
 
                                         { 
 
                                                 i f   ( c m a x   = =   r ) 
 
                                                 { 
 
                                                         h   =   ( g   -   b )   *   6 0   /   c d e s ; 
 
                                                 } 
 
                                                 e l s e   i f   ( c m a x   = =   g ) 
 
                                                 { 
 
                                                         h   =   ( b   -   r )   *   6 0   /   c d e s   +   2   *   6 0 ; 
 
                                                 } 
 
                                                 e l s e 
 
                                                 { 
 
                                                         h   =   ( r   -   g )   *   6 0   /   c d e s   +   4   *   6 0 ; 
 
                                                 } 
 
                                         } 
 
                                         e l s e 
 
                                         { 
 
                                                 h   =   0 ; 
 
                                         } 
 
                                 } 
 
                                 i f   ( h   <   0 ) 
 
                                 { 
 
                                         h   + =   3 6 0 ; 
 
                                 } 
 
                                 / / h s v 	Yc( h 9 s 8 v 8 ) 
 
                                 o u t _ b u f [ i ]   =   ( 0 x 1 f f 0 0 0 0   &   ( h   < <   1 6 ) )   |   ( 0 x 0 0 f f 0 0   &   ( s   < <   8 ) )   |   ( c m a x   &   0 x f f ) ; 
 
                         } 
 
                         r e t u r n ; 
 
                 } 
 
         } 
 
 } 