Package com.ngt.jopenmetaverse.shared.sim.events

Examples of com.ngt.jopenmetaverse.shared.sim.events.ManualResetEvent


      }


  public IBitmap LoadTexture(final UUID textureID, final boolean removeAlpha)
  {
    final ManualResetEvent gotImage = new ManualResetEvent(false);
    IBitmap img = null;

    //FIXME we need to handle caching images with removeAlpha true or false
//    if((img = bitmapLruCache.get(textureID)) != null)
//    {
//      //System.out.println("Found in LRU Cache " + textureID.toString());
//      return img;
//    }
   
    try
    {
      gotImage.reset();             
      LoadCachedImageResult result = client.assets.Cache.loadCompressedImageFromCache(textureID);

      if (result != null)
      {
        ByteArrayInputStream baos = new ByteArrayInputStream(result.data);
        img = LoadTGAClass.LoadTGA(baos);
        baos.close();
      }
      else
      {
        final IBitmap[] texDownloadResult = new IBitmap[1];
        client.assets.RequestImage(textureID, new MethodDelegate<Void, TextureDownloadCallbackArgs>()
            {
          public Void execute(TextureDownloadCallbackArgs e) {
            TextureRequestState state = e.getState();
            AssetTexture assetTexture = e.getAssetTexture();

            if (state == TextureRequestState.Finished)
            {
              try{
                ManagedImage mi = OpenJPEGFactory.getIntance().DecodeToImage(assetTexture.AssetData);

                if (removeAlpha)
                {
                  if ((ImageChannels.and(mi.Channels,  ManagedImage.ImageChannels.Alpha)) != 0)
                  {
                    mi.ConvertChannels(ImageChannels.get(ImageChannels.and(mi.Channels, ~ManagedImage.ImageChannels.Alpha.getIndex())));
                  }
                }
                byte[] tgaData = mi.ExportTGA();
               
                texDownloadResult[0] = LoadTGAClass.LoadTGA(new ByteArrayInputStream(tgaData));               
                client.assets.Cache.compressAndSaveImageToCache(textureID, tgaData, ImageChannels.and(mi.Channels, ManagedImage.ImageChannels.Alpha) != 0, false, false);
              }
              catch(Exception ex)
              {
                JLogger.error(Utils.getExceptionStackTraceAsString(ex));
                texDownloadResult[0]= null;
              }
            }
            gotImage.set();

            return null;
          }
            });
        gotImage.waitOne(30 * 1000);
        img = texDownloadResult[0];       
       
      }
      if (img != null)
      {
View Full Code Here

TOP

Related Classes of com.ngt.jopenmetaverse.shared.sim.events.ManualResetEvent

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.