private int pixelToQuantizationTableIndex(int argb, final int precision) {
        int result = 0;
        final int precisionMask = (1 << precision) - 1;

        for (int i = 0; i < COMPONENTS; i++) {
            int sample = argb & 0xff;
            argb >>= 8;

            sample >>= 8 - precision;
            result = result << precision | sample & precisionMask;
        }

        return result;
    }
Builds an inexact opaque palette of at most {@code max} colors in {@code src} using a variation of the Median Cut algorithm. Accurate to 6 bits per
component, and works by splitting the color bounding box most heavily populated by colors along the component which splits the colors in that box most
evenly.

@param src the image whose palette to build
@param max the maximum number of colors the palette can contain
@return the palette of at most {@code max} colors
src/main/java/org/apache/commons/imaging/palette/PaletteFactory.java