diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs b/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs index 7dd9087..a1a2501 100644 --- a/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs +++ b/OpenSim/Region/CoreModules/Agent/TextureSender/J2KDecoderModule.cs | |||
@@ -103,6 +103,10 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender | |||
103 | // If it's cached, return the cached results | 103 | // If it's cached, return the cached results |
104 | if (m_decodedCache.TryGetValue(assetID, out result)) | 104 | if (m_decodedCache.TryGetValue(assetID, out result)) |
105 | { | 105 | { |
106 | // m_log.DebugFormat( | ||
107 | // "[J2KDecoderModule]: Returning existing cached {0} layers j2k decode for {1}", | ||
108 | // result.Length, assetID); | ||
109 | |||
106 | callback(assetID, result); | 110 | callback(assetID, result); |
107 | } | 111 | } |
108 | else | 112 | else |
@@ -129,18 +133,20 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender | |||
129 | 133 | ||
130 | // Do Decode! | 134 | // Do Decode! |
131 | if (decode) | 135 | if (decode) |
132 | DoJ2KDecode(assetID, j2kData); | 136 | Decode(assetID, j2kData); |
133 | } | 137 | } |
134 | } | 138 | } |
135 | 139 | ||
136 | /// <summary> | 140 | public bool Decode(UUID assetID, byte[] j2kData) |
137 | /// Provides a synchronous decode so that caller can be assured that this executes before the next line | ||
138 | /// </summary> | ||
139 | /// <param name="assetID"></param> | ||
140 | /// <param name="j2kData"></param> | ||
141 | public void Decode(UUID assetID, byte[] j2kData) | ||
142 | { | 141 | { |
143 | DoJ2KDecode(assetID, j2kData); | 142 | OpenJPEG.J2KLayerInfo[] layers; |
143 | int components; | ||
144 | return Decode(assetID, j2kData, out layers, out components); | ||
145 | } | ||
146 | |||
147 | public bool Decode(UUID assetID, byte[] j2kData, out OpenJPEG.J2KLayerInfo[] layers, out int components) | ||
148 | { | ||
149 | return DoJ2KDecode(assetID, j2kData, out layers, out components); | ||
144 | } | 150 | } |
145 | 151 | ||
146 | #endregion IJ2KDecoder | 152 | #endregion IJ2KDecoder |
@@ -150,14 +156,21 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender | |||
150 | /// </summary> | 156 | /// </summary> |
151 | /// <param name="assetID">UUID of Asset</param> | 157 | /// <param name="assetID">UUID of Asset</param> |
152 | /// <param name="j2kData">JPEG2000 data</param> | 158 | /// <param name="j2kData">JPEG2000 data</param> |
153 | private void DoJ2KDecode(UUID assetID, byte[] j2kData) | 159 | /// <param name="layers">layer data</param> |
160 | /// <param name="components">number of components</param> | ||
161 | /// <returns>true if decode was successful. false otherwise.</returns> | ||
162 | private bool DoJ2KDecode(UUID assetID, byte[] j2kData, out OpenJPEG.J2KLayerInfo[] layers, out int components) | ||
154 | { | 163 | { |
155 | // m_log.DebugFormat( | 164 | // m_log.DebugFormat( |
156 | // "[J2KDecoderModule]: Doing J2K decoding of {0} bytes for asset {1}", j2kData.Length, assetID); | 165 | // "[J2KDecoderModule]: Doing J2K decoding of {0} bytes for asset {1}", j2kData.Length, assetID); |
157 | 166 | ||
167 | bool decodedSuccessfully = true; | ||
168 | |||
158 | //int DecodeTime = 0; | 169 | //int DecodeTime = 0; |
159 | //DecodeTime = Environment.TickCount; | 170 | //DecodeTime = Environment.TickCount; |
160 | OpenJPEG.J2KLayerInfo[] layers; | 171 | |
172 | // We don't get this from CSJ2K. Is it relevant? | ||
173 | components = 0; | ||
161 | 174 | ||
162 | if (!TryLoadCacheForAsset(assetID, out layers)) | 175 | if (!TryLoadCacheForAsset(assetID, out layers)) |
163 | { | 176 | { |
@@ -192,14 +205,15 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender | |||
192 | catch (Exception ex) | 205 | catch (Exception ex) |
193 | { | 206 | { |
194 | m_log.Warn("[J2KDecoderModule]: CSJ2K threw an exception decoding texture " + assetID + ": " + ex.Message); | 207 | m_log.Warn("[J2KDecoderModule]: CSJ2K threw an exception decoding texture " + assetID + ": " + ex.Message); |
208 | decodedSuccessfully = false; | ||
195 | } | 209 | } |
196 | } | 210 | } |
197 | else | 211 | else |
198 | { | 212 | { |
199 | int components; | ||
200 | if (!OpenJPEG.DecodeLayerBoundaries(j2kData, out layers, out components)) | 213 | if (!OpenJPEG.DecodeLayerBoundaries(j2kData, out layers, out components)) |
201 | { | 214 | { |
202 | m_log.Warn("[J2KDecoderModule]: OpenJPEG failed to decode texture " + assetID); | 215 | m_log.Warn("[J2KDecoderModule]: OpenJPEG failed to decode texture " + assetID); |
216 | decodedSuccessfully = false; | ||
203 | } | 217 | } |
204 | } | 218 | } |
205 | 219 | ||
@@ -208,6 +222,7 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender | |||
208 | m_log.Warn("[J2KDecoderModule]: Failed to decode layer data for texture " + assetID + ", guessing sane defaults"); | 222 | m_log.Warn("[J2KDecoderModule]: Failed to decode layer data for texture " + assetID + ", guessing sane defaults"); |
209 | // Layer decoding completely failed. Guess at sane defaults for the layer boundaries | 223 | // Layer decoding completely failed. Guess at sane defaults for the layer boundaries |
210 | layers = CreateDefaultLayers(j2kData.Length); | 224 | layers = CreateDefaultLayers(j2kData.Length); |
225 | decodedSuccessfully = false; | ||
211 | } | 226 | } |
212 | 227 | ||
213 | // Cache Decoded layers | 228 | // Cache Decoded layers |
@@ -227,6 +242,8 @@ namespace OpenSim.Region.CoreModules.Agent.TextureSender | |||
227 | m_notifyList.Remove(assetID); | 242 | m_notifyList.Remove(assetID); |
228 | } | 243 | } |
229 | } | 244 | } |
245 | |||
246 | return decodedSuccessfully; | ||
230 | } | 247 | } |
231 | 248 | ||
232 | private OpenJPEG.J2KLayerInfo[] CreateDefaultLayers(int j2kLength) | 249 | private OpenJPEG.J2KLayerInfo[] CreateDefaultLayers(int j2kLength) |