private static MyTiff decodeSubsample(MyCompressTiff myct, MyDeal.ProgressMonitor monitor)
        {
            MyTiff decodeTiff = new MyTiff();
            Bitmap baseImg    = null;

            for (int i = 0; i < myct.baseImg.Count; i++)
            {
                if (myct.baseImg.ElementAt(i) != null)
                {
                    decodeTiff.views.Add(baseImg = new Bitmap(myct.baseImg.ElementAt(i)));
                }
                else
                {
                    Bitmap left  = (Bitmap)decodeTiff.views.Last();
                    Bitmap right = new Bitmap(myct.baseImg.ElementAt(i + 1));
                    baseImg = MyDeal.Interpolation(left, right);
                    decodeTiff.views.Add(baseImg);
                }
                if (monitor != null)
                {
                    monitor.OnValueChanged(new MyDeal.ValueEventArgs()
                    {
                        value = (double)i / myct.baseImg.Count
                    });
                }
            }
            return(decodeTiff);
        }
        private static MyTiff decodeMotion(MyCompressTiff myct, MyDeal.ProgressMonitor monitor)
        {
            MyTiff       decodeTiff = new MyTiff();
            Bitmap       baseImg    = null;
            MyMotionTiff targetMotion;

            for (int i = 0; i < myct.baseImg.Count; i++)
            {
                if (myct.baseImg.ElementAt(i) != null)
                {
                    decodeTiff.views.Add(baseImg = new Bitmap(myct.baseImg.ElementAt(i)));
                }
                else
                {
                    targetMotion = myct.motionTiff.ElementAt(i);
                    baseImg      = MyMotionTiff.decode(baseImg, targetMotion);
                    decodeTiff.views.Add(baseImg);
                }
                if (monitor != null)
                {
                    monitor.OnValueChanged(new MyDeal.ValueEventArgs()
                    {
                        value = (double)i / myct.baseImg.Count
                    });
                }
            }
            return(decodeTiff);
        }
Example #3
0
 public MyCompresser(MyPlayer RefPlayer, PictureBox CurViewer)
 {
     this.RefPlayer = RefPlayer;
     CurPlayer      = new MyPlayer(CurViewer);
     compressFile   = new MyCompressTiff();
     CompressKernel = new MyFilter(compressKernelSize);
     CompressKernel.setData(1.0);
 }
        private static MyTiff decodeBB(MyCompressTiff myct, MyDeal.ProgressMonitor monitor)
        {
            MyTiff decodeTiff = new MyTiff();
            Bitmap dst        = null;

            for (int i = 0; i < myct.baseImg.Count; i++)
            {
                if (i == 0)
                {
                    decodeTiff.views.Add(dst = new Bitmap(myct.baseImg.ElementAt(i)));
                }
                else
                {
                    Bitmap left = (Bitmap)decodeTiff.views.Last();
                    dst = (Bitmap)myct.baseImg.ElementAt(i).Clone();
                    BitmapData leftData = left.LockBits(MyDeal.boundB(left), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                    BitmapData dstData  = dst.LockBits(MyDeal.boundB(dst), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                    unsafe
                    {
                        byte *leftPtr  = (byte *)leftData.Scan0;
                        byte *dstPtr   = (byte *)dstData.Scan0;
                        int   skipByte = dstData.Stride - 3 * dstData.Width;
                        for (int y = 0; y < dstData.Height; y++)
                        {
                            for (int x = 0; x < dstData.Width; x++)
                            {
                                if ((dstPtr[0] != dstPtr[1]) || (dstPtr[1] != dstPtr[2]))
                                {
                                    dstPtr[0] = leftPtr[0];
                                    dstPtr[1] = leftPtr[1];
                                    dstPtr[2] = leftPtr[2];
                                }
                                dstPtr  += 3;
                                leftPtr += 3;
                            }
                            dstPtr  += skipByte;
                            leftPtr += skipByte;
                        }
                    }
                    left.UnlockBits(leftData);
                    dst.UnlockBits(dstData);
                    decodeTiff.views.Add(dst);
                }
                if (monitor != null)
                {
                    monitor.OnValueChanged(new MyDeal.ValueEventArgs()
                    {
                        value = (double)i / myct.baseImg.Count
                    });
                }
            }
            return(decodeTiff);
        }
Example #5
0
        protected virtual void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                switch (openFileDialog1.FilterIndex)
                {
                case 1:
                    if (!openFileDialog1.FileName.Contains(".tiff"))
                    {
                        MessageBox.Show(openFileDialog1.FileName, "open fail < not a tiff file >");
                        return;
                    }
                    myTiff.from(openFileDialog1.FileName);
                    myCompressTiff = null;
                    break;

                case 2:
                    if (!openFileDialog1.FileName.Contains(".MYCT"))
                    {
                        MessageBox.Show(openFileDialog1.FileName, "open fail < not a MYCT file >");
                        return;
                    }
                    if (basicProgress != null)
                    {
                        basicProgress.start();
                    }
                    FileStream fs = (FileStream)openFileDialog1.OpenFile();
                    myCompressTiff = MyCompressTiff.readFromFile(fs);
                    myTiff         = MyCompressTiff.decode(myCompressTiff, basicProgress);
                    fs.Close();
                    if (basicProgress != null)
                    {
                        basicProgress.fine();
                    }
                    break;
                }

                player.open(myTiff);
                player.connect(trackBar1);
                player.OnPlay(new MyPlayer.PlayEventArgs(0, MyPlayer.PlayState.STOP));
                textBox_progress.Text = "0 / " + (myTiff.Size - 1);

                chart1.ChartAreas.ElementAt(0).AxisX.Maximum = myTiff.Size - 1;//set x axis maximun
                if (chart1.Series.FindByName(seriesIdA) != null)
                {
                    chart1.Series.FindByName(seriesIdA).Points.Clear();
                    int[] xValue = Enumerable.Range(0, myTiff.Size).ToArray();
                    chart1.Series.FindByName(seriesIdA).Points.DataBindXY(xValue, new double[myTiff.Size]);
                }
            }
        }
Example #6
0
        private void openBToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                switch (openFileDialog1.FilterIndex)
                {
                case 1:
                    if (!openFileDialog1.FileName.Contains(".tiff"))
                    {
                        MessageBox.Show(openFileDialog1.FileName, "open fail < not a tiff file >");
                        return;
                    }
                    myTiffB.from(openFileDialog1.FileName);
                    myCompressTiffB = null;
                    break;

                case 2:
                    if (!openFileDialog1.FileName.Contains(".MYCT"))
                    {
                        MessageBox.Show(openFileDialog1.FileName, "open fail < not a MYCT file >");
                        return;
                    }
                    if (basicProgress != null)
                    {
                        basicProgress.start();
                    }
                    FileStream fs = (FileStream)openFileDialog1.OpenFile();
                    myCompressTiffB = MyCompressTiff.readFromFile(fs);
                    myTiffB         = MyCompressTiff.decode(myCompressTiffB, basicProgress);
                    fs.Close();
                    if (basicProgress != null)
                    {
                        basicProgress.fine();
                    }
                    break;
                }

                playerB.open(myTiffB);
                playerB.OnPlay(new MyPlayer.PlayEventArgs(0, MyPlayer.PlayState.STOP));

                if (chart1.Series.FindByName(seriesIdB) != null)
                {
                    chart1.Series.FindByName(seriesIdB).Points.Clear();
                    int[]    xValue = Enumerable.Range(0, myTiffB.Size).ToArray();
                    double[] yValue = new double[myTiffB.Size];
                    chart1.Series.FindByName(seriesIdB).Points.DataBindXY(xValue, yValue);
                }
            }
        }
        public static MyTiff decode(MyCompressTiff myct, MyDeal.ProgressMonitor monitor)
        {
            switch (myct.type)
            {
            case MyCompressTiffDefine.TYPE.MOTION:
                return(decodeMotion(myct, monitor));

            case MyCompressTiffDefine.TYPE.SUBSAMPLE:
                return(decodeSubsample(myct, monitor));

            case MyCompressTiffDefine.TYPE.BLOCKBASE:
                return(decodeBB(myct, monitor));
            }
            return(null);
        }
Example #8
0
 private void saveFile()
 {
     if (saver != null)
     {//save compress file
         if (saver.ShowDialog() == DialogResult.OK)
         {
             // If the file name is not an empty string open it for saving.
             if (saver.FileName != "")
             {
                 FileStream fs = (FileStream)saver.OpenFile();
                 MyCompressTiff.writeToFile(fs, compressFile);
                 fs.Close();
             }
         }
     }
     activeFrom.button1.Enabled = true;
 }
 public static MyTiff decode(MyCompressTiff myct)
 {
     return(decode(myct, null));
 }
        public static void writeToFile(Stream fs, MyCompressTiff myct)
        {// write myct to fs
            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(fs, myct);
        }