'
'
'
'
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Runtime.InteropServices
Imports System.Text
Imports Matrox.MatroxImagingLibrary
Namespace MDigDoubleBuffering
Public Class UserDataObject
Public NbGrabStart As MIL_INT
End Class
Friend Class Program
Const STRING_LENGTH_MAX As Integer = 20
Shared Sub Main(ByVal args() As String)
Dim MilApplication As MIL_ID = MIL.M_NULL
Dim MilSystem As MIL_ID = MIL.M_NULL
Dim MilDigitizer As MIL_ID = MIL.M_NULL
Dim MilDisplay As MIL_ID = MIL.M_NULL
Dim MilImage(1) As MIL_ID
Dim MilImageDisp As MIL_ID = MIL.M_NULL
Dim [Default] As MIL_ID = MIL.M_DEFAULT
Dim NbProc As Integer = 0
Dim n As Integer = 0
Dim Time As Double = 0.0
Dim Text As New StringBuilder("0", STRING_LENGTH_MAX)
Dim userObject As New UserDataObject()
MIL.MappAllocDefault(MIL.M_DEFAULT, MilApplication, MilSystem, MilDisplay, MilDigitizer, MilImageDisp)
For n = 0 To 1
MIL.MbufAlloc2d(MilSystem, MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_X, MIL.M_NULL), MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_Y, MIL.M_NULL), 8 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_GRAB + MIL.M_PROC, MilImage(n))
Next n
userObject.NbGrabStart = 0
Dim userObjectHandle As GCHandle = GCHandle.Alloc(userObject)
Dim grabStartDelegate As New MIL_DIG_HOOK_FUNCTION_PTR(AddressOf GrabStart)
MIL.MdigHookFunction(MilDigitizer, MIL.M_GRAB_START, grabStartDelegate, GCHandle.ToIntPtr(userObjectHandle))
Console.WriteLine()
Console.WriteLine("DOUBLE BUFFERING ACQUISITION AND PROCESSING:")
Console.WriteLine("--------------------------------------------")
Console.WriteLine()
Console.WriteLine("Press <Enter> to stop.")
Console.WriteLine()
MIL.MdigControl(MilDigitizer, MIL.M_GRAB_MODE, MIL.M_ASYNCHRONOUS)
MIL.MdigGrab(MilDigitizer, MilImage(0))
n = 0
Do
MIL.MdigGrab(MilDigitizer, MilImage(1 - n))
If NbProc = 0 Then
MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_RESET + MIL.M_SYNCHRONOUS, CType(MIL.M_NULL, IntPtr))
End If
MIL.MgraText([Default], MilImage(n), 32, 32, String.Format("{0}", NbProc + 1))
MIL.MimArith(MilImage(n), MIL.M_NULL, MilImageDisp, MIL.M_NOT)
NbProc += 1
n = 1 - n
Loop While Not Console.KeyAvailable
MIL.MdigGrabWait(MilDigitizer, MIL.M_GRAB_END)
MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ + MIL.M_SYNCHRONOUS, Time)
Console.ReadKey()
Console.WriteLine("{0} frames grabbed, at a frame rate of {1:0.00} frames/sec ({2:0.00} ms/frame).", NbProc, NbProc / Time, 1000.0 * Time / NbProc)
Console.WriteLine("Press <Enter> to end.")
Console.WriteLine()
Console.ReadKey()
MIL.MdigHookFunction(MilDigitizer, MIL.M_GRAB_START + MIL.M_UNHOOK, grabStartDelegate, GCHandle.ToIntPtr(userObjectHandle))
userObjectHandle.Free()
For n = 0 To 1
MIL.MbufFree(MilImage(n))
Next n
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, MilImageDisp)
End Sub
'
Private Shared Function GrabStart(ByVal HookType As MIL_INT, ByVal EventId As MIL_ID, ByVal UserObjectPtr As IntPtr) As MIL_INT
If (UserObjectPtr <> IntPtr.Zero) Then
Dim userObjectHandle As GCHandle = GCHandle.FromIntPtr(UserObjectPtr)
Dim userData As UserDataObject = TryCast(userObjectHandle.Target, UserDataObject)
If (userData IsNot Nothing) Then
userData.NbGrabStart += 1
Console.Write("#{0}" + Constants.vbCr, userData.NbGrabStart)
End If
End If
Return 0
End Function
End Class
End Namespace