@@ -0,0 +1,1679 @@
+package de.jeha.photo.mosaic;%0A%0Aimport java.awt.image.BufferedImage;%0Aimport java.awt.image.Raster;%0A%0A/**%0A * @author jenshadlich@googlemail.com%0A */%0Apublic class ColorCalculator %7B%0A%0A    /**%0A     * Calculates the average color (r,g,b,a) values for a given image.%0A     *%0A     * @param image input image%0A     * @return average r,g,b,a values%0A     */%0A    public static RGBA averageColor(BufferedImage image) %7B%0A        final Raster raster = image.getRaster();%0A        double array%5B%5D = new double%5B4%5D;%0A        double r = .0;%0A        double g = .0;%0A        double b = .0;%0A        double a = .0;%0A%0A        for (int x = 0; x %3C raster.getWidth(); x++) %7B%0A            for (int y = 0; y %3C raster.getHeight(); y++) %7B%0A                raster.getPixel(x, y, array);%0A                r += array%5B0%5D;%0A                g += array%5B1%5D;%0A                b += array%5B2%5D;%0A                a += array%5B3%5D;%0A            %7D%0A        %7D%0A%0A        final double total = raster.getHeight() * raster.getWidth();%0A        r /= total;%0A        g /= total;%0A        b /= total;%0A        a /= total;%0A%0A        return new RGBA(r, g, b, a);%0A    %7D%0A%0A    public static class RGBA %7B%0A%0A        private final double r;%0A        private final double g;%0A        private final double b;%0A        private final double a;%0A%0A        public RGBA(double r, double g, double b, double a) %7B%0A            this.r = r;%0A            this.g = g;%0A            this.b = b;%0A            this.a = a;%0A        %7D%0A%0A        public double getR() %7B%0A            return r;%0A        %7D%0A%0A        public double getG() %7B%0A            return g;%0A        %7D%0A%0A        public double getB() %7B%0A            return b;%0A        %7D%0A%0A        public double getA() %7B%0A            return a;%0A        %7D%0A%0A    %7D%0A%7D%0A

add class to calculate the average color of an image