📄 tools.vb
字号:
Module Tools
'address effect
'0 xx - continue transfer
'1 xx - start transfer
'2 xx - end transfer
'4 xx - change displayed image to xx
'8 xx - perform process xx
'16 xx - change pwm to xx
'32 xx - set horizontal delay xx*20ns
'64 xx - set vertical delay xx*20ns
'128 xx- set the display resolution 0-00 1-01 2-11
Private Declare Function DpcInit Lib "dpcutil.dll" _
(ByRef erc As Integer) As Boolean
Private Declare Sub DpcTerm Lib "dpcutil.dll" ()
Private Declare Function DvmgGetDevCount Lib "dpcutil.dll" _
(ByRef erc As Integer) As Integer
Private Declare Function DvmgGetDefaultDev Lib "dpcutil.dll" _
(ByRef erc As Integer) As Integer
Private Declare Function DvmgGetDevName Lib "dpcutil.dll" _
(ByVal idDev As Integer, ByVal sDev As String, ByRef erc As Integer) As Boolean
Private Declare Function DpcOpenData Lib "dpcutil.dll" _
(ByRef hif As Integer, ByVal sDvc As String, ByRef erc As Integer, _
ByVal ptrid As Int16) As Boolean
Private Declare Function DpcCloseData Lib "dpcutil.dll" _
(ByVal hif As Integer, ByRef erc As Integer) As Boolean
Private Declare Function DpcPutRegRepeat Lib "dpcutil.dll" _
(ByVal hif As Integer, ByVal adr As Byte, ByVal data() As Byte, ByVal size As Integer, _
ByRef erc As Integer, ByVal ptrid As Int16) As Boolean
Private Declare Function DpcGetRegRepeat Lib "dpcutil.dll" _
(ByVal hif As Integer, ByVal adr As Byte, ByVal data() As Byte, ByVal size As Integer, _
ByRef erc As Integer, ByVal ptrid As Int16) As Boolean
Private Declare Function DpcPutReg Lib "dpcutil.dll" _
(ByVal hif As Integer, ByVal adr As Byte, ByVal data As Byte, _
ByRef erc As Integer, ByVal ptrid As Int16) As Boolean
Private Declare Function DpcGetReg Lib "dpcutil.dll" _
(ByVal hif As Integer, ByVal adr As Byte, ByRef data As Byte, _
ByRef erc As Integer, ByVal ptrid As Int16) As Boolean
Public imagefilter() As String = New String() { _
".bmp", ".jpeg", ".gif", ".png", "tiff"}
Public pwmmodeinfo(,) As Integer = New Integer(7, 3) { _
{1, 0, 0, 1}, _
{0, 0, 0, 0}, _
{1, 0, 0, 2}, _
{1, 0, 0, 3}, _
{2, 0, 1, 1}, _
{2, 0, 1, 0}, _
{2, 1, 1, 0}, _
{1, 1, 0, 0}}
Public pwmmodeinfo0() As String = New String(2) { _
"4096 (12 bits)", "4913", "32768 (15 bits)"}
Public pwmmodeinfo1() As String = New String(1) { _
"Constant", "Variable"}
Public pwmmodeinfo2() As String = New String(1) { _
"80 ns", "160 ns"}
Public pwmmodeinfo3() As String = New String(3) { _
"Equaly", "Higher for middle luminosity", "Higher for light colors", "Higher for dark colors"}
Public kernnames() As String = New String() _
{"Copy", _
"Negative", _
"Mean filter", _
"Gaussian Smoothing 1", _
"Gaussian Smoothing 2", _
"Gaussian Smoothing 3", _
"Laplacian Edge Detector 1", _
"Laplacian Edge Detector 2", _
"Laplacian Edge Detector 3", _
"Sobel Edge Detector h", _
"Sobel Edge Detector v", _
"Sobel Edge Detector /", _
"Sobel Edge Detector \\", _
"Prewitt compass edge detector h", _
"Prewitt compass edge detector v", _
"Compass Edge Detector 0", _
"Compass Edge Detector 45", _
"Line Detector h", _
"Line Detector v", _
"Line Detector /", _
"Line Detector \\", _
"Roberts Cross Edge Detector /", _
"Roberts Cross Edge Detector \\"}
Public kerns(,) As Integer = New Integer(22, 9) { _
{0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, _
{0, 0, 0, 0, 1, 0, 0, 0, 0, -1}, _
{1, 1, 1, 1, 1, 1, 1, 1, 1, 8}, _
{0, 1, 0, 1, 4, 1, 0, 1, 0, 8}, _
{1, 1, 1, 1, 8, 1, 1, 1, 1, 16}, _
{1, 2, 1, 2, 4, 2, 1, 2, 1, 16}, _
{0, 1, 0, 1, -4, 1, 0, 1, 0, 1}, _
{1, 1, 1, 1, -8, 1, 1, 1, 1, 1}, _
{-1, 2, -1, 2, -4, 2, -1, 2, -1, 1}, _
{1, 2, 1, 0, 0, 0, -1, -2, -1, 1}, _
{1, 0, -1, 2, 0, -2, 1, 0, -1, 1}, _
{0, 1, 2, -1, 0, 1, -2, -1, 0, 1}, _
{2, 1, 0, 1, 0, -1, 0, -1, -2, 1}, _
{1, 1, 1, 0, 0, 0, -1, -1, -1, 1}, _
{1, 0, -1, 1, 0, -1, 1, 0, -1, 1}, _
{-1, 1, 1, -1, -2, 1, -1, 1, 1, 1}, _
{1, 1, 1, -1, -2, 1, -1, -1, 1, 1}, _
{-1, -1, -1, 2, 2, 2, -1, -1, -1, 1}, _
{-1, 2, -1, -1, 2, -1, -1, 2, -1, 1}, _
{-1, -1, 2, -1, 2, -1, 2, -1, -1, 1}, _
{2, -1, -1, -1, 2, -1, 2, -1, -1, 1}, _
{0, 0, 0, 0, 0, 1, 0, -1, 0, 1}, _
{0, 0, 0, 0, 1, 0, 0, 0, -1, 1}}
Private Const MAXIMGREG = 15
Private Const MAXBLOCK = 255
Private Const RAWSTART = 256
Public Const MAXSIZE = 1048576 '1Mbyte
Public hif As Integer
Public Structure PRC
Public src As String
Public dest As String
Public alg() As Integer
End Structure
Public IMGCOLL As New Collection
Public PRCCOLL As New Collection
Public GDATA() As Byte
Public IMGLST As ListBox
Public PRCLST As ListBox
Public FRMMN As frmMain
Public Function StartDpc() As Boolean
Dim erc As Integer
Dim idDev As Integer
LogC("Initializing DPC... ")
If DpcInit(erc) = False Then
LogN("FAILED")
Exit Function
End If
LogN("done")
StartDpc = True
End Function
Public Function DeviceList(ByRef sDevList As String(), ByRef defDev As Integer) As Boolean
Dim erc As Integer
Dim devcount As Integer
Dim sDev As String
sDev = New String(" ", 24)
LogC("Device list... ")
devcount = DvmgGetDevCount(erc)
ReDim sDevList(devcount - 1)
For iDev As Integer = 0 To devcount - 1
On Error Resume Next
If DvmgGetDevName(iDev, sDev, erc) = False Then
LogN("FAILED")
Exit Function
End If
sDevList(iDev) = sDev
Next
defDev = DvmgGetDefaultDev(erc)
LogN("done")
DeviceList = True
End Function
Public Sub StopDpc()
LogC("Closing DPC... ")
On Error Resume Next
DpcTerm()
LogN("done")
End Sub
Public Function OpenInterface() As Boolean
Dim erc As Integer
LogC("Opening data transfer interface... ")
If DpcOpenData(hif, FRMMN.cboDevice.Text, erc, &H0) = False Then
If DpcOpenData(hif, FRMMN.cboDevice.Text, erc, &H0) = False Then
MsgBox("Please select the right communication module." & Chr(13) & Chr(10) & _
"Or check the connections.", _
MsgBoxStyle.Exclamation, _
"Unable to open interface")
hif = 0
LogN("FAILED")
OpenInterface = False
Exit Function
End If
End If
OpenInterface = True
LogN("done")
End Function
Public Function CloseInterface() As Boolean
Dim erc As Integer
If hif <> 0 Then
LogC("Closing data transfer interface... ")
If DpcCloseData(hif, erc) = False Then
LogN("FAILED")
Else
LogN("done")
CloseInterface = True
End If
End If
hif = 0
End Function
Public Sub EncodeData()
Dim bmpdata As Drawing.Bitmap
Dim pr As PRC
Dim imgcol As Drawing.Color
Dim size, imghead, heightc, widthc, tmp As Integer
ReDim GDATA(MAXSIZE - 1)
Dim rgbmode As Integer
rgbmode = FRMMN.cboResolution.SelectedIndex
LogC("Encoding... ")
If PRCCOLL.Count <> 0 Then
For GDATA(1) = 0 To PRCCOLL.Count - 1
pr = PRCCOLL.Item(GDATA(1) + 1)
imghead = (GDATA(1) << 4) Or &H80
GDATA(imghead) = IMGLST.Items.IndexOf(pr.src) + 1
imghead += 1
GDATA(imghead) = IMGLST.Items.IndexOf(pr.dest) + 1
imghead += 1
For item As Integer = 0 To 9
GDATA(imghead) = Math.Abs(pr.alg(item)) And &H7F
If pr.alg(item) < 0 Then
GDATA(imghead) = GDATA(imghead) Or &H80
End If
imghead += 1
Next
Next
End If
size = RAWSTART
If IMGCOLL.Count <> 0 Then
For GDATA(0) = 0 To IMGCOLL.Count - 1
bmpdata = IMGCOLL.Item(GDATA(0) + 1)
imghead = (GDATA(0) + 1) << 3
GDATA(imghead) = size >> 16
imghead += 1
GDATA(imghead) = (size >> 8) And &HFF
imghead += 1
GDATA(imghead) = size And &HFF
imghead += 1
GDATA(imghead) = bmpdata.Width >> 8
imghead += 1
GDATA(imghead) = bmpdata.Width And &HFF
imghead += 1
GDATA(imghead) = bmpdata.Height >> 8
imghead += 1
GDATA(imghead) = bmpdata.Height And &HFF
imghead += 1
For heightc = 0 To bmpdata.Height - 1
For widthc = 0 To bmpdata.Width - 1
imgcol = bmpdata.GetPixel(widthc, heightc)
If rgbmode = 0 Then
GDATA(size) = imgcol.R
size += 1
GDATA(size) = imgcol.G
size += 1
GDATA(size) = imgcol.B
size += 1
ElseIf rgbmode = 1 Then
GDATA(size) = imgcol.R And &HFC
GDATA(size) += imgcol.G >> 6
size += 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -