question: void toIndexColor ( byte [ ] [ ] r , byte [ ] [ ] g , byte [ ] [ ] b ) throws AWTException { this . allPixels = new byte [ this . imageWidth * this . imageHeight ] ; this . allColors = new byte [ 256 * 3 ] ; int colornum = 0 ; for ( int x = 0 ; x < this . imageWidth ; x ++ ) { for ( int y = 0 ; y < this . imageHeight ; y ++ ) { int search ; for ( search = 0 ; search < colornum ; search ++ ) { if ( this . allColors [ search * 3 ] == r [ x ] [ y ] && this . allColors [ search * 3 + 1 ] == g [ x ] [ y ] && this . allColors [ search * 3 + 2 ] == b [ x ] [ y ] ) { break ; } } if ( search > 255 ) throw new AWTException ( "Too many colors." ) ; this . allPixels [ y * this . imageWidth + x ] = ( byte ) search ; if ( search == colornum ) { this . allColors [ search * 3 ] = r [ x ] [ y ] ; this . allColors [ search * 3 + 1 ] = g [ x ] [ y ] ; this . allColors [ search * 3 + 2 ] = b [ x ] [ y ] ; colornum ++ ; } } } this . numberOfColors = 1 << BitUtils . BitsNeeded ( colornum ) ; byte copy [ ] = new byte [ this . numberOfColors * 3 ] ; System . arraycopy ( this . allColors , 0 , copy , 0 , this . numberOfColors * 3 ) ; this . allColors = copy ; }
target:  Converts rgb desrcription of image to colour number description used by GIF.