/// <summary> /// Gets the property value. /// </summary> /// <param name="name">The name of the property.</param> /// <param name="value">The value of the property.</param> /// <returns>True if the property of the specified name exists. Otherwise, false.</returns> public bool TryGetProperty(string name, [NotNullWhen(true)] out string?value) { var handle = EnsureNotDisposed(); value = OpenSlideInterop.GetPropertyValue(handle, name); return(!(value is null)); }
private unsafe void ReadRegionInternal(int level, long x, long y, long width, long height, void *pointer) { var handle = EnsureNotDisposed(); OpenSlideInterop.ReadRegion(handle, pointer, x, y, level, width, height); ThrowHelper.CheckAndThrowError(handle); }
private unsafe void ReadAssociatedImageInternal(string name, void *pointer) { var handle = EnsureNotDisposed(); OpenSlideInterop.ReadAssociatedImage(handle, name, pointer); ThrowHelper.CheckAndThrowError(handle); }
/// <summary> /// Gets the property value. /// </summary> /// <param name="name">The name of the property.</param> /// <param name="value">The value of the property.</param> /// <returns>True if the property of the specified name exists. Otherwise, false.</returns> public bool TryGetProperty(string name, out string value) { EnsureNotDisposed(); value = OpenSlideInterop.GetPropertyValue(_handle, name); return(value != null); }
/// <summary> /// Get the array of property names. /// </summary> /// <returns>The array of property names</returns> public IReadOnlyList <string> GetAllPropertyNames() { EnsureNotDisposed(); string[] properties = OpenSlideInterop.GetPropertyNames(_handle); ThrowHelper.CheckAndThrowError(_handle); return(properties); }
internal static void CheckAndThrowError(OpenSlideImageSafeHandle osr) { string message = OpenSlideInterop.GetError(osr); if (message != null) { ThrowOpenSlideException(message); } }
/// <summary> /// Get the array of names of associated images. /// </summary> /// <returns>The array of names of associated images.</returns> public IReadOnlyCollection <string> GetAllAssociatedImageNames() { EnsureNotDisposed(); var associatedImages = OpenSlideInterop.GetAssociatedImageNames(_handle); ThrowHelper.CheckAndThrowError(_handle); return(associatedImages); }
/// <summary> /// Get a (width, height) tuple for level k of the slide. /// </summary> /// <param name="level">the k level</param> /// <returns>A (width, height) tuple for level k of the slide.</returns> /// <exception cref="OpenSlideException">An error occurred when calling reading the slide or the <see cref="OpenSlideImage"/> was already in the error state.</exception> public ImageDimensions GetLevelDimensions(int level) { EnsureNotDisposed(); OpenSlideInterop.GetLevelDimensions(_handle, level, out long w, out long h); if (w == -1 || h == -1) { ThrowHelper.CheckAndThrowError(_handle); } return(new ImageDimensions(w, h)); }
public string this[string name] { get { EnsureNotDisposed(); string value = OpenSlideInterop.GetPropertyValue(_handle, name); ThrowHelper.CheckAndThrowError(_handle); return(value); } }
private void EnsureDimensionsCached() { if (_dimensionsCache == null) { OpenSlideInterop.GetLevel0Dimensions(_handle, out long w, out long h); if (w == -1 || h == -1) { ThrowHelper.CheckAndThrowError(_handle); } _dimensionsCache = new ImageDimensions(w, h); } }
/// <summary> /// Get the downsample factor for level k of the slide. /// </summary> /// <param name="level">the k level</param> /// <returns>The downsample factor for level k of the slide.</returns> /// <exception cref="OpenSlideException">An error occurred when calling reading the slide or the <see cref="OpenSlideImage"/> was already in the error state.</exception> public double GetLevelDownsample(int level) { EnsureNotDisposed(); double result = OpenSlideInterop.GetLevelDownsample(_handle, level); if (result == -1.0d) { ThrowHelper.CheckAndThrowError(_handle); } return(result); }
/// <summary> /// Gets the dimensions of the associated image. /// </summary> /// <param name="name">The name of the associated image.</param> /// <param name="dimensions">The dimensions of the associated image.</param> /// <returns>True if the associated image of the specified name exists. Otherwise, false.</returns> public bool TryGetAssociatedImageDimensions(string name, out ImageDimensions dimensions) { EnsureNotDisposed(); OpenSlideInterop.GetAssociatedImageDimensions(_handle, name, out long w, out long h); if (w != -1 && h != -1) { dimensions = new ImageDimensions(w, h); return(true); } dimensions = default; return(false); }
/// <summary> /// Open a whole slide image. /// This function can be expensive; avoid calling it unnecessarily. For example, a tile server should not call Open() on every tile request. Instead, it should maintain a cache of <see cref="OpenSlideImage"/> objects and reuse them when possible. /// </summary> /// <param name="filename">The filename to open.</param> /// <returns>The <see cref="OpenSlideImage"/> object.</returns> /// <exception cref="OpenSlideUnsupportedFormatException">The file format can not be recognized.</exception> /// <exception cref="OpenSlideException">The file format is recognized, but an error occurred when opening the file.</exception> public static OpenSlideImage Open(string filename) { // Open file using OpenSlide var handle = OpenSlideInterop.Open(filename); if (handle.IsInvalid) { throw new OpenSlideUnsupportedFormatException(); } if (!ThrowHelper.TryCheckError(handle, out string errMsg)) { handle.Dispose(); throw new OpenSlideException(errMsg); } return(new OpenSlideImage(handle)); }
private ImageDimensions EnsureDimensionsCached() { var handle = EnsureNotDisposed(); if (_dimensionsCache == null) { OpenSlideInterop.GetLevel0Dimensions(handle, out long w, out long h); if (w == -1 || h == -1) { ThrowHelper.CheckAndThrowError(handle); } var dimensions = new ImageDimensions(w, h); _dimensionsCache = dimensions; return(dimensions); } return(_dimensionsCache.GetValueOrDefault());; }
internal static bool TryCheckError(OpenSlideImageSafeHandle osr, out string message) { message = OpenSlideInterop.GetError(osr); return(message == null); }
/// <summary> /// Return a string describing the format vendor of the specified file. This string is also accessible via the PROPERTY_NAME_VENDOR property. /// If the file is not recognized, return null. /// </summary> /// <param name="filename">the file to examine</param> /// <returns>the format vendor of the specified file.</returns> public static string DetectFormat(string filename) { return(OpenSlideInterop.DetectVendor(filename)); }
/// <summary> /// Get the best level to use for displaying the given downsample. /// </summary> /// <param name="downsample">The downsample factor.</param> /// <returns>The level identifier, or -1 if an error occurred.</returns> public int GetBestLevelForDownsample(double downsample) { EnsureNotDisposed(); return(OpenSlideInterop.GetBestLevelForDownsample(_handle, downsample)); }
private unsafe void ReadRegionInternal(int level, long x, long y, long width, long height, void *pointer) { OpenSlideInterop.ReadRegion(_handle, pointer, x, y, level, width, height); ThrowHelper.CheckAndThrowError(_handle); }
private unsafe void ReadAssociatedImageInternal(string name, void *pointer) { OpenSlideInterop.ReadAssociatedImage(_handle, name, pointer); ThrowHelper.CheckAndThrowError(_handle); }