ImageReader extends AbstractDataReader { @SuppressWarnings({ "unchecked", "rawtypes" }) public DataSource read(InputStream input, Class<? extends Comparable<?>>... types) throws IOException { BufferedImage image = ImageIO.read(input); int w = image.getWidth(); int h = image.getHeight(); Class[] colTypes = new Class[w]; Arrays.fill(colTypes, Double.class); DataTable data = new DataTable(colTypes); double factor = this.<Number>getSetting("factor").doubleValue(); double offset = this.<Number>getSetting("offset").doubleValue(); int[] pixelData = new int[w]; Double[] rowData = new Double[w]; for (int y = 0; y < h; y++) { image.getRGB(0, y, pixelData.length, 1, pixelData, 0, 0); for (int x = 0; x < pixelData.length; x++) { double r = (pixelData[x] >> 16) & 0xFF; rowData[x] = r*factor + offset; } data.add(rowData); } return data; } ImageReader(String mimeType); @SuppressWarnings({ "unchecked", "rawtypes" }) DataSource read(InputStream input, Class<? extends Comparable<?>>... types);  }
@Test @SuppressWarnings("unchecked") public void testReader() throws IOException, ParseException { DataReader reader = DataReaderFactory.getInstance().get("image/png"); DataSource data = reader.read(imageData); assertEquals(3, data.getColumnCount()); assertEquals(4, data.getRowCount()); double[] expected = new double[] { 255.0, 0.0, 0.0, 0.0, 255.0, 0.0, 0.0, 0.0, 255.0, 127.0, 127.0, 127.0 }; for (int i = 0; i < expected.length; i++) { int col = i % 3; int row = i / 3; double value = ((Number) data.get(col, row)).doubleValue(); assertEquals(expected[i], value, DELTA); } }