Search in sources :

Example 21 with WeakHashMap

use of java.util.WeakHashMap in project checker-framework by typetools.

the class ColorModel method getGray8TosRGB8LUT.

/*
     * Return a byte LUT that converts 8-bit gray values in the grayCS
     * ColorSpace to the appropriate 8-bit sRGB value.  I.e., if lut
     * is the byte array returned by this method and sval = lut[gval],
     * then the sRGB triple (sval,sval,sval) is the best match to gval.
     * Cache references to any computed LUT in a Map.
     */
static byte[] getGray8TosRGB8LUT(ICC_ColorSpace grayCS) {
    if (isLinearGRAYspace(grayCS)) {
        return getLinearRGB8TosRGB8LUT();
    }
    if (g8Tos8Map != null) {
        byte[] g8Tos8LUT = g8Tos8Map.get(grayCS);
        if (g8Tos8LUT != null) {
            return g8Tos8LUT;
        }
    }
    byte[] g8Tos8LUT = new byte[256];
    for (int i = 0; i <= 255; i++) {
        g8Tos8LUT[i] = (byte) i;
    }
    ColorTransform[] transformList = new ColorTransform[2];
    PCMM mdl = CMSManager.getModule();
    ICC_ColorSpace srgbCS = (ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_sRGB);
    transformList[0] = mdl.createTransform(grayCS.getProfile(), ColorTransform.Any, ColorTransform.In);
    transformList[1] = mdl.createTransform(srgbCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
    ColorTransform t = mdl.createTransform(transformList);
    byte[] tmp = t.colorConvert(g8Tos8LUT, null);
    for (int i = 0, j = 2; i <= 255; i++, j += 3) {
        // All three components of tmp should be equal, since
        // the input color space to colorConvert is a gray scale
        // space.  However, there are slight anomalies in the results.
        // Copy tmp starting at index 2, since colorConvert seems
        // to be slightly more accurate for the third component!
        g8Tos8LUT[i] = tmp[j];
    }
    if (g8Tos8Map == null) {
        g8Tos8Map = Collections.synchronizedMap(new WeakHashMap<ICC_ColorSpace, byte[]>(2));
    }
    g8Tos8Map.put(grayCS, g8Tos8LUT);
    return g8Tos8LUT;
}
Also used : ColorTransform(sun.java2d.cmm.ColorTransform) ICC_ColorSpace(java.awt.color.ICC_ColorSpace) PCMM(sun.java2d.cmm.PCMM) WeakHashMap(java.util.WeakHashMap)

Example 22 with WeakHashMap

use of java.util.WeakHashMap in project checker-framework by typetools.

the class ColorModel method getLinearGray16ToOtherGray8LUT.

/*
     * Return a byte LUT that converts 16-bit gray values in the CS_GRAY
     * linear gray ColorSpace to the appropriate 8-bit value in the
     * grayCS ColorSpace.  Cache references to any computed LUT in a Map.
     */
static byte[] getLinearGray16ToOtherGray8LUT(ICC_ColorSpace grayCS) {
    if (lg16Toog8Map != null) {
        byte[] lg16Toog8LUT = lg16Toog8Map.get(grayCS);
        if (lg16Toog8LUT != null) {
            return lg16Toog8LUT;
        }
    }
    short[] tmp = new short[65536];
    for (int i = 0; i <= 65535; i++) {
        tmp[i] = (short) i;
    }
    ColorTransform[] transformList = new ColorTransform[2];
    PCMM mdl = CMSManager.getModule();
    ICC_ColorSpace lgCS = (ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_GRAY);
    transformList[0] = mdl.createTransform(lgCS.getProfile(), ColorTransform.Any, ColorTransform.In);
    transformList[1] = mdl.createTransform(grayCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
    ColorTransform t = mdl.createTransform(transformList);
    tmp = t.colorConvert(tmp, null);
    byte[] lg16Toog8LUT = new byte[65536];
    for (int i = 0; i <= 65535; i++) {
        // scale unsigned short (0 - 65535) to unsigned byte (0 - 255)
        lg16Toog8LUT[i] = (byte) (((float) (tmp[i] & 0xffff)) * (1.0f / 257.0f) + 0.5f);
    }
    if (lg16Toog8Map == null) {
        lg16Toog8Map = Collections.synchronizedMap(new WeakHashMap<ICC_ColorSpace, byte[]>(2));
    }
    lg16Toog8Map.put(grayCS, lg16Toog8LUT);
    return lg16Toog8LUT;
}
Also used : ColorTransform(sun.java2d.cmm.ColorTransform) ICC_ColorSpace(java.awt.color.ICC_ColorSpace) PCMM(sun.java2d.cmm.PCMM) WeakHashMap(java.util.WeakHashMap)

Example 23 with WeakHashMap

use of java.util.WeakHashMap in project checker-framework by typetools.

the class ColorModel method getLinearGray16ToOtherGray16LUT.

/*
     * Return a short LUT that converts 16-bit gray values in the CS_GRAY
     * linear gray ColorSpace to the appropriate 16-bit value in the
     * grayCS ColorSpace.  Cache references to any computed LUT in a Map.
     */
static short[] getLinearGray16ToOtherGray16LUT(ICC_ColorSpace grayCS) {
    if (lg16Toog16Map != null) {
        short[] lg16Toog16LUT = lg16Toog16Map.get(grayCS);
        if (lg16Toog16LUT != null) {
            return lg16Toog16LUT;
        }
    }
    short[] tmp = new short[65536];
    for (int i = 0; i <= 65535; i++) {
        tmp[i] = (short) i;
    }
    ColorTransform[] transformList = new ColorTransform[2];
    PCMM mdl = CMSManager.getModule();
    ICC_ColorSpace lgCS = (ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_GRAY);
    transformList[0] = mdl.createTransform(lgCS.getProfile(), ColorTransform.Any, ColorTransform.In);
    transformList[1] = mdl.createTransform(grayCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
    ColorTransform t = mdl.createTransform(transformList);
    short[] lg16Toog16LUT = t.colorConvert(tmp, null);
    if (lg16Toog16Map == null) {
        lg16Toog16Map = Collections.synchronizedMap(new WeakHashMap<ICC_ColorSpace, short[]>(2));
    }
    lg16Toog16Map.put(grayCS, lg16Toog16LUT);
    return lg16Toog16LUT;
}
Also used : ColorTransform(sun.java2d.cmm.ColorTransform) ICC_ColorSpace(java.awt.color.ICC_ColorSpace) PCMM(sun.java2d.cmm.PCMM) WeakHashMap(java.util.WeakHashMap)

Example 24 with WeakHashMap

use of java.util.WeakHashMap in project cache2k by cache2k.

the class Cache2kCoreProviderImpl method getManager.

public CacheManager getManager(ClassLoader cl, String _name, boolean _default) {
    CacheManager mgr;
    Map<String, CacheManager> _loader2managers = loader2name2manager.get(cl);
    if (_loader2managers != null) {
        mgr = _loader2managers.get(_name);
        if (mgr != null) {
            return mgr;
        }
    }
    synchronized (getLockObject()) {
        _loader2managers = loader2name2manager.get(cl);
        if (_loader2managers != null) {
            mgr = _loader2managers.get(_name);
            if (mgr != null) {
                return mgr;
            }
        }
        if (_loader2managers != null) {
            _loader2managers = new HashMap<String, CacheManager>(_loader2managers);
        } else {
            _loader2managers = new HashMap<String, CacheManager>();
        }
        mgr = new CacheManagerImpl(this, cl, _name, _default);
        _loader2managers.put(_name, mgr);
        Map<ClassLoader, Map<String, CacheManager>> _copy = new WeakHashMap<ClassLoader, Map<String, CacheManager>>(loader2name2manager);
        _copy.put(cl, _loader2managers);
        loader2name2manager = _copy;
    }
    return mgr;
}
Also used : CacheManager(org.cache2k.CacheManager) Map(java.util.Map) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) WeakHashMap(java.util.WeakHashMap)

Example 25 with WeakHashMap

use of java.util.WeakHashMap in project cache2k by cache2k.

the class JCacheManagerAdapter method createCache.

public <K, V, C extends Configuration<K, V>> Cache<K, V> createCache(String _cacheName, C cfg) throws IllegalArgumentException {
    checkClosed();
    checkNonNullCacheName(_cacheName);
    synchronized (getLockObject()) {
        Cache _jsr107cache = name2adapter.get(_cacheName);
        if (_jsr107cache != null && !_jsr107cache.isClosed()) {
            throw new CacheException("cache already existing with name: " + _cacheName);
        }
        org.cache2k.Cache _existingCache = manager.getCache(_cacheName);
        if (_existingCache != null && !_existingCache.isClosed()) {
            throw new CacheException("A cache2k instance is already existing with name: " + _cacheName);
        }
        JCacheBuilder<K, V> _builder = new JCacheBuilder<K, V>(_cacheName, this);
        _builder.setConfiguration(cfg);
        Cache<K, V> _cache = _builder.build();
        org.cache2k.Cache _cache2k = _cache.unwrap(org.cache2k.Cache.class);
        Map<org.cache2k.Cache, Cache> _cloneC2k2jCache = new WeakHashMap<org.cache2k.Cache, Cache>();
        _cloneC2k2jCache.putAll(c2k2jCache);
        _cloneC2k2jCache.put(_cache2k, _cache);
        c2k2jCache = _cloneC2k2jCache;
        name2adapter.put(_cache.getName(), _cache);
        if (_builder.getCompleteConfiguration().isStatisticsEnabled()) {
            enableStatistics(_cacheName, true);
        }
        if (_builder.getCompleteConfiguration().isManagementEnabled()) {
            enableManagement(_cacheName, true);
        }
        return _cache;
    }
}
Also used : CacheException(javax.cache.CacheException) Cache(javax.cache.Cache) WeakHashMap(java.util.WeakHashMap)

Aggregations

WeakHashMap (java.util.WeakHashMap)65 Map (java.util.Map)19 HashMap (java.util.HashMap)18 TreeMap (java.util.TreeMap)15 IdentityHashMap (java.util.IdentityHashMap)13 AbstractMap (java.util.AbstractMap)12 LinkedHashMap (java.util.LinkedHashMap)12 ICC_ColorSpace (java.awt.color.ICC_ColorSpace)8 ColorTransform (sun.java2d.cmm.ColorTransform)8 PCMM (sun.java2d.cmm.PCMM)8 Hashtable (java.util.Hashtable)6 AttributedString (java.text.AttributedString)5 Properties (java.util.Properties)5 ArrayList (java.util.ArrayList)4 Comparator (java.util.Comparator)4 List (java.util.List)4 TreeSet (java.util.TreeSet)4 WeakReference (java.lang.ref.WeakReference)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 AttributedCharacterIterator (java.text.AttributedCharacterIterator)3