public void Decompress(IntPtr dataPtr, uint length, IntPtr outputPtr, int outputLength, PixelFormat pixelFormat) { int width; int height; int stride; _decompressor.Decompress(dataPtr, length, outputPtr, outputLength, ConvertPixelFormat(pixelFormat), TJFlags.NONE, out width, out height, out stride); }
public void DecompressByteArray( [Values( PixelFormat.Format32bppArgb, PixelFormat.Format24bppRgb, PixelFormat.Format8bppIndexed)] PixelFormat format) { foreach (var data in TestUtils.GetTestImagesData("*.jpg")) { Assert.DoesNotThrow(() => { var result = _decompressor.Decompress(data.Item2, TestUtils.ConvertPixelFormat(format), TJFlags.NONE); Assert.NotNull(result); }); } }
/// <summary> /// Updates the preview image with a new preview file from the camera. /// </summary> /// <param name="PreviewBitmap">The bitmap that acts as the image source for the preview display</param> public void UpdatePreview(WriteableBitmap PreviewBitmap) { using (CameraFile preview = ActiveCamera.Preview()) using (ILockedFramebuffer bitmapBuffer = PreviewBitmap.Lock()) { int bitmapBufferSize = bitmapBuffer.Size.Width * bitmapBuffer.Size.Height * 4; JpegDecoder.Decompress(preview.Data, preview.Size, bitmapBuffer.Address, bitmapBufferSize, TJPixelFormat.BGRA, TJFlags.None, out _, out _, out _); } }
public void DecompressByteArray( [Values( PixelFormat.Format32bppArgb, PixelFormat.Format24bppRgb, PixelFormat.Format8bppIndexed)] PixelFormat format) { foreach (var data in TestUtils.GetTestImagesData("*.jpg")) { Assert.DoesNotThrow(() => { var result = _decompressor.Decompress(data.Item2, format, TJFlags.NONE); Assert.NotNull(result); var file = Path.Combine(OutDirectory, $"{Path.GetFileNameWithoutExtension(data.Item1)}_{format}.bmp"); result.Save(file); }); } }
public override double DecodeInBgr(List <byte[]> JList, bool debugInfoIsOn = false) { Console.WriteLine(); Console.WriteLine("Converting by libJPEG Turbo to BMP.."); double avgtime = 0; double delta; int i = 0; var decompressor = new TJDecompressor(); foreach (byte[] bitmap in JList) { MemoryStream stream = new MemoryStream(); byte[] output = new byte[] { }; int width, height, stride; DateTime start = DateTime.Now; output = decompressor.Decompress(output, TJPixelFormats.TJPF_RGB, TJFlags.NONE, out width, out height, out stride); DateTime finish = DateTime.Now; delta = (finish - start).TotalMilliseconds; avgtime += delta; try { using (FileStream file = new FileStream("output\\libjpeg-turbo" + i.ToString() + ".bmp", FileMode.Create, System.IO.FileAccess.Write)) { file.Write(output, 0, output.Length); } if (debugInfoIsOn) { Console.WriteLine("Done converting image {0}. Size: {1} x {2}. Time: {3} ms", i, width, height, delta); } } catch (Exception exc) { Console.WriteLine("Error while converint: {0}", exc); } i++; } Console.WriteLine("..done."); return(avgtime); }
// Start is called before the first frame update void Start() { TJDecompressor decompressor = new TJDecompressor(); TJCompressor compressor = new TJCompressor(); byte[] compressedImage = File.ReadAllBytes("Assets/Images/image.jpg"); float startTime = Time.realtimeSinceStartup; DecompressedImage decompressedImage = decompressor.Decompress(compressedImage, TJPixelFormat.RGBA, TJFlags.None); Debug.Log("Image decompressed. Execution time : " + (Time.realtimeSinceStartup - startTime).ToString() + " secondes."); startTime = Time.realtimeSinceStartup; byte[] recompressedImage = compressor.Compress(decompressedImage.Data, decompressedImage.Stride, decompressedImage.Width, decompressedImage.Height, decompressedImage.PixelFormat, TJSubsamplingOption.Chrominance420, 92, TJFlags.None); Debug.Log("Image recompressed. Execution time : " + (Time.realtimeSinceStartup - startTime).ToString() + " secondes."); File.WriteAllBytes("Assets/Images/recompressedImage.jpg", recompressedImage); Debug.Log("Recompressed image saved at : Assets/Images/recompressedImage.jpg"); ; }