/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ /******************************************************************************* Plugin Capture Capture Player permettant de lire des media reconnus par Capture Client part Version: 4.0 Author: Bastien BOURINEAU Date: 21/01/2007 Last update: 02/04/2009 *******************************************************************************/ struct PlugCaptureMotion = [ CAPMT_instance : PInstance, CAPMT_Device : ObjCapture, CAPMT_bOnMaterial : I, CAPMT_Material : SO3_MATERIAL, CAPMT_iTechnique : I, CAPMT_iPass : I, CAPMT_iTexture : I, CAPMT_win : SO3_WIDGET, CAPMT_iPosX : I, CAPMT_iPosY : I, CAPMT_iWidth : I, CAPMT_iHeight : I, CAPMT_tPercent : [I I I I I I I I], CAPMT_tAlign : [I I], CAPMT_iOpacity : I, CAPMT_Buffer : ObjBitmap, CAPMT_prevBuffer : ObjBitmap, CAPMT_bMirror : I, CAPMT_bBackground : I, CAPMT_bShow : I, CAPMT_iSendTick : I, CAPMT_bDataEvent : I, CAPMT_iSendInterval : I, CAPMT_iJpegComp : I, CAPMT_bPrevBuffer : I, CAPMT_iSensivity : I, CAPMT_iDetectInterval : I, CAPMT_iDetectTick : I, CAPMT_bSavePict : I ] MkPlugCaptureMotion;; var sMotionPath = "tmp/motion/";; fun cbRenderCapture(inst, viewstr, capstr) = if (_BLTcapture capstr.CAPMT_Device capstr.CAPMT_Buffer) == nil then nil else let _GETbitmapSize capstr.CAPMT_Buffer -> [bw bh] in ( if (capstr.CAPMT_bMirror != 1) then nil else ( _BTFLIPbitmap capstr.CAPMT_Buffer; ); if (!capstr.CAPMT_bShow) then nil else SO3BitmapWidgetBlit capstr.CAPMT_win capstr.CAPMT_Buffer; //motion detection if (!capstr.CAPMT_bPrevBuffer) then nil else ( if !(_BTMOTIONdetect capstr.CAPMT_prevBuffer capstr.CAPMT_Buffer 65 capstr.CAPMT_iSensivity) then nil else ( if ((capstr.CAPMT_iDetectTick != nil) && ((_tickcount - capstr.CAPMT_iDetectTick) < (capstr.CAPMT_iDetectInterval * 1000))) then nil else ( SendPluginEvent inst "Motion detected" nil nil; set capstr.CAPMT_iDetectTick = _tickcount; if (!capstr.CAPMT_bSavePict) then nil else ( let ctime time -> date in let strcatn sMotionPath::(getPluginInstanceName inst)::"_"::(substr (ctime time) 0 ((strlen date) -1))::".jpg"::nil -> path in let strreplace (strreplace path " " "_") ":" "-" -> path in _SAVEjpeg capstr.CAPMT_Buffer (_getmodifypack path) 90; ); ); ); ); if (!capstr.CAPMT_bDataEvent) then nil else if (capstr.CAPMT_iSendTick != nil) && ((_tickcount - capstr.CAPMT_iSendTick) < capstr.CAPMT_iSendInterval) then nil else let if capstr.CAPMT_iJpegComp <= 20 then [bw/4 bh/4] else if capstr.CAPMT_iJpegComp <= 50 then [bw/3 bh/3] else if capstr.CAPMT_iJpegComp <= 80 then [bw/2 bh/2] else [bw bh] -> [nw nh] in let G2DstrechBitmap _channel capstr.CAPMT_Buffer nw nh 0 -> bmp in let _BTCompBitmap bmp capstr.CAPMT_iJpegComp -> sbmp in ( _DSbitmap bmp; let strcatn "Z"::"_"::(itoa nw)::"_"::(itoa nh)::"_"::(zip sbmp)::nil -> data in SendPluginEvent inst "Data changed" data nil; set capstr.CAPMT_iSendTick = _tickcount; ); _CPbitmap24 capstr.CAPMT_prevBuffer 0 0 capstr.CAPMT_Buffer 0 0 bw bh nil; set capstr.CAPMT_bPrevBuffer = 1; ); 0;; fun restoreTexture(capstr)= if (capstr.CAPMT_Device == nil) then nil else ( setPluginInstanceCbPreRender capstr.CAPMT_instance nil; V3DremoveWidgetControl (V3DgetDefaultViewport (V3DgetSessionView c3dXsession)) capstr.CAPMT_win; SO3WidgetDestroy capstr.CAPMT_win; set capstr.CAPMT_win = nil; _DSbitmap capstr.CAPMT_Buffer; _DSbitmap capstr.CAPMT_prevBuffer; set capstr.CAPMT_Buffer = nil; set capstr.CAPMT_prevBuffer = nil; set capstr.CAPMT_bPrevBuffer = 0; ); 0;; fun cbShow(inst, from, action, param, reply, capstr)= SO3WidgetSetVisibility capstr.CAPMT_win 1; set capstr.CAPMT_bShow = 1; 0;; fun cbHide(inst, from, action, param, reply, capstr)= SO3WidgetSetVisibility capstr.CAPMT_win 0; set capstr.CAPMT_bShow = 0; 0;; fun computePosSize(capstr, vw, vh)= let capstr.CAPMT_tPercent -> [px py pw ph xo yo wo ho] in let capstr.CAPMT_tAlign -> [ax ay] in let if pw then (ftoi (((itof capstr.CAPMT_iWidth) /. 100.0) *. (itof vw))) + wo else capstr.CAPMT_iWidth -> pw in let if ph then (ftoi (((itof capstr.CAPMT_iHeight) /. 100.0) *. (itof vh))) + ho else capstr.CAPMT_iHeight -> ph in let if px then (ftoi (((itof capstr.CAPMT_iPosX) /. 100.0) *. (itof vw))) + xo else capstr.CAPMT_iPosX -> px in let if (ax == 1) then ((vw / 2) - (pw / 2)) + px else if (ax == 2) then (vw - pw) - px else px -> px in let if py then (ftoi (((itof capstr.CAPMT_iPosY) /. 100.0) *. (itof vh))) + yo else capstr.CAPMT_iPosY -> py in let if (ay == 1) then ((vh / 2) - (ph / 2)) + py else if (ay == 2) then (vh - ph) - py else py -> py in [px py pw ph];; fun cbResizeCtrl(inst, viewstr, vw, vh, capstr)= if capstr.CAPMT_win == nil || capstr.CAPMT_bOnMaterial then nil else let computePosSize capstr vw vh -> [px py pw ph] in ( SO3WidgetSetPosition capstr.CAPMT_win px py; SO3WidgetSetSize capstr.CAPMT_win pw ph; ); 0;; fun connectCapture(inst, from, action, param, rep, capstr)= if (capstr.CAPMT_Device != nil) then nil else ( set capstr.CAPMT_Device = _CRcapture _channel (atoi _getress "videocapture"); // try to find one let 0 -> i in while capstr.CAPMT_Device == nil && (i < 16) do ( set capstr.CAPMT_Device = _CRcapture _channel i; set i = i + 1; ); if (capstr.CAPMT_Device == nil) then nil else ( _SETcaptureSize capstr.CAPMT_Device 640 480; _SETcaptureMirror capstr.CAPMT_Device capstr.CAPMT_bMirror; if (capstr.CAPMT_Device == nil) then nil else let _GETcaptureSize capstr.CAPMT_Device -> [cw ch] in ( set capstr.CAPMT_Buffer = _FILLbitmap _CRbitmap _channel cw ch 0; set capstr.CAPMT_prevBuffer = _FILLbitmap _CRbitmap _channel cw ch 0; let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in if capstr.CAPMT_win != nil then nil else ( V3DremoveWidgetControl viewportstr capstr.CAPMT_win; SO3WidgetDestroy capstr.CAPMT_win; if capstr.CAPMT_bOnMaterial then ( set capstr.CAPMT_win = SO3BitmapWidgetCreateOnMaterial (V3DgetSession c3dXsession) capstr.CAPMT_Material (strcat (getPluginInstanceName inst) "_captureMotionCtrl") capstr.CAPMT_iWidth capstr.CAPMT_iHeight capstr.CAPMT_iTechnique capstr.CAPMT_iPass capstr.CAPMT_iTexture; 0; ) else if capstr.CAPMT_bBackground then ( let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let computePosSize capstr vw vh -> [px py pw ph] in set capstr.CAPMT_win = SO3BitmapWidgetCreateBackground (V3DgetSession c3dXsession) viewportstr.V3D_viewport (strcat (getPluginInstanceName inst) "_captureMotionCtrl") px py pw ph; 0; ) else ( let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let computePosSize capstr vw vh -> [px py pw ph] in set capstr.CAPMT_win = SO3BitmapWidgetCreate (V3DgetSession c3dXsession) viewportstr.V3D_viewport (strcat (getPluginInstanceName inst) "_captureMotionCtrl") px py pw ph 100; SO3WidgetSetTopOnFocus capstr.CAPMT_win 0; SO3WidgetSetForeground capstr.CAPMT_win 1; 0; ); V3DaddWidgetControl viewportstr capstr.CAPMT_win; SO3WidgetSetKeyboardEnable capstr.CAPMT_win 0; SO3WidgetSetMouseEnable capstr.CAPMT_win 0; SO3WidgetSetOpacity capstr.CAPMT_win (itof capstr.CAPMT_iOpacity) *. 0.01; ); set capstr.CAPMT_bPrevBuffer = 0; if (capstr.CAPMT_bShow) then SO3WidgetSetVisibility capstr.CAPMT_win 1 else SO3WidgetSetVisibility capstr.CAPMT_win 0; setPluginInstanceCbPreRender inst mkfun3 @cbRenderCapture capstr; ); ); ); 0;; fun disconnectCapture(inst, from, action, param, rep, capstr)= restoreTexture capstr; if (capstr.CAPMT_Device == nil) then nil else ( _DScapture capstr.CAPMT_Device; set capstr.CAPMT_Device = nil; set capstr.CAPMT_bPrevBuffer = 0; ); 0;; // Destroy instance fun deleteOb(inst, capstr)= disconnectCapture inst nil nil nil nil capstr; SendPluginEvent inst "Disconnected" nil nil; 0;; fun cbNewOb(inst)= let atoi (getPluginInstanceParam inst "istexture") -> istexture in let if istexture == nil then 0 else istexture -> istexture in let (getPluginInstanceParam inst "object") -> objname in let (getPluginInstanceParam inst "material") -> matname in let atoi (getPluginInstanceParam inst "technique") -> technique in let if technique == nil then 0 else technique -> technique in let atoi (getPluginInstanceParam inst "pass") -> pass in let if pass == nil then 0 else pass -> pass in let atoi (getPluginInstanceParam inst "texture") -> texture in let if texture == nil then 0 else texture -> texture in let atoi (getPluginInstanceParam inst "posx") -> posx in let atoi (getPluginInstanceParam inst "posy") -> posy in let atoi (getPluginInstanceParam inst "width") -> width in let atoi (getPluginInstanceParam inst "height") -> height in let atoi (getPluginInstanceParam inst "xpercent") -> xpercent in let atoi (getPluginInstanceParam inst "ypercent") -> ypercent in let atoi (getPluginInstanceParam inst "wpercent") -> wpercent in let atoi (getPluginInstanceParam inst "hpercent") -> hpercent in let atoi (getPluginInstanceParam inst "xoffset") -> xoffset in let if xoffset == nil then 0 else xoffset -> xoffset in let atoi (getPluginInstanceParam inst "yoffset") -> yoffset in let if yoffset == nil then 0 else yoffset -> yoffset in let atoi (getPluginInstanceParam inst "woffset") -> woffset in let if woffset == nil then 0 else woffset -> woffset in let atoi (getPluginInstanceParam inst "hoffset") -> hoffset in let if hoffset == nil then 0 else hoffset -> hoffset in let atoi (getPluginInstanceParam inst "xalign") -> xalign in let atoi (getPluginInstanceParam inst "yalign") -> yalign in let atoi (getPluginInstanceParam inst "background") -> background in let if (background == nil) then 0 else background -> background in let atoi (getPluginInstanceParam inst "opacity") -> opacity in let if opacity == nil then 100 else opacity -> opacity in let atoi (getPluginInstanceParam inst "mirror") -> mirror in let if (mirror == nil) then 0 else mirror -> mirror in let atoi (getPluginInstanceParam inst "init") -> init in let if (init == nil) then 1 else init -> init in let atoi (getPluginInstanceParam inst "show") -> show in let if (show == nil) then 1 else show -> show in let atoi (getPluginInstanceParam inst "msensivity") -> msensivity in let if (msensivity == nil) then 80 else msensivity -> msensivity in let atoi (getPluginInstanceParam inst "minterval") -> minterval in let if (minterval == nil) then 0 else minterval -> minterval in let atoi (getPluginInstanceParam inst "msavepict") -> msavepict in let if (msavepict == nil) then 0 else msavepict -> msavepict in let atoi (getPluginInstanceParam inst "dataevent") -> dataevent in let if (dataevent == nil) then 0 else dataevent -> dataevent in let atoi (getPluginInstanceParam inst "sendinterval") -> sendinterval in let if (dataevent == nil) then 200 else sendinterval -> sendinterval in let atoi (getPluginInstanceParam inst "jpegcomp") -> jpegcomp in let if (jpegcomp == nil) then 60 else jpegcomp -> jpegcomp in let SO3SceneGetObject (V3DgetSession c3dXsession) objname -> obj in let if !istexture then nil else SO3SceneGetMaterial (V3DgetSession c3dXsession) (SO3EntityGetResourceGroup obj) matname -> mat in let MkPlugCaptureMotion [inst nil istexture mat technique pass texture nil posx posy width height [xpercent ypercent wpercent hpercent xoffset yoffset woffset hoffset] [xalign yalign] opacity nil nil mirror background show nil dataevent sendinterval jpegcomp 0 msensivity minterval nil msavepict] -> capstr in ( if capstr.CAPMT_bOnMaterial then nil else setPluginInstanceCbResizeView inst mkfun5 @cbResizeCtrl capstr; if !init then nil else connectCapture inst nil nil nil nil capstr; PluginRegisterAction inst "Connect" mkfun6 @connectCapture capstr; PluginRegisterAction inst "Disconnect" mkfun6 @disconnectCapture capstr; PluginRegisterAction inst "Show" mkfun6 @cbShow capstr; PluginRegisterAction inst "Hide" mkfun6 @cbHide capstr; setPluginInstanceCbDel inst mkfun2 @deleteOb capstr; ); 0;; fun IniPlug(file) = PlugRegister @cbNewOb nil; setPluginEditor @dynamicedit; 0;;