Example #1
0
        public unsafe void DecompressIntPtrToIntPtr(
            [Values(
                 PixelFormat.Format32bppArgb,
                 PixelFormat.Format24bppRgb,
                 PixelFormat.Format8bppIndexed)] PixelFormat format)
        {
            foreach (var data in TestUtils.GetTestImagesData("*.jpg"))
            {
                var dataPtr = TJUtils.CopyDataToPointer(data.Item2);

                Assert.DoesNotThrow(() =>
                {
                    _decompressor.GetImageInfo(dataPtr, (ulong)data.Item2.Length, TestUtils.ConvertPixelFormat(format), out var width, out var height, out var stride, out var decompressedBufferSize);

                    var decompressed = new byte[decompressedBufferSize];
                    fixed(byte *ptr  = decompressed)
                    {
                        _decompressor.Decompress(
                            dataPtr,
                            (ulong)data.Item2.Length,
                            (IntPtr)ptr,
                            decompressedBufferSize,
                            TestUtils.ConvertPixelFormat(format),
                            TJFlags.NONE);
                    }

                    Assert.IsTrue(decompressed.Any(b => b != 0));
                });
                TJUtils.FreePtr(dataPtr);
            }
        }
Example #2
0
 /// <summary>
 /// Creates a writeable bitmap large enough to store the provided JPEG image. This bitmap can be reused
 /// for new JPEGs of the same size.
 /// </summary>
 /// <returns>A writeable bitmap with the correct dimensions for containing preview images.</returns>
 public WriteableBitmap CreateWriteableBitmapForPreview()
 {
     using (CameraFile preview = ActiveCamera.Preview())
     {
         JpegDecoder.GetImageInfo(preview.Data, preview.Size, TJPixelFormat.BGRA, out int width, out int height, out int stride, out int bufferSize);
         WriteableBitmap bitmap = new WriteableBitmap(new PixelSize(width, height), new Vector(96, 96), PixelFormat.Bgra8888);
         return(bitmap);
     }
 }