* Added code to support either CSJ2K or OpenJPEG texture decoding. Currently hardcoded to CSJ2K (so no functional change) but this could easily be switched to a config option

slimupdates
John Hurliman 2010-03-07 17:03:56 -08:00
parent d71ed7081b
commit fa38cf3ee8
1 changed files with 33 additions and 20 deletions

View File

@ -144,41 +144,54 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender
/// <param name="j2kData">JPEG2000 data</param> /// <param name="j2kData">JPEG2000 data</param>
private void DoJ2KDecode(UUID assetID, byte[] j2kData) private void DoJ2KDecode(UUID assetID, byte[] j2kData)
{ {
// int DecodeTime = 0; bool USE_CSJ2K = true;
// DecodeTime = Environment.TickCount;
//int DecodeTime = 0;
//DecodeTime = Environment.TickCount;
OpenJPEG.J2KLayerInfo[] layers; OpenJPEG.J2KLayerInfo[] layers;
if (!TryLoadCacheForAsset(assetID, out layers)) if (!TryLoadCacheForAsset(assetID, out layers))
{ {
try if (USE_CSJ2K)
{ {
List<int> layerStarts = CSJ2K.J2kImage.GetLayerBoundaries(new MemoryStream(j2kData)); try
if (layerStarts != null && layerStarts.Count > 0)
{ {
layers = new OpenJPEG.J2KLayerInfo[layerStarts.Count]; List<int> layerStarts = CSJ2K.J2kImage.GetLayerBoundaries(new MemoryStream(j2kData));
for (int i = 0; i < layerStarts.Count; i++) if (layerStarts != null && layerStarts.Count > 0)
{ {
OpenJPEG.J2KLayerInfo layer = new OpenJPEG.J2KLayerInfo(); layers = new OpenJPEG.J2KLayerInfo[layerStarts.Count];
if (i == 0) for (int i = 0; i < layerStarts.Count; i++)
layer.Start = 0; {
else OpenJPEG.J2KLayerInfo layer = new OpenJPEG.J2KLayerInfo();
layer.Start = layerStarts[i];
if (i == layerStarts.Count - 1) if (i == 0)
layer.End = j2kData.Length; layer.Start = 0;
else else
layer.End = layerStarts[i + 1] - 1; layer.Start = layerStarts[i];
layers[i] = layer; if (i == layerStarts.Count - 1)
layer.End = j2kData.Length;
else
layer.End = layerStarts[i + 1] - 1;
layers[i] = layer;
}
} }
} }
catch (Exception ex)
{
m_log.Warn("[J2KDecoderModule]: CSJ2K threw an exception decoding texture " + assetID + ": " + ex.Message);
}
} }
catch (Exception ex) else
{ {
m_log.Warn("[J2KDecoderModule]: CSJ2K threw an exception decoding texture " + assetID + ": " + ex.Message); int components;
if (!OpenJPEG.DecodeLayerBoundaries(j2kData, out layers, out components))
{
m_log.Warn("[J2KDecoderModule]: OpenJPEG failed to decode texture " + assetID);
}
} }
if (layers == null || layers.Length == 0) if (layers == null || layers.Length == 0)