question: public static IndexedImage pack ( int [ ] rgb , int width , int height ) { int arrayLength = width * height ; int [ ] tempPalette = new int [ 256 ] ; int paletteLocation = 0 ; for ( int iter = 0 ; iter < arrayLength ; iter ++ ) { int current = rgb [ iter ] ; if ( ! contains ( tempPalette , paletteLocation , current ) ) { if ( paletteLocation > 255 ) { return null ; } tempPalette [ paletteLocation ] = current ; paletteLocation ++ ; } } if ( paletteLocation != tempPalette . length ) { int [ ] newArray = new int [ paletteLocation ] ; System . arraycopy ( tempPalette , 0 , newArray , 0 , paletteLocation ) ; tempPalette = newArray ; } IndexedImage i = new IndexedImage ( width , height , tempPalette , rgb ) ; return i ; }
target:  Packs the source rgba image and returns null if it fails