BioGTK  6.5.0
A .NET library & program for annotating, editing various microscopy imaging formats using Bioformats supported images. Including whole slide, pyramidal, and series.
Loading...
Searching...
No Matches
BioGTK.SKSlideRenderer Class Reference

Manages slide rendering by coordinating between the SkiaStitchingPipeline and SlideGLArea Handles async updates, caching, and progressive rendering for large pyramidal images. More...

Inheritance diagram for BioGTK.SKSlideRenderer:

Classes

class  CacheStatistics
 

Public Member Functions

 SKSlideRenderer (SKDrawingArea sk)
 Initialize renderer for a specific GLArea widget.
 
void SetSource (OpenSlideGTK.OpenSlideBase openSlideSource)
 Set OpenSlide source and initialize pipeline.
 
void SetSource (SlideBase slideSource)
 Set BioLib slide source and initialize pipeline.
 
async Task UpdateViewAsync (PointD origin, double resolution, ZCT coordinate, int width=600, int height=400)
 Update the rendered view asynchronously - main entry point for rendering.
 
SKImage RenderRegion (RectangleD region, int level, ZCT coordinate, double resolution, int pxwidth, int pxheight)
 Render a specific region synchronously (for exports, small areas)
 
SKImage RenderCurrentViewSync ()
 Render current viewport synchronously (blocking)
 
SKImage GetCurrentImage ()
 Get the current image for rendering - called by GLArea during draw Returns the best available image (full quality or preview)
 
void DrawToCanvas (SKCanvas canvas, int canvasWidth, int canvasHeight)
 Draw the current image to a canvas with proper scaling Called during the Skia render callback from SlideGLArea.
 
void ClearCache ()
 Clear the tile cache.
 
CacheStatistics GetCacheStatistics ()
 Get cache statistics for monitoring.
 
void UpdateConfiguration (int? maxCacheSizeMB=null, int? tileSize=null, SKSamplingOptions? sampling=null, bool? enablePrefetch=null, bool? enableProgressiveRendering=null)
 Update renderer configuration and reinitialize if needed.
 
void Dispose ()
 

Properties

int MaxCacheSizeMB = 512 [get, set]
 
int TileSize = 256 [get, set]
 
SKSamplingOptions Sampling = SKSamplingOptions.Default [get, set]
 
bool EnablePrefetch = true [get, set]
 
bool IsRendering [get]
 
bool HasValidImage [get]
 

Detailed Description

Manages slide rendering by coordinating between the SkiaStitchingPipeline and SlideGLArea Handles async updates, caching, and progressive rendering for large pyramidal images.

Definition at line 15 of file SKSlideRenderer.cs.

Constructor & Destructor Documentation

◆ SKSlideRenderer()

BioGTK.SKSlideRenderer.SKSlideRenderer ( SKDrawingArea sk)

Initialize renderer for a specific GLArea widget.

Definition at line 50 of file SKSlideRenderer.cs.

51 {
52 InitializeDefaults();
53 }

Member Function Documentation

◆ ClearCache()

void BioGTK.SKSlideRenderer.ClearCache ( )

Clear the tile cache.

Definition at line 410 of file SKSlideRenderer.cs.

411 {
412 _stitchingPipeline?.ClearCache();
413 }
void ClearCache()
Clear entire cache.

◆ Dispose()

void BioGTK.SKSlideRenderer.Dispose ( )

Definition at line 475 of file SKSlideRenderer.cs.

476 {
477 _currentRenderedImage?.Dispose();
478 _stitchingPipeline?.Dispose();
479 _currentRenderedImage = null;
480 _stitchingPipeline = null;
481 }

◆ DrawToCanvas()

void BioGTK.SKSlideRenderer.DrawToCanvas ( SKCanvas canvas,
int canvasWidth,
int canvasHeight )

Draw the current image to a canvas with proper scaling Called during the Skia render callback from SlideGLArea.

Definition at line 330 of file SKSlideRenderer.cs.

331 {
332 if (canvas == null)
333 return;
334
335 var image = GetCurrentImage();
336 if (image == null)
337 return;
338 try
339 {
340 using (var paint = new SKPaint
341 {
342 IsAntialias = true,
343 BlendMode = SKBlendMode.SrcOver
344 })
345 {
346 // Draw image to fill canvas
347 var destRect = new SKRect(0, 0, canvasWidth, canvasHeight);
348 canvas.DrawImage(image, destRect, paint);
349 }
350 }
351 catch (Exception ex)
352 {
353 Console.WriteLine($"Error drawing to canvas: {ex.Message}");
354 }
355 }
SKImage GetCurrentImage()
Get the current image for rendering - called by GLArea during draw Returns the best available image (...

◆ GetCacheStatistics()

CacheStatistics BioGTK.SKSlideRenderer.GetCacheStatistics ( )

Get cache statistics for monitoring.

Definition at line 418 of file SKSlideRenderer.cs.

419 {
420 // Could be extended to expose actual stats from pipeline
421 return new CacheStatistics
422 {
423 IsEnabled = _stitchingPipeline != null,
424 MaxSizeMB = MaxCacheSizeMB,
425 TileSize = TileSize
426 };
427 }

◆ GetCurrentImage()

SKImage BioGTK.SKSlideRenderer.GetCurrentImage ( )

Get the current image for rendering - called by GLArea during draw Returns the best available image (full quality or preview)

Definition at line 320 of file SKSlideRenderer.cs.

321 {
322 // Return full quality if available, otherwise preview
323 return _currentRenderedImage;
324 }

◆ RenderCurrentViewSync()

SKImage BioGTK.SKSlideRenderer.RenderCurrentViewSync ( )

Render current viewport synchronously (blocking)

Definition at line 298 of file SKSlideRenderer.cs.

299 {
300 if (!_hasSource || _stitchingPipeline == null)
301 return null;
302
303 return _stitchingPipeline.StitchViewportAsync(
304 _lastOrigin,
305 _lastResolution,
306 _lastCoordinate,
307 _lastWidth,
308 _lastHeight
309 ).Result;
310 }
async Task< SKImage > StitchViewportAsync(PointD origin, double resolution, ZCT coordinate, int viewportWidth=600, int viewportHeight=400)
Stitch tiles for a given viewport asynchronously.

◆ RenderRegion()

SKImage BioGTK.SKSlideRenderer.RenderRegion ( RectangleD region,
int level,
ZCT coordinate,
double resolution,
int pxwidth,
int pxheight )

Render a specific region synchronously (for exports, small areas)

Definition at line 284 of file SKSlideRenderer.cs.

288 {
289 if (!_hasSource || _stitchingPipeline == null)
290 return null;
291
292 return _stitchingPipeline.StitchRegion(region, level, coordinate, resolution, pxwidth, pxheight);
293 }
SKImage StitchRegion(RectangleD region, int level, ZCT coordinate, double resolution, int pxwidth, int pxheight)
Stitch a specific region synchronously (for smaller areas)

◆ SetSource() [1/2]

void BioGTK.SKSlideRenderer.SetSource ( OpenSlideGTK.OpenSlideBase openSlideSource)

Set OpenSlide source and initialize pipeline.

Definition at line 71 of file SKSlideRenderer.cs.

72 {
73 if (openSlideSource == null)
74 throw new ArgumentNullException(nameof(openSlideSource));
75
76 ClearCurrentSource();
77
78 _openSlideSource = openSlideSource;
79 _isOpenSlide = true;
80 _hasSource = true;
81
82 InitializeStitchingPipeline();
83 }

◆ SetSource() [2/2]

void BioGTK.SKSlideRenderer.SetSource ( SlideBase slideSource)

Set BioLib slide source and initialize pipeline.

Definition at line 88 of file SKSlideRenderer.cs.

89 {
90 if (slideSource == null)
91 throw new ArgumentNullException(nameof(slideSource));
92
93 ClearCurrentSource();
94
95 _slideSource = slideSource;
96 _isOpenSlide = false;
97 _hasSource = true;
98
99 InitializeStitchingPipeline();
100 }

◆ UpdateConfiguration()

void BioGTK.SKSlideRenderer.UpdateConfiguration ( int? maxCacheSizeMB = null,
int? tileSize = null,
SKSamplingOptions? sampling = null,
bool? enablePrefetch = null,
bool? enableProgressiveRendering = null )

Update renderer configuration and reinitialize if needed.

Definition at line 443 of file SKSlideRenderer.cs.

449 {
450 bool needsReinit = false;
451
452 if (maxCacheSizeMB.HasValue && maxCacheSizeMB.Value != MaxCacheSizeMB)
453 {
454 MaxCacheSizeMB = maxCacheSizeMB.Value;
455 needsReinit = true;
456 }
457
458 if (tileSize.HasValue && tileSize.Value != TileSize)
459 {
460 TileSize = tileSize.Value;
461 needsReinit = true;
462 }
463
464 // Reinitialize pipeline if structural changes were made
465 if (needsReinit && _hasSource)
466 {
467 InitializeStitchingPipeline();
468 }
469 }

◆ UpdateViewAsync()

async Task BioGTK.SKSlideRenderer.UpdateViewAsync ( PointD origin,
double resolution,
ZCT coordinate,
int width = 600,
int height = 400 )

Update the rendered view asynchronously - main entry point for rendering.

Definition at line 145 of file SKSlideRenderer.cs.

151 {
152 if (!_hasSource || _stitchingPipeline == null)
153 return;
154 /*
155 // Check if update is needed
156 if (!forceUpdate && !NeedsUpdate(origin, width, height, resolution, coordinate))
157 return;
158 */
159 // Cancel any in-progress render
160 //CancelCurrentRender();
161
162 // Acquire update lock
163 //await _updateSemaphore.WaitAsync();
164
165 try
166 {
167 IsRendering = true;
168 /*
169 // Create new cancellation token for this render
170 _renderCancellation = new CancellationTokenSource();
171 var cancellationToken = _renderCancellation.Token;
172 */
173 // Store current parameters
174 _lastOrigin = origin;
175 _lastResolution = resolution;
176 _lastCoordinate = coordinate;
177 _lastWidth = width;
178 _lastHeight = height;
179 /*
180 // Progressive rendering: render low-res preview first if enabled
181 if (_useProgressiveRendering && ShouldRenderPreview(resolution))
182 {
183 await RenderLowResPreviewAsync(origin, width, height, resolution, coordinate);
184 }
185 */
186 // Render full quality
187 await RenderFullQualityAsync(origin, resolution, coordinate, width, height);
188 }
189 catch (Exception ex)
190 {
191 Console.WriteLine($"Error during view update: {ex.Message}");
192 }
193 finally
194 {
195 IsRendering = false;
196 }
197 }

Property Documentation

◆ EnablePrefetch

bool BioGTK.SKSlideRenderer.EnablePrefetch = true
getset

Definition at line 37 of file SKSlideRenderer.cs.

37{ get; set; } = true;

◆ HasValidImage

bool BioGTK.SKSlideRenderer.HasValidImage
get

Definition at line 41 of file SKSlideRenderer.cs.

◆ IsRendering

bool BioGTK.SKSlideRenderer.IsRendering
get

Definition at line 40 of file SKSlideRenderer.cs.

40{ get; private set; }

◆ MaxCacheSizeMB

int BioGTK.SKSlideRenderer.MaxCacheSizeMB = 512
getset

Definition at line 34 of file SKSlideRenderer.cs.

34{ get; set; } = 512;

◆ Sampling

SKSamplingOptions BioGTK.SKSlideRenderer.Sampling = SKSamplingOptions.Default
getset

Definition at line 36 of file SKSlideRenderer.cs.

36{ get; set; } = SKSamplingOptions.Default;

◆ TileSize

int BioGTK.SKSlideRenderer.TileSize = 256
getset

Definition at line 35 of file SKSlideRenderer.cs.

35{ get; set; } = 256;

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