diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/Agent/TextureSender/J2KDecoderCommandModule.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Agent/TextureSender/J2KDecoderCommandModule.cs | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/Agent/TextureSender/J2KDecoderCommandModule.cs b/OpenSim/Region/OptionalModules/Agent/TextureSender/J2KDecoderCommandModule.cs new file mode 100644 index 0000000..b224132 --- /dev/null +++ b/OpenSim/Region/OptionalModules/Agent/TextureSender/J2KDecoderCommandModule.cs | |||
@@ -0,0 +1,145 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using log4net; | ||
34 | using Mono.Addins; | ||
35 | using Nini.Config; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Console; | ||
39 | using OpenSim.Region.Framework.Interfaces; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | |||
42 | namespace OpenSim.Region.OptionalModules.Agent.TextureSender | ||
43 | { | ||
44 | /// <summary> | ||
45 | /// Commands for the J2KDecoder module. For debugging purposes. | ||
46 | /// </summary> | ||
47 | /// <remarks> | ||
48 | /// Placed here so that they can be removed if not required and to keep the J2KDecoder module itself simple. | ||
49 | /// </remarks> | ||
50 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "J2KDecoderCommandModule")] | ||
51 | public class J2KDecoderCommandModule : ISharedRegionModule | ||
52 | { | ||
53 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
54 | |||
55 | private Scene m_scene; | ||
56 | |||
57 | public string Name { get { return "Asset Information Module"; } } | ||
58 | |||
59 | public Type ReplaceableInterface { get { return null; } } | ||
60 | |||
61 | public void Initialise(IConfigSource source) | ||
62 | { | ||
63 | // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: INITIALIZED MODULE"); | ||
64 | } | ||
65 | |||
66 | public void PostInitialise() | ||
67 | { | ||
68 | // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: POST INITIALIZED MODULE"); | ||
69 | } | ||
70 | |||
71 | public void Close() | ||
72 | { | ||
73 | // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: CLOSED MODULE"); | ||
74 | } | ||
75 | |||
76 | public void AddRegion(Scene scene) | ||
77 | { | ||
78 | // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName); | ||
79 | } | ||
80 | |||
81 | public void RemoveRegion(Scene scene) | ||
82 | { | ||
83 | // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName); | ||
84 | } | ||
85 | |||
86 | public void RegionLoaded(Scene scene) | ||
87 | { | ||
88 | // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName); | ||
89 | |||
90 | if (m_scene == null) | ||
91 | m_scene = scene; | ||
92 | |||
93 | MainConsole.Instance.Commands.AddCommand( | ||
94 | "j2k", | ||
95 | false, | ||
96 | "j2k decode", | ||
97 | "j2k decode <ID>", | ||
98 | "Do JPEG2000 decoding of an asset.", | ||
99 | "This is for debugging purposes. The asset id given must contain JPEG2000 data.", | ||
100 | HandleDecode); | ||
101 | } | ||
102 | |||
103 | void HandleDecode(string module, string[] args) | ||
104 | { | ||
105 | if (args.Length < 3) | ||
106 | { | ||
107 | MainConsole.Instance.Output("Usage is j2k decode <ID>"); | ||
108 | return; | ||
109 | } | ||
110 | |||
111 | UUID assetId; | ||
112 | string rawAssetId = args[2]; | ||
113 | |||
114 | if (!UUID.TryParse(rawAssetId, out assetId)) | ||
115 | { | ||
116 | MainConsole.Instance.OutputFormat("ERROR: {0} is not a valid ID format", rawAssetId); | ||
117 | return; | ||
118 | } | ||
119 | |||
120 | AssetBase asset = m_scene.AssetService.Get(assetId.ToString()); | ||
121 | if (asset == null) | ||
122 | { | ||
123 | MainConsole.Instance.OutputFormat("ERROR: No asset found with ID {0}", assetId); | ||
124 | return; | ||
125 | } | ||
126 | |||
127 | if (asset.Type != (sbyte)AssetType.Texture) | ||
128 | { | ||
129 | MainConsole.Instance.OutputFormat("ERROR: Asset {0} is not a texture type", assetId); | ||
130 | return; | ||
131 | } | ||
132 | |||
133 | IJ2KDecoder decoder = m_scene.RequestModuleInterface<IJ2KDecoder>(); | ||
134 | if (decoder == null) | ||
135 | { | ||
136 | MainConsole.Instance.OutputFormat("ERROR: No IJ2KDecoder module available"); | ||
137 | return; | ||
138 | } | ||
139 | |||
140 | if (decoder.Decode(assetId, asset.Data)) | ||
141 | MainConsole.Instance.OutputFormat("Successfully decoded asset {0}", assetId); | ||
142 | else | ||
143 | MainConsole.Instance.OutputFormat("Decode of asset {0} failed", assetId); } | ||
144 | } | ||
145 | } \ No newline at end of file | ||