void (@NotNull JBHiDPIScaledImage dst, @NotNull ByteBuffer src, Rectangle[] rectangles) { BufferedImage image = (BufferedImage)dst.getDelegate(); assert image != null; int[] dstData = ((DataBufferInt)image.getRaster().getDataBuffer()).getData(); IntBuffer srcData = src.order(ByteOrder.LITTLE_ENDIAN).asIntBuffer(); for (Rectangle rect : rectangles) { if (rect.width < image.getWidth()) { for (int line = rect.y; line < rect.y + rect.height; line++) { int offset = line * image.getWidth() + rect.x; srcData.position(offset).get(dstData, offset, Math.min(rect.width, src.capacity() - offset)); } } else { // optimized for a buffer wide dirty rect int offset = rect.y * image.getWidth(); srcData.position(offset).get(dstData, offset, Math.min(rect.height * image.getWidth(), src.capacity() - offset)); } } }