Skip to content

Commit

Permalink
Use SKBitmap rather than AnyBitmap
Browse files Browse the repository at this point in the history
  • Loading branch information
cinderblocks committed Aug 7, 2024
1 parent e6099a4 commit 732638e
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
<ProjectReference Include="..\PrimMesher\LibreMetaverse.PrimMesher.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="IronSoftware.System.Drawing" Version="2024.7.2" />
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions LibreMetaverse.Rendering.Meshmerizer/MeshmerizerR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using IronSoftware.Drawing;
using SkiaSharp;
using OpenMetaverse.StructuredData;
using LibreMetaverse.PrimMesher;

Expand Down Expand Up @@ -130,7 +130,7 @@ public SimpleMesh GenerateSimpleMeshWithNormals(Primitive prim, DetailLevel lod)
/// <param name="sculptTexture">Sculpt texture</param>
/// <param name="lod">Level of detail to generate the mesh at</param>
/// <returns>The generated mesh or null on failure</returns>
public SimpleMesh GenerateSimpleSculptMesh(Primitive prim, AnyBitmap sculptTexture, DetailLevel lod)
public SimpleMesh GenerateSimpleSculptMesh(Primitive prim, SKBitmap sculptTexture, DetailLevel lod)
{
var faceted = GenerateFacetedSculptMesh(prim, sculptTexture, lod);

Expand Down Expand Up @@ -225,7 +225,7 @@ public FacetedMesh GenerateFacetedMesh(Primitive prim, DetailLevel lod)
/// routine since all the context for finding teh texture is elsewhere.
/// </summary>
/// <returns>The faceted mesh or null if can't do it</returns>
public FacetedMesh GenerateFacetedSculptMesh(Primitive prim, AnyBitmap scupltTexture, DetailLevel lod)
public FacetedMesh GenerateFacetedSculptMesh(Primitive prim, SKBitmap scupltTexture, DetailLevel lod)
{
LibreMetaverse.PrimMesher.SculptMesh.SculptType smSculptType;
switch (prim.Sculpt.Type)
Expand Down
6 changes: 3 additions & 3 deletions LibreMetaverse.Rendering.Simple/SimpleRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/

using System.Collections.Generic;
using IronSoftware.Drawing;
using SkiaSharp;

namespace OpenMetaverse.Rendering
{
Expand All @@ -48,7 +48,7 @@ public SimpleMesh GenerateSimpleMesh(Primitive prim, DetailLevel lod)
return mesh;
}

public SimpleMesh GenerateSimpleSculptMesh(Primitive prim, AnyBitmap sculptTexture, DetailLevel lod)
public SimpleMesh GenerateSimpleSculptMesh(Primitive prim, SKBitmap sculptTexture, DetailLevel lod)
{
return GenerateSimpleMesh(prim, lod);
}
Expand All @@ -67,7 +67,7 @@ public FacetedMesh GenerateFacetedMesh(Primitive prim, DetailLevel lod)
return mesh;
}

public FacetedMesh GenerateFacetedSculptMesh(Primitive prim, AnyBitmap sculptTexture, DetailLevel lod)
public FacetedMesh GenerateFacetedSculptMesh(Primitive prim, SKBitmap sculptTexture, DetailLevel lod)
{
return GenerateFacetedMesh(prim, lod);
}
Expand Down
6 changes: 3 additions & 3 deletions LibreMetaverse/Imaging/BakeLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using IronSoftware.Drawing;
using SkiaSharp;
using OpenMetaverse.Assets;

namespace OpenMetaverse.Imaging
Expand Down Expand Up @@ -356,14 +356,14 @@ public static ManagedImage LoadResourceLayer(string fileName)
{
try
{
AnyBitmap bitmap = null;
SKBitmap bitmap = null;
lock (ResourceSync)
{
using (Stream stream = Helpers.GetResourceStream(fileName, Settings.RESOURCE_DIR))
{
if (stream != null)
{
bitmap = SkiaSharp.SKImage.FromEncodedData(stream);
bitmap = SKBitmap.Decode(stream);
}
}
}
Expand Down
21 changes: 11 additions & 10 deletions LibreMetaverse/Imaging/ManagedImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/

using System;
using IronSoftware.Drawing;
using SkiaSharp;

namespace OpenMetaverse.Imaging
{
Expand Down Expand Up @@ -117,16 +117,16 @@ public ManagedImage(int width, int height, ImageChannels channels)
/// Constructs ManagedImage class from AnyBitmap
/// </summary>
/// <param name="bitmap">Input AnyBitmap</param>
public ManagedImage(AnyBitmap bitmap)
public ManagedImage(SKBitmap bitmap)
{
Width = bitmap.Width;
Height = bitmap.Height;
var pixelCount = Width * Height;
var bpp = bitmap.BitsPerPixel;
var bpp = bitmap.BytesPerPixel;

switch (bpp)
{
case 32:
case 4:
Channels = ImageChannels.Alpha | ImageChannels.Color;
Red = new byte[pixelCount];
Green = new byte[pixelCount];
Expand All @@ -135,7 +135,7 @@ public ManagedImage(AnyBitmap bitmap)

unsafe
{
byte* pixel = (byte*)bitmap.Scan0;
byte* pixel = (byte*)bitmap.GetPixels();

for (var i = 0; i < pixelCount; ++i)
{
Expand All @@ -148,15 +148,15 @@ public ManagedImage(AnyBitmap bitmap)
}

break;
case 24:
case 3:
Channels = ImageChannels.Color;
Red = new byte[pixelCount];
Green = new byte[pixelCount];
Blue = new byte[pixelCount];

unsafe
{
byte* pixel = (byte*)bitmap.Scan0;
byte* pixel = (byte*)bitmap.GetPixels();

for (var i = 0; i < pixelCount; ++i)
{
Expand All @@ -168,7 +168,7 @@ public ManagedImage(AnyBitmap bitmap)
}

break;
case 16:
case 2:
Channels = ImageChannels.Gray;
Red = new byte[pixelCount];

Expand Down Expand Up @@ -340,7 +340,7 @@ public byte[] ExportRaw()
/// origin, suitable for feeding directly into OpenGL
/// </summary>
/// <returns>A byte array containing raw texture data</returns>
public AnyBitmap ExportBitmap()
public SKBitmap ExportBitmap()
{
var raw = new byte[Width * Height * 4];

Expand Down Expand Up @@ -377,7 +377,8 @@ public AnyBitmap ExportBitmap()
}
}

return AnyBitmap.FromBytes(raw);
var img = SKImage.FromEncodedData(raw);
return SKBitmap.FromImage(img);
}

public byte[] ExportTGA()
Expand Down
9 changes: 4 additions & 5 deletions LibreMetaverse/ImportExport/ColladalLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@
using System.Xml;
using System.Linq;
using System.Xml.Serialization;
using IronSoftware.Drawing;
using OpenMetaverse.ImportExport.Collada14;
using OpenMetaverse.Rendering;
using OpenMetaverse.Imaging;
using SkiaSharp;

namespace OpenMetaverse.ImportExport
Expand Down Expand Up @@ -120,7 +118,7 @@ void LoadImage(ModelMaterial material)
{
string ext = System.IO.Path.GetExtension(material.Texture).ToLower();

AnyBitmap bitmap;
SKBitmap bitmap;

switch (ext)
{
Expand All @@ -129,7 +127,8 @@ void LoadImage(ModelMaterial material)
material.TextureData = File.ReadAllBytes(fname);
return;
default:
bitmap = AnyBitmap.FromFile(fname);
var img = SKImage.FromEncodedData(fname);
bitmap = SKBitmap.FromImage(img);
break;
}

Expand All @@ -154,7 +153,7 @@ void LoadImage(ModelMaterial material)
var scaledImage = SKImage.Create(info);
var skImage = SKImage.FromBitmap(bitmap);
skImage.ScalePixels(scaledImage.PeekPixels(), SKFilterQuality.High);
bitmap = scaledImage;
bitmap = SKBitmap.FromImage(scaledImage);
}

using (var writer = new OpenJpegDotNet.IO.Writer(bitmap))
Expand Down
6 changes: 3 additions & 3 deletions LibreMetaverse/Interfaces/IRendering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

using System;
using System.Collections.Generic;
using IronSoftware.Drawing;
using SkiaSharp;

namespace OpenMetaverse.Rendering
{
Expand Down Expand Up @@ -67,7 +67,7 @@ public interface IRendering
/// <param name="sculptTexture">Sculpt texture</param>
/// <param name="lod">Level of detail to generate the mesh at</param>
/// <returns>The generated mesh</returns>
SimpleMesh GenerateSimpleSculptMesh(Primitive prim, AnyBitmap sculptTexture, DetailLevel lod);
SimpleMesh GenerateSimpleSculptMesh(Primitive prim, SKBitmap sculptTexture, DetailLevel lod);

/// <summary>
/// Generates a series of faces, each face containing a mesh and
Expand All @@ -86,7 +86,7 @@ public interface IRendering
/// <param name="sculptTexture">Sculpt texture</param>
/// <param name="lod">Level of detail to generate the mesh at</param>
/// <returns>The generated mesh</returns>
FacetedMesh GenerateFacetedSculptMesh(Primitive prim, AnyBitmap sculptTexture, DetailLevel lod);
FacetedMesh GenerateFacetedSculptMesh(Primitive prim, SKBitmap sculptTexture, DetailLevel lod);

/// <summary>
/// Apply texture coordinate modifications from a
Expand Down
1 change: 0 additions & 1 deletion LibreMetaverse/LibreMetaverse.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="IronSoftware.System.Drawing" Version="2024.7.2" />
<PackageReference Include="log4net" Version="2.0.17" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="8.0.6" />
<PackageReference Include="OggVorbisEncoder" Version="1.2.2" />
Expand Down
1 change: 0 additions & 1 deletion PrimMesher/LibreMetaverse.PrimMesher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
<None Include="..\data\logo.png" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="IronSoftware.System.Drawing" Version="2024.7.2" />
<PackageReference Include="SkiaSharp" Version="2.88.8" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8" />
</ItemGroup>
Expand Down
19 changes: 9 additions & 10 deletions PrimMesher/SculptMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

using System;
using System.Collections.Generic;
using IronSoftware.Drawing;
using SkiaSharp;

namespace LibreMetaverse.PrimMesher
Expand All @@ -44,7 +43,7 @@ public SculptMap()
{
}

public SculptMap(AnyBitmap bm, int lod)
public SculptMap(SKBitmap bm, int lod)
{
var bmW = bm.Width;
var bmH = bm.Height;
Expand Down Expand Up @@ -100,9 +99,9 @@ public SculptMap(AnyBitmap bm, int lod)
{
var c = bm.GetPixel(x, y);

redBytes[byteNdx] = c.R;
greenBytes[byteNdx] = c.G;
blueBytes[byteNdx] = c.B;
redBytes[byteNdx] = c.Red;
greenBytes[byteNdx] = c.Green;
blueBytes[byteNdx] = c.Blue;

++byteNdx;
}
Expand All @@ -113,9 +112,9 @@ public SculptMap(AnyBitmap bm, int lod)
var c = bm.GetPixel(x < width ? x * 2 : x * 2 - 1,
y < height ? y * 2 : y * 2 - 1);

redBytes[byteNdx] = c.R;
greenBytes[byteNdx] = c.G;
blueBytes[byteNdx] = c.B;
redBytes[byteNdx] = c.Red;
greenBytes[byteNdx] = c.Green;
blueBytes[byteNdx] = c.Blue;

++byteNdx;
}
Expand Down Expand Up @@ -163,13 +162,13 @@ public List<List<Coord>> ToRows(bool mirror)
return rows;
}

private AnyBitmap ScaleImage(AnyBitmap srcImage, int destWidth, int destHeight)
private SKBitmap ScaleImage(SKBitmap srcImage, int destWidth, int destHeight)
{
var info = new SKImageInfo(destWidth, destHeight);
var scaledImage = SKImage.Create(info);
var skImage = SKImage.FromBitmap(srcImage);
skImage.ScalePixels(scaledImage.PeekPixels(), SKFilterQuality.High);
return scaledImage;
return SKBitmap.FromImage(scaledImage);
}
}
}
Loading

0 comments on commit 732638e

Please sign in to comment.