Ignore:
Timestamp:
2020-08-23T23:43:22+02:00 (4 years ago)
Author:
simon04
Message:

see #19705 - Remove unused ImageProvider.createRotatedImage

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r16885 r16923  
    77import java.awt.Cursor;
    88import java.awt.Dimension;
    9 import java.awt.Graphics;
    109import java.awt.Graphics2D;
    1110import java.awt.GraphicsEnvironment;
     
    3837import java.util.Collection;
    3938import java.util.EnumMap;
    40 import java.util.HashMap;
    4139import java.util.Hashtable;
    4240import java.util.Iterator;
     
    297295    private static final Map<String, ImageResource> cache = new ConcurrentHashMap<>();
    298296
    299     /**
    300      * Caches the image data for rotated versions of the same image.
    301      */
    302     private static final Map<Image, Map<Long, Image>> ROTATE_CACHE = new HashMap<>();
    303 
    304297    /** small cache of critical images used in many parts of the application */
    305298    private static final Map<OsmPrimitiveType, ImageIcon> osmPrimitiveTypeCache = new EnumMap<>(OsmPrimitiveType.class);
     
    855848    public static void clearCache() {
    856849        cache.clear();
    857         synchronized (ROTATE_CACHE) {
    858             ROTATE_CACHE.clear();
    859         }
    860850        synchronized (osmPrimitiveTypeCache) {
    861851            osmPrimitiveTypeCache.clear();
     
    13951385    /** 90 degrees in radians units */
    13961386    private static final double DEGREE_90 = 90.0 * Math.PI / 180.0;
    1397 
    1398     /**
    1399      * Creates a rotated version of the input image.
    1400      *
    1401      * @param img the image to be rotated.
    1402      * @param rotatedAngle the rotated angle, in degree, clockwise. It could be any double but we
    1403      * will mod it with 360 before using it. More over for caching performance, it will be rounded to
    1404      * an entire value between 0 and 360.
    1405      *
    1406      * @return the image after rotating.
    1407      * @since 6172
    1408      */
    1409     public static Image createRotatedImage(Image img, double rotatedAngle) {
    1410         return createRotatedImage(img, rotatedAngle, ImageResource.DEFAULT_DIMENSION);
    1411     }
    1412 
    1413     /**
    1414      * Creates a rotated version of the input image.
    1415      *
    1416      * @param img the image to be rotated.
    1417      * @param rotatedAngle the rotated angle, in degree, clockwise. It could be any double but we
    1418      * will mod it with 360 before using it. More over for caching performance, it will be rounded to
    1419      * an entire value between 0 and 360.
    1420      * @param dimension ignored
    1421      * @return the image after rotating and scaling.
    1422      * @since 6172
    1423      */
    1424     public static Image createRotatedImage(Image img, double rotatedAngle, Dimension dimension) {
    1425         CheckParameterUtil.ensureParameterNotNull(img, "img");
    1426 
    1427         // convert rotatedAngle to an integer value from 0 to 360
    1428         Long angleLong = Math.round(rotatedAngle % 360);
    1429         Long originalAngle = rotatedAngle != 0 && angleLong == 0 ? Long.valueOf(360L) : angleLong;
    1430 
    1431         synchronized (ROTATE_CACHE) {
    1432             Map<Long, Image> cacheByAngle = ROTATE_CACHE.computeIfAbsent(img, k -> new HashMap<>());
    1433             Image rotatedImg = cacheByAngle.get(originalAngle);
    1434 
    1435             if (rotatedImg == null) {
    1436                 // convert originalAngle to a value from 0 to 90
    1437                 double angle = originalAngle % 90;
    1438                 if (originalAngle != 0 && angle == 0) {
    1439                     angle = 90.0;
    1440                 }
    1441                 double radian = Utils.toRadians(angle);
    1442 
    1443                 rotatedImg = HiDPISupport.processMRImage(img, img0 -> {
    1444                     new ImageIcon(img0); // load completely
    1445                     int iw = img0.getWidth(null);
    1446                     int ih = img0.getHeight(null);
    1447                     int w;
    1448                     int h;
    1449 
    1450                     if ((originalAngle >= 0 && originalAngle <= 90) || (originalAngle > 180 && originalAngle <= 270)) {
    1451                         w = (int) (iw * Math.sin(DEGREE_90 - radian) + ih * Math.sin(radian));
    1452                         h = (int) (iw * Math.sin(radian) + ih * Math.sin(DEGREE_90 - radian));
    1453                     } else {
    1454                         w = (int) (ih * Math.sin(DEGREE_90 - radian) + iw * Math.sin(radian));
    1455                         h = (int) (ih * Math.sin(radian) + iw * Math.sin(DEGREE_90 - radian));
    1456                     }
    1457                     Image image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    1458                     Graphics g = image.getGraphics();
    1459                     Graphics2D g2d = (Graphics2D) g.create();
    1460 
    1461                     // calculate the center of the icon.
    1462                     int cx = iw / 2;
    1463                     int cy = ih / 2;
    1464 
    1465                     // move the graphics center point to the center of the icon.
    1466                     g2d.translate(w / 2, h / 2);
    1467 
    1468                     // rotate the graphics about the center point of the icon
    1469                     g2d.rotate(Utils.toRadians(originalAngle));
    1470 
    1471                     g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    1472                     g2d.drawImage(img0, -cx, -cy, null);
    1473 
    1474                     g2d.dispose();
    1475                     new ImageIcon(image); // load completely
    1476                     return image;
    1477                 });
    1478                 cacheByAngle.put(originalAngle, rotatedImg);
    1479             }
    1480             return rotatedImg;
    1481         }
    1482     }
    14831387
    14841388    /**
Note: See TracChangeset for help on using the changeset viewer.