private static @NotNull BufferedImage _drawIconIntoMemory(@NotNull Icon icon, float scale, @NotNull Pointer memory, int offset) {
    int w = Math.round(icon.getIconWidth() * scale);
    int h = Math.round(icon.getIconHeight() * scale);
    int rasterSizeInBytes = w * h * 4;

    memory.setMemory(offset, rasterSizeInBytes, (byte)0);

    DataBuffer dataBuffer = new DirectDataBufferInt(memory, rasterSizeInBytes, offset);
    DirectColorModel colorModel =
      new DirectColorModel(ColorModel.getRGBdefault().getColorSpace(), 32, 0xFF, 0xFF00, 0x00FF0000, 0xff000000/*alpha*/, false,
                           DataBuffer.TYPE_INT);
    SampleModel sampleModel = colorModel.createCompatibleSampleModel(w, h);
    WritableRaster raster = WritableRasterNative.createNativeRaster(sampleModel, dataBuffer);
    //noinspection UndesirableClassUsage
    BufferedImage image = new BufferedImage(colorModel, raster, false, null);

    Graphics2D g = image.createGraphics();
    if (icon instanceof ScalableIcon scalableIcon) {
      icon = scalableIcon.scale(scale);
    }
    else {
      g.scale(scale, scale);
    }
    g.setComposite(AlphaComposite.SrcOver);
    icon.paintIcon(null, g, 0, 0);
    g.dispose();

    return image;
  }
private static @NotNull BufferedImage _drawIconIntoMemory(@NotNull Icon icon, float scale, @NotNull Pointer memory, int offset)