Exemplo n.º 1
0
        /// <summary>
        /// This API usage is optimized for multiple runs of the same image size, by reusing the byte arrays instead of allocating new ones for every operation.
        /// </summary>
        private static void benchTJOptimized()
        {
            byte[] data = File.ReadAllBytes(inputFilePath);
            byte[] recompressed;
            int    recompressedSize = 0;

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            using (TJDecompressor decomp = new TJDecompressor(data))
            {
                // Optimize by pre-allocating the buffers and re-using them.
                byte[] rawImg = new byte[decomp.getWidth() * decomp.getHeight() * TJ.getPixelSize(PixelFormat.RGB)];
                recompressed = new byte[TJ.bufSize(decomp.getWidth(), decomp.getHeight(), decomp.getSubsamp())];
                using (TJCompressor comp = new TJCompressor(rawImg, decomp.getWidth(), decomp.getHeight()))
                {
                    comp.setJPEGQuality(jpegQuality);
                    for (int i = 0; i < numIterations; i++)
                    {
                        decomp.decompress(rawImg);
                        comp.compress(ref recompressed, Flag.NONE);
                    }
                    recompressedSize = comp.getCompressedSize();
                }
            }
            sw.Stop();
            PrintBenchmarkResult("turbojpegCLI optimized", sw.ElapsedMilliseconds);
            using (FileStream fs = new FileStream("out-libjpeg-turbo-optimized.jpg", FileMode.Create))
            {
                fs.Write(recompressed, 0, recompressedSize);
            }
        }
 public void SetUp()
 {
     _decompressor = new TJDecompressor();
     if (Directory.Exists(OutDirectory))
     {
         Directory.Delete(OutDirectory, true);
     }
     Directory.CreateDirectory(OutDirectory);
 }
 public void SetUp()
 {
     _decompressor = new TJDecompressor();
     if (Directory.Exists(OutDirectory))
     {
         Directory.Delete(OutDirectory, true);
     }
     Directory.CreateDirectory(OutDirectory);
 }
Exemplo n.º 4
0
 public JpegDiffVideoEncoder()
 {
     decoder       = new JpegDiffVideoDecoder();
     decomp        = new TJDecompressor();
     comp          = new TJCompressor();
     decoderThread = new Thread(decoderThreadLoop);
     decoderThread.IsBackground = true;
     decoderThread.Name         = "JpegDiffVideoEncoder Decoder Thread";
     decoderThread.Start();
 }
Exemplo n.º 5
0
        public TJDecompressorTests()
        {
            this.decompressor = new TJDecompressor();
            if (Directory.Exists(this.OutDirectory))
            {
                Directory.Delete(this.OutDirectory, true);
            }

            Directory.CreateDirectory(this.OutDirectory);
        }
Exemplo n.º 6
0
 public void SetUp()
 {
     TJInitializer.Initialize(logger: Console.WriteLine);
     _decompressor = new TJDecompressor();
     if (Directory.Exists(OutDirectory))
     {
         Directory.Delete(OutDirectory, true);
     }
     Directory.CreateDirectory(OutDirectory);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Creates a new <see cref="CameraManager"/> instance.
 /// </summary>
 /// <param name="Logger">A logger for capturing status and debug messages</param>
 public CameraManager(Logger Logger)
 {
     this.Logger = Logger;
     JpegDecoder = new TJDecompressor();
     Context     = new Context();
     Context.StatusNotification += Context_StatusNotification;
     Context.ProgressStarted    += Context_ProgressStarted;
     Context.ProgressUpdated    += Context_ProgressUpdated;
     Context.ProgressStopped    += Context_ProgressStopped;
     Context.MessageReceived    += Context_MessageReceived;
     Context.IdleNotification   += Context_IdleNotification;
     Context.ErrorOccurred      += Context_ErrorOccurred;
 }
        public TurboJpgImageCompression(bool decompress)
        {
            _decompress = decompress;

            if (decompress)
            {
                _decompressor = new TJDecompressor();
            }
            else
            {
                _compressor = new TJCompressor();
            }
        }
        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);
        }
Exemplo n.º 10
0
    // 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");
        ;
    }
Exemplo n.º 11
0
 private static void benchTJSimpleAPI()
 {
     byte[] data                     = File.ReadAllBytes(inputFilePath);
     byte[] rawImg                   = null;
     byte[] recompressed             = null;
     System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
     sw.Start();
     using (TJDecompressor decomp = new TJDecompressor(data))
     {
         using (TJCompressor comp = new TJCompressor())
         {
             comp.setJPEGQuality(jpegQuality);
             for (int i = 0; i < numIterations; i++)
             {
                 rawImg = decomp.decompress();
                 comp.setSourceImage(rawImg, decomp.getWidth(), decomp.getHeight());
                 recompressed = comp.compressToExactSize();
             }
         }
     }
     sw.Stop();
     PrintBenchmarkResult("turbojpegCLI simple API", sw.ElapsedMilliseconds);
     File.WriteAllBytes("out-libjpeg-turbo.jpg", recompressed);
 }
Exemplo n.º 12
0
 public JpegDiffVideoDecoder()
 {
     decomp = new TJDecompressor();
 }
Exemplo n.º 13
0
        public static void DoThing()
        {
            try {
                //Console.WriteLine("DoThing");

                int pos = 0;

                bool isTop      = false;
                bool iscomplete = false;
                int  lastSeq    = 0;
                int  lastSub    = 0;

                bool loop = true;
                while (loop)
                {
                    int length = udpClient.Client.ReceiveFrom(data, ref udpEP);

                    if (data[3] == 0x00)
                    {
                        lastSeq = data[0];
                        lastSub = -1;
                        pos     = 0;
                    }

                    if (data[0] == lastSeq && lastSub + 1 == data[3])
                    {
                        lastSub = data[3];

                        if (data[1] == 0x01 || data[1] == 0x11)
                        {
                            isTop = true;
                        }
                        else if (isTop)
                        {
                            isTop = false; //LIES!
                        }
                        //Need to valid that the entire UDP stream is received before proceeding... Otherwise TDJ crashes.
                        //Console.WriteLine("{0:x2} {1:x2} {2:x2} {3:x2}", data[0], data[1], data[2], data[3]);

                        if (pos + length > jpegImage.Length)
                        {
                            loop = false;
                            pos  = 0;
                        }
                        else
                        {
                            Array.Copy(data, 4, jpegImage, pos, length - 4);
                            pos += length - 4;

                            if (data[1] >= 0x10)
                            {
                                iscomplete = true;
                                loop       = false;
                                //Console.WriteLine("S");
                            }
                        }
                    }
                    else
                    {
                        loop = false;
                        pos  = 0;
                        //Console.WriteLine("FB");
                    }
                }

                if (iscomplete)
                {
                    byte[] decom;
                    tjd = new TJDecompressor(jpegImage);

                    if (isTop)
                    {
                        decom = new byte[240 * 400 * TJ.getPixelSize(turbojpegCLI.PixelFormat.RGB)];
                        tjd.decompress(decom, turbojpegCLI.PixelFormat.RGB, Flag.NONE);

                        if (FormMain.viewerTop != null)
                        {
                            FormMain.viewerTop.LoadTexture(400, 240, decom);
                        }
                    }
                    else
                    {
                        decom = new byte[240 * 320 * TJ.getPixelSize(turbojpegCLI.PixelFormat.RGB)];
                        tjd.decompress(decom, turbojpegCLI.PixelFormat.RGB, Flag.NONE);

                        if (FormMain.viewerTop != null)
                        {
                            FormMain.viewerBottom.LoadTexture(320, 240, decom);
                        }
                    }

                    tjd.Dispose();
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.ToString());
            }
        }