src/share/classes/sun/awt/image/MultiResolutionToolkitImage.java

Print this page




  49         return resolutionVariant;
  50     }
  51 
  52     @Override
  53     public List<Image> getResolutionVariants() {
  54         return Arrays.<Image>asList(this, resolutionVariant);
  55     }
  56 
  57     private static final int BITS_INFO = ImageObserver.SOMEBITS
  58             | ImageObserver.FRAMEBITS | ImageObserver.ALLBITS;
  59 
  60     private static class ObserverCache {
  61 
  62         static final SoftCache INSTANCE = new SoftCache();
  63     }
  64 
  65     public static ImageObserver getResolutionVariantObserver(
  66             final Image image, final ImageObserver observer,
  67             final int imgWidth, final int imgHeight,
  68             final int rvWidth, final int rvHeight) {








  69 
  70         if (observer == null) {
  71             return null;
  72         }
  73 
  74         synchronized (ObserverCache.INSTANCE) {
  75             ImageObserver o = (ImageObserver) ObserverCache.INSTANCE.get(image);
  76 
  77             if (o == null) {
  78 
  79                 o = (Image resolutionVariant, int flags,
  80                         int x, int y, int width, int height) -> {
  81 
  82                             if ((flags & (ImageObserver.WIDTH | BITS_INFO)) != 0) {
  83                                 width = (width + 1) / 2;
  84                             }
  85 
  86                             if ((flags & (ImageObserver.HEIGHT | BITS_INFO)) != 0) {
  87                                 height = (height + 1) / 2;
  88                             }
  89 
  90                             if ((flags & BITS_INFO) != 0) {
  91                                 x /= 2;
  92                                 y /= 2;
  93                             }
  94 





  95                             return observer.imageUpdate(
  96                                     image, flags, x, y, width, height);
  97                         };
  98 
  99                 ObserverCache.INSTANCE.put(image, o);
 100             }
 101             return o;
 102         }
 103     }
 104 }


  49         return resolutionVariant;
  50     }
  51 
  52     @Override
  53     public List<Image> getResolutionVariants() {
  54         return Arrays.<Image>asList(this, resolutionVariant);
  55     }
  56 
  57     private static final int BITS_INFO = ImageObserver.SOMEBITS
  58             | ImageObserver.FRAMEBITS | ImageObserver.ALLBITS;
  59 
  60     private static class ObserverCache {
  61 
  62         static final SoftCache INSTANCE = new SoftCache();
  63     }
  64 
  65     public static ImageObserver getResolutionVariantObserver(
  66             final Image image, final ImageObserver observer,
  67             final int imgWidth, final int imgHeight,
  68             final int rvWidth, final int rvHeight) {
  69         return getResolutionVariantObserver(image, observer,
  70                 imgWidth, imgHeight, rvWidth, rvHeight, false);
  71     }
  72 
  73     public static ImageObserver getResolutionVariantObserver(
  74             final Image image, final ImageObserver observer,
  75             final int imgWidth, final int imgHeight,
  76             final int rvWidth, final int rvHeight, boolean concatenateInfo) {
  77 
  78         if (observer == null) {
  79             return null;
  80         }
  81 
  82         synchronized (ObserverCache.INSTANCE) {
  83             ImageObserver o = (ImageObserver) ObserverCache.INSTANCE.get(image);
  84 
  85             if (o == null) {
  86 
  87                 o = (Image resolutionVariant, int flags,
  88                         int x, int y, int width, int height) -> {
  89 
  90                             if ((flags & (ImageObserver.WIDTH | BITS_INFO)) != 0) {
  91                                 width = (width + 1) / 2;
  92                             }
  93 
  94                             if ((flags & (ImageObserver.HEIGHT | BITS_INFO)) != 0) {
  95                                 height = (height + 1) / 2;
  96                             }
  97 
  98                             if ((flags & BITS_INFO) != 0) {
  99                                 x /= 2;
 100                                 y /= 2;
 101                             }
 102 
 103                             if(concatenateInfo){
 104                                 flags &= ((ToolkitImage) image).
 105                                         getImageRep().check(null);
 106                             }
 107 
 108                             return observer.imageUpdate(
 109                                     image, flags, x, y, width, height);
 110                         };
 111 
 112                 ObserverCache.INSTANCE.put(image, o);
 113             }
 114             return o;
 115         }
 116     }
 117 }