Package com.lightcrafts.mediax.jai

Examples of com.lightcrafts.mediax.jai.TileCache


                try {
                    // Attempt to compute the tile.
                    tile = owner.computeTile(tileX, tileY);
                } catch (OutOfMemoryError e) {
                    // Empty the cache and call System.gc()
                    TileCache tileCache = owner.getTileCache();
                    if(tileCache != null) {
                        tileCache.flush();
                        System.gc(); //slow
                    }

                    // Re-attempt to compute the tile.
                    tile = owner.computeTile(tileX, tileY);
View Full Code Here


                try {
                    // Attempt to compute the tile.
                    tile = owner.computeTile(tileX, tileY);
                } catch (OutOfMemoryError e) {
                    // Empty the cache and call System.gc()
                    TileCache tileCache = owner.getTileCache();
                    if(tileCache != null) {
                        tileCache.flush();
                        System.gc(); //slow
                    }

                    // Re-attempt to compute the tile.
                    tile = owner.computeTile(tileX, tileY);
View Full Code Here

                // Ran out of memory - may be due to the decoder being
                // obliged to read the entire image when it creates the
                // RenderedImage it returns.
                if(canAttemptRecovery) {
                    // First flush the cache if one is defined.
                    TileCache cache = image != null ?
                        image.getTileCache() :
                        RIFUtil.getTileCacheHint(renderHints);
                    if(cache != null) {
                        cache.flush();
                    }

                    // Force garbage collection.
                    System.gc(); //slow
View Full Code Here

    public Raster getTile(int tileX, int tileY) {
        if (isServer || isSourceRemote) {
            return source.getTile(tileX, tileY);
        }

  TileCache cache = JAI.getDefaultInstance().getTileCache();
  if (cache != null) {
      Raster tile = cache.getTile(this, tileX, tileY);
      if (tile != null)
    return tile;
  }

  // Determine the active area; tile intersects with image's bounds.
  Rectangle imageBounds = new Rectangle(getMinX(), getMinY(),
                getWidth(), getHeight());
  Rectangle destRect =
      imageBounds.intersection(new Rectangle(tileXToX(tileX),
               tileYToY(tileY),
               getTileWidth(),
               getTileHeight()));

  Raster tile = getData(destRect);

  if (cache != null) {
      cache.add(this, tileX, tileY, tile);
  }

  return tile;
    }
View Full Code Here

                // Ran out of memory - may be due to the decoder being
                // obliged to read the entire image when it creates the
                // RenderedImage it returns.
                if(canAttemptRecovery) {
                    // First flush the cache if one is defined.
                    TileCache cache = RIFUtil.getTileCacheHint(renderHints);
                    if(cache != null) {
                        cache.flush();
                    }

                    // Force garbage collection.
                    System.gc(); //slow
View Full Code Here

                        invalidRegion = (gp == null) ? null : new Area(gp);
                    }

                    // Retrieve the old TileCache.
                    TileCache oldCache = oldPISP.getTileCache();
        theImage = null;

                    // Only perform further processing if there is a cache
                    // and there are tiles to save.
                    if (oldCache != null &&
      (saveAllTiles || validTiles != null)) {

      // Create new rendering
      newEventRendering(protocolName,
            oldPISP,
            (PropertyChangeEventJAI)evt);

                        // Only perform further processing if the new
                        // rendering is an OpImage with a non-null TileCache.
                        if (theImage instanceof PlanarImageServerProxy &&
                           ((PlanarImageServerProxy)theImage).getTileCache() !=
         null) {
                            PlanarImageServerProxy newPISP =
        (PlanarImageServerProxy)theImage;
                            TileCache newCache = newPISP.getTileCache();

                            Object tileCacheMetric =
                                newPISP.getTileCacheMetric();

                            if (saveAllTiles) {
                                Raster[] tiles = oldCache.getTiles(oldPISP);
                                int numTiles = tiles == null ?
            0 : tiles.length;
                                for(int i = 0; i < numTiles; i++) {
                                    Raster tile = tiles[i];
                                    int tx = newPISP.XToTileX(tile.getMinX());
                                    int ty = newPISP.YToTileY(tile.getMinY());
                                    newCache.add(newPISP,
                                                 tx, ty, tile,
                   tileCacheMetric);
                                }
                            } else { // save some, but not all, tiles
                                int numValidTiles = validTiles.size();
                                for(int i = 0; i < numValidTiles; i++) {
                                    Point tileIndex = (Point)validTiles.get(i);
                                    Raster tile =
                                        oldCache.getTile(oldPISP,
                                                         tileIndex.x,
                                                         tileIndex.y);
                                    if (tile != null) {
                                        newCache.add(newPISP,
                                                     tileIndex.x,
                                                     tileIndex.y,
                                                     tile,
                 tileCacheMetric);
                                    }
                                }
                            }
                        }
                    }
                }
            } else { // not op name or registry change nor RenderingChangeEvent
                ParameterBlock oldPB = null;
                ParameterBlock newPB = null;
    String oldServerName = serverName;
    String newServerName = serverName;

                boolean checkInvalidRegion = false;

    if (propName.equals("operationname")) {

        if (theImage instanceof PlanarImageServerProxy) {
      newEventRendering(protocolName,
            (PlanarImageServerProxy)theImage,
            (PropertyChangeEventJAI)evt);
        } else {
      theImage = null;
      createRendering();
        }

        // Do not set checkInvalidRegion to true, since there
        // are no tiles to save for this case.

        shouldFireEvent = true;

        // XXX Do we need to do any evaluation of any
        // DeferredData parameters.

    } else if (propName.equals("parameterblock")) {
                    oldPB = (ParameterBlock)evt.getOldValue();
                    newPB = (ParameterBlock)evt.getNewValue();
                    checkInvalidRegion = true;
                } else if (propName.equals("sources")) {
                    // Replace source(s)
                    Vector params =
      nodeSupport.getParameterBlock().getParameters();
                    oldPB = new ParameterBlock((Vector)evt.getOldValue(),
                                               params);
                    newPB = new ParameterBlock((Vector)evt.getNewValue(),
                                               params);
                    checkInvalidRegion = true;
                } else if (propName.equals("parameters")) {
                    // Replace parameter(s)
                    oldPB = new ParameterBlock(nodeSources,
                                               (Vector)evt.getOldValue());
                    newPB = new ParameterBlock(nodeSources,
                                               (Vector)evt.getNewValue());
                    checkInvalidRegion = true;
                } else if (propName.equals("renderinghints")) {
                    oldPB = newPB = nodeSupport.getParameterBlock();
                    checkInvalidRegion = true;
                } else if (propName.equals("servername")) {
        oldPB = newPB = nodeSupport.getParameterBlock();
        oldServerName = (String)evt.getOldValue();
        newServerName = (String)evt.getNewValue();
        checkInvalidRegion = true;
    } else if (evt instanceof CollectionChangeEvent) {
        // Event from a CollectionOp source.
                    // Replace appropriate source.
                    int collectionIndex = nodeSources.indexOf(evtSrc);
                    Vector oldSources = (Vector)nodeSources.clone();
                    Vector newSources = (Vector)nodeSources.clone();
                    oldSources.set(collectionIndex, evt.getOldValue());
                    newSources.set(collectionIndex, evt.getNewValue());

                    Vector params =
                        nodeSupport.getParameterBlock().getParameters();

                    oldPB = new ParameterBlock(oldSources, params);
                    newPB = new ParameterBlock(newSources, params);

                    checkInvalidRegion = true;
                }

                if (checkInvalidRegion) {
                    // Set event flag.
                    shouldFireEvent = true;

                    // Get the associated RemoteDescriptor.
                    OperationRegistry registry = nodeSupport.getRegistry();
                    RemoteDescriptor odesc = (RemoteDescriptor)
                        registry.getDescriptor(RemoteDescriptor.class,
                                               protocolName);

        // XXX
                    // Evaluate any DeferredData parameters.
                    oldPB = ImageUtil.evaluateParameters(oldPB);
                    newPB = ImageUtil.evaluateParameters(newPB);

                    // Determine the invalid region.
                    invalidRegion = (Shape)
                        odesc.getInvalidRegion("rendered",
                 oldServerName,
                                               oldPB,
                                               oldHints,
                 newServerName,
                                               newPB,
                                               nodeSupport.getRenderingHints(),
                                               this);

                    if (invalidRegion == null ||
                       !(theImage instanceof PlanarImageServerProxy)) {
                        // Can't save any tiles; clear the rendering.
                        theImage = null;

                    } else {

                        // Create a new rendering.
                        PlanarImageServerProxy oldRendering =
          (PlanarImageServerProxy)theImage;

      newEventRendering(protocolName, oldRendering,
            (PropertyChangeEventJAI)evt);

                        // If the new rendering is also a
      // PlanarImageServerProxy, save some tiles.
                        if (theImage instanceof PlanarImageServerProxy &&
          oldRendering.getTileCache() != null &&
          ((PlanarImageServerProxy)theImage).getTileCache()
          != null) {
                            PlanarImageServerProxy newRendering =
        (PlanarImageServerProxy)theImage;

                            TileCache oldCache = oldRendering.getTileCache();
                            TileCache newCache = newRendering.getTileCache();

                            Object tileCacheMetric =
                                newRendering.getTileCacheMetric();

                            // If bounds are empty, replace invalidRegion with
                            // the complement of the image bounds within the
                            // bounds of all tiles.
                            if (invalidRegion.getBounds().isEmpty()) {
                                int x = oldRendering.tileXToX(
                                            oldRendering.getMinTileX());
                                int y = oldRendering.tileYToY(
                                            oldRendering.getMinTileY());
                                int w = oldRendering.getNumXTiles() *
                                    oldRendering.getTileWidth();
                                int h = oldRendering.getNumYTiles() *
                                    oldRendering.getTileHeight();
                                Rectangle tileBounds =
            new Rectangle(x, y, w, h);
                                Rectangle imageBounds =
                                    oldRendering.getBounds();
                                if (!tileBounds.equals(imageBounds)) {
                                    Area tmpArea = new Area(tileBounds);
                                    tmpArea.subtract(new Area(imageBounds));
                                    invalidRegion = tmpArea;
                                }
                            }

                            if (invalidRegion.getBounds().isEmpty()) {

                                // Save all tiles.
                                Raster[] tiles =
                                    oldCache.getTiles(oldRendering);
                                int numTiles = tiles == null ?
                                    0 : tiles.length;
                                for(int i = 0; i < numTiles; i++) {
                                    Raster tile = tiles[i];
                                    int tx =
                                        newRendering.XToTileX(tile.getMinX());
                                    int ty =
                                        newRendering.YToTileY(tile.getMinY());
                                    newCache.add(newRendering,
                                                 tx, ty, tile,
             tileCacheMetric);
                                }
                            } else {
                                // Copy tiles not in invalid region from old
                                // TileCache to new TileCache.
                                Raster[] tiles =
                                    oldCache.getTiles(oldRendering);
                                int numTiles = tiles == null ?
                                    0 : tiles.length;
                                for(int i = 0; i < numTiles; i++) {
                                    Raster tile = tiles[i];
                                    Rectangle bounds = tile.getBounds();
                                    if (!invalidRegion.intersects(bounds)) {
                                        newCache.add(
                newRendering,
                newRendering.XToTileX(bounds.x),
                newRendering.YToTileY(bounds.y),
                tile,
                tileCacheMetric);
View Full Code Here

        // Get ImageLayout from renderHints if any.
        ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
       
        // Get TileCache from renderHints if any.
        TileCache cache = RIFUtil.getTileCacheHint(renderHints);

        // Get BorderExtender from renderHints if any.
        BorderExtender extender = RIFUtil.getBorderExtenderHint(renderHints);

        RenderedImage source = paramBlock.getRenderedSource(0);
View Full Code Here

                                RenderingHints renderHints) {
        // Get ImageLayout from renderHints if any.
        ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);

        // Get TileCache from renderHints if any.
        TileCache cache = RIFUtil.getTileCacheHint(renderHints);

        // Get BorderExtender from renderHints if any.
        BorderExtender extender = RIFUtil.getBorderExtenderHint(renderHints);

        RenderedImage source = paramBlock.getRenderedSource(0);
View Full Code Here

             (int)xTrans,
             (int)yTrans);
        } else {
           
            // Get TileCache from renderHints if any.
            TileCache cache = RIFUtil.getTileCacheHint(renderHints);

            // Get BorderExtender from renderHints if any.
            BorderExtender extender =
                RIFUtil.getBorderExtenderHint(renderHints);
           
View Full Code Here

TOP

Related Classes of com.lightcrafts.mediax.jai.TileCache

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.