Package java.lang.ref

Examples of java.lang.ref.SoftReference


                    }
                }
            }

            // Cache the table.
            hintTableReference = new SoftReference(table);
        }

        return table;
    }
View Full Code Here


            data = (byte[]) imageData.get();
        }
        if (data == null)
        {
            data = render();
            imageData = new SoftReference(data);
        }
        return data;
    }
View Full Code Here

            //
            // First time or reference has been cleared.
            // Create  the table and make a soft reference to it.
            //
            byteTable = new byte[256*256];
            softRef = new SoftReference(byteTable);

            // Initialize table which implements Min
            int idx = 0;
            for (int i1 = 0; i1 < 256; i1++) {
                int base = i1 << 8;
View Full Code Here

    coords = new Coordinate[size()];
    for (int i = 0; i < coords.length; i++) {
      coords[i] = getCoordinateInternal(i);
    }
    coordRef = new SoftReference(coords);

    return coords;
  }
View Full Code Here

            numBands == 3 ? TYPE_OD_BYTE_LUT_3BAND : TYPE_OD_BYTE_LUT_NBAND;

        // Check whether an equivalent DitherLUT object already exists.
        int index = 0;
        while(index < ditherLUTCache.size()) {
            SoftReference lutRef = (SoftReference)ditherLUTCache.get(index);
            DitherLUT lut = (DitherLUT)lutRef.get();
            if(lut == null) {
                // The reference has been cleared: remove the Vector element
                // but do not increment the loop index.
                ditherLUTCache.remove(index);
            } else {
                if(lut.equals(dims, mults, maskDataByte)) {
                    // Found an equivalent DitherLUT so use it and exit loop.
                    odLUT = lut;
                    break;
                }
                // Move on to the next Vector element.
                index++;
            }
        }

        // Create a new DitherLUT if an equivalent one was not found.
        if(odLUT == null) {
            odLUT = new DitherLUT(dims, mults, maskDataByte);
            // Cache a reference to the DitherLUT if there is room.
            if(ditherLUTCache.size() < DITHER_LUT_CACHE_LENGTH_MAX) {
                ditherLUTCache.add(new SoftReference(odLUT));
            }
        }
    }
View Full Code Here

            //
            // First time or reference has been cleared.
            // Create  the table and make a soft reference to it.
            //
            byteTable = new byte[256*256];
            softRef = new SoftReference(byteTable);

            // Initialize table which implements Min
            int idx = 0;
            for (int i1 = 0; i1 < 256; i1++) {
                int base = i1 << 8;
View Full Code Here

            mresTable = new Hashtable();
        }

        // Check for a SoftReference hashed on a ParameterBlock-derived key.
        Object key = getKey(paramBlock);
        SoftReference ref = (SoftReference)mresTable.get(key);

        // Retrieve the image from the SoftReference if possible.
        RenderableImage mres = null;
        if(ref != null && (mres = (RenderableImage)ref.get()) == null) {
            // null referent: remove the ParameterBlock key from the Hashtable.
            mresTable.remove(key);
        }

        // Derive the image if necessary.
        if(mres == null) {
            // Retrieve the source and parameters.
            RenderedImage source = paramBlock.getRenderedSource(0);
            RenderedOp downSampler =
                (RenderedOp)paramBlock.getObjectParameter(0);
            int maxLowResDim = paramBlock.getIntParameter(1);
            float minX = paramBlock.getFloatParameter(2);
            float minY = paramBlock.getFloatParameter(3);
            float height = paramBlock.getFloatParameter(4);

            // Create an image pyramid.
            ImageMIPMap pyramid = new ImageMIPMap(source, downSampler);

            // Create a Vector of RenderedImages from the pyramid.
            Vector sourceVector = new Vector();
            RenderedImage currentImage = pyramid.getCurrentImage();
            sourceVector.add(currentImage);
            while(currentImage.getWidth() > maxLowResDim ||
                  currentImage.getHeight() > maxLowResDim) {
                RenderedImage nextImage = pyramid.getDownImage();
                if(nextImage.getWidth() >= currentImage.getWidth() ||
                   nextImage.getHeight() >= currentImage.getHeight()) {
                    throw new IllegalArgumentException(JaiI18N.getString("RenderableCRIF0"));
                }
                sourceVector.add(nextImage);
                currentImage = nextImage;
            }

            // Create a RenderableImage
            mres = new MultiResolutionRenderableImage(sourceVector,
                                                      minX, minY, height);

            // Store a SoftReference to the RenderableImage in the Hashtable.
            mresTable.put(key, new SoftReference(mres));
        }

        return mres;
    }
View Full Code Here

        synchronized(reference) {
            Object referent = reference.get();
            IHSColorSpace cs;
            if (referent == null) {
                // First invocation or SoftReference has been cleared.
                reference = new SoftReference(cs = new IHSColorSpace());
            } else {
                // SoftReference has not been cleared.
                cs = (IHSColorSpace)referent;
            }
View Full Code Here

    // generate the cos table used in RGBtoIHS for byte type
    private synchronized void generateACosTable() {

        if ((acosSoftRef == null) || (acosSoftRef.get() == null)) {
            acosTable = new byte[1001] ;
            acosSoftRef = new SoftReference(acosTable);

            for (int i=0; i<=1000; i++)
                acosTable[i] =
        (byte)(BYTESCALE *Math.acos((i - 500) * 0.002) + 0.5) ;
        }
View Full Code Here

    // generate the square root table used in RGBtoIHS for byte type
    private synchronized void generateSqrtTable() {
        if ((sqrtSoftRef == null) || (sqrtSoftRef.get() == null)) {
            sqrtTable = new double[1001] ;
            sqrtSoftRef = new SoftReference(sqrtTable);

            for (int i = 0; i <= 1000; i++)
                sqrtTable[i] = Math.sqrt(i / 1000.0) ;
        }
    }
View Full Code Here

TOP

Related Classes of java.lang.ref.SoftReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.