
! Right, well, I can get a red dot to follow a real red dot around a mouse mat, onto Kinectimals.
First I think I should learn how to use memblocks
Anyone wana link me to a tutorial or something based on the fact I only really need to be able to understand how to access colour information from the clipboard data retrieved in the code
sladeiw provided.
Original code snippet:
Rem Project: Dark Basic Pro Project
Rem Created: Wednesday, November 24, 2010
Rem ***** Main Source File *****
Rem Project: Camtest
Rem Created: 07/11/2010 04:25:55
Rem ***** Main Source File *****
load dll "c:\windows\system32\avicap32.dll",1
load dll "c:\windows\system32\user32.dll",2
#constant _USER32 2
#constant _TRUE 1
#constant _FALSE 0
disable escapekey
dim RUNNING(15,2)
WS_CHILD=1073741824
WS_VISIBLE=268435456
WM_CAP_SET_SCALE=1024+53
WM_CAP_DRIVER_CONNECT=1024+10
WM_CAP_DRIVER_DISCONNECT=1024+11
WM_CAP_SET_PREVIEW=1024+50
WM_CAP_SET_PREVIEWRATE=1024+52
WM_CAP_EDIT_COPY=1024+30
WM_CAP_SEQUENCE=1024+62
WM_CAP_FILE_SAVEDIB=1024+25
WM_CAP_DLG_VIDEODISPLAY=1024+43
WM_CAP_SET_OVERLAY=1024+51
PICID=call dll (2,"GetActiveWindow")
HHWND=call dll (1,"capCreateCaptureWindowA","driver",WS_VISIBLE Or WS_CHILD,0,0,1,1,PICID,0)
call dll 2,"SendMessageA",HHWND,WM_CAP_DRIVER_CONNECT,0,0
call dll 2,"SendMessageA",HHWND,WM_CAP_SET_PREVIEW,1,0
call dll 2,"SendMessageA",HHWND,WM_CAP_SET_PREVIEWRATE,33,0
SW=1440
SH=900
set display mode SW,SH,32,0
sync on
sync rate 0
do
cls
call dll 2,"SendMessageA",HHWND,WM_CAP_EDIT_COPY,0,0
result=GetClipboardImage(2)
make image from memblock 1,2
delete memblock 2
box (SW/2)-1,SH/4,(SW/2)+1,3*(SH/4)
box SW/3,(SH/2)-1,2*(SW/3),(SH/2)+1
box (SW/2)-((image width(1)/2)+4),(SH/2)-((image height(1)/2)+4),(SW/2)+(image width(1)/2)+4,(SH/2)+(image height(1)/2)+4
paste image 1,SW/2-(image width(1)/2),SH/2-(image height(1)/2)
GT_RED=rgbr(point(SW/2,SH/2))
GT_GREEN=rgbg(point(SW/2,SH/2))
GT_BLUE=rgbb(point(SW/2,SH/2))
box 0,0,255,255,rgb(128,128,128),rgb(128,128,128),rgb(128,128,128),rgb(128,128,128)
box (INDEX*16),255-GT_RED,(INDEX*16)-2,255,rgb(GT_RED,0,0),rgb(GT_RED,0,0),rgb(GT_RED,0,0),rgb(GT_RED,0,0)
box (INDEX*16),255-GT_GREEN,(INDEX*16)+2,255,rgb(0,GT_GREEN,0),rgb(0,GT_GREEN,0),rgb(0,GT_GREEN,0),rgb(0,GT_GREEN,0)
box (INDEX*16)+2,255-GT_BLUE,(INDEX*16)+4,255,rgb(0,0,GT_BLUE),rgb(0,0,GT_BLUE),rgb(0,0,GT_BLUE),rgb(0,0,GT_BLUE)
RUNNING(INDEX,0)=GT_RED
RUNNING(INDEX,1)=GT_GREEN
RUNNING(INDEX,2)=GT_BLUE
INDEX=INDEX+1
if INDEX>15 then INDEX=0
for I=1 to 15
line (I-1)*16,255-RUNNING(I-1,0),I*16,255-RUNNING(I,0)
line (I-1)*16,255-RUNNING(I-1,1),I*16,255-RUNNING(I,1)
line (I-1)*16,255-RUNNING(I-1,2),I*16,255-RUNNING(I,2)
dot I*16,255-RUNNING(I,0),rgb(RUNNING(I,0),0,0)
dot I*16,255-RUNNING(I,1),rgb(0,RUNNING(I,1),0)
dot I*16,255-RUNNING(I,2),rgb(0,0,RUNNING(I,2))
next I
`text 540,0,str$((RUNNING(0,0)+RUNNING(1,0)+RUNNING(2,0)+RUNNING(3,0)+RUNNING(4,0)+RUNNING(5,0)+RUNNING(6,0)+RUNNING(7,0)+RUNNING(8,0)+RUNNING(9,0)+RUNNING(10,0)+RUNNING(11,0)+RUNNING(12,0)+RUNNING(13,0)+RUNNING(14,0)+RUNNING(15,0))/16)
if escapekey() then cls : center text SW/2,SH/2,"<CLOSING>" : sync : exit
sync
loop
call dll 2,"SendMessageA",HHWND,WM_CAP_DRIVER_DISCONNECT,0,0
call dll 2,"DestroyWindow",HHWND
delete dll 2
delete dll 1
end
Function CheckClipboardImage()
`*************************************************************************************************************************************************************************************************************************************
`Checks if an image is available on the clipboard. Returns _TRUE for yes, _FALSE for no
result=call dll(_USER32,"OpenClipboard",0) `Try opening clipboard (0=For this process)
if result=0 then ExitFunction _FALSE `If can't open clipboard then immediate exit with failure
local handle as dword
handle=call dll(_USER32,"GetClipboardData",_CF_DIBV5) `Try get handle to clipboard object in requested format
call dll _USER32,"CloseClipboard" `Close clipboard for this process (Ignore resultcode even if error)
if handle>0 then ExitFunction _TRUE `Found a valid image - return TRUE
EndFunction _FALSE
Function GetClipboardImage(memblk)
`*************************************************************************************************************************************************************************************************************************************
`Gets an image from the clipboard and stores it as a memblock image structure in the specified memblock
`Returns 1 if successful, 0 if not. (eg. no image, not compatable, compressed etc)
`** Could be altered to only copy 3 bytes (1 word & 1 byte) for 32 bit or 24 bit images.
`BITMAPV5HEADER Structure - see http://msdn.microsoft.com/en-us/library/dd183381%28VS.85%29.aspx
`memblk Number of the memblock to use for image (Must not already exist)
#constant _CF_BITMAP 2 `Types of bitmap structure for clipboard
#constant _CF_DIBV5 17 `This is preferred format
result=call dll(_USER32,"OpenClipboard",0) `Try opening clipboard (0=For this process)
if result=0 then ExitFunction _FALSE `If can't open clipboard then immediate exit with failure
local handle as dword
handle=call dll(_USER32,"GetClipboardData",_CF_DIBV5) `Try get handle to clipboard object in requested format
if handle>0
bV5Size =peek dword(handle) `Size of BitmapV5 structure
bV5Width =peek dword(handle+4) `Pixel width of image
bV5Height =peek dword(handle+8) `and height
bV5BitCount=peek word(handle+14) `Get bits depth from structure (Can only copy 24 or 32bit images)
bV5Compress=peek dword(handle+16) `Compression mode, 0 or 3=uncompressed
if (bV5BitCount=24 or bV5BitCount=32) and (bV5Compress=0 or bV5Compress=3)
make memblock memblk,(bV5Width*bV5Height*4)+12 `Make a memblock to fit destination image
dptr=get memblock ptr(memblk) `Dest pointer
poke dword dptr,bV5Width `Memblock image width
poke dword dptr+4,bV5Height `and height
poke dword dptr+8,32 `depth always 32bit
inc dptr,12 `Set dest pointer to start position for pixel data
`?Some pics need padding and some dont work if it's there?
pad=0 `4-((bV5Width*3) mod 4) : if pad=4 then pad=0 `Padding to keep source bitmap each line on 32bit boundary
byteCount=bV5BitCount/8 `Calc bytes per pixel used in source img
for y=bV5Height-1 to 0 step -1
sptr=handle+bV5Size+(bV5Width*y*byteCount)+(y*pad) `Calc source bitmap pointer for each line
for x=0 to bV5Width-1
poke dword dptr,peek dword(sptr) `Copy each pixel from source to dest memblock
inc dptr,4 `Inc dest ptr (Should really check/clear spare byte in dest - alpha?)
inc sptr,byteCount `Inc source pointer by bytes per pixel (3 or 4)
next x
next y
call dll _USER32,"CloseClipboard" `Close clipboard for this process (Ignore resultcode even if error)
ExitFunction _TRUE `Completed successfully - return TRUE
endif
endif
call dll _USER32,"CloseClipboard" `Close clipboard for this process (Ignore resultcode even if error)
EndFunction _FALSE
The code for my application (which makes a red dot follow a red square around on a black background):
// Project: Camtest
// Created: 07/11/2010 04:25:55
// ***** Main Source File *****
load dll "c:\windows\system32\avicap32.dll",1
load dll "c:\windows\system32\user32.dll",2
disable escapekey
#constant USER32 2
#constant TRUE 1
#constant FALSE 0
WS_CHILD=1073741824
WS_VISIBLE=268435456
WM_CAP_SET_SCALE=1024+53
WM_CAP_DRIVER_CONNECT=1024+10
WM_CAP_DRIVER_DISCONNECT=1024+11
WM_CAP_SET_PREVIEW=1024+50
WM_CAP_SET_PREVIEWRATE=1024+52
WM_CAP_EDIT_COPY=1024+30
WM_CAP_SEQUENCE=1024+62
WM_CAP_FILE_SAVEDIB=1024+25
WM_CAP_DLG_VIDEODISPLAY=1024+43
WM_CAP_SET_OVERLAY=1024+51
PICID=call dll (2,"GetActiveWindow")
HHWND=call dll (1,"capCreateCaptureWindowA","driver",WS_VISIBLE Or WS_CHILD,0,0,1,1,PICID,0)
call dll 2,"SendMessageA",HHWND,WM_CAP_DRIVER_CONNECT,0,0
call dll 2,"SendMessageA",HHWND,WM_CAP_SET_PREVIEW,1,0
call dll 2,"SendMessageA",HHWND,WM_CAP_SET_PREVIEWRATE,66,0
SW=800
SH=600
set display mode SW,SH,32,0
set window on
restore window
set window size SW,SH
set window position 192,96
set window title "Camtest"
ink rgb(0,255,255),rgb(0,0,0)
set text font "Tahoma"
set text to bold
set text size 16
input "X divisions: ",XDIVS
input "Y divisions: ",YDIVS
if XDIVS=0 then XDIVS=2
if YDIVS=0 then YDIVS=2
sync on
sync rate 66
sync
dim MAP(XDIVS-1,YDIVS-1)
PLACEX#=SW/2
PLACEY#=SH/2
SPEED=32
do
cls
call dll 2,"SendMessageA",HHWND,WM_CAP_EDIT_COPY,0,0
RESULT=GETCLIPBOARDIMAGE(2)
make image from memblock 1,2
delete memblock 2
XDIVSIZE=image width(1)/XDIVS
YDIVSIZE=image height(1)/YDIVS
if keystate(41)
if GKEY=0
STATSON=1-STATSON
endif
endif
GKEY=keystate(41)
if STATSON=1 then text (SW/2)-((image width(1)/2)+4),(SH/2)-((image height(1)/2)+4)-16,"FPS: "+str$(screen fps())
box (SW/2)-1,SH/4,(SW/2)+1,3*(SH/4)
box SW/3,(SH/2)-1,2*(SW/3),(SH/2)+1
box (SW/2)-((image width(1)/2)+4),(SH/2)-((image height(1)/2)+4),(SW/2)+(image width(1)/2)+4,(SH/2)+(image height(1)/2)+4
paste image 1,SW/2-(image width(1)/2),SH/2-(image height(1)/2)
for XI=0 to XDIVS-1
for YI=0 to YDIVS-1
MAP(XI,YI)=rgbr(point((SW/2)+((XI-(XDIVS/2))*XDIVSIZE)+XDIVSIZE/2,(SH/2)+((YI-(YDIVS/2))*YDIVSIZE)+YDIVSIZE/2))
if MAP(XI,YI)>128
if STATSON=1 then text DESTX#,DESTY#,str$(MAP(XI,YI))
DESTX#=(SW/2)+((XI-(XDIVS/2))*XDIVSIZE)+XDIVSIZE/2
DESTY#=(SH/2)+((YI-(YDIVS/2))*YDIVSIZE)+YDIVSIZE/2
`PLACEX#=PLACEX#+((DESTX#-PLACEX#)/(((DESTX#-PLACEX#)*(DESTX#-PLACEX#))^0.5))*4
`PLACEY#=PLACEY#+((DESTY#-PLACEY#)/(((DESTY#-PLACEY#)*(DESTY#-PLACEY#))^0.5))*4
ANG#=atanfull(DESTX#-PLACEX#,DESTY#-PLACEY#)
PLACEX#=PLACEX#+sin(ANG#)*4
PLACEY#=PLACEY#+cos(ANG#)*4
endif
if STATSON=1 then dot (SW/2)+((XI-(XDIVS/2))*XDIVSIZE)+XDIVSIZE/2,(SH/2)+((YI-(YDIVS/2))*YDIVSIZE)+YDIVSIZE/2
next YI
next XI
box PLACEX#-4,PLACEY#-4,PLACEX#+4,PLACEY#+4,rgb(255,0,0),rgb(255,0,0),rgb(255,0,0),rgb(255,0,0)
text 0,0,"Press ` for stats"
if escapekey() then cls : center text SW/2,SH/2,"<CLOSING>" : sync : exit
sync
loop
call dll 2,"SendMessageA",HHWND,WM_CAP_DRIVER_DISCONNECT,0,0
call dll 2,"DestroyWindow",HHWND
delete dll 2
delete dll 1
end
function GETCLIPBOARDIMAGE(MEMBLK)
#constant CFBITMAP 2
#constant CFDIBV5 17
RESULT=call dll(USER32,"OpenClipboard",0)
if RESULT=0 then exitfunction FALSE
local HANDLE as dword
HANDLE=call dll(USER32,"GetClipboardData",CFDIBV5)
if HANDLE>0
BV5SIZE=peek dword(HANDLE)
BV5WIDTH=peek dword(HANDLE+4)
BV5HEIGHT=peek dword(HANDLE+8)
BV5BITCOUNT=peek word(HANDLE+14)
BV5COMPRESS=peek dword(HANDLE+16)
if (BV5BITCOUNT=24 or BV5BITCOUNT=32) and (BV5COMPRESS=0 or BV5COMPRESS=3)
make memblock MEMBLK,(BV5WIDTH*BV5HEIGHT*4)+12
DPTR=get memblock ptr(MEMBLK)
poke dword DPTR,BV5WIDTH
poke dword DPTR+4,BV5HEIGHT
poke dword DPTR+8,32
DPTR=DPTR+12
PAD=0
BYTECOUNT=BV5BITCOUNT/8
for Y=BV5HEIGHT-1 to 0 step -1
SPTR=HANDLE+BV5SIZE+(BV5WIDTH*Y*BYTECOUNT)+(Y*PAD)
for X=0 to BV5WIDTH-1
poke dword DPTR,peek dword(SPTR)
DPTR=DPTR+4
SPTR=SPTR+BYTECOUNT
next X
next Y
call dll USER32,"CloseClipboard"
exitfunction TRUE
endif
endif
call dll USER32,"CloseClipboard"
endfunction FALSE
function CHECKCLIPBOARDIMAGE()
RESULT=call dll(USER32,"OpenClipboard",0)
if RESULT=0 then exitfunction FALSE
local HANDLE as dword
HANDLE=call dll(USER32,"GetClipboardData",CFDIBV5)
call dll USER32,"CloseClipboard"
if HANDLE>0 then exitfunction TRUE
endfunction FALSE

!