Exemplo n.º 1
0
        public Form1()
        {
            InitializeComponent();

            BWCodec.InitParams(out name);
            Text += " (" + rev + ") '" + name + '\'';
        }
Exemplo n.º 2
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
            BWCodec    codec = new BWCodec();
            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(CultureInfo.InvariantCulture, "Enc: {0:f2}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);
                long diffHash = Draw.ImageCompareBW(inputImage, outputImage, diffImage);
                labelResult.Text  = string.Format("Errs: {0}", diffHash);
                pictureBox1.Image = checkDiff.Checked ? diffImage : outputImage;
#if LOG
                // log results:
                Util.LogFormat("Recoding finished - err: {0}, codeSize: {1}, total: {2} (image '{3}', res: {4}x{5}), name: '{6}'",
                               diffHash, fileSize, (totalLen += fileSize),
                               fileName, inputImage.Width, inputImage.Height, name);
#endif
            }
            else
            {
                labelResult.Text  = "File error";
                pictureBox1.Image = null;
                diffImage         = null;
            }

            Cursor.Current = Cursors.Default;
        }
Exemplo n.º 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
              BWCodec codec = new BWCodec();
              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 );
            long diffHash = Draw.ImageCompareBW( inputImage, outputImage, diffImage );
            labelResult.Text = String.Format( "Errs: {0}", diffHash );
            pictureBox1.Image = checkDiff.Checked ? diffImage : outputImage;
              }
              else
              {
            labelResult.Text = "File error";
            pictureBox1.Image = null;
            outputImage = diffImage = null;
              }

              dominantColorLabel.Text = (codec.ComputeDominantColor(inputImage) == 0) ? "black" : "white";

              Cursor.Current = Cursors.Default;
        }