// package access for tests static int[] addPngToIntArray(byte[] pngBytes, int[] counts) { if (pngBytes == null) { return counts; } // read PNG final BufferedImage image = PngHelper.readImage(pngBytes); int columns = image.getWidth(); int rows = image.getHeight(); if (counts == null) { counts = new int[columns * rows]; } else { assert counts.length == columns * rows; } for (int c = 0; c < columns; c++) { for (int r = 0; r < rows; r++) { counts[c * rows + r] += PngHelper.getCountAtColumnRow(image, rows, c, r); } } return counts; }
// package access for tests static byte[] asPngBytes( final int columns, final int rows, final int[] counts, ResponseBuilder rb) { long startTimeNano = System.nanoTime(); BufferedImage image = PngHelper.newImage(columns, rows); for (int c = 0; c < columns; c++) { for (int r = 0; r < rows; r++) { PngHelper.writeCountAtColumnRow(image, rows, c, r, counts[c * rows + r]); } } byte[] bytes = PngHelper.writeImage(image); long durationMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTimeNano); log.debug( "heatmap nativeSize={} pngSize={} pngTime={}", (counts.length * 4), bytes.length, durationMs); if (rb != null && rb.isDebugTimings()) { rb.addDebug(durationMs, "timing", "heatmap png generation"); } return bytes; }