private boolean Cut(Box set1, Box set2) {
    		int dir;
    		int cutr[] = new int[1];
            int cutg[] = new int[1];
            int cutb[] = new int[1];
    		float maxr, maxg, maxb;
    		long whole_r, whole_g, whole_b, whole_w;

    		whole_r = Vol(set1, mr);
    		whole_g = Vol(set1, mg);
    		whole_b = Vol(set1, mb);
    		whole_w = Vol(set1, wt);

    		maxr = Maximize(set1, RED, set1.r0 + 1, set1.r1, cutr,
    				whole_r, whole_g, whole_b, whole_w);
    		maxg = Maximize(set1, GREEN, set1.g0 + 1, set1.g1, cutg,
    				whole_r, whole_g, whole_b, whole_w);
    		maxb = Maximize(set1, BLUE, set1.b0 + 1, set1.b1, cutb,
    				whole_r, whole_g, whole_b, whole_w);

    		if(maxr >= maxg && maxr >= maxb) {
    			dir = RED;
    			if (cutr[0] < 0) return false; /* can't split the box */
    		} else if(maxg >= maxr && maxg >= maxb) 
    			dir = GREEN;
    		else
    			dir = BLUE; 

    		set2.r1 = set1.r1;
    		set2.g1 = set1.g1;
    		set2.b1 = set1.b1;

    		switch (dir){
    			case RED:
    				set2.r0 = set1.r1 = cutr[0];
    				set2.g0 = set1.g0;
    				set2.b0 = set1.b0;
    				break;
    			case GREEN:
    				set2.g0 = set1.g1 = cutg[0];
    				set2.r0 = set1.r0;
    				set2.b0 = set1.b0;
    				break;
    			case BLUE:
    				set2.b0 = set1.b1 = cutb[0];
    				set2.r0 = set1.r0;
    				set2.g0 = set1.g0;
    				break;
    		}
    		set1.vol = (set1.r1 - set1.r0)*(set1.g1 - set1.g0)*(set1.b1 - set1.b0);
    		set2.vol = (set2.r1 - set2.r0)*(set2.g1 - set2.g0)*(set2.b1 - set2.b0);
    	
    		return true;  
    	}
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