Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public static Bitmap drawVector(MyMotionTiff motion)
        {
            if (motion == null)
            {
                return(null);
            }
            MyFilter filter = new MyFilter(MyCompresser.compressKernelSize);

            filter.setData(1);
            Bitmap   newImg         = new Bitmap(motion.Width, motion.Height);
            Graphics grapic         = Graphics.FromImage(newImg);
            int      colorLowBound  = 64;// for random color value lower bound
            int      colorHighBound = 256 - colorLowBound;

            Color[] colors = new Color[motion.Width * motion.Height / MyCompresser.compressKernelSize / MyCompresser.compressKernelSize];
            Random  random = new Random();
            int     i      = 0;//pen sequence

            //draw box
            for (int y = MyCompresser.compressKernelSize / 2; y < motion.Height; y += MyCompresser.compressKernelSize)
            {
                for (int x = MyCompresser.compressKernelSize / 2; x < motion.Width; x += MyCompresser.compressKernelSize)
                {
                    if ((motion[x, y][0] == x) && (motion[x, y][1] == y))
                    {//no motiom
                        colors[i] = Color.Black;
                    }
                    else
                    {
                        colors[i] = Color.FromArgb(colorLowBound + random.Next() % colorHighBound, colorLowBound + random.Next() % colorHighBound, colorLowBound + random.Next() % colorHighBound);
                    }
                    grapic.FillRectangle(new SolidBrush(colors[i]), x - MyCompresser.compressKernelSize / 4, y - MyCompresser.compressKernelSize / 4, MyCompresser.compressKernelSize / 2, MyCompresser.compressKernelSize / 2);
                    //grapic.FillRectangle(new SolidBrush(colors[i]), x - MyCompresser.compressKernelSize / 2, y - MyCompresser.compressKernelSize / 2, MyCompresser.compressKernelSize / 2, MyCompresser.compressKernelSize / 2);
                    //grapic.DrawRectangle(new Pen(colors[i]), x , y, MyCompresser.compressKernelSize, MyCompresser.compressKernelSize);
                    i++;
                }
            }
            i = 0;//pen sequence
            //draw vector line
            for (int y = 0 + MyCompresser.compressKernelSize / 2; y < motion.Height; y += MyCompresser.compressKernelSize)
            {
                for (int x = 0 + MyCompresser.compressKernelSize / 2; x < motion.Width; x += MyCompresser.compressKernelSize)
                {
                    grapic.DrawLine(new Pen(Color.FromArgb(128, colors[i]), 2.0f), x, y, motion[x, y][0], motion[x, y][1]);
                    i++;
                }
            }

            return(newImg);
        }
Exemplo n.º 3
0
        protected override void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Enabled = false;
            base.openToolStripMenuItem_Click(sender, e);
            if (myCompressTiff != null)
            {
                switch (myCompressTiff.type)
                {
                case MyCompressTiffDefine.TYPE.MOTION:
                    motionVector = new MyTiff();
                    foreach (MyMotionTiff motionTiff in myCompressTiff.motionTiff)
                    {
                        motionVector.views.Add(MyMotionTiff.drawVector(motionTiff));
                    }
                    motionPlayer.open(motionVector);
                    groupBox3.Text = "motion Vector";
                    break;

                case MyCompressTiffDefine.TYPE.BLOCKBASE:
                    motionVector = new MyTiff();
                    foreach (Image tiff in myCompressTiff.baseImg)
                    {
                        motionVector.views.Add(tiff);
                    }
                    motionPlayer.open(motionVector);
                    groupBox3.Text = "Block Base diff";
                    break;

                default:
                    motionVector      = null;
                    motionPlayer.Tiff = null;
                    groupBox3.Text    = "not use";
                    break;
                }
            }
            else
            {
                motionVector      = null;
                motionPlayer.Tiff = null;
                groupBox3.Text    = "not use";
            }
            this.Enabled = true;
        }
Exemplo n.º 4
0
        public static Bitmap decode(Bitmap baseImg, MyMotionTiff motion)
        {
            MyFilter filter = new MyFilter(MyCompresser.compressKernelSize);

            filter.setData(1);
            Bitmap       newImg        = new Bitmap(baseImg.Width, baseImg.Height);
            BitmapData   baseData      = baseImg.LockBits(MyDeal.boundB(baseImg), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
            BitmapData   newData       = newImg.LockBits(MyDeal.boundB(newImg), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
            MyFilterData srcFilterData = new MyFilterData();

            for (int y = 0 + MyCompresser.compressKernelSize / 2; y < motion.Height; y += MyCompresser.compressKernelSize)
            {
                for (int x = 0 + MyCompresser.compressKernelSize / 2; x < motion.Width; x += MyCompresser.compressKernelSize)
                {
                    srcFilterData.fill(baseData, motion[x, y][0], motion[x, y][1], MyFilter.BorderMethod.ZERO, filter);
                    Debug.Print("the " + x + " , " + y + " from " + motion[x, y][0] + " , " + motion[x, y][1]);
                    unsafe
                    {
                        byte *dstPtr   = (byte *)newData.Scan0;
                        int   skipByte = newData.Stride - 3 * MyCompresser.compressKernelSize;
                        dstPtr += (y - MyCompresser.compressKernelSize / 2) * newData.Stride + (x - MyCompresser.compressKernelSize / 2) * 3;
                        for (int j = 0; j < MyCompresser.compressKernelSize; j++)
                        {
                            for (int i = 0; i < MyCompresser.compressKernelSize; i++)
                            {
                                byte[] result = MyFilterData.boundPixel(srcFilterData[i, j]);
                                //Debug.Print("Data get " + result[0] + " , " + result[1] + " , " + result[2]);
                                dstPtr[0] = result[0];
                                dstPtr[1] = result[1];
                                dstPtr[2] = result[2];
                                dstPtr   += 3;
                            }
                            dstPtr += skipByte;
                        }
                    }
                }
            }
            baseImg.UnlockBits(baseData);
            newImg.UnlockBits(newData);
            return(newImg);
        }
Exemplo n.º 5
0
        protected void motionMethod()
        {
            compressFile.type = MyCompressTiffDefine.TYPE.MOTION;
            if (RefPlayer != null)
            {
                MyFilterData CurKernelGet = new MyFilterData();                                   // the data copy from cur frame of kernel size
                for (int i = 0; i < RefPlayer.Tiff.Size; i++)
                {                                                                                 //run frames
                 //Debug.Print("in frame " + i);
                    trackBar.Invoke(new threadHandler2(progressTrack), i);                        // reflash progress view

                    RefPlayer.OnPlay(new MyPlayer.PlayEventArgs(i - 1, MyPlayer.PlayState.KEEP)); //flash ref frame view
                    CurPlayer.OnPlay(RefPlayer.NextView, new MyPlayer.PlayEventArgs(0));          //flash current frame view

                    //clear motion view
                    Bitmap motionBlock  = null;
                    Bitmap motionVector = null;
                    for (int t = 0; t < 5; t++)
                    {
                        try
                        {
                            motionBlock  = new Bitmap(RefPlayer.NextView.Width, RefPlayer.NextView.Height);
                            motionVector = new Bitmap(RefPlayer.NextView.Width, RefPlayer.NextView.Height);
                        }
                        catch (InvalidOperationException)
                        {
                            Thread.Sleep(29);
                            continue;
                        }
                        break;
                    }
                    MyDeal.tryDraw(MotionViewer, motionVector);
                    MyDeal.tryDrawBack(MotionViewer, motionBlock);
                    Graphics graphicMotionBlock  = Graphics.FromImage(motionBlock);
                    Graphics graphicMotionVector = Graphics.FromImage(motionVector);
                    int      colorLowBound       = 64;// for random color value lower bound
                    int      colorHighBound      = 256 - colorLowBound;
                    Color    penColor            = Color.Black;

                    if (i == 0)
                    {                                                               //uncompress frame number
                        compressFile.baseImg.Add((Image)RefPlayer.Tiff[i].Clone()); // add ref imge
                        compressFile.motionTiff.Add(null);
                        continue;
                    }

                    Bitmap refBitmapCp; // the copy Bitmap for ref frame
                    Bitmap curBitmapCp; // the copy Bitmap for cur frame
                    while (true)
                    {
                        try
                        {
                            refBitmapCp = new Bitmap((Image)RefPlayer.PredictView.Clone());// the copy Bitmap for ref frame
                        }
                        catch (InvalidOperationException)
                        {
                            Thread.Sleep(33);
                            continue;
                        }
                        break;
                    }
                    while (true)
                    {
                        try
                        {
                            curBitmapCp = new Bitmap((Image)RefPlayer.NextView.Clone());// the copy Bitmap for cur frame
                        }
                        catch (InvalidOperationException)
                        {
                            Thread.Sleep(33);
                            continue;
                        }
                        break;
                    }
                    BitmapData   refData   = refBitmapCp.LockBits(MyDeal.boundB(refBitmapCp), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                    BitmapData   curData   = curBitmapCp.LockBits(MyDeal.boundB(curBitmapCp), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                    MyMotionTiff theMotion = new MyMotionTiff(curBitmapCp.Width, curBitmapCp.Height);
                    compressFile.baseImg.Add(null);
                    compressFile.motionTiff.Add(theMotion);
                    for (int y = 0 + compressKernelSize / 2; y < curBitmapCp.Height; y += compressKernelSize)
                    {
                        for (int x = 0 + compressKernelSize / 2; x < curBitmapCp.Width; x += compressKernelSize)
                        {
                            if (activeFrom != null)
                            {
                                if (activeFrom.IsDisposed)//form be dispose
                                {
                                    return;
                                }
                            }
                            //draw target
                            if (!CurrentPlayer.flashIgnore)
                            {
                                CurPlayer.OnPlay(RefPlayer.NextView, new MyPlayer.PlayEventArgs(0, MyPlayer.PlayState.KEEP, x, y, compressKernelSize, compressKernelSize));
                            }
                            CurKernelGet.fill(curData, x, y, MyFilter.BorderMethod.ZERO, CompressKernel);
                            penColor = Color.FromArgb(colorLowBound + random.Next() % colorHighBound, colorLowBound + random.Next() % colorHighBound, colorLowBound + random.Next() % colorHighBound);

                            if (!this.CurrentPlayer.flashIgnore)
                            {
                                MyDeal.tryDraw(featureViewer, CurKernelGet.transToBitmap());
                                //draw motion
                                graphicMotionBlock.FillRectangle(new SolidBrush(penColor), x - MyCompresser.compressKernelSize / 4, y - MyCompresser.compressKernelSize / 4, MyCompresser.compressKernelSize / 2, MyCompresser.compressKernelSize / 2);
                                MotionViewer.Invalidate();
                            }

                            //find match
                            int targetX = x;
                            int targetY = y;
                            findMatch(CurKernelGet, refData, RefPlayer, ref targetX, ref targetY);
                            theMotion[x, y] = new int[] { targetX, targetY };
                            if (!this.CurrentPlayer.flashIgnore)
                            {
                                //draw match vector
                                graphicMotionVector.DrawLine(new Pen(Color.FromArgb(128, penColor), 2.0f), x, y, targetX, targetY);
                            }

                            //Debug.Print("in frame " + i + " in " + x + " , "+ y + "find target " + targetX + " , " + targetY);
                        }
                    }
                    refBitmapCp.UnlockBits(refData);
                    curBitmapCp.UnlockBits(curData);
                }

                if (activeFrom != null)
                {
                    activeFrom.Invoke(new threadHandler(saveFile));// save the result
                }
            }
        }