public static @NotNull BufferedImage clipImage(@NotNull BufferedImage image, @NotNull Shape clip) {
    if (image instanceof JBHiDPIScaledImage scaledImage) {
      Image delegate = scaledImage.getDelegate();
      if (delegate == null) return doClipImage(scaledImage, clip);
      BufferedImage clippedImage = doClipImage(toBufferedImage(delegate), clip);
      return new JBHiDPIScaledImage(clippedImage,
                                    ScaleContext.create(ScaleType.SYS_SCALE.of(scaledImage.getScale())),
                                    scaledImage.getType());
    }

    return doClipImage(image, clip);
  }
public static @NotNull BufferedImage clipImage(@NotNull BufferedImage image, @NotNull Shape clip)