private void calculateMultipleArrayGradient
            (Color[] loColors, Color[] hiColors) {

        //set the flag so we know later it is a non-simple lookup
        isSimpleLookup = false;

        int rgb1; //2 colors to interpolate
        int rgb2;

        // These are fixed point 8.16 (start with 0.5)
        int aveA = 0x008000;
        int aveR = 0x008000;
        int aveG = 0x008000;
        int aveB = 0x008000;

        //for every interval (transition between 2 colors)
        for (int i = 0; i < gradients.length; i++) {

            // This interval will never actually be used (zero size)
            if (normalizedIntervals[i] == 0)
                continue;

            //create an array of the maximum theoretical size for each interval
            gradients[i] = new int[GRADIENT_SIZE];

            //get the the 2 colors
            rgb1 = loColors[i].getRGB();
            rgb2 = hiColors[i].getRGB();

            //fill this array with the colors in between rgb1 and rgb2
            interpolate(rgb1, rgb2, gradients[i]);

            // Calculate Average of two colors...
            int argb = gradients[i][GRADIENT_SIZE / 2];
            float norm = normalizedIntervals[i];
            aveA += (int) (((argb >> 8) & 0xFF0000) * norm);
            aveR += (int) (((argb) & 0xFF0000) * norm);
            aveG += (int) (((argb << 8) & 0xFF0000) * norm);
            aveB += (int) (((argb << 16) & 0xFF0000) * norm);

            //if the colors are opaque, transparency should still be 0xff000000
            transparencyTest &= rgb1;
            transparencyTest &= rgb2;
        }

        gradientAverage = (((aveA & 0xFF0000) << 8) |
                ((aveR & 0xFF0000)) |
                ((aveG & 0xFF0000) >> 8) |
                ((aveB & 0xFF0000) >> 16));

        //if interpolation occurred in Linear RGB space, convert the
        //gradients back to SRGB using the lookup table
        if (colorSpace == LinearGradientPaint.LINEAR_RGB) {
            if (dataModel.getColorSpace() ==
                    ColorSpace.getInstance(ColorSpace.CS_sRGB)) {
                for (int j = 0; j < gradients.length; j++) {
                    for (int i = 0; i < gradients[j].length; i++) {
                        gradients[j][i] =
                                convertEntireColorLinearRGBtoSRGB(gradients[j][i]);
                    }
                }
                gradientAverage =
                        convertEntireColorLinearRGBtoSRGB(gradientAverage);
            }
        } else {
            if (dataModel.getColorSpace() ==
                    ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB)) {
                for (int j = 0; j < gradients.length; j++) {
                    for (int i = 0; i < gradients[j].length; i++) {
                        gradients[j][i] =
                                convertEntireColorSRGBtoLinearRGB(gradients[j][i]);
                    }
                }
                gradientAverage =
                        convertEntireColorSRGBtoLinearRGB(gradientAverage);
            }
        }
    }