(ImageIcon in, double factor)
| 580 | } |
| 581 | |
| 582 | @AstroImageJ(reason = "Scale frames") |
| 583 | private static ImageIcon scaleImageIcon(ImageIcon in, double factor) { |
| 584 | if (in == null || factor <= 0) { |
| 585 | return in; |
| 586 | } |
| 587 | |
| 588 | var img = in.getImage(); |
| 589 | if (img == null) { |
| 590 | return in; |
| 591 | } |
| 592 | |
| 593 | var w = img.getWidth(null); |
| 594 | var h = img.getHeight(null); |
| 595 | if (w <= 0 || h <= 0) { |
| 596 | return in; |
| 597 | } |
| 598 | |
| 599 | var nw = Math.max(1, (int) Math.round(w * factor)); |
| 600 | var nh = Math.max(1, (int) Math.round(h * factor)); |
| 601 | |
| 602 | var bufferedImage = new BufferedImage(nw, nh, BufferedImage.TYPE_INT_ARGB); |
| 603 | var g2 = bufferedImage.createGraphics(); |
| 604 | g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); |
| 605 | g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); |
| 606 | g2.drawImage(img, 0, 0, nw, nh, null); |
| 607 | g2.dispose(); |
| 608 | |
| 609 | return new ImageIcon(bufferedImage, in.getDescription()); |
| 610 | } |
| 611 | |
| 612 | /** Works around an OpenJDK bug on Windows that |
| 613 | * causes the scrollbar thumb color and background |
no test coverage detected