1
0

J2KDecoderCommandModule.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Reflection;
  31. using System.Text;
  32. using log4net;
  33. using Mono.Addins;
  34. using Nini.Config;
  35. using OpenMetaverse;
  36. using OpenMetaverse.Imaging;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Console;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes;
  41. namespace OpenSim.Region.OptionalModules.Agent.TextureSender
  42. {
  43. /// <summary>
  44. /// Commands for the J2KDecoder module. For debugging purposes.
  45. /// </summary>
  46. /// <remarks>
  47. /// Placed here so that they can be removed if not required and to keep the J2KDecoder module itself simple.
  48. /// </remarks>
  49. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "J2KDecoderCommandModule")]
  50. public class J2KDecoderCommandModule : ISharedRegionModule
  51. {
  52. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  53. private Scene m_scene;
  54. public string Name { get { return "Asset Information Module"; } }
  55. public Type ReplaceableInterface { get { return null; } }
  56. public void Initialise(IConfigSource source)
  57. {
  58. // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: INITIALIZED MODULE");
  59. }
  60. public void PostInitialise()
  61. {
  62. // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: POST INITIALIZED MODULE");
  63. }
  64. public void Close()
  65. {
  66. // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: CLOSED MODULE");
  67. }
  68. public void AddRegion(Scene scene)
  69. {
  70. // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
  71. }
  72. public void RemoveRegion(Scene scene)
  73. {
  74. // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
  75. }
  76. public void RegionLoaded(Scene scene)
  77. {
  78. // m_log.DebugFormat("[J2K DECODER COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
  79. if (m_scene == null)
  80. m_scene = scene;
  81. MainConsole.Instance.Commands.AddCommand(
  82. "Assets",
  83. false,
  84. "j2k decode",
  85. "j2k decode <ID>",
  86. "Do JPEG2000 decoding of an asset.",
  87. "This is for debugging purposes. The asset id given must contain JPEG2000 data.",
  88. HandleDecode);
  89. }
  90. void HandleDecode(string module, string[] args)
  91. {
  92. if (args.Length < 3)
  93. {
  94. MainConsole.Instance.Output("Usage is j2k decode <ID>");
  95. return;
  96. }
  97. UUID assetId;
  98. string rawAssetId = args[2];
  99. if (!UUID.TryParse(rawAssetId, out assetId))
  100. {
  101. MainConsole.Instance.Output("ERROR: {0} is not a valid ID format", rawAssetId);
  102. return;
  103. }
  104. AssetBase asset = m_scene.AssetService.Get(assetId.ToString());
  105. if (asset == null)
  106. {
  107. MainConsole.Instance.Output("ERROR: No asset found with ID {0}", assetId);
  108. return;
  109. }
  110. if (asset.Type != (sbyte)AssetType.Texture)
  111. {
  112. MainConsole.Instance.Output("ERROR: Asset {0} is not a texture type", assetId);
  113. return;
  114. }
  115. IJ2KDecoder decoder = m_scene.RequestModuleInterface<IJ2KDecoder>();
  116. if (decoder == null)
  117. {
  118. MainConsole.Instance.Output("ERROR: No IJ2KDecoder module available");
  119. return;
  120. }
  121. OpenJPEG.J2KLayerInfo[] layers;
  122. int components;
  123. if (decoder.Decode(assetId, asset.Data, out layers, out components))
  124. {
  125. MainConsole.Instance.Output(
  126. "Successfully decoded asset {0} with {1} layers and {2} components",
  127. assetId, layers.Length, components);
  128. }
  129. else
  130. {
  131. MainConsole.Instance.Output("Decode of asset {0} failed", assetId);
  132. }
  133. }
  134. }
  135. }