private void M3d(long vwt[][][], long vmr[][][], long vmg[][][], long vmb[][][], float m2[][][]) {
    		/* compute cumulative moments. */
    		int i, r, g, b;
    		int line, line_r, line_g, line_b;
    		int area[] = new int[QUANT_SIZE];
    		int area_r[] = new int[QUANT_SIZE];
    		int area_g[] = new int[QUANT_SIZE];
    		int area_b[] = new int[QUANT_SIZE];
    		float line2, area2[] = new float[QUANT_SIZE];
    	
    		for(r = 1; r < QUANT_SIZE; ++r) {
    			for(i = 0; i < QUANT_SIZE; ++i) 
    				area2[i] = area[i] = area_r[i] = area_g[i] = area_b[i] = 0;
    			for(g = 1; g < QUANT_SIZE; ++g) {
    				line2 = line = line_r = line_g = line_b = 0;
    				for(b = 1; b < QUANT_SIZE; ++b){
    					line   += vwt[r][g][b];
    					line_r += vmr[r][g][b]; 
    					line_g += vmg[r][g][b]; 
    					line_b += vmb[r][g][b];
    					line2  += m2[r][g][b];
    					
    					area[b] += line;
    					area_r[b] += line_r;
    					area_g[b] += line_g;
    					area_b[b] += line_b;
    					area2[b] += line2;
    					
    					vwt[r][g][b] = vwt[r-1][g][b] + area[b];
    					vmr[r][g][b] = vmr[r-1][g][b] + area_r[b];
    					vmg[r][g][b] = vmg[r-1][g][b] + area_g[b];
    					vmb[r][g][b] = vmb[r-1][g][b] + area_b[b];
    					m2[r][g][b]  = m2[r-1][g][b]  + area2[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