private void Hist3d(long vwt[][][], long vmr[][][], long vmg[][][], long vmb[][][], float m2[][][]) {
    		/* build 3-D color histogram of counts, r/g/b, c^2 */
    		int r, g, b;
    		int	i, inr, ing, inb, table[] = new int[256];
    	
    		for(i = 0; i < 256; ++i) table[i]= i*i;
    		
    		qadd = new int[size];
    	
    		for(i = 0; i < size; ++i) {
    			int rgb = pixels[i];
    			if((rgb >>> 24) < 0x80) { // Transparent
    				if (transparent_color < 0)	// Find the transparent color	
    					transparent_color = rgb;
    			}
    			r = ((rgb >> 16)& 0xff);
    			g = ((rgb >> 8 )& 0xff);
    			b = ( rgb       & 0xff);
    			inr = (r >> 3) + 1; 
    			ing = (g >> 3) + 1; 
    			inb = (b >> 3) + 1; 
    			qadd[i] = (inr << 10) + (inr << 6) + inr + (ing << 5) + ing + inb;
    			/*[inr][ing][inb]*/
    			++vwt[inr][ing][inb];
    			vmr[inr][ing][inb] += r;
    			vmg[inr][ing][inb] += g;
    			vmb[inr][ing][inb] += b;
    		    m2[inr][ing][inb] += table[r] + table[g] + table[b];
    		}
    	}
Java port of
C Implementation of Wu's Color Quantizer (v. 2)
(see Graphics Gems vol. II, pp. 126-133)
Author:	Xiaolin Wu
Dept. of Computer Science
Univ. of Western Ontario
London, Ontario N6A 5B7
wu@csd.uwo.ca

Algorithm: Greedy orthogonal bipartition of RGB space for variance
minimization aided by inclusion-exclusion tricks.
For speed no nearest neighbor search is done. Slightly
better performance can be expected by more sophisticated
but more expensive versions.

The author thanks Tom Lane at Tom_Lane@G.GP.CS.CMU.EDU for much of
additional documentation and a cure to a previous bug.

Free to distribute, comments and suggestions are appreciated.
subs/gif-revert/src/main/java/com/engineer/gif/revert/lib/AnimatedGIFWriter.java