BioGTK  5.1.1
A .NET library & program for annotating, editing various microscopy imaging formats using Bioformats supported images.
Loading...
Searching...
No Matches
Bio.SlideSourceBase Class Referenceabstract
Inheritance diagram for Bio.SlideSourceBase:
Bio.ISlideSource Bio.ISliceProvider Bio.ISlideExternInfo Bio.SlideBase

Public Member Functions

async Task< byte[]> GetSlice (SliceInfo sliceInfo)
 Get slice.
 
byte[] GetRgb24Bytes (Image< Rgb24 > image)
 
byte[] Get16Bytes (Image< L16 > image)
 
abstract IReadOnlyDictionary< string, byte[]> GetExternImages ()
 Extern image.
 
void Dispose ()
 
async Task< byte[]> GetTileAsync (TileInformation tileInfo)
 
async Task< byte[]> GetTileAsync (BruTile.TileInfo tileInfo)
 
Task< byte[]> GetSlice (SliceInfo sliceInfo)
 Get slice.
 
IReadOnlyDictionary< string, byte[]> GetExternImages ()
 Extern image.
 

Static Public Member Functions

static void Resister (string extensionUpper, Func< string, bool, ISlideSource > factory)
 resister decode for Specific format
 
static ISlideSource Create (BioImage source, SlideImage im, bool enableCache=true)
 
static byte[] ConvertRgbaToRgb (byte[] rgbaArray)
 

Public Attributes

TileCache cache = null
 

Static Public Attributes

static Extent destExtent
 
static Extent sourceExtent
 
static double curUnitsPerPixel = 1
 
static bool UseVips = true
 

Protected Member Functions

virtual void Dispose (bool disposing)
 

Properties

static bool UseRealResolution = true [get, set]
 
double MinUnitsPerPixel [get, protected set]
 um/pixel
 
SlideImage Image [get, set]
 
ITileSchema Schema [get, protected set]
 
string Name [get, protected set]
 
Attribution Attribution [get, protected set]
 
IReadOnlyDictionary< string, object > ExternInfo [get, protected set]
 Extern info.
 
string Source [get, protected set]
 File path.
 
- Properties inherited from Bio.ISliceProvider
double MinUnitsPerPixel [get]
 um/pixel
 
- Properties inherited from Bio.ISlideExternInfo
string Source [get]
 File path.
 
IReadOnlyDictionary< string, object > ExternInfo [get]
 Extern info.
 

Member Function Documentation

◆ ConvertRgbaToRgb()

static byte[] Bio.SlideSourceBase.ConvertRgbaToRgb ( byte[]  rgbaArray)
inlinestatic
358 {
359 // Initialize a new byte array for RGB24 format
360 byte[] rgbArray = new byte[(rgbaArray.Length / 4) * 3];
361
362 for (int i = 0, j = 0; i < rgbaArray.Length; i += 4, j += 3)
363 {
364 // Copy the R, G, B values, skip the A value
365 rgbArray[j] = rgbaArray[i + 2]; // B
366 rgbArray[j + 1] = rgbaArray[i + 1]; // G
367 rgbArray[j + 2] = rgbaArray[i]; // R
368 }
369
370 return rgbArray;
371 }

◆ Create()

static ISlideSource Bio.SlideSourceBase.Create ( BioImage  source,
SlideImage  im,
bool  enableCache = true 
)
inlinestatic
154 {
155
156 var ext = Path.GetExtension(source.file).ToUpper();
157 try
158 {
159 if (keyValuePairs.TryGetValue(ext, out var factory) && factory != null)
160 return factory.Invoke(source.file, enableCache);
161
162 if (!string.IsNullOrEmpty(SlideBase.DetectVendor(source.file)))
163 {
164 SlideBase b = new SlideBase(source, im, enableCache);
165
166 }
167 }
168 catch (Exception e)
169 {
170 Console.WriteLine(e.Message);
171 }
172 return null;
173 }
string file
Definition Bio.cs:2721

◆ Dispose() [1/2]

void Bio.SlideSourceBase.Dispose ( )
inline
324 {
325 Dispose(disposing: true);
326 GC.SuppressFinalize(this);
327 }
void Dispose()
Definition ISlideSource.cs:323

◆ Dispose() [2/2]

virtual void Bio.SlideSourceBase.Dispose ( bool  disposing)
inlineprotectedvirtual

Reimplemented in Bio.SlideBase.

307 {
308 if (!disposedValue)
309 {
310 if (disposing)
311 {
312 //_bgraCache.Dispose();
313 }
314 disposedValue = true;
315 }
316 }

◆ Get16Bytes()

byte[] Bio.SlideSourceBase.Get16Bytes ( Image< L16 >  image)
inline
269 {
270 int width = image.Width;
271 int height = image.Height;
272 byte[] bytes = new byte[width * height * 2];
273
274 int byteIndex = 0;
275 for (int y = 0; y < height; y++)
276 {
277 for (int x = 0; x < width; x++)
278 {
279 L16 pixel = image[x, y];
280 byte[] bts = BitConverter.GetBytes(pixel.PackedValue);
281 bytes[byteIndex++] = bts[0];
282 bytes[byteIndex++] = bts[1];
283 }
284 }
285
286 return bytes;
287 }

◆ GetExternImages()

abstract IReadOnlyDictionary< string, byte[]> Bio.SlideSourceBase.GetExternImages ( )
pure virtual

Extern image.

Returns

Implements Bio.ISlideExternInfo.

Implemented in Bio.SlideBase.

◆ GetRgb24Bytes()

byte[] Bio.SlideSourceBase.GetRgb24Bytes ( Image< Rgb24 >  image)
inline
249 {
250 int width = image.Width;
251 int height = image.Height;
252 byte[] rgbBytes = new byte[width * height * 3]; // 3 bytes per pixel (RGB)
253
254 int byteIndex = 0;
255 for (int y = 0; y < height; y++)
256 {
257 for (int x = 0; x < width; x++)
258 {
259 Rgb24 pixel = image[x, y];
260 rgbBytes[byteIndex++] = pixel.B;
261 rgbBytes[byteIndex++] = pixel.G;
262 rgbBytes[byteIndex++] = pixel.R;
263 }
264 }
265
266 return rgbBytes;
267 }

◆ GetSlice()

async Task< byte[]> Bio.SlideSourceBase.GetSlice ( SliceInfo  sliceInfo)
inline

Get slice.

Parameters
sliceInfoSlice info
Returns

Implements Bio.ISliceProvider.

182 {
183 if (cache == null)
184 cache = new TileCache(this);
185 var curLevel = Image.BioImage.LevelFromResolution(sliceInfo.Resolution);
186 var curUnitsPerPixel = Schema.Resolutions[curLevel].UnitsPerPixel;
187 var tileInfos = Schema.GetTileInfos(sliceInfo.Extent, curLevel);
188 List<Tuple<Extent, byte[]>> tiles = new List<Tuple<Extent, byte[]>>();
189 foreach (BruTile.TileInfo t in tileInfos)
190 {
191 TileInformation tf = new TileInformation();
192 tf.Extent = t.Extent;
193 tf.Coordinate = App.viewer.GetCoordinate();
194 tf.Index = t.Index;
195 byte[] c = await cache.GetTile(tf);
196 if(c!=null)
197 tiles.Add(Tuple.Create(t.Extent.WorldToPixelInvertedY(curUnitsPerPixel), c));
198 }
199 var srcPixelExtent = sliceInfo.Extent.WorldToPixelInvertedY(curUnitsPerPixel);
200 var dstPixelExtent = sliceInfo.Extent.WorldToPixelInvertedY(sliceInfo.Resolution);
201 var dstPixelHeight = sliceInfo.Parame.DstPixelHeight > 0 ? sliceInfo.Parame.DstPixelHeight : dstPixelExtent.Height;
202 var dstPixelWidth = sliceInfo.Parame.DstPixelWidth > 0 ? sliceInfo.Parame.DstPixelWidth : dstPixelExtent.Width;
203 destExtent = new Extent(0, 0, dstPixelWidth, dstPixelHeight);
204 sourceExtent = srcPixelExtent;
205 if (UseVips)
206 {
207 try
208 {
209 NetVips.Image im = null;
210 if (this.Image.BioImage.Resolutions[curLevel].PixelFormat == PixelFormat.Format16bppGrayScale)
211 im = ImageUtil.JoinVips16(tiles, srcPixelExtent, new Extent(0, 0, dstPixelWidth, dstPixelHeight));
212 else if(this.Image.BioImage.Resolutions[curLevel].PixelFormat == PixelFormat.Format24bppRgb)
213 im = ImageUtil.JoinVipsRGB24(tiles, srcPixelExtent, new Extent(0, 0, dstPixelWidth, dstPixelHeight));
214 return im.WriteToMemory();
215 }
216 catch (Exception e)
217 {
218 UseVips = false;
219 Console.WriteLine("Failed to use LibVips please install Libvips for your platform.");
220 Console.WriteLine(e.Message);
221 }
222 }
223 try
224 {
225 Image im = null;
226 if (this.Image.BioImage.Resolutions[curLevel].PixelFormat == PixelFormat.Format16bppGrayScale)
227 {
228 im = ImageUtil.Join16(tiles, srcPixelExtent, new Extent(0, 0, dstPixelWidth, dstPixelHeight));
229 byte[] bts = Get16Bytes((Image<L16>)im);
230 im.Dispose();
231 return bts;
232 }
233 else if (this.Image.BioImage.Resolutions[curLevel].PixelFormat == PixelFormat.Format24bppRgb)
234 {
235 im = ImageUtil.JoinRGB24(tiles, srcPixelExtent, new Extent(0, 0, dstPixelWidth, dstPixelHeight));
236 byte[] bts = GetRgb24Bytes((Image<Rgb24>)im);
237 im.Dispose();
238 return bts;
239 }
240 }
241 catch (Exception er)
242 {
243 Console.WriteLine(er.Message);
244 return null;
245 }
246 return null;
247 }
SixLabors.ImageSharp.Image Image
Definition ISlideSource.cs:11
TileCache cache
Definition ISlideSource.cs:180
static double curUnitsPerPixel
Definition ISlideSource.cs:178
static Extent destExtent
Definition ISlideSource.cs:176
static bool UseVips
Definition ISlideSource.cs:179
ITileSchema Schema
Definition ISlideSource.cs:291
byte[] GetRgb24Bytes(Image< Rgb24 > image)
Definition ISlideSource.cs:248
static Extent sourceExtent
Definition ISlideSource.cs:177
byte[] Get16Bytes(Image< L16 > image)
Definition ISlideSource.cs:268
async Task< byte[]> GetTile(TileInformation info)
Definition ISlideSource.cs:87

◆ GetTileAsync() [1/2]

async Task< byte[]> Bio.SlideSourceBase.GetTileAsync ( BruTile::TileInfo  tileInfo)
inline
344 {
345 if (tileInfo == null)
346 return null;
347 var r = Schema.Resolutions[tileInfo.Index.Level].UnitsPerPixel;
348 var tileWidth = Schema.Resolutions[tileInfo.Index.Level].TileWidth;
349 var tileHeight = Schema.Resolutions[tileInfo.Index.Level].TileHeight;
350 var curLevelOffsetXPixel = tileInfo.Extent.MinX / Schema.Resolutions[tileInfo.Index.Level].UnitsPerPixel;
351 var curLevelOffsetYPixel = -tileInfo.Extent.MaxY / Schema.Resolutions[tileInfo.Index.Level].UnitsPerPixel;
352 var curTileWidth = (int)(tileInfo.Extent.MaxX > Schema.Extent.Width ? tileWidth - (tileInfo.Extent.MaxX - Schema.Extent.Width) / r : tileWidth);
353 var curTileHeight = (int)(-tileInfo.Extent.MinY > Schema.Extent.Height ? tileHeight - (-tileInfo.Extent.MinY - Schema.Extent.Height) / r : tileHeight);
354 var bgraData = await Image.ReadRegionAsync(tileInfo.Index.Level, (long)curLevelOffsetXPixel, (long)curLevelOffsetYPixel, curTileWidth, curTileHeight, new ZCT());
355 return bgraData;
356 }

◆ GetTileAsync() [2/2]

async Task< byte[]> Bio.SlideSourceBase.GetTileAsync ( TileInformation  tileInfo)
inline
330 {
331 if (tileInfo == null)
332 return null;
333 var r = Schema.Resolutions[tileInfo.Index.Level].UnitsPerPixel;
334 var tileWidth = Schema.Resolutions[tileInfo.Index.Level].TileWidth;
335 var tileHeight = Schema.Resolutions[tileInfo.Index.Level].TileHeight;
336 var curLevelOffsetXPixel = tileInfo.Extent.MinX / Schema.Resolutions[tileInfo.Index.Level].UnitsPerPixel;
337 var curLevelOffsetYPixel = -tileInfo.Extent.MaxY / Schema.Resolutions[tileInfo.Index.Level].UnitsPerPixel;
338 var curTileWidth = (int)(tileInfo.Extent.MaxX > Schema.Extent.Width ? tileWidth - (tileInfo.Extent.MaxX - Schema.Extent.Width) / r : tileWidth);
339 var curTileHeight = (int)(-tileInfo.Extent.MinY > Schema.Extent.Height ? tileHeight - (-tileInfo.Extent.MinY - Schema.Extent.Height) / r : tileHeight);
340 var bgraData = await Image.ReadRegionAsync(tileInfo.Index.Level, (long)curLevelOffsetXPixel, (long)curLevelOffsetYPixel, curTileWidth, curTileHeight,tileInfo.Coordinate);
341 return bgraData;
342 }

◆ Resister()

static void Bio.SlideSourceBase.Resister ( string  extensionUpper,
Func< string, bool, ISlideSource factory 
)
inlinestatic

resister decode for Specific format

Parameters
extensionUpperdot and extension upper
factoryfile path,enable cache,decoder
148 {
149 keyValuePairs.Add(extensionUpper, factory);
150 }

Member Data Documentation

◆ cache

TileCache Bio.SlideSourceBase.cache = null

◆ curUnitsPerPixel

double Bio.SlideSourceBase.curUnitsPerPixel = 1
static

◆ destExtent

Extent Bio.SlideSourceBase.destExtent
static

◆ sourceExtent

Extent Bio.SlideSourceBase.sourceExtent
static

◆ UseVips

bool Bio.SlideSourceBase.UseVips = true
static

Property Documentation

◆ Attribution

Attribution Bio.SlideSourceBase.Attribution
getprotected set
295{ get; protected set; }

◆ ExternInfo

IReadOnlyDictionary<string, object> Bio.SlideSourceBase.ExternInfo
getprotected set

Extern info.

Implements Bio.ISlideExternInfo.

297{ get; protected set; }

◆ Image

SlideImage Bio.SlideSourceBase.Image
getset
289{ get; set; }

◆ MinUnitsPerPixel

double Bio.SlideSourceBase.MinUnitsPerPixel
getprotected set

um/pixel

Implements Bio.ISliceProvider.

175{ get; protected set; }

◆ Name

string Bio.SlideSourceBase.Name
getprotected set
293{ get; protected set; }

◆ Schema

ITileSchema Bio.SlideSourceBase.Schema
getprotected set
291{ get; protected set; }

◆ Source

string Bio.SlideSourceBase.Source
getprotected set

File path.

Implements Bio.ISlideExternInfo.

299{ get; protected set; }

◆ UseRealResolution

bool Bio.SlideSourceBase.UseRealResolution = true
staticgetset
138{ get; set; } = true;

The documentation for this class was generated from the following file: