/* ----------------------------------------------------------------------------- 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 PlugCapture = [ CAP_instance : PInstance, CAP_Device : ObjCapture, CAP_iDeviceIndex : I, CAP_bOnMaterial : I, CAP_Material : SO3_MATERIAL, CAP_iTechnique : I, CAP_iPass : I, CAP_iTexture : I, CAP_win : SO3_WIDGET, CAP_iPosX : I, CAP_iPosY : I, CAP_iWidth : I, CAP_iHeight : I, CAP_tPercent : [I I I I I I I I], CAP_tAlign : [I I], CAP_iOpacity : I, CAP_Buffer : ObjBitmap, CAP_CamParam : ObjArCameraParam, CAP_bMirror : I, CAP_bBackground : I, CAP_bShow : I, CAP_iTick : I, CAP_bDataEvent : I, CAP_iSendInterval : I, CAP_iJpegComp : I, CAP_bDetectAr : I ] MkPlugCapture;; fun cbRenderCapture(inst, viewstr, capstr) = if (_BLTcapture capstr.CAP_Device capstr.CAP_Buffer) == nil then nil else ( _UPDATEarMarkers capstr.CAP_Buffer capstr.CAP_CamParam capstr.CAP_bMirror 1; if (capstr.CAP_bMirror != 1) then nil else _BTFLIPbitmap capstr.CAP_Buffer; if (!capstr.CAP_bShow) then nil else SO3BitmapWidgetBlit capstr.CAP_win capstr.CAP_Buffer; if (!capstr.CAP_bDataEvent) then nil else if (capstr.CAP_iTick != nil) && ((_tickcount - capstr.CAP_iTick) < capstr.CAP_iSendInterval) then nil else let _GETbitmapSize capstr.CAP_Buffer -> [bw bh] in let if capstr.CAP_iJpegComp <= 20 then [bw/4 bh/4] else if capstr.CAP_iJpegComp <= 50 then [bw/3 bh/3] else if capstr.CAP_iJpegComp <= 80 then [bw/2 bh/2] else [ftoi ((itof bw) /. 1.5) ftoi ((itof bh) /. 1.5)] -> [bw bh] in let G2DstrechBitmap _channel capstr.CAP_Buffer bw bh 0 -> bmp in let _BTCompBitmap bmp capstr.CAP_iJpegComp -> sbmp in ( //do not destroy bitmap is this is the same if (capstr.CAP_Buffer == bmp) then nil else _DSbitmap bmp; let strcatn "Z"::"_"::(itoa bw)::"_"::(itoa bh)::"_"::(zip sbmp)::nil -> data in SendPluginEvent inst "Data changed" data nil; set capstr.CAP_iTick = _tickcount; ); ); 0;; fun restoreTexture(capstr)= if (capstr.CAP_Device == nil) then nil else ( setPluginInstanceCbPreRender capstr.CAP_instance nil; V3DremoveWidgetControl (V3DgetDefaultViewport (V3DgetSessionView c3dXsession)) capstr.CAP_win; SO3WidgetDestroy capstr.CAP_win; set capstr.CAP_win = nil; _DSbitmap capstr.CAP_Buffer; set capstr.CAP_Buffer = nil; ); 0;; fun cbShow(inst, from, action, param, reply, capstr)= SO3WidgetSetVisibility capstr.CAP_win 1; set capstr.CAP_bShow = 1; 0;; fun cbHide(inst, from, action, param, reply, capstr)= SO3WidgetSetVisibility capstr.CAP_win 0; set capstr.CAP_bShow = 0; 0;; fun computePosSize(capstr, vw, vh)= let capstr.CAP_tPercent -> [px py pw ph xo yo wo ho] in let capstr.CAP_tAlign -> [ax ay] in let if pw then (ftoi (((itof capstr.CAP_iWidth) /. 100.0) *. (itof vw))) + wo else capstr.CAP_iWidth -> pw in let if ph then (ftoi (((itof capstr.CAP_iHeight) /. 100.0) *. (itof vh))) + ho else capstr.CAP_iHeight -> ph in let if px then (ftoi (((itof capstr.CAP_iPosX) /. 100.0) *. (itof vw))) + xo else capstr.CAP_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.CAP_iPosY) /. 100.0) *. (itof vh))) + yo else capstr.CAP_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, ww, wh, capstr)= if capstr.CAP_win == nil || capstr.CAP_bOnMaterial then nil else let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let computePosSize capstr vw vh -> [px py pw ph] in ( SO3WidgetSetPosition capstr.CAP_win px py; SO3WidgetSetSize capstr.CAP_win pw ph; ); 0;; fun cbSetPosition(inst, from, action, param, reply, capstr)= if param == nil then nil else let strextr param -> lp in let (nth_list (hd lp) 0) -> sx in let (nth_list (hd lp) 1) -> sy in let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in ( let 0 -> xpercent in let if (!strcmp "%" (substr sx ((strlen sx) - 1) 1)) then ( set xpercent = 1; atoi sx; ) else atoi sx -> px in let 0 -> ypercent in let if (!strcmp "%" (substr sy ((strlen sy) - 1) 1)) then ( set ypercent = 1; atoi sy; ) else atoi sy -> py in let [(if px == nil then 0 else px) (if py == nil then 0 else py)] -> [px py] in ( mutate capstr.CAP_tPercent <- [xpercent ypercent _ _ _ _ _ _]; set capstr.CAP_iPosX = px; set capstr.CAP_iPosY = py; let computePosSize capstr vw vh -> [px py pw ph] in ( SO3WidgetSetPosition capstr.CAP_win px py; SO3WidgetSetSize capstr.CAP_win pw ph; ); ); ); 0;; fun cbSetSize(inst, from, action, param, reply, capstr)= if param == nil then nil else let strextr param -> lp in let (nth_list (hd lp) 0) -> sx in let (nth_list (hd lp) 1) -> sy in let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in ( let 0 -> wpercent in let if (!strcmp "%" (substr sx ((strlen sx) - 1) 1)) then ( set wpercent = 1; atoi sx; ) else atoi sx -> px in let 0 -> hpercent in let if (!strcmp "%" (substr sy ((strlen sy) - 1) 1)) then ( set hpercent = 1; atoi sy; ) else atoi sy -> py in let [(if px == nil then 0 else px) (if py == nil then 0 else py)] -> [px py] in ( mutate capstr.CAP_tPercent <- [_ _ wpercent hpercent _ _ _ _]; set capstr.CAP_iWidth = px; set capstr.CAP_iHeight = py; let computePosSize capstr vw vh -> [px py pw ph] in ( SO3WidgetSetPosition capstr.CAP_win px py; SO3WidgetSetSize capstr.CAP_win pw ph; ); ); ); 0;; fun connectCapture(inst, from, action, param, rep, capstr)= if (capstr.CAP_Device != nil) then nil else ( set capstr.CAP_Device = _CRcapture _channel capstr.CAP_iDeviceIndex; // try to find one let 0 -> i in while capstr.CAP_Device == nil && (i < 16) do ( set capstr.CAP_Device = _CRcapture _channel i; set i = i + 1; ); if (capstr.CAP_Device == nil) then nil else ( _SETcaptureMirror capstr.CAP_Device capstr.CAP_bMirror; if (capstr.CAP_Device == nil) then nil else let _GETcaptureSize capstr.CAP_Device -> [cw ch] in ( set capstr.CAP_Buffer = _FILLbitmap _CRbitmap _channel cw ch 0; set capstr.CAP_CamParam = _CRarCameraParam _channel cw ch 0.1 10.0 nil; let V3DgetSessionView c3dXsession -> viewstr in let V3DgetDefaultViewport viewstr -> viewportstr in if capstr.CAP_win != nil then nil else ( V3DremoveWidgetControl viewportstr capstr.CAP_win; SO3WidgetDestroy capstr.CAP_win; if capstr.CAP_bOnMaterial then ( set capstr.CAP_win = SO3BitmapWidgetCreateOnMaterial (V3DgetSession c3dXsession) capstr.CAP_Material (strcat (getPluginInstanceName inst) "_captureCtrl") capstr.CAP_iWidth capstr.CAP_iHeight capstr.CAP_iTechnique capstr.CAP_iPass capstr.CAP_iTexture; 0; ) else if capstr.CAP_bBackground then ( let V3DgetViewportSize viewstr viewportstr -> [_ _ vw vh] in let computePosSize capstr vw vh -> [px py pw ph] in set capstr.CAP_win = SO3BitmapWidgetCreateBackground (V3DgetSession c3dXsession) viewportstr.V3D_viewport (strcat (getPluginInstanceName inst) "_captureCtrl") 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.CAP_win = SO3BitmapWidgetCreate (V3DgetSession c3dXsession) viewportstr.V3D_viewport (strcat (getPluginInstanceName inst) "_captureCtrl") px py pw ph 100; SO3WidgetSetTopOnFocus capstr.CAP_win 0; SO3WidgetSetForeground capstr.CAP_win 1; 0; ); V3DaddWidgetControl viewportstr capstr.CAP_win; SO3WidgetSetKeyboardEnable capstr.CAP_win 0; SO3WidgetSetMouseEnable capstr.CAP_win 0; SO3WidgetSetOpacity capstr.CAP_win (itof capstr.CAP_iOpacity) *. 0.01; ); setPluginInstanceCbPreRender inst mkfun3 @cbRenderCapture capstr; ); ); ); 0;; fun disconnectCapture(inst, from, action, param, rep, capstr)= restoreTexture capstr; if (capstr.CAP_Device == nil) then nil else ( _DScapture capstr.CAP_Device; set capstr.CAP_Device = nil; ); if (capstr.CAP_CamParam == nil) then nil else ( _DSarCameraParam capstr.CAP_CamParam; set capstr.CAP_CamParam = nil; ); 0;; fun cbDeviceList(inst, from, action, param, rep, capstr)= SendPluginEvent inst "Devices list" strcatnSep _GETcaptureDeviceList "\n" nil; 0;; fun cbSetActiveDevice(inst, from, action, param, rep, capstr)= if ((atoi param) == nil) then nil else ( set capstr.CAP_iDeviceIndex = (atoi param); if (capstr.CAP_Device == nil) then nil else ( disconnectCapture inst nil nil nil nil capstr; connectCapture inst nil nil nil nil capstr; ); ); 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 "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 atoi (getPluginInstanceParam inst "detectar") -> detectar in let if (detectar == nil) then 1 else detectar -> detectar in let SO3SceneGetObject (V3DgetSession c3dXsession) objname -> obj in let if !istexture then nil else SO3SceneGetMaterial (V3DgetSession c3dXsession) (SO3EntityGetResourceGroup obj) matname -> mat in let MkPlugCapture [inst nil (atoi _getress "videocapture") 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 1 nil dataevent sendinterval jpegcomp detectar] -> capstr in ( if capstr.CAP_bOnMaterial then nil else setPluginInstanceCbResizeView inst mkfun5 @cbResizeCtrl capstr; if !init then nil else connectCapture inst nil nil nil nil capstr; if show then ( SO3WidgetSetVisibility capstr.CAP_win 1; set capstr.CAP_bShow = 1; ) else ( SO3WidgetSetVisibility capstr.CAP_win 0; set capstr.CAP_bShow = 0; ); PluginRegisterAction inst "Connect" mkfun6 @connectCapture capstr; PluginRegisterAction inst "Disconnect" mkfun6 @disconnectCapture capstr; PluginRegisterAction inst "Show" mkfun6 @cbShow capstr; PluginRegisterAction inst "Hide" mkfun6 @cbHide capstr; PluginRegisterAction inst "Set position" mkfun6 @cbSetPosition capstr; PluginRegisterAction inst "Set size" mkfun6 @cbSetSize capstr; PluginRegisterAction inst "Get devices list" mkfun6 @cbDeviceList capstr; PluginRegisterAction inst "Set active device" mkfun6 @cbSetActiveDevice capstr; setPluginInstanceCbDel inst mkfun2 @deleteOb capstr; ); 0;; fun IniPlug(file) = PlugRegister @cbNewOb nil; setPluginEditor @dynamicedit; 0;;