Ejemplo n.º 1
0
        /// <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));
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        private unsafe void ReadAssociatedImageInternal(string name, void *pointer)
        {
            var handle = EnsureNotDisposed();

            OpenSlideInterop.ReadAssociatedImage(handle, name, pointer);
            ThrowHelper.CheckAndThrowError(handle);
        }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        internal static void CheckAndThrowError(OpenSlideImageSafeHandle osr)
        {
            string message = OpenSlideInterop.GetError(osr);

            if (message != null)
            {
                ThrowOpenSlideException(message);
            }
        }
Ejemplo n.º 7
0
        /// <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);
        }
Ejemplo n.º 8
0
        /// <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));
        }
Ejemplo n.º 9
0
        public string this[string name]
        {
            get
            {
                EnsureNotDisposed();

                string value = OpenSlideInterop.GetPropertyValue(_handle, name);
                ThrowHelper.CheckAndThrowError(_handle);
                return(value);
            }
        }
Ejemplo n.º 10
0
 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);
     }
 }
Ejemplo n.º 11
0
        /// <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);
        }
Ejemplo n.º 12
0
        /// <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);
        }
Ejemplo n.º 13
0
        /// <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));
        }
Ejemplo n.º 14
0
        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());;
        }
Ejemplo n.º 15
0
 internal static bool TryCheckError(OpenSlideImageSafeHandle osr, out string message)
 {
     message = OpenSlideInterop.GetError(osr);
     return(message == null);
 }
Ejemplo n.º 16
0
 /// <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));
 }
Ejemplo n.º 17
0
        /// <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));
        }
Ejemplo n.º 18
0
 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);
 }
Ejemplo n.º 19
0
 private unsafe void ReadAssociatedImageInternal(string name, void *pointer)
 {
     OpenSlideInterop.ReadAssociatedImage(_handle, name, pointer);
     ThrowHelper.CheckAndThrowError(_handle);
 }