protected void accumulateStatistics(String name,
                                        Raster source,
                                        Object stats) {
        // Get image and band count.
        PlanarImage sourceImage = getSourceImage(0);
        int numBands = sourceImage.getSampleModel().getNumBands();

        // Determine the format tag and create an accessor.
        int formatTag = MediaLibAccessor.findCompatibleTag(null, source);
        MediaLibAccessor srcAccessor = new MediaLibAccessor(source,
                                                            source.getBounds(),
                                                            formatTag);

        // Get the mediaLib image.
        mediaLibImage[] srcML = srcAccessor.getMediaLibImages();

        // NOTE:  currently srcML.length always equals 1

        double[] dmean = new double[numBands];

        switch (srcAccessor.getDataType()) {
        case DataBuffer.TYPE_BYTE:
        case DataBuffer.TYPE_USHORT:
        case DataBuffer.TYPE_SHORT:
        case DataBuffer.TYPE_INT:
            for (int i = 0 ; i < srcML.length; i++) {
                Image.Mean(dmean, srcML[i]);
            }
            break;

        case DataBuffer.TYPE_FLOAT:
        case DataBuffer.TYPE_DOUBLE:
            for (int i = 0 ; i < srcML.length; i++) {
                Image.Mean_Fp(dmean, srcML[i]);
            }
            break;

        default:
            throw new RuntimeException(JaiI18N.getString("Generic2"));
        }

        dmean = srcAccessor.getDoubleParameters(0, dmean);

        // Update the mean.
        double[] mean = (double[])stats;
        double weight =
            (double)(source.getWidth()*source.getHeight())/
            (double)(width*height);
        for ( int i = 0; i < numBands; i++ ) {
            mean[i] += dmean[i]*weight;
        }
    }