コード例 #1
0
        /// <inheritdoc/>
        public void DecodeFromStream(Stream stream, DepthImage depthImage)
        {
            var          decoder      = BitmapDecoder.Create(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
            BitmapSource bitmapSource = decoder.Frames[0];

            bitmapSource.CopyPixels(Int32Rect.Empty, depthImage.ImageData, depthImage.Stride * depthImage.Height, depthImage.Stride);
        }
コード例 #2
0
ファイル: EncodedDepthImage.cs プロジェクト: yusharth/psi
        /// <summary>
        /// Decodes the depth image using a specified decoder.
        /// </summary>
        /// <param name="depthImageDecoder">The depth image decoder to use.</param>
        /// <returns>A new, corresponding decoded depth image.</returns>
        public DepthImage Decode(IDepthImageFromStreamDecoder depthImageDecoder)
        {
            var depthImage = new DepthImage(this.Width, this.Height);

            depthImage.DecodeFrom(this, depthImageDecoder);
            return(depthImage);
        }
コード例 #3
0
        /// <summary>
        /// Decodes the depth image using a specified decoder.
        /// </summary>
        /// <param name="depthImageDecoder">The depth image decoder to use.</param>
        /// <returns>A new, corresponding decoded depth image.</returns>
        public DepthImage Decode(IDepthImageFromStreamDecoder depthImageDecoder)
        {
            var depthImage = new DepthImage(this.Width, this.Height, this.DepthValueSemantics, this.DepthValueToMetersScaleFactor);

            depthImage.DecodeFrom(this, depthImageDecoder);
            return(depthImage);
        }
コード例 #4
0
        /// <summary>
        /// Copies the image into a target depth image of the same size.
        /// </summary>
        /// <param name="target">Target depth image to copy this image to.</param>
        /// <remarks><para>The method copies the current image into the specified depth image.
        /// The size of the images must be the same, and the image must have a <see cref="PixelFormat.Gray_16bpp"/> pixel format.</para></remarks>
        public void CopyTo(DepthImage target)
        {
            if (this.PixelFormat != PixelFormat.Gray_16bpp)
            {
                throw new InvalidOperationException($"The image must have the {nameof(PixelFormat.Gray_16bpp)} pixel format in order to copy it to a {nameof(DepthImage)}.");
            }

            this.CopyTo(target.ImageData, target.Width, target.Height, target.Stride, target.PixelFormat);
        }
コード例 #5
0
ファイル: DepthImageCompressor.cs プロジェクト: mwstiber/psi
        /// <inheritdoc/>
        public void Deserialize(BufferReader reader, ref DepthImage depthImage, SerializationContext context)
        {
            Shared <EncodedDepthImage> sharedEncodedDepthImage = null;

            Serializer.Deserialize(reader, ref sharedEncodedDepthImage, context);
            using var sharedDepthImage = DepthImagePool.GetOrCreate(sharedEncodedDepthImage.Resource.Width, sharedEncodedDepthImage.Resource.Height);
            sharedDepthImage.Resource.DecodeFrom(sharedEncodedDepthImage.Resource, this.decoder);
            depthImage = sharedDepthImage.Resource.DeepClone();
            sharedEncodedDepthImage.Dispose();
        }
コード例 #6
0
ファイル: EncodedDepthImage.cs プロジェクト: yusharth/psi
        /// <summary>
        /// Encodes a specified depth image with a specified encoder into the current encoded image.
        /// </summary>
        /// <param name="depthImage">The depth image to encode.</param>
        /// <param name="depthImageEncoder">The depth image encoder to use.</param>
        /// <remarks>The depth image width, height and pixel format must match. The method should not be called concurrently.</remarks>
        public void EncodeFrom(DepthImage depthImage, IDepthImageToStreamEncoder depthImageEncoder)
        {
            if (depthImage.Width != this.Width || depthImage.Height != this.Height || depthImage.PixelFormat != this.PixelFormat)
            {
                throw new InvalidOperationException("Cannot encode from an image that has a different width, height, or pixel format.");
            }

            this.stream.Position = 0;
            depthImageEncoder.EncodeToStream(depthImage, this.stream);
        }
コード例 #7
0
ファイル: DepthImageCompressor.cs プロジェクト: yusharth/psi
 /// <inheritdoc/>
 public void Serialize(BufferWriter writer, DepthImage depthImage, SerializationContext context)
 {
     if (this.encoder != null)
     {
         using var sharedEncodedDepthImage = EncodedDepthImagePool.GetOrCreate(depthImage.Width, depthImage.Height);
         sharedEncodedDepthImage.Resource.EncodeFrom(depthImage, this.encoder);
         Serializer.Serialize(writer, sharedEncodedDepthImage, context);
     }
     else
     {
         Serializer.Serialize(writer, depthImage, context);
     }
 }
コード例 #8
0
        /// <summary>
        /// Copies the depth image into a target depth image of the same size.
        /// </summary>
        /// <param name="target">Target depth image to copy this depth image to.</param>
        /// <remarks><para>The method copies the current depth image into the specified depth image.
        /// The size of the images must be the same.</para></remarks>
        public void CopyTo(DepthImage target)
        {
            if (this.depthValueSemantics != target.depthValueSemantics)
            {
                throw new InvalidOperationException("Destination image has a different depth value semantics.");
            }

            if (this.depthValueToMetersScaleFactor != target.depthValueToMetersScaleFactor)
            {
                throw new InvalidOperationException("Destination image has a different depth value scale factor.");
            }

            this.CopyTo(target.ImageData, target.Width, target.Height, target.Stride, target.PixelFormat);
        }
コード例 #9
0
        /// <summary>
        /// Encodes a specified depth image with a specified encoder into the current encoded image.
        /// </summary>
        /// <param name="depthImage">The depth image to encode.</param>
        /// <param name="depthImageEncoder">The depth image encoder to use.</param>
        /// <remarks>The depth image width, height and pixel format must match. The method should not be called concurrently.</remarks>
        public void EncodeFrom(DepthImage depthImage, IDepthImageToStreamEncoder depthImageEncoder)
        {
            if (depthImage.Width != this.Width ||
                depthImage.Height != this.Height ||
                depthImage.PixelFormat != this.PixelFormat ||
                depthImage.DepthValueSemantics != this.DepthValueSemantics ||
                depthImage.DepthValueToMetersScaleFactor != this.DepthValueToMetersScaleFactor)
            {
                throw new InvalidOperationException("Cannot encode from an image that has a different width, height, pixel format, depth value semantics, or depth value scale factor.");
            }

            this.stream.Position = 0;
            depthImageEncoder.EncodeToStream(depthImage, this.stream);
        }
コード例 #10
0
        /// <inheritdoc/>
        public void EncodeToStream(DepthImage depthImage, Stream stream)
        {
            var encoder      = new TiffBitmapEncoder();
            var bitmapSource = BitmapSource.Create(
                depthImage.Width,
                depthImage.Height,
                96,
                96,
                depthImage.PixelFormat.ToWindowsMediaPixelFormat(),
                null,
                depthImage.ImageData,
                depthImage.Stride * depthImage.Height,
                depthImage.Stride);

            encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
            encoder.Save(stream);
        }
コード例 #11
0
ファイル: DepthImage.cs プロジェクト: annelo-msft/psi
        /// <summary>
        /// Create a new <see cref="DepthImage"/> from a specified bitmap.
        /// </summary>
        /// <param name="bitmap">A bitmap to create the depth image from.</param>
        /// <returns>A new depth image, which contains a copy of the specified bitmap.</returns>
        public static DepthImage CreateFrom(Bitmap bitmap)
        {
            CheckPixelFormat(bitmap.PixelFormat);

            DepthImage depthImage = null;
            BitmapData sourceData = bitmap.LockBits(
                new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                ImageLockMode.ReadOnly,
                bitmap.PixelFormat);

            try
            {
                depthImage = new DepthImage(sourceData, true);
            }
            finally
            {
                bitmap.UnlockBits(sourceData);
            }

            return(depthImage);
        }
コード例 #12
0
        /// <summary>
        /// Create a new <see cref="DepthImage"/> from a specified bitmap.
        /// </summary>
        /// <param name="bitmap">A bitmap to create the depth image from.</param>
        /// <param name="depthValueSemantics">Optional depth value semantics.</param>
        /// <param name="depthValueToMetersScaleFactor">Optional scale factor to convert from depth values to meters.</param>
        /// <returns>A new depth image, which contains a copy of the specified bitmap.</returns>
        public static DepthImage CreateFrom(Bitmap bitmap, DepthValueSemantics depthValueSemantics = DepthValueSemantics.DistanceToPlane, double depthValueToMetersScaleFactor = 0.001)
        {
            CheckPixelFormat(bitmap.PixelFormat);

            DepthImage depthImage = null;
            BitmapData sourceData = bitmap.LockBits(
                new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                ImageLockMode.ReadOnly,
                bitmap.PixelFormat);

            try
            {
                depthImage = new DepthImage(sourceData, depthValueSemantics, depthValueToMetersScaleFactor, true);
            }
            finally
            {
                bitmap.UnlockBits(sourceData);
            }

            return(depthImage);
        }
コード例 #13
0
ファイル: DepthImage.cs プロジェクト: annelo-msft/psi
 /// <summary>
 /// Copies the depth image into a target depth image of the same size.
 /// </summary>
 /// <param name="target">Target depth image to copy this depth image to.</param>
 /// <remarks><para>The method copies the current depth image into the specified depth image.
 /// The size of the images must be the same.</para></remarks>
 public void CopyTo(DepthImage target)
 {
     this.CopyTo(target.ImageData, target.Width, target.Height, target.Stride, target.PixelFormat);
 }
コード例 #14
0
ファイル: DepthImage.cs プロジェクト: annelo-msft/psi
 /// <summary>
 /// Copies the depth image from a specified source depth image of the same size.
 /// </summary>
 /// <param name="source">Source depth image to copy the depth image from.</param>
 /// <remarks><para>The method copies the current depth image from the specified source depth image.
 /// The size of the images must be the same.</para></remarks>
 public void CopyFrom(DepthImage source)
 {
     source.CopyTo(this);
 }
コード例 #15
0
        /// <inheritdoc/>
        public void DecodeFromStream(Stream stream, DepthImage depthImage)
        {
            var decoded = SKBitmap.Decode(stream);

            Marshal.Copy(decoded.Bytes, 0, depthImage.ImageData, decoded.ByteCount);
        }
コード例 #16
0
 /// <inheritdoc/>
 public void EncodeToStream(DepthImage depthImage, Stream stream)
 {
     depthImage.AsSKImage().Encode(SKEncodedImageFormat.Png, 100).SaveTo(stream);
 }