Example #1
0
        public Bitmap transToBitmap()
        {
            Bitmap     newBitmap = new Bitmap(size, size);
            BitmapData newData   = newBitmap.LockBits(MyDeal.boundB(newBitmap), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            unsafe
            {
                byte *newPtr   = (byte *)newData.Scan0;
                int   skipByte = newData.Stride - 3 * newData.Width;
                for (int j = 0; j < newData.Height; j++)
                {
                    for (int i = 0; i < newData.Width; i++)
                    {
                        byte[] pixel = boundPixel(_data[i, j]);
                        newPtr[0] = pixel[0];
                        newPtr[1] = pixel[1];
                        newPtr[2] = pixel[2];
                        newPtr   += 3;
                    }
                    newPtr += skipByte;
                }
            }
            newBitmap.UnlockBits(newData);
            return(newBitmap);
        }
        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);
        }
Example #3
0
 public static void tryDraw(PictureBox viewer, Image image, int tryTimes)
 {// try to set PictureBox . Image , if tryTimes < 0 , try until access
     if (viewer == null)
     {
         return;
     }
     for (int i = 0; (i < tryTimes) || (tryTimes < 0); i++)
     {
         try
         {
             if ((viewer.Image == null) || (image == null))
             {
                 viewer.Image = image;
             }
             else
             {
                 if (!Object.Equals(viewer.BackgroundImage, image))
                 {
                     Graphics graphic = Graphics.FromImage(viewer.Image);
                     graphic.Clear(Color.Transparent);
                     graphic.DrawImage(image, MyDeal.boundB(image));
                 }
                 viewer.Invalidate();
             }
         }
         catch (InvalidOperationException)
         {
             Thread.Sleep(7);
             continue;
         }
         break;
     }
 }
Example #4
0
 protected void draw()
 {
     if (viewer != null)
     {
         new Thread(new ThreadStart(new Action(() =>
         {
             MyDeal.tryDrawBack(viewer, tiff.View, -1);
             MyDeal.tryDraw(viewer, null);
         }))).Start();
     }
 }
        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 #6
0
        private void countPSNR2_chart(Chart here, object[] args)
        {//chartDelegate for count psnr each view args = { player, player , seriesName }
            string seriesName = (string)args.ElementAtOrDefault(2);

            Debug.Print("in countPSNR_chart " + seriesName);
            Series target = here.Series.FindByName(seriesName);
            //Series target = here.Series.ElementAt(0);
            MyPlayer A = (MyPlayer)args.ElementAtOrDefault(0);
            MyPlayer B = (MyPlayer)args.ElementAtOrDefault(1);

            if (A == null)
            {
                return;
            }
            if (B == null)
            {
                return;
            }
            if (target == null)
            {
                return;
            }
            Debug.Print(" " + A.Tiff.Current);
            try
            {
                if (A.Tiff.Current >= target.Points.Count)
                {
                    return;
                }
                else if (A.Tiff.Current < 0)
                {
                    return;
                }
                //target.Points.RemoveAt(src.Tiff.Current);
            }
            catch (ArgumentOutOfRangeException e)
            {
                Debug.Print(e.StackTrace);
            }
            //target.Points.InsertXY(src.Tiff.Current, src.Tiff.Current, MyDeal.PSNR(src.Tiff.BackView, src.Tiff.View).ToString());
            target.Points.ElementAt(A.Tiff.Current).XValue = A.Tiff.Current;
            target.Points.ElementAt(A.Tiff.Current).SetValueY(MyDeal.PSNR(A.Tiff.View, B.Tiff.View));
            foreach (DataPoint data in target.Points)
            {
                Debug.Print("check in countPSNR2_chart in " + A.Tiff.Current + " , " + B.Tiff.Current + " :" + data.XValue + " , " + data.YValues[0]);
            }
        }
Example #7
0
        protected void draw(int X, int Y, int width, int height)
        {
            if ((viewer != null) && (!flashIgnore))
            {
                new Thread(new ThreadStart(new Action(() =>
                {
                    int startX = X - width / 2;
                    int startY = Y - height / 2;

                    Bitmap targetDraw;
                    int viewWidth;
                    int viewHeight;
                    MyDeal.tryDrawBack(viewer, tiff.View);
                    while (true)
                    {
                        try
                        {
                            viewWidth  = tiff.View.Width;
                            viewHeight = tiff.View.Height;
                        }
                        catch (InvalidOperationException)
                        {
                            Thread.Sleep(23);
                            continue;
                        }
                        break;
                    }
                    targetDraw       = new Bitmap(viewWidth, viewHeight);
                    Graphics targetG = Graphics.FromImage(targetDraw);
                    for (int time = 0; time < 5; time++)
                    {
                        try
                        {
                            targetG.DrawRectangle(redPen, startX, startY, width, height);
                        }
                        catch (InvalidOperationException)
                        {
                            Thread.Sleep(17);
                            continue;
                        }
                        break;
                    }
                    MyDeal.tryDraw(viewer, targetDraw);
                }))).Start();
            }
        }
Example #8
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);
        }
Example #9
0
        private void compareBlock(MyFilterData search, BitmapData refData, MyPlayer RefPlayer, int x, int y, matchRatePair dataRecord)
        {// compare the (x , y) similar rate && flash dataRecord & view
            if (!RefPlayer.flashIgnore)
            {
                RefPlayer.OnPlay(new MyPlayer.PlayEventArgs(-1, MyPlayer.PlayState.KEEP, x, y, compressKernelSize, compressKernelSize));
            }
            MyFilterData refKernelGet = new MyFilterData();

            refKernelGet.fill(refData, x, y, MyFilter.BorderMethod.ZERO, CompressKernel);
            double distance = MyFilterData.compare(search, refKernelGet, criteria);

            if (dataRecord > distance)
            {// find min distance
                dataRecord.rate = distance;
                dataRecord.x    = x;
                dataRecord.y    = y;
                if (!RefPlayer.flashIgnore)
                {
                    MyDeal.tryDraw(MatchViewer, refKernelGet.transToBitmap());
                }
            }
            Thread.Sleep(sleepTime);
        }
Example #10
0
        public double findMatchNormal(MyFilterData search, BitmapData refData, MyPlayer RefPlayer, ref int targetX, ref int targetY)
        {                                                     // 2D loorer methd if x,y < 0 ? all seach : local primary
            matchRatePair dataRecord    = new matchRatePair(Double.PositiveInfinity, 0, 0);
            MyFilterData  refKernelGet  = new MyFilterData(); // the data copy from ref frame of kernel size
            int           farDistance2  = 128;                //define half of this is mean the distance value from target is far
            int           nearDistance2 = 32;                 //define half of this is mean the distance value from target is near
            int           farJumpStap   = compressKernelSize; // define search pixel jump step lenth when seach in far area

            if ((targetX < 0) || (targetY < 0))
            {// search all pixels
                for (int y = 0 + compressKernelSize / 2; y < refData.Height; y += 1)
                {
                    for (int x = 0 + compressKernelSize / 2; x < refData.Width; x += 1)
                    {
                        if ((!RefPlayer.flashIgnore) && (x % 3 == 0))// reduce the reflash view frequence
                        {
                            RefPlayer.OnPlay(new MyPlayer.PlayEventArgs(-1, MyPlayer.PlayState.KEEP, x, y, compressKernelSize, compressKernelSize));
                        }
                        refKernelGet.fill(refData, x, y, MyFilter.BorderMethod.ZERO, CompressKernel);
                        double distance = MyFilterData.compare(search, refKernelGet, criteria);
                        if (dataRecord > distance)
                        {// find min distance
                            dataRecord.rate = distance;
                            dataRecord.x    = x;
                            dataRecord.y    = y;
                            if (!RefPlayer.flashIgnore)
                            {
                                MyDeal.tryDraw(MatchViewer, refKernelGet.transToBitmap());
                            }
                        }
                        Thread.Sleep(sleepTime);
                    }
                }
                targetX = dataRecord.x;
                targetY = dataRecord.y;
                return(dataRecord.rate);
            }
            else
            {//local primary
                // the far area  left & top posion
                int fx = targetX - farDistance2 / 2;
                int fy = targetY - farDistance2 / 2;
                // the near area posion
                int nl = targetX - nearDistance2 / 2;
                int nt = targetY - nearDistance2 / 2;
                int nr = targetX + nearDistance2 / 2;
                int nb = targetY + nearDistance2 / 2;

                int jumpStap = farJumpStap;
                for (int y = (fy < (0 + compressKernelSize / 2) ? (0 + compressKernelSize / 2) : fy); (y < refData.Height) && (y < fy + farDistance2); y += jumpStap)
                {
                    for (int x = (fx < (0 + compressKernelSize / 2) ? (0 + compressKernelSize / 2) : fx); (x < refData.Width) && (x < fx + farDistance2); x += jumpStap)
                    {
                        if ((x >= nl) && (x < nr) && (y >= nt) && (y < nb))
                        {// in near
                            jumpStap = 1;
                        }
                        else
                        {//in far
                            jumpStap = farJumpStap;
                        }
                        compareBlock(search, refData, RefPlayer, x, y, dataRecord);
                    }
                }
                targetX = dataRecord.x;
                targetY = dataRecord.y;
                return(dataRecord.rate);
            }
        }
Example #11
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
                }
            }
        }
Example #12
0
        protected void blockBaseMethod()
        {
            compressFile.type = MyCompressTiffDefine.TYPE.BLOCKBASE;
            if (RefPlayer != null)
            {
                Rectangle    cutRect      = new Rectangle(0, 0, compressKernelSize, compressKernelSize);
                MyFilterData CurKernelGet = new MyFilterData();// the data copy from cur frame of kernel
                MyFilterData RefKernelGet = new MyFilterData();
                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;
                    while (true)
                    {
                        try
                        {
                            motionBlock = new Bitmap(RefPlayer.NextView.Width, RefPlayer.NextView.Height);
                        }
                        catch (InvalidOperationException)
                        {
                            Thread.Sleep(29);
                            continue;
                        }
                        break;
                    }
                    MyDeal.tryDrawBack(MotionViewer, motionBlock);
                    Graphics graphicMotionBlock = Graphics.FromImage(motionBlock);
                    Brush    redPen             = new SolidBrush(Color.Red);

                    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);

                    for (int y = 0 + compressKernelSizeHalf; y < curBitmapCp.Height; y += compressKernelSize)
                    {
                        for (int x = 0 + compressKernelSizeHalf; 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));
                            }
                            if (!RefPlayer.flashIgnore)
                            {
                                RefPlayer.OnPlay(new MyPlayer.PlayEventArgs(-1, MyPlayer.PlayState.KEEP, x, y, compressKernelSize, compressKernelSize));
                            }

                            CurKernelGet.fill(curData, x, y, MyFilter.BorderMethod.ZERO, CompressKernel);
                            RefKernelGet.fill(refData, x, y, MyFilter.BorderMethod.ZERO, CompressKernel);
                            switch (criteria)
                            {
                            case MyFilterData.CRITERIA_METHOD.ABSOLUTE:
                                if (_BBthreshold < MyFilterData.compare(CurKernelGet, RefKernelGet, criteria))
                                {
                                    graphicMotionBlock.DrawImage(CurKernelGet.transToBitmap(), x - compressKernelSizeHalf, y - compressKernelSizeHalf);
                                    //graphicMotionBlock.DrawImage(curBitmapCp, cutRect, x - compressKernelSizeHalf, y - compressKernelSizeHalf, compressKernelSize, compressKernelSize, GraphicsUnit.Pixel);
                                }
                                else
                                {
                                    graphicMotionBlock.FillRectangle(redPen, x - compressKernelSizeHalf, y - compressKernelSizeHalf, MyCompresser.compressKernelSize, MyCompresser.compressKernelSize);
                                }
                                break;

                            case MyFilterData.CRITERIA_METHOD.SQUARE:
                                if (_BBthresholdSQ < MyFilterData.compare(CurKernelGet, RefKernelGet, criteria))
                                {
                                    graphicMotionBlock.DrawImage(CurKernelGet.transToBitmap(), x - compressKernelSizeHalf, y - compressKernelSizeHalf);
                                    //graphicMotionBlock.DrawImage(curBitmapCp, cutRect, x - compressKernelSizeHalf, y - compressKernelSizeHalf, compressKernelSize, compressKernelSize, GraphicsUnit.Pixel);
                                }
                                else
                                {
                                    graphicMotionBlock.FillRectangle(redPen, x - compressKernelSizeHalf, y - compressKernelSizeHalf, MyCompresser.compressKernelSize, MyCompresser.compressKernelSize);
                                }
                                break;
                            }


                            if (!this.RefPlayer.flashIgnore)
                            {
                                MyDeal.tryDraw(MatchViewer, RefKernelGet.transToBitmap());
                            }
                            if (!this.CurrentPlayer.flashIgnore)
                            {
                                MyDeal.tryDraw(featureViewer, CurKernelGet.transToBitmap());
                                //draw motion
                                MotionViewer.Invalidate();
                            }
                            Thread.Sleep(sleepTime);
                            //Debug.Print("in frame " + i + " in " + x + " , "+ y + "find target " + targetX + " , " + targetY);
                        }
                    }

                    compressFile.baseImg.Add(motionBlock);// add ref imge
                    compressFile.motionTiff.Add(null);

                    refBitmapCp.UnlockBits(refData);
                    curBitmapCp.UnlockBits(curData);
                }

                if (activeFrom != null)
                {
                    activeFrom.Invoke(new threadHandler(saveFile));// save the result
                }
            }
        }
Example #13
0
        protected void intraSubsample()
        {
            compressFile.type = MyCompressTiffDefine.TYPE.SUBSAMPLE;
            if (RefPlayer != null)
            {
                RefPlayer.OnPlay(new MyPlayer.PlayEventArgs(0, MyPlayer.PlayState.KEEP));
                CurPlayer.Tiff = RefPlayer.Tiff.clone();
                MyFilterData CurKernelGet   = new MyFilterData();// the data copy from cur frame of kernel size
                int          intraSubSize   = 2;
                int          subSizeHalf    = intraSubSize / 2;
                double       subWeight      = 1.0 / (intraSubSize * intraSubSize);
                MyFilter     intraSubFilter = new MyFilter(intraSubSize);
                intraSubFilter.setData(1.0);

                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
                    CurPlayer.OnPlay(new MyPlayer.PlayEventArgs(i));       //flash current frame view

                    Bitmap curBitmapCp;                                    // the copy Bitmap for cur frame
                    Bitmap dstBitmap;                                      // viewer in counting out view
                    while (true)
                    {
                        try
                        {
                            curBitmapCp = new Bitmap((Image)CurPlayer.PredictView.Clone());// the copy Bitmap for cur frame
                        }
                        catch (InvalidOperationException)
                        {
                            Thread.Sleep(33);
                            continue;
                        }
                        break;
                    }
                    dstBitmap = new Bitmap(curBitmapCp.Width, curBitmapCp.Height);
                    while (true)
                    {
                        try
                        {
                            MotionViewer.Image = dstBitmap;
                        }
                        catch (InvalidOperationException)
                        {
                            Thread.Sleep(33);
                            continue;
                        }
                        break;
                    }

                    BitmapData curData = curBitmapCp.LockBits(MyDeal.boundB(curBitmapCp), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                    //Bitmap afterSubView = new Bitmap(intraSubSize, intraSubSize);// view in match blok
                    //while (true)
                    //{
                    //    try
                    //    {
                    //        MatchViewer.Image = afterSubView;
                    //    }
                    //    catch (InvalidOperationException)
                    //    {
                    //        Thread.Sleep(33);
                    //        continue;
                    //    }
                    //    break;
                    //}
                    //Graphics afterSubViewG = Graphics.FromImage(afterSubView);
                    Graphics dstBitmapG = Graphics.FromImage(dstBitmap);
                    int      freq       = 0;
                    for (int y = 0 + subSizeHalf; y < curBitmapCp.Height; y += intraSubSize)
                    {
                        for (int x = 0 + subSizeHalf; x < curBitmapCp.Width; x += intraSubSize)
                        {
                            if (activeFrom != null)
                            {
                                if (activeFrom.IsDisposed)//form be dispose
                                {
                                    return;
                                }
                            }
                            //draw target
                            if (!this.CurrentPlayer.flashIgnore)
                            {
                                if (freq % 2 == 0)
                                { // reduce flash freq
                                    freq = 0;
                                    CurPlayer.OnPlay(new MyPlayer.PlayEventArgs(-1, MyPlayer.PlayState.KEEP, x, y, intraSubSize, intraSubSize));
                                }
                                else
                                {
                                    freq++;
                                }
                            }
                            CurKernelGet.fill(curData, x, y, MyFilter.BorderMethod.ZERO, intraSubFilter);
                            //MyDeal.tryDraw(featureViewer, CurKernelGet.transToBitmap());
                            byte[] subSample = CurKernelGet.count(subWeight);
                            //Debug.Print("in " + x + " , " + y + " : " + subSample[2] + " " + subSample[1] + " " + subSample[0]);
                            Color sampleColor = Color.FromArgb(subSample[2], subSample[1], subSample[0]);
                            Brush sample      = new SolidBrush(sampleColor);
                            dstBitmapG.FillRectangle(sample, x - subSizeHalf, y - subSizeHalf, intraSubSize, intraSubSize);
                            if (!this.CurrentPlayer.flashIgnore)
                            {
                                MotionViewer.Invalidate();
                            }
                            //MatchViewer.Invalidate();
                            Thread.Sleep(sleepTime);
                            //Debug.Print("in frame " + i + " in " + x + " , "+ y + "find target " + targetX + " , " + targetY);
                        }
                    }
                    curBitmapCp.UnlockBits(curData);
                    compressFile.baseImg.Add(dstBitmap);// add dst imge
                    compressFile.motionTiff.Add(null);
                }

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