コード例 #1
0
        public void CopyToByteBuffer_ShouldReturnByteArray_When_BufferSizeIsLargeEnough()
        {
            var imageFrame   = new ImageFrame(ImageFormat.Format.GRAY8, 10, 10);
            var normalBuffer = imageFrame.CopyToByteBuffer(100);
            var largeBuffer  = imageFrame.CopyToByteBuffer(120);

            Assert.IsEmpty(normalBuffer.Where((x, i) => x != largeBuffer[i]));
        }
コード例 #2
0
        public void SetToZero_ShouldSetZeroToAllBytes()
        {
            using (var imageFrame = new ImageFrame(ImageFormat.Format.GRAY8, 10, 10)) {
                var origBytes = imageFrame.CopyToByteBuffer(100);
                Assert.False(origBytes.All((x) => x == 0));

                imageFrame.SetToZero();
                var bytes = imageFrame.CopyToByteBuffer(100);
                Assert.True(bytes.All((x) => x == 0));
            }
        }
コード例 #3
0
        public void Ctor_ShouldInstantiateImageFrame_When_CalledWithPixelData()
        {
            var pixelData = new NativeArray <byte>(32, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            var srcBytes  = new byte[] {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
                16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
            };

            pixelData.CopyFrom(srcBytes);

            using (var imageFrame = new ImageFrame(ImageFormat.Format.SBGRA, 4, 2, 16, pixelData)) {
                Assert.AreEqual(imageFrame.Width(), 4);
                Assert.AreEqual(imageFrame.Height(), 2);
                Assert.False(imageFrame.IsEmpty());

                var bytes = imageFrame.CopyToByteBuffer(32);
                Assert.IsEmpty(bytes.Where((x, i) => x != srcBytes[i]));
            }
        }
コード例 #4
0
        public void CopyToByteBuffer_ShouldThrowException_When_BufferSizeIsTooSmall()
        {
            var imageFrame = new ImageFrame(ImageFormat.Format.GRAY8, 10, 10);

            Assert.Throws <MediaPipeException>(() => { imageFrame.CopyToByteBuffer(99); });
        }