mirror of
https://github.com/opensim/opensim.git
synced 2026-08-08 10:15:33 +08:00
Update svn properties. Minor formatting cleanup.
This commit is contained in:
@@ -1,283 +1,283 @@
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenJPEGNet;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules.Scripting.DynamicTexture
|
||||
{
|
||||
public class DynamicTextureModule : IRegionModule, IDynamicTextureManager
|
||||
{
|
||||
private Dictionary<LLUUID, Scene> RegisteredScenes = new Dictionary<LLUUID, Scene>();
|
||||
|
||||
private Dictionary<string, IDynamicTextureRender> RenderPlugins =
|
||||
new Dictionary<string, IDynamicTextureRender>();
|
||||
|
||||
private Dictionary<LLUUID, DynamicTextureUpdater> Updaters = new Dictionary<LLUUID, DynamicTextureUpdater>();
|
||||
|
||||
#region IDynamicTextureManager Members
|
||||
|
||||
public void RegisterRender(string handleType, IDynamicTextureRender render)
|
||||
{
|
||||
if (!RenderPlugins.ContainsKey(handleType))
|
||||
{
|
||||
RenderPlugins.Add(handleType, render);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReturnData(LLUUID id, byte[] data)
|
||||
{
|
||||
if (Updaters.ContainsKey(id))
|
||||
{
|
||||
DynamicTextureUpdater updater = Updaters[id];
|
||||
if (RegisteredScenes.ContainsKey(updater.SimUUID))
|
||||
{
|
||||
Scene scene = RegisteredScenes[updater.SimUUID];
|
||||
updater.DataReceived(data, scene);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public LLUUID AddDynamicTextureURL(LLUUID simID, LLUUID primID, string contentType, string url,
|
||||
string extraParams, int updateTimer)
|
||||
{
|
||||
return AddDynamicTextureURL(simID, primID, contentType, url, extraParams, updateTimer, false, 255);
|
||||
}
|
||||
|
||||
public LLUUID AddDynamicTextureURL(LLUUID simID, LLUUID primID, string contentType, string url,
|
||||
string extraParams, int updateTimer, bool SetBlending, byte AlphaValue)
|
||||
{
|
||||
if (RenderPlugins.ContainsKey(contentType))
|
||||
{
|
||||
//Console.WriteLine("dynamic texture being created: " + url + " of type " + contentType);
|
||||
|
||||
DynamicTextureUpdater updater = new DynamicTextureUpdater();
|
||||
updater.SimUUID = simID;
|
||||
updater.PrimID = primID;
|
||||
updater.ContentType = contentType;
|
||||
updater.Url = url;
|
||||
updater.UpdateTimer = updateTimer;
|
||||
updater.UpdaterID = LLUUID.Random();
|
||||
updater.Params = extraParams;
|
||||
updater.BlendWithOldTexture = SetBlending;
|
||||
updater.FrontAlpha = AlphaValue;
|
||||
|
||||
if (!Updaters.ContainsKey(updater.UpdaterID))
|
||||
{
|
||||
Updaters.Add(updater.UpdaterID, updater);
|
||||
}
|
||||
|
||||
RenderPlugins[contentType].AsyncConvertUrl(updater.UpdaterID, url, extraParams);
|
||||
return updater.UpdaterID;
|
||||
}
|
||||
return LLUUID.Zero;
|
||||
}
|
||||
|
||||
public LLUUID AddDynamicTextureData(LLUUID simID, LLUUID primID, string contentType, string data,
|
||||
string extraParams, int updateTimer)
|
||||
{
|
||||
return AddDynamicTextureData(simID, primID, contentType, data, extraParams, updateTimer, false, 255);
|
||||
}
|
||||
|
||||
public LLUUID AddDynamicTextureData(LLUUID simID, LLUUID primID, string contentType, string data,
|
||||
string extraParams, int updateTimer, bool SetBlending, byte AlphaValue)
|
||||
{
|
||||
if (RenderPlugins.ContainsKey(contentType))
|
||||
{
|
||||
DynamicTextureUpdater updater = new DynamicTextureUpdater();
|
||||
updater.SimUUID = simID;
|
||||
updater.PrimID = primID;
|
||||
updater.ContentType = contentType;
|
||||
updater.BodyData = data;
|
||||
updater.UpdateTimer = updateTimer;
|
||||
updater.UpdaterID = LLUUID.Random();
|
||||
updater.Params = extraParams;
|
||||
updater.BlendWithOldTexture = SetBlending;
|
||||
updater.FrontAlpha = AlphaValue;
|
||||
|
||||
if (!Updaters.ContainsKey(updater.UpdaterID))
|
||||
{
|
||||
Updaters.Add(updater.UpdaterID, updater);
|
||||
}
|
||||
|
||||
RenderPlugins[contentType].AsyncConvertData(updater.UpdaterID, data, extraParams);
|
||||
return updater.UpdaterID;
|
||||
}
|
||||
return LLUUID.Zero;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IRegionModule Members
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID))
|
||||
{
|
||||
RegisteredScenes.Add(scene.RegionInfo.RegionID, scene);
|
||||
scene.RegisterModuleInterface<IDynamicTextureManager>(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "DynamicTextureModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Nested type: DynamicTextureUpdater
|
||||
|
||||
public class DynamicTextureUpdater
|
||||
{
|
||||
public bool BlendWithOldTexture = false;
|
||||
public string BodyData;
|
||||
public string ContentType;
|
||||
public byte FrontAlpha = 255;
|
||||
public LLUUID LastAssetID;
|
||||
public string Params;
|
||||
public LLUUID PrimID;
|
||||
public bool SetNewFrontAlpha = false;
|
||||
public LLUUID SimUUID;
|
||||
public LLUUID UpdaterID;
|
||||
public int UpdateTimer;
|
||||
public string Url;
|
||||
|
||||
public DynamicTextureUpdater()
|
||||
{
|
||||
LastAssetID = LLUUID.Zero;
|
||||
UpdateTimer = 0;
|
||||
BodyData = null;
|
||||
}
|
||||
|
||||
public void DataReceived(byte[] data, Scene scene)
|
||||
{
|
||||
SceneObjectPart part = scene.GetSceneObjectPart(PrimID);
|
||||
byte[] assetData;
|
||||
AssetBase oldAsset = null;
|
||||
if (BlendWithOldTexture)
|
||||
{
|
||||
LLUUID lastTextureID = part.Shape.Textures.DefaultTexture.TextureID;
|
||||
oldAsset = scene.AssetCache.GetAsset(lastTextureID, true);
|
||||
if (oldAsset != null)
|
||||
{
|
||||
assetData = BlendTextures(data, oldAsset.Data, SetNewFrontAlpha, FrontAlpha);
|
||||
}
|
||||
else
|
||||
{
|
||||
assetData = new byte[data.Length];
|
||||
Array.Copy(data, assetData, data.Length);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assetData = new byte[data.Length];
|
||||
Array.Copy(data, assetData, data.Length);
|
||||
}
|
||||
|
||||
//TODO delete the last asset(data), if it was a dynamic texture
|
||||
AssetBase asset = new AssetBase();
|
||||
asset.FullID = LLUUID.Random();
|
||||
asset.Data = assetData;
|
||||
asset.Name = "DynamicImage" + Util.RandomClass.Next(1, 10000);
|
||||
asset.Type = 0;
|
||||
asset.Description = "dynamic image";
|
||||
asset.Local = false;
|
||||
asset.Temporary = true;
|
||||
scene.AssetCache.AddAsset(asset);
|
||||
|
||||
LastAssetID = asset.FullID;
|
||||
|
||||
|
||||
part.Shape.Textures = new LLObject.TextureEntry(asset.FullID);
|
||||
part.ScheduleFullUpdate();
|
||||
}
|
||||
|
||||
private byte[] BlendTextures(byte[] frontImage, byte[] backImage, bool setNewAlpha, byte newAlpha)
|
||||
{
|
||||
Bitmap image1 = new Bitmap(OpenJPEG.DecodeToImage(frontImage));
|
||||
Bitmap image2 = new Bitmap(OpenJPEG.DecodeToImage(backImage));
|
||||
if (setNewAlpha)
|
||||
{
|
||||
SetAlpha(ref image1, newAlpha);
|
||||
}
|
||||
Bitmap joint = MergeBitMaps(image1, image2);
|
||||
|
||||
return OpenJPEG.EncodeFromImage(joint, true);
|
||||
}
|
||||
|
||||
public Bitmap MergeBitMaps(Bitmap front, Bitmap back)
|
||||
{
|
||||
Bitmap joint;
|
||||
Graphics jG;
|
||||
|
||||
joint = new Bitmap(back.Width, back.Height, PixelFormat.Format32bppArgb);
|
||||
jG = Graphics.FromImage(joint);
|
||||
|
||||
jG.DrawImage(back, 0, 0, back.Width, back.Height);
|
||||
jG.DrawImage(front, 0, 0, back.Width, back.Height);
|
||||
|
||||
return joint;
|
||||
}
|
||||
|
||||
private void SetAlpha(ref Bitmap b, byte alpha)
|
||||
{
|
||||
for (int w = 0; w < b.Width; w++)
|
||||
{
|
||||
for (int h = 0; h < b.Height; h++)
|
||||
{
|
||||
b.SetPixel(w, h, Color.FromArgb(alpha, b.GetPixel(w, h)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenJPEGNet;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules.Scripting.DynamicTexture
|
||||
{
|
||||
public class DynamicTextureModule : IRegionModule, IDynamicTextureManager
|
||||
{
|
||||
private Dictionary<LLUUID, Scene> RegisteredScenes = new Dictionary<LLUUID, Scene>();
|
||||
|
||||
private Dictionary<string, IDynamicTextureRender> RenderPlugins =
|
||||
new Dictionary<string, IDynamicTextureRender>();
|
||||
|
||||
private Dictionary<LLUUID, DynamicTextureUpdater> Updaters = new Dictionary<LLUUID, DynamicTextureUpdater>();
|
||||
|
||||
#region IDynamicTextureManager Members
|
||||
|
||||
public void RegisterRender(string handleType, IDynamicTextureRender render)
|
||||
{
|
||||
if (!RenderPlugins.ContainsKey(handleType))
|
||||
{
|
||||
RenderPlugins.Add(handleType, render);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReturnData(LLUUID id, byte[] data)
|
||||
{
|
||||
if (Updaters.ContainsKey(id))
|
||||
{
|
||||
DynamicTextureUpdater updater = Updaters[id];
|
||||
if (RegisteredScenes.ContainsKey(updater.SimUUID))
|
||||
{
|
||||
Scene scene = RegisteredScenes[updater.SimUUID];
|
||||
updater.DataReceived(data, scene);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public LLUUID AddDynamicTextureURL(LLUUID simID, LLUUID primID, string contentType, string url,
|
||||
string extraParams, int updateTimer)
|
||||
{
|
||||
return AddDynamicTextureURL(simID, primID, contentType, url, extraParams, updateTimer, false, 255);
|
||||
}
|
||||
|
||||
public LLUUID AddDynamicTextureURL(LLUUID simID, LLUUID primID, string contentType, string url,
|
||||
string extraParams, int updateTimer, bool SetBlending, byte AlphaValue)
|
||||
{
|
||||
if (RenderPlugins.ContainsKey(contentType))
|
||||
{
|
||||
//Console.WriteLine("dynamic texture being created: " + url + " of type " + contentType);
|
||||
|
||||
DynamicTextureUpdater updater = new DynamicTextureUpdater();
|
||||
updater.SimUUID = simID;
|
||||
updater.PrimID = primID;
|
||||
updater.ContentType = contentType;
|
||||
updater.Url = url;
|
||||
updater.UpdateTimer = updateTimer;
|
||||
updater.UpdaterID = LLUUID.Random();
|
||||
updater.Params = extraParams;
|
||||
updater.BlendWithOldTexture = SetBlending;
|
||||
updater.FrontAlpha = AlphaValue;
|
||||
|
||||
if (!Updaters.ContainsKey(updater.UpdaterID))
|
||||
{
|
||||
Updaters.Add(updater.UpdaterID, updater);
|
||||
}
|
||||
|
||||
RenderPlugins[contentType].AsyncConvertUrl(updater.UpdaterID, url, extraParams);
|
||||
return updater.UpdaterID;
|
||||
}
|
||||
return LLUUID.Zero;
|
||||
}
|
||||
|
||||
public LLUUID AddDynamicTextureData(LLUUID simID, LLUUID primID, string contentType, string data,
|
||||
string extraParams, int updateTimer)
|
||||
{
|
||||
return AddDynamicTextureData(simID, primID, contentType, data, extraParams, updateTimer, false, 255);
|
||||
}
|
||||
|
||||
public LLUUID AddDynamicTextureData(LLUUID simID, LLUUID primID, string contentType, string data,
|
||||
string extraParams, int updateTimer, bool SetBlending, byte AlphaValue)
|
||||
{
|
||||
if (RenderPlugins.ContainsKey(contentType))
|
||||
{
|
||||
DynamicTextureUpdater updater = new DynamicTextureUpdater();
|
||||
updater.SimUUID = simID;
|
||||
updater.PrimID = primID;
|
||||
updater.ContentType = contentType;
|
||||
updater.BodyData = data;
|
||||
updater.UpdateTimer = updateTimer;
|
||||
updater.UpdaterID = LLUUID.Random();
|
||||
updater.Params = extraParams;
|
||||
updater.BlendWithOldTexture = SetBlending;
|
||||
updater.FrontAlpha = AlphaValue;
|
||||
|
||||
if (!Updaters.ContainsKey(updater.UpdaterID))
|
||||
{
|
||||
Updaters.Add(updater.UpdaterID, updater);
|
||||
}
|
||||
|
||||
RenderPlugins[contentType].AsyncConvertData(updater.UpdaterID, data, extraParams);
|
||||
return updater.UpdaterID;
|
||||
}
|
||||
return LLUUID.Zero;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IRegionModule Members
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID))
|
||||
{
|
||||
RegisteredScenes.Add(scene.RegionInfo.RegionID, scene);
|
||||
scene.RegisterModuleInterface<IDynamicTextureManager>(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "DynamicTextureModule"; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Nested type: DynamicTextureUpdater
|
||||
|
||||
public class DynamicTextureUpdater
|
||||
{
|
||||
public bool BlendWithOldTexture = false;
|
||||
public string BodyData;
|
||||
public string ContentType;
|
||||
public byte FrontAlpha = 255;
|
||||
public LLUUID LastAssetID;
|
||||
public string Params;
|
||||
public LLUUID PrimID;
|
||||
public bool SetNewFrontAlpha = false;
|
||||
public LLUUID SimUUID;
|
||||
public LLUUID UpdaterID;
|
||||
public int UpdateTimer;
|
||||
public string Url;
|
||||
|
||||
public DynamicTextureUpdater()
|
||||
{
|
||||
LastAssetID = LLUUID.Zero;
|
||||
UpdateTimer = 0;
|
||||
BodyData = null;
|
||||
}
|
||||
|
||||
public void DataReceived(byte[] data, Scene scene)
|
||||
{
|
||||
SceneObjectPart part = scene.GetSceneObjectPart(PrimID);
|
||||
byte[] assetData;
|
||||
AssetBase oldAsset = null;
|
||||
if (BlendWithOldTexture)
|
||||
{
|
||||
LLUUID lastTextureID = part.Shape.Textures.DefaultTexture.TextureID;
|
||||
oldAsset = scene.AssetCache.GetAsset(lastTextureID, true);
|
||||
if (oldAsset != null)
|
||||
{
|
||||
assetData = BlendTextures(data, oldAsset.Data, SetNewFrontAlpha, FrontAlpha);
|
||||
}
|
||||
else
|
||||
{
|
||||
assetData = new byte[data.Length];
|
||||
Array.Copy(data, assetData, data.Length);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assetData = new byte[data.Length];
|
||||
Array.Copy(data, assetData, data.Length);
|
||||
}
|
||||
|
||||
//TODO delete the last asset(data), if it was a dynamic texture
|
||||
AssetBase asset = new AssetBase();
|
||||
asset.FullID = LLUUID.Random();
|
||||
asset.Data = assetData;
|
||||
asset.Name = "DynamicImage" + Util.RandomClass.Next(1, 10000);
|
||||
asset.Type = 0;
|
||||
asset.Description = "dynamic image";
|
||||
asset.Local = false;
|
||||
asset.Temporary = true;
|
||||
scene.AssetCache.AddAsset(asset);
|
||||
|
||||
LastAssetID = asset.FullID;
|
||||
|
||||
|
||||
part.Shape.Textures = new LLObject.TextureEntry(asset.FullID);
|
||||
part.ScheduleFullUpdate();
|
||||
}
|
||||
|
||||
private byte[] BlendTextures(byte[] frontImage, byte[] backImage, bool setNewAlpha, byte newAlpha)
|
||||
{
|
||||
Bitmap image1 = new Bitmap(OpenJPEG.DecodeToImage(frontImage));
|
||||
Bitmap image2 = new Bitmap(OpenJPEG.DecodeToImage(backImage));
|
||||
if (setNewAlpha)
|
||||
{
|
||||
SetAlpha(ref image1, newAlpha);
|
||||
}
|
||||
Bitmap joint = MergeBitMaps(image1, image2);
|
||||
|
||||
return OpenJPEG.EncodeFromImage(joint, true);
|
||||
}
|
||||
|
||||
public Bitmap MergeBitMaps(Bitmap front, Bitmap back)
|
||||
{
|
||||
Bitmap joint;
|
||||
Graphics jG;
|
||||
|
||||
joint = new Bitmap(back.Width, back.Height, PixelFormat.Format32bppArgb);
|
||||
jG = Graphics.FromImage(joint);
|
||||
|
||||
jG.DrawImage(back, 0, 0, back.Width, back.Height);
|
||||
jG.DrawImage(front, 0, 0, back.Width, back.Height);
|
||||
|
||||
return joint;
|
||||
}
|
||||
|
||||
private void SetAlpha(ref Bitmap b, byte alpha)
|
||||
{
|
||||
for (int w = 0; w < b.Width; w++)
|
||||
{
|
||||
for (int h = 0; h < b.Height; h++)
|
||||
{
|
||||
b.SetPixel(w, h, Color.FromArgb(alpha, b.GetPixel(w, h)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,364 +1,364 @@
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
/*****************************************************
|
||||
*
|
||||
* ScriptsHttpRequests
|
||||
*
|
||||
* Implements the llHttpRequest and http_response
|
||||
* callback.
|
||||
*
|
||||
* Some stuff was already in LSLLongCmdHandler, and then
|
||||
* there was this file with a stub class in it. So,
|
||||
* I am moving some of the objects and functions out of
|
||||
* LSLLongCmdHandler, such as the HttpRequestClass, the
|
||||
* start and stop methods, and setting up pending and
|
||||
* completed queues. These are processed in the
|
||||
* LSLLongCmdHandler polling loop. Similiar to the
|
||||
* XMLRPCModule, since that seems to work.
|
||||
*
|
||||
* //TODO
|
||||
*
|
||||
* This probably needs some throttling mechanism but
|
||||
* its wide open right now. This applies to both
|
||||
* number of requests and data volume.
|
||||
*
|
||||
* Linden puts all kinds of header fields in the requests.
|
||||
* Not doing any of that:
|
||||
* User-Agent
|
||||
* X-SecondLife-Shard
|
||||
* X-SecondLife-Object-Name
|
||||
* X-SecondLife-Object-Key
|
||||
* X-SecondLife-Region
|
||||
* X-SecondLife-Local-Position
|
||||
* X-SecondLife-Local-Velocity
|
||||
* X-SecondLife-Local-Rotation
|
||||
* X-SecondLife-Owner-Name
|
||||
* X-SecondLife-Owner-Key
|
||||
*
|
||||
* HTTPS support
|
||||
*
|
||||
* Configurable timeout?
|
||||
* Configurable max repsonse size?
|
||||
* Configurable
|
||||
*
|
||||
* **************************************************/
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules.Scripting.HttpRequest
|
||||
{
|
||||
public class HttpRequestModule : IRegionModule, IHttpRequests
|
||||
{
|
||||
private object HttpListLock = new object();
|
||||
private int httpTimeout = 30000;
|
||||
private string m_name = "HttpScriptRequests";
|
||||
|
||||
// <request id, HttpRequestClass>
|
||||
private Dictionary<LLUUID, HttpRequestClass> m_pendingRequests;
|
||||
private Scene m_scene;
|
||||
private Queue<HttpRequestClass> rpcQueue = new Queue<HttpRequestClass>();
|
||||
|
||||
public HttpRequestModule()
|
||||
{
|
||||
}
|
||||
|
||||
#region IHttpRequests Members
|
||||
|
||||
public LLUUID MakeHttpRequest(string url, string parameters, string body)
|
||||
{
|
||||
return LLUUID.Zero;
|
||||
}
|
||||
|
||||
public LLUUID StartHttpRequest(uint localID, LLUUID itemID, string url, List<string> parameters, string body)
|
||||
{
|
||||
LLUUID reqID = LLUUID.Random();
|
||||
HttpRequestClass htc = new HttpRequestClass();
|
||||
|
||||
// Partial implementation: support for parameter flags needed
|
||||
// see http://wiki.secondlife.com/wiki/LlHTTPRequest
|
||||
//
|
||||
// Parameters are expected in {key, value, ... , key, value}
|
||||
if (parameters != null)
|
||||
{
|
||||
string[] parms = parameters.ToArray();
|
||||
for (int i = 0; i < parms.Length / 2; i += 2)
|
||||
{
|
||||
switch (Int32.Parse(parms[i]))
|
||||
{
|
||||
case HttpRequestClass.HTTP_METHOD:
|
||||
|
||||
htc.httpMethod = parms[i + 1];
|
||||
break;
|
||||
|
||||
case HttpRequestClass.HTTP_MIMETYPE:
|
||||
|
||||
htc.httpMIMEType = parms[i + 1];
|
||||
break;
|
||||
|
||||
case HttpRequestClass.HTTP_BODY_MAXLENGTH:
|
||||
|
||||
// TODO implement me
|
||||
break;
|
||||
|
||||
case HttpRequestClass.HTTP_VERIFY_CERT:
|
||||
|
||||
// TODO implement me
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
htc.localID = localID;
|
||||
htc.itemID = itemID;
|
||||
htc.url = url;
|
||||
htc.reqID = reqID;
|
||||
htc.httpTimeout = httpTimeout;
|
||||
htc.outbound_body = body;
|
||||
|
||||
lock (HttpListLock)
|
||||
{
|
||||
m_pendingRequests.Add(reqID, htc);
|
||||
}
|
||||
|
||||
htc.process();
|
||||
|
||||
return reqID;
|
||||
}
|
||||
|
||||
public void StopHttpRequest(uint m_localID, LLUUID m_itemID)
|
||||
{
|
||||
if (m_pendingRequests != null)
|
||||
{
|
||||
lock (HttpListLock)
|
||||
{
|
||||
HttpRequestClass tmpReq;
|
||||
if (m_pendingRequests.TryGetValue(m_itemID, out tmpReq))
|
||||
{
|
||||
tmpReq.Stop();
|
||||
m_pendingRequests.Remove(m_itemID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO
|
||||
* Not sure how important ordering is is here - the next first
|
||||
* one completed in the list is returned, based soley on its list
|
||||
* position, not the order in which the request was started or
|
||||
* finsihed. I thought about setting up a queue for this, but
|
||||
* it will need some refactoring and this works 'enough' right now
|
||||
*/
|
||||
|
||||
public HttpRequestClass GetNextCompletedRequest()
|
||||
{
|
||||
lock (HttpListLock)
|
||||
{
|
||||
foreach (LLUUID luid in m_pendingRequests.Keys)
|
||||
{
|
||||
HttpRequestClass tmpReq;
|
||||
|
||||
if (m_pendingRequests.TryGetValue(luid, out tmpReq))
|
||||
{
|
||||
if (tmpReq.finished)
|
||||
{
|
||||
return tmpReq;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void RemoveCompletedRequest(LLUUID id)
|
||||
{
|
||||
lock (HttpListLock)
|
||||
{
|
||||
HttpRequestClass tmpReq;
|
||||
if (m_pendingRequests.TryGetValue(id, out tmpReq))
|
||||
{
|
||||
tmpReq.Stop();
|
||||
tmpReq = null;
|
||||
m_pendingRequests.Remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IRegionModule Members
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_scene = scene;
|
||||
|
||||
m_scene.RegisterModuleInterface<IHttpRequests>(this);
|
||||
|
||||
m_pendingRequests = new Dictionary<LLUUID, HttpRequestClass>();
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return m_name; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class HttpRequestClass
|
||||
{
|
||||
// Constants for parameters
|
||||
public const int HTTP_BODY_MAXLENGTH = 2;
|
||||
public const int HTTP_METHOD = 0;
|
||||
public const int HTTP_MIMETYPE = 1;
|
||||
public const int HTTP_VERIFY_CERT = 3;
|
||||
public bool finished;
|
||||
public int httpBodyMaxLen = 2048; // not implemented
|
||||
|
||||
// Parameter members and default values
|
||||
public string httpMethod = "GET";
|
||||
public string httpMIMEType = "text/plain;charset=utf-8";
|
||||
private Thread httpThread;
|
||||
public int httpTimeout;
|
||||
public bool httpVerifyCert = true; // not implemented
|
||||
|
||||
// Request info
|
||||
public LLUUID itemID;
|
||||
public uint localID;
|
||||
public DateTime next;
|
||||
public string outbound_body;
|
||||
public LLUUID reqID;
|
||||
public HttpWebRequest request;
|
||||
public string response_body;
|
||||
public List<string> response_metadata;
|
||||
public int status;
|
||||
public string url;
|
||||
|
||||
public void process()
|
||||
{
|
||||
httpThread = new Thread(SendRequest);
|
||||
httpThread.Name = "HttpRequestThread";
|
||||
httpThread.Priority = ThreadPriority.BelowNormal;
|
||||
httpThread.IsBackground = true;
|
||||
finished = false;
|
||||
httpThread.Start();
|
||||
ThreadTracker.Add(httpThread);
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: More work on the response codes. Right now
|
||||
* returning 200 for success or 499 for exception
|
||||
*/
|
||||
|
||||
public void SendRequest()
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
byte[] buf = new byte[8192];
|
||||
string tempString = null;
|
||||
int count = 0;
|
||||
|
||||
try
|
||||
{
|
||||
request = (HttpWebRequest)
|
||||
WebRequest.Create(url);
|
||||
request.Method = httpMethod;
|
||||
request.ContentType = httpMIMEType;
|
||||
|
||||
request.Timeout = httpTimeout;
|
||||
// execute the request
|
||||
response = (HttpWebResponse)
|
||||
request.GetResponse();
|
||||
|
||||
Stream resStream = response.GetResponseStream();
|
||||
|
||||
do
|
||||
{
|
||||
// fill the buffer with data
|
||||
count = resStream.Read(buf, 0, buf.Length);
|
||||
|
||||
// make sure we read some data
|
||||
if (count != 0)
|
||||
{
|
||||
// translate from bytes to ASCII text
|
||||
tempString = Encoding.UTF8.GetString(buf, 0, count);
|
||||
|
||||
// continue building the string
|
||||
sb.Append(tempString);
|
||||
}
|
||||
} while (count > 0); // any more data to read?
|
||||
|
||||
response_body = sb.ToString();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
status = 499;
|
||||
response_body = e.Message;
|
||||
finished = true;
|
||||
return;
|
||||
}
|
||||
|
||||
status = 200;
|
||||
finished = true;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
try
|
||||
{
|
||||
httpThread.Abort();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
/*****************************************************
|
||||
*
|
||||
* ScriptsHttpRequests
|
||||
*
|
||||
* Implements the llHttpRequest and http_response
|
||||
* callback.
|
||||
*
|
||||
* Some stuff was already in LSLLongCmdHandler, and then
|
||||
* there was this file with a stub class in it. So,
|
||||
* I am moving some of the objects and functions out of
|
||||
* LSLLongCmdHandler, such as the HttpRequestClass, the
|
||||
* start and stop methods, and setting up pending and
|
||||
* completed queues. These are processed in the
|
||||
* LSLLongCmdHandler polling loop. Similiar to the
|
||||
* XMLRPCModule, since that seems to work.
|
||||
*
|
||||
* //TODO
|
||||
*
|
||||
* This probably needs some throttling mechanism but
|
||||
* its wide open right now. This applies to both
|
||||
* number of requests and data volume.
|
||||
*
|
||||
* Linden puts all kinds of header fields in the requests.
|
||||
* Not doing any of that:
|
||||
* User-Agent
|
||||
* X-SecondLife-Shard
|
||||
* X-SecondLife-Object-Name
|
||||
* X-SecondLife-Object-Key
|
||||
* X-SecondLife-Region
|
||||
* X-SecondLife-Local-Position
|
||||
* X-SecondLife-Local-Velocity
|
||||
* X-SecondLife-Local-Rotation
|
||||
* X-SecondLife-Owner-Name
|
||||
* X-SecondLife-Owner-Key
|
||||
*
|
||||
* HTTPS support
|
||||
*
|
||||
* Configurable timeout?
|
||||
* Configurable max repsonse size?
|
||||
* Configurable
|
||||
*
|
||||
* **************************************************/
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules.Scripting.HttpRequest
|
||||
{
|
||||
public class HttpRequestModule : IRegionModule, IHttpRequests
|
||||
{
|
||||
private object HttpListLock = new object();
|
||||
private int httpTimeout = 30000;
|
||||
private string m_name = "HttpScriptRequests";
|
||||
|
||||
// <request id, HttpRequestClass>
|
||||
private Dictionary<LLUUID, HttpRequestClass> m_pendingRequests;
|
||||
private Scene m_scene;
|
||||
private Queue<HttpRequestClass> rpcQueue = new Queue<HttpRequestClass>();
|
||||
|
||||
public HttpRequestModule()
|
||||
{
|
||||
}
|
||||
|
||||
#region IHttpRequests Members
|
||||
|
||||
public LLUUID MakeHttpRequest(string url, string parameters, string body)
|
||||
{
|
||||
return LLUUID.Zero;
|
||||
}
|
||||
|
||||
public LLUUID StartHttpRequest(uint localID, LLUUID itemID, string url, List<string> parameters, string body)
|
||||
{
|
||||
LLUUID reqID = LLUUID.Random();
|
||||
HttpRequestClass htc = new HttpRequestClass();
|
||||
|
||||
// Partial implementation: support for parameter flags needed
|
||||
// see http://wiki.secondlife.com/wiki/LlHTTPRequest
|
||||
//
|
||||
// Parameters are expected in {key, value, ... , key, value}
|
||||
if (parameters != null)
|
||||
{
|
||||
string[] parms = parameters.ToArray();
|
||||
for (int i = 0; i < parms.Length / 2; i += 2)
|
||||
{
|
||||
switch (Int32.Parse(parms[i]))
|
||||
{
|
||||
case HttpRequestClass.HTTP_METHOD:
|
||||
|
||||
htc.httpMethod = parms[i + 1];
|
||||
break;
|
||||
|
||||
case HttpRequestClass.HTTP_MIMETYPE:
|
||||
|
||||
htc.httpMIMEType = parms[i + 1];
|
||||
break;
|
||||
|
||||
case HttpRequestClass.HTTP_BODY_MAXLENGTH:
|
||||
|
||||
// TODO implement me
|
||||
break;
|
||||
|
||||
case HttpRequestClass.HTTP_VERIFY_CERT:
|
||||
|
||||
// TODO implement me
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
htc.localID = localID;
|
||||
htc.itemID = itemID;
|
||||
htc.url = url;
|
||||
htc.reqID = reqID;
|
||||
htc.httpTimeout = httpTimeout;
|
||||
htc.outbound_body = body;
|
||||
|
||||
lock (HttpListLock)
|
||||
{
|
||||
m_pendingRequests.Add(reqID, htc);
|
||||
}
|
||||
|
||||
htc.process();
|
||||
|
||||
return reqID;
|
||||
}
|
||||
|
||||
public void StopHttpRequest(uint m_localID, LLUUID m_itemID)
|
||||
{
|
||||
if (m_pendingRequests != null)
|
||||
{
|
||||
lock (HttpListLock)
|
||||
{
|
||||
HttpRequestClass tmpReq;
|
||||
if (m_pendingRequests.TryGetValue(m_itemID, out tmpReq))
|
||||
{
|
||||
tmpReq.Stop();
|
||||
m_pendingRequests.Remove(m_itemID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO
|
||||
* Not sure how important ordering is is here - the next first
|
||||
* one completed in the list is returned, based soley on its list
|
||||
* position, not the order in which the request was started or
|
||||
* finsihed. I thought about setting up a queue for this, but
|
||||
* it will need some refactoring and this works 'enough' right now
|
||||
*/
|
||||
|
||||
public HttpRequestClass GetNextCompletedRequest()
|
||||
{
|
||||
lock (HttpListLock)
|
||||
{
|
||||
foreach (LLUUID luid in m_pendingRequests.Keys)
|
||||
{
|
||||
HttpRequestClass tmpReq;
|
||||
|
||||
if (m_pendingRequests.TryGetValue(luid, out tmpReq))
|
||||
{
|
||||
if (tmpReq.finished)
|
||||
{
|
||||
return tmpReq;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void RemoveCompletedRequest(LLUUID id)
|
||||
{
|
||||
lock (HttpListLock)
|
||||
{
|
||||
HttpRequestClass tmpReq;
|
||||
if (m_pendingRequests.TryGetValue(id, out tmpReq))
|
||||
{
|
||||
tmpReq.Stop();
|
||||
tmpReq = null;
|
||||
m_pendingRequests.Remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IRegionModule Members
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
m_scene = scene;
|
||||
|
||||
m_scene.RegisterModuleInterface<IHttpRequests>(this);
|
||||
|
||||
m_pendingRequests = new Dictionary<LLUUID, HttpRequestClass>();
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return m_name; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class HttpRequestClass
|
||||
{
|
||||
// Constants for parameters
|
||||
public const int HTTP_BODY_MAXLENGTH = 2;
|
||||
public const int HTTP_METHOD = 0;
|
||||
public const int HTTP_MIMETYPE = 1;
|
||||
public const int HTTP_VERIFY_CERT = 3;
|
||||
public bool finished;
|
||||
public int httpBodyMaxLen = 2048; // not implemented
|
||||
|
||||
// Parameter members and default values
|
||||
public string httpMethod = "GET";
|
||||
public string httpMIMEType = "text/plain;charset=utf-8";
|
||||
private Thread httpThread;
|
||||
public int httpTimeout;
|
||||
public bool httpVerifyCert = true; // not implemented
|
||||
|
||||
// Request info
|
||||
public LLUUID itemID;
|
||||
public uint localID;
|
||||
public DateTime next;
|
||||
public string outbound_body;
|
||||
public LLUUID reqID;
|
||||
public HttpWebRequest request;
|
||||
public string response_body;
|
||||
public List<string> response_metadata;
|
||||
public int status;
|
||||
public string url;
|
||||
|
||||
public void process()
|
||||
{
|
||||
httpThread = new Thread(SendRequest);
|
||||
httpThread.Name = "HttpRequestThread";
|
||||
httpThread.Priority = ThreadPriority.BelowNormal;
|
||||
httpThread.IsBackground = true;
|
||||
finished = false;
|
||||
httpThread.Start();
|
||||
ThreadTracker.Add(httpThread);
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: More work on the response codes. Right now
|
||||
* returning 200 for success or 499 for exception
|
||||
*/
|
||||
|
||||
public void SendRequest()
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
byte[] buf = new byte[8192];
|
||||
string tempString = null;
|
||||
int count = 0;
|
||||
|
||||
try
|
||||
{
|
||||
request = (HttpWebRequest)
|
||||
WebRequest.Create(url);
|
||||
request.Method = httpMethod;
|
||||
request.ContentType = httpMIMEType;
|
||||
|
||||
request.Timeout = httpTimeout;
|
||||
// execute the request
|
||||
response = (HttpWebResponse)
|
||||
request.GetResponse();
|
||||
|
||||
Stream resStream = response.GetResponseStream();
|
||||
|
||||
do
|
||||
{
|
||||
// fill the buffer with data
|
||||
count = resStream.Read(buf, 0, buf.Length);
|
||||
|
||||
// make sure we read some data
|
||||
if (count != 0)
|
||||
{
|
||||
// translate from bytes to ASCII text
|
||||
tempString = Encoding.UTF8.GetString(buf, 0, count);
|
||||
|
||||
// continue building the string
|
||||
sb.Append(tempString);
|
||||
}
|
||||
} while (count > 0); // any more data to read?
|
||||
|
||||
response_body = sb.ToString();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
status = 499;
|
||||
response_body = e.Message;
|
||||
finished = true;
|
||||
return;
|
||||
}
|
||||
|
||||
status = 200;
|
||||
finished = true;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
try
|
||||
{
|
||||
httpThread.Abort();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,191 +1,191 @@
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenJPEGNet;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules.Scripting.LoadImageURL
|
||||
{
|
||||
public class LoadImageURLModule : IRegionModule, IDynamicTextureRender
|
||||
{
|
||||
private string m_name = "LoadImageURL";
|
||||
private Scene m_scene;
|
||||
private IDynamicTextureManager m_textureManager;
|
||||
|
||||
#region IDynamicTextureRender Members
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
public string GetContentType()
|
||||
{
|
||||
return ("image");
|
||||
}
|
||||
|
||||
public bool SupportsAsynchronous()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public byte[] ConvertUrl(string url, string extraParams)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] ConvertStream(Stream data, string extraParams)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool AsyncConvertUrl(LLUUID id, string url, string extraParams)
|
||||
{
|
||||
MakeHttpRequest(url, id);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AsyncConvertData(LLUUID id, string bodyData, string extraParams)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IRegionModule Members
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
if (m_scene == null)
|
||||
{
|
||||
m_scene = scene;
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
m_textureManager = m_scene.RequestModuleInterface<IDynamicTextureManager>();
|
||||
if (m_textureManager != null)
|
||||
{
|
||||
m_textureManager.RegisterRender(GetContentType(), this);
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return m_name; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void MakeHttpRequest(string url, LLUUID requestID)
|
||||
{
|
||||
WebRequest request = HttpWebRequest.Create(url);
|
||||
RequestState state = new RequestState((HttpWebRequest) request, requestID);
|
||||
IAsyncResult result = request.BeginGetResponse(new AsyncCallback(HttpRequestReturn), state);
|
||||
|
||||
TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1));
|
||||
state.TimeOfRequest = (int) t.TotalSeconds;
|
||||
}
|
||||
|
||||
private void HttpRequestReturn(IAsyncResult result)
|
||||
{
|
||||
RequestState state = (RequestState) result.AsyncState;
|
||||
WebRequest request = (WebRequest) state.Request;
|
||||
HttpWebResponse response = (HttpWebResponse) request.EndGetResponse(result);
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
Bitmap image = new Bitmap(response.GetResponseStream());
|
||||
Size newsize;
|
||||
|
||||
// TODO: make this a bit less hard coded
|
||||
if ((image.Height < 64) && (image.Width < 64))
|
||||
{
|
||||
newsize = new Size(32, 32);
|
||||
}
|
||||
else if ((image.Height < 128) && (image.Width < 128))
|
||||
{
|
||||
newsize = new Size(64, 64);
|
||||
}
|
||||
else if ((image.Height < 256) && (image.Width < 256))
|
||||
{
|
||||
newsize = new Size(128, 128);
|
||||
}
|
||||
else if ((image.Height < 512 && image.Width < 512))
|
||||
{
|
||||
newsize = new Size(256, 256);
|
||||
}
|
||||
else if ((image.Height < 1024 && image.Width < 1024))
|
||||
{
|
||||
newsize = new Size(512, 512);
|
||||
}
|
||||
else
|
||||
{
|
||||
newsize = new Size(1024, 1024);
|
||||
}
|
||||
|
||||
Bitmap resize = new Bitmap(image, newsize);
|
||||
byte[] imageJ2000 = OpenJPEG.EncodeFromImage(resize, true);
|
||||
|
||||
m_textureManager.ReturnData(state.RequestID, imageJ2000);
|
||||
}
|
||||
}
|
||||
|
||||
#region Nested type: RequestState
|
||||
|
||||
public class RequestState
|
||||
{
|
||||
public HttpWebRequest Request = null;
|
||||
public LLUUID RequestID = LLUUID.Zero;
|
||||
public int TimeOfRequest = 0;
|
||||
|
||||
public RequestState(HttpWebRequest request, LLUUID requestID)
|
||||
{
|
||||
Request = request;
|
||||
RequestID = requestID;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenJPEGNet;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules.Scripting.LoadImageURL
|
||||
{
|
||||
public class LoadImageURLModule : IRegionModule, IDynamicTextureRender
|
||||
{
|
||||
private string m_name = "LoadImageURL";
|
||||
private Scene m_scene;
|
||||
private IDynamicTextureManager m_textureManager;
|
||||
|
||||
#region IDynamicTextureRender Members
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
public string GetContentType()
|
||||
{
|
||||
return ("image");
|
||||
}
|
||||
|
||||
public bool SupportsAsynchronous()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public byte[] ConvertUrl(string url, string extraParams)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] ConvertStream(Stream data, string extraParams)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool AsyncConvertUrl(LLUUID id, string url, string extraParams)
|
||||
{
|
||||
MakeHttpRequest(url, id);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AsyncConvertData(LLUUID id, string bodyData, string extraParams)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IRegionModule Members
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
if (m_scene == null)
|
||||
{
|
||||
m_scene = scene;
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
m_textureManager = m_scene.RequestModuleInterface<IDynamicTextureManager>();
|
||||
if (m_textureManager != null)
|
||||
{
|
||||
m_textureManager.RegisterRender(GetContentType(), this);
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return m_name; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void MakeHttpRequest(string url, LLUUID requestID)
|
||||
{
|
||||
WebRequest request = HttpWebRequest.Create(url);
|
||||
RequestState state = new RequestState((HttpWebRequest) request, requestID);
|
||||
IAsyncResult result = request.BeginGetResponse(new AsyncCallback(HttpRequestReturn), state);
|
||||
|
||||
TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1));
|
||||
state.TimeOfRequest = (int) t.TotalSeconds;
|
||||
}
|
||||
|
||||
private void HttpRequestReturn(IAsyncResult result)
|
||||
{
|
||||
RequestState state = (RequestState) result.AsyncState;
|
||||
WebRequest request = (WebRequest) state.Request;
|
||||
HttpWebResponse response = (HttpWebResponse) request.EndGetResponse(result);
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
Bitmap image = new Bitmap(response.GetResponseStream());
|
||||
Size newsize;
|
||||
|
||||
// TODO: make this a bit less hard coded
|
||||
if ((image.Height < 64) && (image.Width < 64))
|
||||
{
|
||||
newsize = new Size(32, 32);
|
||||
}
|
||||
else if ((image.Height < 128) && (image.Width < 128))
|
||||
{
|
||||
newsize = new Size(64, 64);
|
||||
}
|
||||
else if ((image.Height < 256) && (image.Width < 256))
|
||||
{
|
||||
newsize = new Size(128, 128);
|
||||
}
|
||||
else if ((image.Height < 512 && image.Width < 512))
|
||||
{
|
||||
newsize = new Size(256, 256);
|
||||
}
|
||||
else if ((image.Height < 1024 && image.Width < 1024))
|
||||
{
|
||||
newsize = new Size(512, 512);
|
||||
}
|
||||
else
|
||||
{
|
||||
newsize = new Size(1024, 1024);
|
||||
}
|
||||
|
||||
Bitmap resize = new Bitmap(image, newsize);
|
||||
byte[] imageJ2000 = OpenJPEG.EncodeFromImage(resize, true);
|
||||
|
||||
m_textureManager.ReturnData(state.RequestID, imageJ2000);
|
||||
}
|
||||
}
|
||||
|
||||
#region Nested type: RequestState
|
||||
|
||||
public class RequestState
|
||||
{
|
||||
public HttpWebRequest Request = null;
|
||||
public LLUUID RequestID = LLUUID.Zero;
|
||||
public int TimeOfRequest = 0;
|
||||
|
||||
public RequestState(HttpWebRequest request, LLUUID requestID)
|
||||
{
|
||||
Request = request;
|
||||
RequestID = requestID;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,369 +1,369 @@
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenJPEGNet;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
using Image=System.Drawing.Image;
|
||||
|
||||
//using Cairo;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules.Scripting.VectorRender
|
||||
{
|
||||
public class VectorRenderModule : IRegionModule, IDynamicTextureRender
|
||||
{
|
||||
private string m_name = "VectorRenderModule";
|
||||
private Scene m_scene;
|
||||
private IDynamicTextureManager m_textureManager;
|
||||
|
||||
public VectorRenderModule()
|
||||
{
|
||||
}
|
||||
|
||||
#region IDynamicTextureRender Members
|
||||
|
||||
public string GetContentType()
|
||||
{
|
||||
return ("vector");
|
||||
}
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
public bool SupportsAsynchronous()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public byte[] ConvertUrl(string url, string extraParams)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] ConvertStream(Stream data, string extraParams)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool AsyncConvertUrl(LLUUID id, string url, string extraParams)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool AsyncConvertData(LLUUID id, string bodyData, string extraParams)
|
||||
{
|
||||
Draw(bodyData, id, extraParams);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IRegionModule Members
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
if (m_scene == null)
|
||||
{
|
||||
m_scene = scene;
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
m_textureManager = m_scene.RequestModuleInterface<IDynamicTextureManager>();
|
||||
if (m_textureManager != null)
|
||||
{
|
||||
m_textureManager.RegisterRender(GetContentType(), this);
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return m_name; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void Draw(string data, LLUUID id, string extraParams)
|
||||
{
|
||||
// TODO: this is a brutal hack. extraParams should actually be parsed reasonably.
|
||||
int size = 256;
|
||||
try
|
||||
{
|
||||
size = Convert.ToInt32(extraParams);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//Ckrinke: Add a WriteLine to remove the warning about 'e' defined but not used
|
||||
Console.WriteLine("Problem with Draw. Please verify parameters." + e.ToString());
|
||||
}
|
||||
|
||||
if ((size < 128) || (size > 1024))
|
||||
size = 256;
|
||||
|
||||
Bitmap bitmap = new Bitmap(size, size, PixelFormat.Format32bppArgb);
|
||||
|
||||
Graphics graph = Graphics.FromImage(bitmap);
|
||||
|
||||
extraParams = extraParams.ToLower();
|
||||
int alpha = 255;
|
||||
if (extraParams == "setalpha")
|
||||
{
|
||||
alpha = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
graph.FillRectangle(new SolidBrush(Color.White), 0, 0, size, size);
|
||||
}
|
||||
|
||||
for (int w = 0; w < bitmap.Width; w++)
|
||||
{
|
||||
for (int h = 0; h < bitmap.Height; h++)
|
||||
{
|
||||
bitmap.SetPixel(w, h, Color.FromArgb(alpha, bitmap.GetPixel(w, h)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GDIDraw(data, graph);
|
||||
|
||||
byte[] imageJ2000 = OpenJPEG.EncodeFromImage(bitmap, true);
|
||||
m_textureManager.ReturnData(id, imageJ2000);
|
||||
}
|
||||
|
||||
/*
|
||||
private void CairoDraw(string data, System.Drawing.Graphics graph)
|
||||
{
|
||||
using (Win32Surface draw = new Win32Surface(graph.GetHdc()))
|
||||
{
|
||||
Context contex = new Context(draw);
|
||||
|
||||
contex.Antialias = Antialias.None; //fastest method but low quality
|
||||
contex.LineWidth = 7;
|
||||
char[] lineDelimiter = { ';' };
|
||||
char[] partsDelimiter = { ',' };
|
||||
string[] lines = data.Split(lineDelimiter);
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string nextLine = line.Trim();
|
||||
|
||||
if (nextLine.StartsWith("MoveTO"))
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
GetParams(partsDelimiter, ref nextLine, ref x, ref y);
|
||||
contex.MoveTo(x, y);
|
||||
}
|
||||
else if (nextLine.StartsWith("LineTo"))
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
GetParams(partsDelimiter, ref nextLine, ref x, ref y);
|
||||
contex.LineTo(x, y);
|
||||
contex.Stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
graph.ReleaseHdc();
|
||||
}
|
||||
*/
|
||||
|
||||
private void GDIDraw(string data, Graphics graph)
|
||||
{
|
||||
Point startPoint = new Point(0, 0);
|
||||
Point endPoint = new Point(0, 0);
|
||||
Pen drawPen = new Pen(Color.Black, 7);
|
||||
Font myFont = new Font("Times New Roman", 14);
|
||||
SolidBrush myBrush = new SolidBrush(Color.Black);
|
||||
char[] lineDelimiter = {';'};
|
||||
char[] partsDelimiter = {','};
|
||||
string[] lines = data.Split(lineDelimiter);
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string nextLine = line.Trim();
|
||||
//replace with switch, or even better, do some proper parsing
|
||||
if (nextLine.StartsWith("MoveTo"))
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
GetParams(partsDelimiter, ref nextLine, 6, ref x, ref y);
|
||||
startPoint.X = (int) x;
|
||||
startPoint.Y = (int) y;
|
||||
}
|
||||
else if (nextLine.StartsWith("LineTo"))
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
GetParams(partsDelimiter, ref nextLine, 6, ref x, ref y);
|
||||
endPoint.X = (int) x;
|
||||
endPoint.Y = (int) y;
|
||||
graph.DrawLine(drawPen, startPoint, endPoint);
|
||||
startPoint.X = endPoint.X;
|
||||
startPoint.Y = endPoint.Y;
|
||||
}
|
||||
else if (nextLine.StartsWith("Text"))
|
||||
{
|
||||
nextLine = nextLine.Remove(0, 4);
|
||||
nextLine = nextLine.Trim();
|
||||
graph.DrawString(nextLine, myFont, myBrush, startPoint);
|
||||
}
|
||||
else if (nextLine.StartsWith("Image"))
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
GetParams(partsDelimiter, ref nextLine, 5, ref x, ref y);
|
||||
endPoint.X = (int) x;
|
||||
endPoint.Y = (int) y;
|
||||
Image image = ImageHttpRequest(nextLine);
|
||||
graph.DrawImage(image, (float) startPoint.X, (float) startPoint.Y, x, y);
|
||||
startPoint.X += endPoint.X;
|
||||
startPoint.Y += endPoint.Y;
|
||||
}
|
||||
else if (nextLine.StartsWith("Rectangle"))
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
GetParams(partsDelimiter, ref nextLine, 9, ref x, ref y);
|
||||
endPoint.X = (int) x;
|
||||
endPoint.Y = (int) y;
|
||||
graph.DrawRectangle(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
|
||||
startPoint.X += endPoint.X;
|
||||
startPoint.Y += endPoint.Y;
|
||||
}
|
||||
else if (nextLine.StartsWith("FillRectangle"))
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
GetParams(partsDelimiter, ref nextLine, 13, ref x, ref y);
|
||||
endPoint.X = (int) x;
|
||||
endPoint.Y = (int) y;
|
||||
graph.FillRectangle(myBrush, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
|
||||
startPoint.X += endPoint.X;
|
||||
startPoint.Y += endPoint.Y;
|
||||
}
|
||||
else if (nextLine.StartsWith("Ellipse"))
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
GetParams(partsDelimiter, ref nextLine, 7, ref x, ref y);
|
||||
endPoint.X = (int) x;
|
||||
endPoint.Y = (int) y;
|
||||
graph.DrawEllipse(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
|
||||
startPoint.X += endPoint.X;
|
||||
startPoint.Y += endPoint.Y;
|
||||
}
|
||||
else if (nextLine.StartsWith("FontSize"))
|
||||
{
|
||||
nextLine = nextLine.Remove(0, 8);
|
||||
nextLine = nextLine.Trim();
|
||||
float size = Convert.ToSingle(nextLine, CultureInfo.InvariantCulture);
|
||||
myFont = new Font("Times New Roman", size);
|
||||
}
|
||||
else if (nextLine.StartsWith("PenSize"))
|
||||
{
|
||||
nextLine = nextLine.Remove(0, 8);
|
||||
nextLine = nextLine.Trim();
|
||||
float size = Convert.ToSingle(nextLine, CultureInfo.InvariantCulture);
|
||||
drawPen.Width = size;
|
||||
}
|
||||
else if (nextLine.StartsWith("PenColour"))
|
||||
{
|
||||
nextLine = nextLine.Remove(0, 9);
|
||||
nextLine = nextLine.Trim();
|
||||
|
||||
Color newColour = Color.FromName(nextLine);
|
||||
|
||||
myBrush.Color = newColour;
|
||||
drawPen.Color = newColour;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void GetParams(char[] partsDelimiter, ref string line, int startLength, ref float x, ref float y)
|
||||
{
|
||||
line = line.Remove(0, startLength);
|
||||
string[] parts = line.Split(partsDelimiter);
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
string xVal = parts[0].Trim();
|
||||
string yVal = parts[1].Trim();
|
||||
x = Convert.ToSingle(xVal, CultureInfo.InvariantCulture);
|
||||
y = Convert.ToSingle(yVal, CultureInfo.InvariantCulture);
|
||||
}
|
||||
else if (parts.Length > 2)
|
||||
{
|
||||
string xVal = parts[0].Trim();
|
||||
string yVal = parts[1].Trim();
|
||||
x = Convert.ToSingle(xVal, CultureInfo.InvariantCulture);
|
||||
y = Convert.ToSingle(yVal, CultureInfo.InvariantCulture);
|
||||
|
||||
line = "";
|
||||
for (int i = 2; i < parts.Length; i++)
|
||||
{
|
||||
line = line + parts[i].Trim();
|
||||
line = line + " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Bitmap ImageHttpRequest(string url)
|
||||
{
|
||||
WebRequest request = HttpWebRequest.Create(url);
|
||||
//Ckrinke: Comment out for now as 'str' is unused. Bring it back into play later when it is used.
|
||||
//Ckrinke Stream str = null;
|
||||
HttpWebResponse response = (HttpWebResponse) (request).GetResponse();
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
Bitmap image = new Bitmap(response.GetResponseStream());
|
||||
return image;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using libsecondlife;
|
||||
using Nini.Config;
|
||||
using OpenJPEGNet;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
using Image=System.Drawing.Image;
|
||||
|
||||
//using Cairo;
|
||||
|
||||
namespace OpenSim.Region.Environment.Modules.Scripting.VectorRender
|
||||
{
|
||||
public class VectorRenderModule : IRegionModule, IDynamicTextureRender
|
||||
{
|
||||
private string m_name = "VectorRenderModule";
|
||||
private Scene m_scene;
|
||||
private IDynamicTextureManager m_textureManager;
|
||||
|
||||
public VectorRenderModule()
|
||||
{
|
||||
}
|
||||
|
||||
#region IDynamicTextureRender Members
|
||||
|
||||
public string GetContentType()
|
||||
{
|
||||
return ("vector");
|
||||
}
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
public bool SupportsAsynchronous()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public byte[] ConvertUrl(string url, string extraParams)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] ConvertStream(Stream data, string extraParams)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool AsyncConvertUrl(LLUUID id, string url, string extraParams)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool AsyncConvertData(LLUUID id, string bodyData, string extraParams)
|
||||
{
|
||||
Draw(bodyData, id, extraParams);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IRegionModule Members
|
||||
|
||||
public void Initialise(Scene scene, IConfigSource config)
|
||||
{
|
||||
if (m_scene == null)
|
||||
{
|
||||
m_scene = scene;
|
||||
}
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
{
|
||||
m_textureManager = m_scene.RequestModuleInterface<IDynamicTextureManager>();
|
||||
if (m_textureManager != null)
|
||||
{
|
||||
m_textureManager.RegisterRender(GetContentType(), this);
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return m_name; }
|
||||
}
|
||||
|
||||
public bool IsSharedModule
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void Draw(string data, LLUUID id, string extraParams)
|
||||
{
|
||||
// TODO: this is a brutal hack. extraParams should actually be parsed reasonably.
|
||||
int size = 256;
|
||||
try
|
||||
{
|
||||
size = Convert.ToInt32(extraParams);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//Ckrinke: Add a WriteLine to remove the warning about 'e' defined but not used
|
||||
Console.WriteLine("Problem with Draw. Please verify parameters." + e.ToString());
|
||||
}
|
||||
|
||||
if ((size < 128) || (size > 1024))
|
||||
size = 256;
|
||||
|
||||
Bitmap bitmap = new Bitmap(size, size, PixelFormat.Format32bppArgb);
|
||||
|
||||
Graphics graph = Graphics.FromImage(bitmap);
|
||||
|
||||
extraParams = extraParams.ToLower();
|
||||
int alpha = 255;
|
||||
if (extraParams == "setalpha")
|
||||
{
|
||||
alpha = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
graph.FillRectangle(new SolidBrush(Color.White), 0, 0, size, size);
|
||||
}
|
||||
|
||||
for (int w = 0; w < bitmap.Width; w++)
|
||||
{
|
||||
for (int h = 0; h < bitmap.Height; h++)
|
||||
{
|
||||
bitmap.SetPixel(w, h, Color.FromArgb(alpha, bitmap.GetPixel(w, h)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GDIDraw(data, graph);
|
||||
|
||||
byte[] imageJ2000 = OpenJPEG.EncodeFromImage(bitmap, true);
|
||||
m_textureManager.ReturnData(id, imageJ2000);
|
||||
}
|
||||
|
||||
/*
|
||||
private void CairoDraw(string data, System.Drawing.Graphics graph)
|
||||
{
|
||||
using (Win32Surface draw = new Win32Surface(graph.GetHdc()))
|
||||
{
|
||||
Context contex = new Context(draw);
|
||||
|
||||
contex.Antialias = Antialias.None; //fastest method but low quality
|
||||
contex.LineWidth = 7;
|
||||
char[] lineDelimiter = { ';' };
|
||||
char[] partsDelimiter = { ',' };
|
||||
string[] lines = data.Split(lineDelimiter);
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string nextLine = line.Trim();
|
||||
|
||||
if (nextLine.StartsWith("MoveTO"))
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
GetParams(partsDelimiter, ref nextLine, ref x, ref y);
|
||||
contex.MoveTo(x, y);
|
||||
}
|
||||
else if (nextLine.StartsWith("LineTo"))
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
GetParams(partsDelimiter, ref nextLine, ref x, ref y);
|
||||
contex.LineTo(x, y);
|
||||
contex.Stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
graph.ReleaseHdc();
|
||||
}
|
||||
*/
|
||||
|
||||
private void GDIDraw(string data, Graphics graph)
|
||||
{
|
||||
Point startPoint = new Point(0, 0);
|
||||
Point endPoint = new Point(0, 0);
|
||||
Pen drawPen = new Pen(Color.Black, 7);
|
||||
Font myFont = new Font("Times New Roman", 14);
|
||||
SolidBrush myBrush = new SolidBrush(Color.Black);
|
||||
char[] lineDelimiter = {';'};
|
||||
char[] partsDelimiter = {','};
|
||||
string[] lines = data.Split(lineDelimiter);
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string nextLine = line.Trim();
|
||||
//replace with switch, or even better, do some proper parsing
|
||||
if (nextLine.StartsWith("MoveTo"))
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
GetParams(partsDelimiter, ref nextLine, 6, ref x, ref y);
|
||||
startPoint.X = (int) x;
|
||||
startPoint.Y = (int) y;
|
||||
}
|
||||
else if (nextLine.StartsWith("LineTo"))
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
GetParams(partsDelimiter, ref nextLine, 6, ref x, ref y);
|
||||
endPoint.X = (int) x;
|
||||
endPoint.Y = (int) y;
|
||||
graph.DrawLine(drawPen, startPoint, endPoint);
|
||||
startPoint.X = endPoint.X;
|
||||
startPoint.Y = endPoint.Y;
|
||||
}
|
||||
else if (nextLine.StartsWith("Text"))
|
||||
{
|
||||
nextLine = nextLine.Remove(0, 4);
|
||||
nextLine = nextLine.Trim();
|
||||
graph.DrawString(nextLine, myFont, myBrush, startPoint);
|
||||
}
|
||||
else if (nextLine.StartsWith("Image"))
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
GetParams(partsDelimiter, ref nextLine, 5, ref x, ref y);
|
||||
endPoint.X = (int) x;
|
||||
endPoint.Y = (int) y;
|
||||
Image image = ImageHttpRequest(nextLine);
|
||||
graph.DrawImage(image, (float) startPoint.X, (float) startPoint.Y, x, y);
|
||||
startPoint.X += endPoint.X;
|
||||
startPoint.Y += endPoint.Y;
|
||||
}
|
||||
else if (nextLine.StartsWith("Rectangle"))
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
GetParams(partsDelimiter, ref nextLine, 9, ref x, ref y);
|
||||
endPoint.X = (int) x;
|
||||
endPoint.Y = (int) y;
|
||||
graph.DrawRectangle(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
|
||||
startPoint.X += endPoint.X;
|
||||
startPoint.Y += endPoint.Y;
|
||||
}
|
||||
else if (nextLine.StartsWith("FillRectangle"))
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
GetParams(partsDelimiter, ref nextLine, 13, ref x, ref y);
|
||||
endPoint.X = (int) x;
|
||||
endPoint.Y = (int) y;
|
||||
graph.FillRectangle(myBrush, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
|
||||
startPoint.X += endPoint.X;
|
||||
startPoint.Y += endPoint.Y;
|
||||
}
|
||||
else if (nextLine.StartsWith("Ellipse"))
|
||||
{
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
GetParams(partsDelimiter, ref nextLine, 7, ref x, ref y);
|
||||
endPoint.X = (int) x;
|
||||
endPoint.Y = (int) y;
|
||||
graph.DrawEllipse(drawPen, startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
|
||||
startPoint.X += endPoint.X;
|
||||
startPoint.Y += endPoint.Y;
|
||||
}
|
||||
else if (nextLine.StartsWith("FontSize"))
|
||||
{
|
||||
nextLine = nextLine.Remove(0, 8);
|
||||
nextLine = nextLine.Trim();
|
||||
float size = Convert.ToSingle(nextLine, CultureInfo.InvariantCulture);
|
||||
myFont = new Font("Times New Roman", size);
|
||||
}
|
||||
else if (nextLine.StartsWith("PenSize"))
|
||||
{
|
||||
nextLine = nextLine.Remove(0, 8);
|
||||
nextLine = nextLine.Trim();
|
||||
float size = Convert.ToSingle(nextLine, CultureInfo.InvariantCulture);
|
||||
drawPen.Width = size;
|
||||
}
|
||||
else if (nextLine.StartsWith("PenColour"))
|
||||
{
|
||||
nextLine = nextLine.Remove(0, 9);
|
||||
nextLine = nextLine.Trim();
|
||||
|
||||
Color newColour = Color.FromName(nextLine);
|
||||
|
||||
myBrush.Color = newColour;
|
||||
drawPen.Color = newColour;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void GetParams(char[] partsDelimiter, ref string line, int startLength, ref float x, ref float y)
|
||||
{
|
||||
line = line.Remove(0, startLength);
|
||||
string[] parts = line.Split(partsDelimiter);
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
string xVal = parts[0].Trim();
|
||||
string yVal = parts[1].Trim();
|
||||
x = Convert.ToSingle(xVal, CultureInfo.InvariantCulture);
|
||||
y = Convert.ToSingle(yVal, CultureInfo.InvariantCulture);
|
||||
}
|
||||
else if (parts.Length > 2)
|
||||
{
|
||||
string xVal = parts[0].Trim();
|
||||
string yVal = parts[1].Trim();
|
||||
x = Convert.ToSingle(xVal, CultureInfo.InvariantCulture);
|
||||
y = Convert.ToSingle(yVal, CultureInfo.InvariantCulture);
|
||||
|
||||
line = "";
|
||||
for (int i = 2; i < parts.Length; i++)
|
||||
{
|
||||
line = line + parts[i].Trim();
|
||||
line = line + " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Bitmap ImageHttpRequest(string url)
|
||||
{
|
||||
WebRequest request = HttpWebRequest.Create(url);
|
||||
//Ckrinke: Comment out for now as 'str' is unused. Bring it back into play later when it is used.
|
||||
//Ckrinke Stream str = null;
|
||||
HttpWebResponse response = (HttpWebResponse) (request).GetResponse();
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
Bitmap image = new Bitmap(response.GetResponseStream());
|
||||
return image;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user