static Matrix imageToMatrix(BufferedImage etc img) { if (img == null) null; int _w = img.getWidth(), _h = img.getHeight(); class ImageToMatrix extends AbstractMatrix { *() { super(_w, _h); } public Int get(int x, int y) { assertPointInBounds(x, y, w, h); ret img.getRGB(x, y); } public void set(int x, int y, Int val) { assertPointInBounds(x, y, w, h); img.setRGB(x, y, val); } }; ret new ImageToMatrix; }