privatestaticvoidreadPixel(BufferedImage img, int x, int y, int[] pixels){ int xStart = x - 1; int yStart = y - 1; int current = 0; for (int i = xStart; i < 3 + xStart; i++) for (int j = yStart; j < 3 + yStart; j++) { int tx = i; if (tx < 0) { tx = -tx;
} elseif (tx >= img.getWidth()) { tx = x; } int ty = j; if (ty < 0) { ty = -ty; } elseif (ty >= img.getHeight()) { ty = y; } pixels[current++] = img.getRGB(tx, ty);
} }
privatestaticvoidfillMatrix(int[][] matrix, int[] values){ int filled = 0; for (int i = 0; i < matrix.length; i++) { int[] x = matrix[i]; for (int j = 0; j < x.length; j++) { x[j] = values[filled++]; } } }
privatestaticintavgMatrix(int[][] matrix){ int r = 0; int g = 0; int b = 0; for (int i = 0; i < matrix.length; i++) { int[] x = matrix[i]; for (int j = 0; j < x.length; j++) { if (j == 1) { continue; } Color c = new Color(x[j]); r += c.getRed(); g += c.getGreen(); b += c.getBlue(); } } returnnew Color(r / 8, g / 8, b / 8).getRGB();