+ IA_TestAsyncImage tests the async download code of ImageManager, by downloading all textures encountered when listening to OnNewPrim
+ Removed KakaduWrap, no longer needed now that ImageTool uses Jasper + Exposed an accessor for Textures in TextureEntry git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@454 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
141
libsecondlife-cs/examples/IA_TestAsyncImage/IA_TestAsyncImage.cs
Normal file
141
libsecondlife-cs/examples/IA_TestAsyncImage/IA_TestAsyncImage.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using IA_SimpleInventory;
|
||||
|
||||
using libsecondlife;
|
||||
using libsecondlife.AssetSystem;
|
||||
|
||||
namespace IA_TestAsyncImage
|
||||
{
|
||||
class TestAsync : SimpleInventory
|
||||
{
|
||||
ImageManager imgManager;
|
||||
|
||||
Queue<LLUUID> TextureQueue = new Queue<LLUUID>();
|
||||
|
||||
string OutputDirectory = "IA_TestAsyncImages";
|
||||
|
||||
[STAThread]
|
||||
static new void Main(string[] args)
|
||||
{
|
||||
TestAsync app = new TestAsync();
|
||||
app.DownloadInventoryOnConnect = false;
|
||||
|
||||
app.client.Objects.OnNewPrim += new NewPrimCallback(app.Objects_OnNewPrim);
|
||||
app.client.Objects.OnNewAvatar += new NewAvatarCallback(app.Objects_OnNewAvatar);
|
||||
|
||||
|
||||
app.Connect(args[0], args[1], args[2]);
|
||||
app.doStuff();
|
||||
app.Disconnect();
|
||||
|
||||
System.Threading.Thread.Sleep(500);
|
||||
|
||||
Console.WriteLine("Done...");
|
||||
}
|
||||
|
||||
private void Objects_OnNewAvatar(Simulator simulator, Avatar avatar, ulong regionHandle, ushort timeDilation)
|
||||
{
|
||||
if (imgManager == null)
|
||||
{
|
||||
Console.WriteLine("ImageManager not ready yet, queueing Avatar textures.");
|
||||
TextureQueue.Enqueue(avatar.FirstLifeImage);
|
||||
TextureQueue.Enqueue(avatar.ProfileImage);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (avatar.FirstLifeImage != null)
|
||||
{
|
||||
imgManager.RequestImageAsync(avatar.FirstLifeImage);
|
||||
}
|
||||
|
||||
if (avatar.ProfileImage != null)
|
||||
{
|
||||
imgManager.RequestImageAsync(avatar.ProfileImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Objects_OnNewPrim(Simulator simulator, PrimObject prim, ulong regionHandle, ushort timeDilation)
|
||||
{
|
||||
if (imgManager == null)
|
||||
{
|
||||
Console.WriteLine("ImageManager not ready yet, queueing Prim textures.");
|
||||
TextureQueue.Enqueue(prim.Textures.DefaultTexture.TextureID);
|
||||
|
||||
foreach (TextureEntryFace tef in prim.Textures.FaceTextures.Values)
|
||||
{
|
||||
TextureQueue.Enqueue(tef.TextureID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((prim.Textures.DefaultTexture != null) && (prim.Textures.DefaultTexture.TextureID != null))
|
||||
{
|
||||
imgManager.RequestImageAsync(prim.Textures.DefaultTexture.TextureID);
|
||||
}
|
||||
|
||||
if (prim.Textures.FaceTextures != null)
|
||||
{
|
||||
foreach (TextureEntryFace tef in prim.Textures.FaceTextures.Values)
|
||||
{
|
||||
imgManager.RequestImageAsync(tef.TextureID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void NewImageRetrievedCallBack( LLUUID ImageID, byte[] data, bool wasCached )
|
||||
{
|
||||
if (wasCached)
|
||||
{
|
||||
Console.WriteLine("Cache ( " + data.Length + "): " + ImageID);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Finished ( " + data.Length + "): " + ImageID);
|
||||
|
||||
String filename = Path.Combine(OutputDirectory, ImageID.ToStringHyphenated()) + ".tif";
|
||||
|
||||
TiffJob tj = new TiffJob( filename, data );
|
||||
Thread t = new Thread(tj.RunMe);
|
||||
t.Start();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected new void doStuff()
|
||||
{
|
||||
imgManager = new ImageManager(client, ImageManager.CacheTypes.Disk, OutputDirectory);
|
||||
imgManager.OnImageRetrieved += new ImageRetrievedCallback(NewImageRetrievedCallBack);
|
||||
|
||||
while (TextureQueue.Count > 0)
|
||||
{
|
||||
imgManager.RequestImageAsync(TextureQueue.Dequeue());
|
||||
}
|
||||
|
||||
Console.WriteLine("Press any key to stop.");
|
||||
Console.Read();
|
||||
}
|
||||
|
||||
protected class TiffJob
|
||||
{
|
||||
string filename;
|
||||
byte[] j2cdata;
|
||||
|
||||
public TiffJob(string path, byte[] data)
|
||||
{
|
||||
filename = path;
|
||||
j2cdata = data;
|
||||
}
|
||||
|
||||
public void RunMe()
|
||||
{
|
||||
File.WriteAllBytes(filename, JasperWrapper.jasper_decode_j2c_to_tiff(j2cdata));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user