Re: ESCAPI problems
Posted: Wed Mar 02, 2016 11:29 am
Here is a simple webcam program which works with the existing escapi.pbi and the escapi3 dll.
Code: Select all
;webcam_simple.pb
;UPDATED 3/2/2016
DisableDebugger
IncludeFile "escapi.pbi"
WIDTH = 1279/1 ;640
HEIGHT = 719/1 ;360
WIDTHM1 = WIDTH - 1
HEIGHTM1 = HEIGHT - 1
#DEVICE = 0
If setupESCAPI() = 0
MessageRequester("Error", "Unable to initialize ESCAPI.")
End
EndIf
name$ = Space(255)
getCaptureDeviceName(#DEVICE, @name$, 255)
bufSize = WIDTH * HEIGHT * 4
scp.SimpleCapParams
scp\mWidth = WIDTH
scp\mHeight = HEIGHT
scp\mTargetBuf = AllocateMemory(bufSize)
*buf = scp\mTargetBuf
If initCapture(#DEVICE, @scp)
image = CreateImage(1, WIDTH, HEIGHT, 24)
OpenWindow(0, 0, 0, WIDTH, HEIGHT, name$, #PB_Window_SystemMenu)
ImageGadget(0, 0, 0, WIDTH, HEIGHT, ImageID(1))
offset = 0
Quit = #False
offset = 0
StartDrawing(ImageOutput(1))
*writeBuffer = DrawingBuffer()
pitch = DrawingBufferPitch()
StopDrawing()
Repeat
;If WaitWindowEvent(1) = #PB_Event_CloseWindow
If WindowEvent() = #PB_Event_CloseWindow
Quit = #True
Break
EndIf
doCapture(#DEVICE)
;Repeat: Until isCaptureDone(#DEVICE) <> #False
;NEEDS PIXEL-BY-PIXEL READING AND WRITING -- CANNOT USE CATCHIMAGE
hm1 = *writebuffer + (HEIGHTM1 * pitch)
*bufoff = *buf
For y = 0 To HEIGHTM1
For x = 0 To WIDTHM1
PokeL(hm1 + x*3, PeekL(*bufoff))
*bufoff + 4
Next
hm1 - pitch
Next
Repeat: Until isCaptureDone(#DEVICE) <> #False
SetGadgetState(0, ImageID(1))
Until Quit = #True
deinitCapture(#DEVICE)
FreeImage(1)
FreeMemory(scp\mTargetBuf)
CloseWindow(0)
Else
MessageRequester("ERROR", "Init capture failed.")
End
EndIf
End