+ 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{A4F59DE9-E382-401D-AA8D-4557779D764E}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>IA_TestAsyncImage</RootNamespace>
|
||||
<AssemblyName>IA_TestAsyncImage</AssemblyName>
|
||||
<StartupObject>IA_TestAsyncImage.TestAsync</StartupObject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\..\..\bin\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="IA_TestAsyncImage.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\libjaspernet\libjaspernet.csproj">
|
||||
<Project>{7D4C4807-7705-48A7-9D82-F6689FBBCC8B}</Project>
|
||||
<Name>libjaspernet</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\libsecondlife.csproj">
|
||||
<Project>{D9CDEDFB-8169-4B03-B57F-0DF638F044EC}</Project>
|
||||
<Name>libsecondlife</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\IA_SimpleInventory\IA_SimpleInventory.csproj">
|
||||
<Project>{E464B963-46E3-4E1A-A36F-9C640C880E68}</Project>
|
||||
<Name>IA_SimpleInventory</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,33 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("IA_TestAsyncImage")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("IA_TestAsyncImage")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2006")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("224dd7e4-244c-4f89-8e5a-bc84a636a7b9")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Reference in New Issue
Block a user