Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ private bool FetchTexture(Hashtable request, Hashtable response, UUID textureID,
return true;
}
}
}
else // it was on the cache
{
//m_log.DebugFormat("[GETTEXTURE]: texture was in the cache");
WriteTextureData(request, response, texture, format);
return true;
}
}
else // it was on the cache
{
//m_log.DebugFormat("[GETTEXTURE]: texture was in the cache");
WriteTextureData(request, response, texture, format);
return true;
}

//response = new Hashtable();

Expand Down Expand Up @@ -300,8 +300,7 @@ private byte[] ConvertTextureData(AssetBase texture, string format)
{
// Try CoreJ2K first
var j2k = J2kImage.FromBytes(texture.Data);
if (j2k != null)
skImage = j2k.As<SKImage>();
skImage = j2k?.As<SKImage>();
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,20 +314,19 @@ private byte[] ConvertTextureData(AssetBase texture, string format)
{
m_log.DebugFormat("[GETTEXTURE]: Converting texture {0} to {1}", texture.ID, format);
byte[] data = Array.Empty<byte>();
// Try CSJ2K (CoreJ2K) first to get an SKImage
// Try CoreJ2K first to get an SKImage
try
{
SKImage skImage = null;

try
{
var j2k = J2kImage.FromBytes(texture.Data);
if (j2k != null)
skImage = j2k.As<SKImage>();
skImage = j2k?.As<SKImage>();
}
catch (Exception)
{
// CSJ2K not available or failed, fall back to OpenJPEG
// CoreJ2K not available or failed, fall back to OpenJPEG
skImage = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
<PackageReference Include="log4net" Version="3.2.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.10" />
<PackageReference Include="SkiaSharp" Version="3.119.1" />
<PackageReference Include="CoreJ2K.Skia" Version="1.2.2.68" />
<PackageReference Include="CoreJ2K.Skia" Version="2.1.0.101" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion OpenSim/Framework/OpenSim.Framework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SkiaSharp" Version="3.119.1" />
<PackageReference Include="CoreJ2K.Skia" Version="1.2.2.68" />
<PackageReference Include="CoreJ2K.Skia" Version="2.1.0.101" />
<PackageReference Include="log4net" Version="3.2.0" />
<PackageReference Include="Mono.Addins" Version="1.4.1" />
<PackageReference Include="Mono.Addins.Setup" Version="1.4.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private bool DoJ2KDecode(UUID assetID, byte[] j2kData, out J2KLayerInfo[] layers
// "[J2KDecoderModule]: Doing J2K decoding of {0} bytes for asset {1}", j2kData.Length, assetID);

bool decodedSuccessfully = true;
components = 0; // Not used by CoreJ2K decode path
components = 0;

if (!TryLoadCacheForAsset(assetID, out layers))
{
Expand All @@ -237,7 +237,7 @@ private bool DoJ2KDecode(UUID assetID, byte[] j2kData, out J2KLayerInfo[] layers
{
// Extract layer information from CoreJ2K - create default layers for now
layers = CreateDefaultLayers(j2kData.Length);
components = 3; // Typical JPEG2000 has 3 components (RGB)
components = j2k.NumberOfComponents;
decodedSuccessfully = true;
// Cache decoded layers
SaveFileCacheForAsset(assetID, layers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<PackageReference Include="Mono.Addins.CecilReflector" Version="1.4.1" />
<PackageReference Include="MySqlConnector" Version="2.4.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.10" />
<PackageReference Include="CoreJ2K.Skia" Version="1.2.2.68" />
<PackageReference Include="CoreJ2K.Skia" Version="2.1.0.101" />
<PackageReference Include="SkiaSharp" Version="3.119.1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@

using SkiaSharp;
using System.Globalization;
using System.Net;
using Nini.Config;
using OpenMetaverse;
using OpenMetaverse.Imaging;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using log4net;
using System.Reflection;
using CoreJ2K;
using CoreJ2K.Configuration;
using Mono.Addins;

//using Cairo;
Expand All @@ -53,6 +53,11 @@ public class VectorRenderModule : ISharedRegionModule, IDynamicTextureRender
private static object thisLock = new object();
private static SKTypeface m_typeface = null; // SkiaSharp typeface for measurements

private readonly J2KEncoderConfiguration encoderConfig = new J2KEncoderConfiguration()
.WithTiles(t => t.SetSize(256, 256))
.WithWavelet(w => w.UseIrreversible97().WithDecompositionLevels(4))
.WithProgression(p => p.WithOrder(ProgressionOrder.LRCP).WithQualityLayers(0.1f, 0.5f, 1.0f));

private Scene m_scene;
private IDynamicTextureManager m_textureManager;

Expand Down Expand Up @@ -226,8 +231,8 @@ public Type ReplaceableInterface

private IDynamicTexture Draw(string data, string extraParams)
{
// We need to cater for old scripts that didnt use extraParams neatly, they use either an integer size which represents both width and height, or setalpha
// we will now support multiple comma seperated params in the form width:256,height:512,alpha:255
// We need to cater for old scripts that didn't use extraParams neatly, they use either an integer size which represents both width and height, or setalpha
// we will now support multiple comma separated params in the form width:256,height:512,alpha:255
int width = 256;
int height = 256;
int alpha = 255; // 0 is transparent
Expand Down Expand Up @@ -361,7 +366,7 @@ private IDynamicTexture Draw(string data, string extraParams)
height = temp;
}
}
break;
break;
}
}

Expand Down Expand Up @@ -403,13 +408,7 @@ private IDynamicTexture Draw(string data, string extraParams)

try
{
// Convert SKBitmap to SKImage and encode as JPEG
// TODO: Replace with CoreJ2K encoding when encoder becomes available
using (var image = SKImage.FromBitmap(bitmap))
{
var data_encoded = image.Encode(SKEncodedImageFormat.Jpeg, 100);
imageJ2000 = data_encoded.ToArray();
}
imageJ2000 = J2kImage.ToBytes(bitmap, encoderConfig);
}
catch (Exception e)
{
Expand All @@ -425,11 +424,8 @@ private IDynamicTexture Draw(string data, string extraParams)
{
lock (thisLock)
{
if (canvas != null)
canvas.Dispose();

if (bitmap != null)
bitmap.Dispose();
canvas?.Dispose();
bitmap?.Dispose();
}
}
}
Expand Down
23 changes: 10 additions & 13 deletions OpenSim/Region/CoreModules/World/LegacyMap/MapImageModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

using System;
using System.Collections.Generic;
using System.Reflection;
using System.IO;
using log4net;
using Mono.Addins;
using Nini.Config;
using CoreJ2K;
using CoreJ2K.Configuration;
using OpenMetaverse;
using OpenMetaverse.Imaging;
using OpenSim.Framework;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
Expand Down Expand Up @@ -73,6 +71,12 @@ public class MapImageModule : IMapImageGenerator, INonSharedRegionModule
private IMapTileTerrainRenderer terrainRenderer;
private bool m_Enabled = false;

private readonly J2KEncoderConfiguration encoderConfig = new J2KEncoderConfiguration()
.WithQuality(0.85)
.WithTiles(t => t.SetSize(256, 256))
.WithWavelet(w => w.UseIrreversible97().WithDecompositionLevels(7))
.WithProgression(p => p.WithOrder(ProgressionOrder.RPCL));

#region IMapImageGenerator Members

public SKBitmap CreateMapTile()
Expand All @@ -94,9 +98,8 @@ public SKBitmap CreateMapTile()
float minHeight = float.MaxValue;

// Find height range
for (int i = 0; i < heightData.Length; i++)
foreach (var height in heightData)
{
float height = heightData[i];
maxHeight = Math.Max(maxHeight, height);
minHeight = Math.Min(minHeight, height);
}
Expand Down Expand Up @@ -147,13 +150,7 @@ public byte[] WriteJpeg2000Image()
{
if (skBitmap != null)
{
// Convert SKBitmap to SKImage and encode as JPEG
// TODO: Replace with CoreJ2K encoding when encoder becomes available
using (var image = SKImage.FromBitmap(skBitmap))
{
var encoded = image.Encode(SKEncodedImageFormat.Jpeg, 100);
return encoded.ToArray();
}
return J2kImage.ToBytes(skBitmap, encoderConfig);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Region/Framework/OpenSim.Region.Framework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SkiaSharp" Version="3.119.1" />
<PackageReference Include="CoreJ2K.Skia" Version="1.2.2.68" />
<PackageReference Include="CoreJ2K.Skia" Version="2.1.0.101" />
<PackageReference Include="log4net" Version="3.2.0" />
<PackageReference Include="Mono.Addins" Version="1.4.1" />
<PackageReference Include="Mono.Addins.CecilReflector" Version="1.4.1" />
Expand Down
12 changes: 6 additions & 6 deletions OpenSim/Region/PhysicsModules/Meshing/Meshmerizer/Meshmerizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

using System;
using System.Collections.Generic;
using System.Reflection;
using System.IO;
using OpenSim.Framework;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Region.Framework.Interfaces;
Expand All @@ -37,6 +34,7 @@
using OpenMetaverse.StructuredData;
using SkiaSharp;
using CoreJ2K;
using CoreJ2K.Configuration;
using System.IO.Compression;
using PrimMesher;
using log4net;
Expand Down Expand Up @@ -71,6 +69,9 @@ public class Meshmerizer : IMesher, INonSharedRegionModule
// Mesh cache. Static so it can be shared across instances of this class
private static Dictionary<ulong, Mesh> m_uniqueMeshes = new Dictionary<ulong, Mesh>();

private readonly J2KDecoderConfiguration decoderConfig = new J2KDecoderConfiguration()
.WithHighestResolution();

#region INonSharedRegionModule
public string Name
{
Expand Down Expand Up @@ -661,9 +662,8 @@ private bool GenerateCoordsAndFacesFromPrimSculptData(
SKImage skImage = null;
try
{
var j2k = J2kImage.FromBytes(primShape.SculptData);
if (j2k != null)
skImage = j2k.As<SKImage>();
var j2k = J2kImage.FromBytes(primShape.SculptData, decoderConfig);
skImage = j2k?.As<SKImage>();
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="Mono.Addins" Version="1.4.1" />
<PackageReference Include="Mono.Addins.CecilReflector" Version="1.4.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.10" />
<PackageReference Include="CoreJ2K.Skia" Version="1.2.2.68" />
<PackageReference Include="CoreJ2K.Skia" Version="2.1.0.101" />
<PackageReference Include="SkiaSharp" Version="3.119.1" />
</ItemGroup>
<ItemGroup>
Expand Down
29 changes: 15 additions & 14 deletions OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,23 @@
*/
//#define SPAM

using CoreJ2K;
using CoreJ2K.Configuration;
using log4net;
using Mono.Addins;
using Nini.Config;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
using OpenSim.Framework;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.PhysicsModules.SharedBase;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Region.PhysicsModules.ConvexDecompositionDotNet;

using OpenMetaverse;
using OpenMetaverse.StructuredData;

using OpenSim.Region.PhysicsModules.SharedBase;
using PrimMesher;
using SkiaSharp;
using CoreJ2K;
using System.IO.Compression;
using PrimMesher;
using log4net;
using Nini.Config;
using System.Reflection;

using Mono.Addins;

namespace OpenSim.Region.PhysicsModule.ubODEMeshing
{
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ubODEMeshmerizer")]
Expand All @@ -56,7 +54,7 @@ public class ubMeshmerizer : IMesher, INonSharedRegionModule
// raw files can be imported by blender so a visual inspection of the results can be done

const float floatPI = MathF.PI;
private readonly static string cacheControlFilename = "cntr";
private static readonly string cacheControlFilename = "cntr";
private bool m_Enabled = false;

public static object diskLock = new();
Expand All @@ -76,6 +74,9 @@ public class ubMeshmerizer : IMesher, INonSharedRegionModule
private readonly Dictionary<AMeshKey, Mesh> m_uniqueMeshes = new();
private readonly Dictionary<AMeshKey, Mesh> m_uniqueReleasedMeshes = new();

private readonly J2KDecoderConfiguration decoderConfig = new J2KDecoderConfiguration()
.WithHighestResolution();

#region INonSharedRegionModule
public string Name
{
Expand Down Expand Up @@ -715,7 +716,7 @@ private static bool GenerateCoordsAndFacesFromPrimSculptData(
SKBitmap skBitmap = null;
try
{
var j2k = J2kImage.FromBytes(primShape.SculptData);
var j2k = J2kImage.FromBytes(primShape.SculptData, decoderConfig);
if (j2k != null)
skBitmap = j2k.As<SKBitmap>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="Mono.Addins" Version="1.4.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.10" />
<PackageReference Include="Mono.Addins.CecilReflector" Version="1.4.1" />
<PackageReference Include="CoreJ2K.Skia" Version="1.2.2.68" />
<PackageReference Include="CoreJ2K.Skia" Version="2.1.0.101" />
<PackageReference Include="SkiaSharp" Version="3.119.1" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SkiaSharp" Version="3.119.1" />
<PackageReference Include="CoreJ2K.Skia" Version="1.2.2.68" />
<PackageReference Include="CoreJ2K.Skia" Version="2.1.0.101" />
<PackageReference Include="log4net" Version="3.2.0" />
<PackageReference Include="Mono.Addins" Version="1.4.1" />
<PackageReference Include="Mono.Addins.CecilReflector" Version="1.4.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SkiaSharp" Version="3.119.1" />
<PackageReference Include="CoreJ2K.Skia" Version="1.2.2.68" />
<PackageReference Include="CoreJ2K.Skia" Version="2.1.0.101" />
<ProjectReference Include="..\..\Framework\OpenSim.Framework.csproj" />
<ProjectReference Include="..\..\Framework\Console\OpenSim.Framework.Console.csproj" />
<ProjectReference Include="..\..\Framework\Servers\HttpServer\OpenSim.Framework.Servers.HttpServer.csproj" />
Expand Down
Loading