Skip to content

Commit 8a87077

Browse files
committed
OpenSlide on arm64, x64 for Linux and MacOS.
Adds support for OpenSlide on arm64 & x64 for Linux and MacOS.
1 parent 4f833ff commit 8a87077

5 files changed

Lines changed: 63 additions & 26 deletions

File tree

BioLib.csproj

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
<PackageIcon>banner.jpg</PackageIcon>
1212
<PackageReadmeFile>README.md</PackageReadmeFile>
1313
<RepositoryUrl>https://github.com/BiologyTools/BioLib</RepositoryUrl>
14-
<AssemblyVersion>3.8.1</AssemblyVersion>
15-
<FileVersion>3.8.1</FileVersion>
16-
<PackageVersion>3.8.1</PackageVersion>
14+
<AssemblyVersion>3.9.0</AssemblyVersion>
15+
<FileVersion>3.9.0</FileVersion>
16+
<PackageVersion>3.9.0</PackageVersion>
1717
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
1818
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
1919
<PackageProjectUrl>https://biologytools.github.io/</PackageProjectUrl>
2020
<PackageTags>Biology; ImageJ; Bio-Formats; OMERO; Image-Stacks; Microscopy; Whole-Slide-Image; QuPath; </PackageTags>
21-
<PackageReleaseNotes>OMERO pyramidal and stack support.</PackageReleaseNotes>
21+
<PackageReleaseNotes>Adds support for OpenSlide on arm64 &amp; x64 for Linux and MacOS.</PackageReleaseNotes>
2222
<Authors>Erik Repo</Authors>
2323
<Platforms>AnyCPU;x64</Platforms>
2424
</PropertyGroup>
@@ -36,22 +36,19 @@
3636
</ItemGroup>
3737
<ItemGroup>
3838
<PackageReference Include="BitMiracle.LibTiff.NET" Version="2.4.660" />
39-
<PackageReference Include="CS-Script" Version="4.11.2" />
39+
<PackageReference Include="CS-Script" Version="4.13.2" />
4040
<PackageReference Include="ImageJ.NET" Version="154.0.0.2" />
4141
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
4242
<PackageReference Include="NuGet.Build.Tasks.Pack" Version="6.14.0">
4343
<PrivateAssets>all</PrivateAssets>
4444
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
4545
</PackageReference>
4646
<PackageReference Include="OMERO.NET" Version="1.0.5" />
47+
<PackageReference Include="OpenSlideGTK" Version="2.6.0" />
4748
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.12" />
48-
<PackageReference Include="SkiaSharp" Version="3.119.1" />
49-
<PackageReference Include="SkiaSharp.Views.Gtk3" Version="3.119.1" />
49+
<PackageReference Include="SkiaSharp" Version="3.119.2" />
50+
<PackageReference Include="SkiaSharp.Views.Gtk3" Version="3.119.2" />
5051
</ItemGroup>
51-
<ItemGroup>
52-
<ProjectReference Include="..\AForgeBio\AForgeBio\AForgeBio.csproj" />
53-
<ProjectReference Include="..\OpenSlideSharp\src\OpenSlideSharp\OpenSlideGTK.csproj" />
54-
</ItemGroup>
5552
<ItemGroup>
5653
<None Update="banner.jpg">
5754
<Pack>True</Pack>

Source/Bio.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7089,12 +7089,14 @@ public static BioImage OpenOME(string file, int serie, bool tab, bool addToImage
70897089
if (st != null && !file.EndsWith("ome.tif") && useOpenSlide)
70907090
{
70917091
Status = "Opening file with OpenSlide.";
7092+
Console.WriteLine("Opening file with OpenSlide.");
70927093
b.openSlideImage = OpenSlideImage.Open(file);
70937094
b.openslideBase = (OpenSlideBase)OpenSlideGTK.SlideSourceBase.Create(file, true);
70947095
}
70957096
else
70967097
{
70977098
Status = "Opening file with BioFormats.";
7099+
Console.WriteLine("Opening file with BioFormats.");
70987100
b.slideBase = new SlideBase(b, SlideImage.Open(b));
70997101
}
71007102
}

Source/Bio/ISlideSource.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,17 @@ public static ISlideSource Create(BioImage source, SlideImage im, bool enableCac
220220
public static Extent sourceExtent;
221221
public static double curUnitsPerPixel = 1;
222222
public static bool UseVips = true;
223-
public static bool UseGPU = true;
223+
public static bool UseGPU
224+
{
225+
get
226+
{
227+
if (OperatingSystem.IsMacOS())
228+
return false;
229+
else
230+
return true;
231+
}
232+
set;
233+
}
224234
public TileCache cache = null;
225235
public Stitch stitch = new Stitch();
226236
public bool HasTile(TileInfo tile, ZCT coord)

Source/Bio/SlideBase.cs

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,37 @@ private static Image<Rgb24> CreateImageFromRgbaData(byte[] rgbaData, int width,
8080
}
8181
public byte[] GetTile(TileInfo tileInfo, ZCT coord)
8282
{
83-
var r = Schema.Resolutions[tileInfo.Index.Level].UnitsPerPixel;
84-
var tileWidth = Schema.Resolutions[tileInfo.Index.Level].TileWidth;
85-
var tileHeight = Schema.Resolutions[tileInfo.Index.Level].TileHeight;
86-
var curLevelOffsetXPixel = tileInfo.Extent.MinX / MinUnitsPerPixel;
87-
var curLevelOffsetYPixel = -tileInfo.Extent.MaxY / MinUnitsPerPixel;
88-
var curTileWidth = (int)(tileInfo.Extent.MaxX > Schema.Extent.Width ? tileWidth - (tileInfo.Extent.MaxX - Schema.Extent.Width) / r : tileWidth);
89-
var curTileHeight = (int)(-tileInfo.Extent.MinY > Schema.Extent.Height ? tileHeight - (-tileInfo.Extent.MinY - Schema.Extent.Height) / r : tileHeight);
90-
var bgraData = SlideImage.ReadRegion(tileInfo.Index.Level, coord, (long)curLevelOffsetXPixel, (long)curLevelOffsetYPixel, curTileWidth, curTileHeight);
91-
//We check to see if the data is valid.
92-
if (bgraData.Length != curTileWidth * curTileHeight * 4)
93-
return null;
94-
byte[] bm = ConvertRgbaToRgb(bgraData);
95-
return bm;
83+
try
84+
{
85+
if(Schema == null)
86+
{
87+
Console.WriteLine("Schema is null.");
88+
return null;
89+
}
90+
var r = Schema.Resolutions[tileInfo.Index.Level].UnitsPerPixel;
91+
var tileWidth = Schema.Resolutions[tileInfo.Index.Level].TileWidth;
92+
var tileHeight = Schema.Resolutions[tileInfo.Index.Level].TileHeight;
93+
var curLevelOffsetXPixel = tileInfo.Extent.MinX / MinUnitsPerPixel;
94+
var curLevelOffsetYPixel = -tileInfo.Extent.MaxY / MinUnitsPerPixel;
95+
var curTileWidth = (int)(tileInfo.Extent.MaxX > Schema.Extent.Width ? tileWidth - (tileInfo.Extent.MaxX - Schema.Extent.Width) / r : tileWidth);
96+
var curTileHeight = (int)(-tileInfo.Extent.MinY > Schema.Extent.Height ? tileHeight - (-tileInfo.Extent.MinY - Schema.Extent.Height) / r : tileHeight);
97+
if(SlideImage == null)
98+
{
99+
Console.WriteLine("SlideImage is null.");
100+
return null;
101+
}
102+
var bgraData = SlideImage.ReadRegion(tileInfo.Index.Level, coord, (long)curLevelOffsetXPixel, (long)curLevelOffsetYPixel, curTileWidth, curTileHeight);
103+
//We check to see if the data is valid.
104+
if (bgraData.Length != curTileWidth * curTileHeight * 4)
105+
return null;
106+
byte[] bm = ConvertRgbaToRgb(bgraData);
107+
return bm;
108+
}
109+
catch (Exception e)
110+
{
111+
Console.WriteLine(e.Message + " " + e.StackTrace);
112+
}
113+
return null;
96114
}
97115
public static byte[] ConvertRgbaToRgb(byte[] rgbaArray)
98116
{

Source/Bio/SlideImage.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,17 @@ public int GetBestLevelForDownsample(double downsample)
223223
/// <exception cref="OpenSlideException"/>
224224
public unsafe byte[] ReadRegion(int level, ZCT zct, long x, long y, long width, long height)
225225
{
226-
return BioImage.GetTile(BioImage, BioImage.GetFrameIndex(zct.Z, zct.C, zct.T), level, (int)x, (int)y, (int)width, (int)height).Bytes;
226+
try
227+
{
228+
return BioImage.GetTile(BioImage, BioImage.GetFrameIndex(zct.Z, zct.C, zct.T), level, (int)x, (int)y, (int)width, (int)height).Bytes;
229+
}
230+
catch (Exception e)
231+
{
232+
if (BioImage == null)
233+
Console.WriteLine("BioImage is null. ");
234+
Console.WriteLine(e.Message + " " + e.StackTrace);
235+
}
236+
return null;
227237
}
228238

229239
/// <summary>

0 commit comments

Comments
 (0)