protected void draw() { if (viewer != null) { new Thread(new ThreadStart(new Action(() => { MyDeal.tryDrawBack(viewer, tiff.View, -1); MyDeal.tryDraw(viewer, null); }))).Start(); } }
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(); } }
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 } } }
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 } } }