Beispiel #1
0
        private void buttonRecode_Click(object sender, EventArgs e)
        {
            if (inputImage == null)
            {
                return;
            }
            Cursor.Current = Cursors.WaitCursor;

            pictureBox1.Image = inputImage;
            resetImage(ref outputImage);
            resetImage(ref diffImage);

            Stopwatch sw = new Stopwatch();

            sw.Start();

            // 1. image encoding
            TRCodec    codec   = new TRCodec();
            FileStream fs      = new FileStream("code.bin", FileMode.Create);
            float      quality = (float)numericQuality.Value;

            codec.EncodeImage(inputImage, fs, quality);

            // 2. code size
            fs.Flush();
            long fileSize = fs.Position;

            sw.Stop();
            labelElapsed.Text = string.Format(CultureInfo.InvariantCulture, "Enc: {0:f3}s, {1}b ({2}x{3})",
                                              1.0e-3 * sw.ElapsedMilliseconds, fileSize,
                                              inputImage.Width, inputImage.Height);

            // 3. image decoding
            fs.Seek(0L, SeekOrigin.Begin);
            outputImage = codec.DecodeImage(fs);
            fs.Close();

            // 5. comparison
            if (outputImage != null)
            {
                diffImage = new Bitmap(inputImage.Width, inputImage.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                float RMSE = Draw.ImageRMSE(inputImage, outputImage, diffImage);
                labelResult.Text  = string.Format(CultureInfo.InvariantCulture, "RMSE: {0:f2}", RMSE);
                pictureBox1.Image = checkDiff.Checked ? diffImage : outputImage;
#if LOG
                // log results:
                Util.LogFormat("Recoding finished - RMSE: {0:f2}, codeSize: {1}, total: {2} (image res: {3}x{4})",
                               RMSE, fileSize, (totalLen += fileSize),
                               inputImage.Width, inputImage.Height);
#endif
            }
            else
            {
                labelResult.Text  = "File error";
                pictureBox1.Image = null;
                diffImage         = null;
            }

            Cursor.Current = Cursors.Default;
        }
Beispiel #2
0
        public Form1()
        {
            InitializeComponent();

            string name;

            TRCodec.InitParams(out name);
            Text += " (" + rev + ") '" + name + '\'';
        }
Beispiel #3
0
        private void buttonRecode_Click( object sender, EventArgs e )
        {
            if ( inputImage == null ) return;
              Cursor.Current = Cursors.WaitCursor;

              Stopwatch sw = new Stopwatch();
              sw.Start();

              // 1. image encoding
              TRCodec codec = new TRCodec();
              FileStream fs = new FileStream( "code.bin", FileMode.Create );
              codec.EncodeImage( inputImage, fs );

              // 2. code size
              fs.Flush();
              long fileSize = fs.Position;

              sw.Stop();
              labelElapsed.Text = String.Format( "Enc: {0:f}s, {1}kb", 1.0e-3 * sw.ElapsedMilliseconds, (fileSize + 1023L) >> 10 );

              // 3. image decoding
              fs.Seek( 0L, SeekOrigin.Begin );
              outputImage = codec.DecodeImage( fs );
              fs.Close();

              // 5. comparison
              if ( outputImage != null )
              {
            diffImage = new Bitmap( inputImage.Width, inputImage.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb );
            float RMSE = Draw.ImageRMSE( inputImage, outputImage, diffImage );
            labelResult.Text = String.Format( "RMSE: {0}", RMSE );
            pictureBox1.Image = checkDiff.Checked ? diffImage : outputImage;
              }
              else
              {
            labelResult.Text = "File error";
            pictureBox1.Image = null;
            outputImage = diffImage = null;
              }

              Cursor.Current = Cursors.Default;
        }