code: public static ColorRgba getWeightedColor(ImageBuffer surface, int sx, int sy, int width, int height)
      {
          Check.notNull(surface);
  
          int r = 0;
          int g = 0;
          int b = 0;
          int count = 0;
          for (int x = 0; x < width; x++)
          {
              for (int y = 0; y < height; y++)
              {
                  final ColorRgba color = new ColorRgba(surface.getRgb(sx + x, sy + y));
                  if (color.getAlpha() > 0)
                  {
                      r += color.getRed();
                      g += color.getGreen();
                      b += color.getBlue();
                      count++;
                  }
              }
          }
          if (count == 0)
          {
              return ColorRgba.TRANSPARENT;
          }
          return new ColorRgba((int) Math.floor(r / (double) count),
                               (int) Math.floor(g / (double) count),
                               (int) Math.floor(b / (double) count));
      }
docs: Get the weighted color of an area.
  
  @param surface The surface reference (must not be <code>null</code>).
  @param sx The starting horizontal location.
  @param sy The starting vertical location.
  @param width The area width.
  @param height The area height.
  @return The weighted color.