40#include <opencv2/highgui/highgui.hpp>
45extern int(*CallMainThread)(
void*, mmachine m);
71 ICameraInput* CaptureOBJ = MMgetPointer<ICameraInput*>(m, MTOP(obj));
72 SAFE_DELETE(CaptureOBJ);
74 MMsetPointer<ICameraInput*>(m, MTOP(obj), 0);
76 MMechostr(MSKDEBUG,
"ObjCapture destroyed.\n");
92 MMechostr(MSKDEBUG,
"_DScapture\n");
95 int obj = MMget(m, 0);
103 MMset(m, 0, ITOM(0));
106 MMechostr(MSKDEBUG,
"ok\n");
112int CheckCameraPermissionSync(mmachine m)
129int _CRcaptureSync(mmachine m)
135 MMechostr(MSKDEBUG,
"_CRcapture\n");
144 int sidx = MMpull(m);
146 if ((sidx != NIL) && (MTOI(sidx) > 0))
154 MMechostr(MSKDEBUG,
"Failed to create device\n");
162 MMechostr(MSKDEBUG,
"Failed to open device\n");
163 SAFE_DELETE(CaptureOBJ);
168 if ((MMpushPointer(m, CaptureOBJ) != 0))
170 SAFE_DELETE(CaptureOBJ);
176 MMechostr(MSKDEBUG,
"ok\n");
184 return CallMainThread((
void*)_CRcaptureSync, m);
200 MMechostr(MSKDEBUG,
"_BLTcapture\n");
203 int bitmap = MMpull(m);
204 int capture = MMget(m, 0);
205 if ((capture == NIL) || (bitmap == NIL))
211 ICameraInput* CaptureOBJ = MMgetPointer<ICameraInput*>(m, MTOP(capture));
212 if (CaptureOBJ == NULL)
223 catch (std::exception e)
236 PtrObjVoid OB = (PtrObjVoid) MMstart(m, MTOP(bitmap));
237 PtrObjBitmap B = (PtrObjBitmap) MMstart(m, MTOP(OB->Buffer));
247 if (B->TailleH != image.rows || B->TailleW != image.cols)
249 imgdest = cv::Mat(B->TailleH, B->TailleW, image.type());
250 cv::resize(image, imgdest, imgdest.size(), 0, 0, cv::INTER_LINEAR);
260 MMechostr(MSKDEBUG,
"ok\n");
276 MMechostr(MSKDEBUG,
"_BLTcapture\n");
279 int capture = MMget(m, 0);
286 ICameraInput* CaptureOBJ = MMgetPointer<ICameraInput*>(m, MTOP(capture));
287 if (CaptureOBJ == NULL)
298 catch (std::exception e)
312 if ((MMpushPointer(m, image.data) != 0))
319 MMechostr(MSKDEBUG,
"ok\n");
334 MMechostr(MSKDEBUG,
"_BLTcapture\n");
337 int capture = MMget(m, 0);
344 ICameraInput* CaptureOBJ = MMgetPointer<ICameraInput*>(m, MTOP(capture));
345 if (CaptureOBJ == NULL)
356 catch (std::exception e)
371 if ((MMpushPointer(m, image.data) != 0))
376 MMpush (m, ITOM (image.cols));
377 MMpush (m, ITOM (image.rows));
378 MMpush (m, ITOM (image.channels()));
379 MMpush (m, ITOM (4));
383 MMechostr(MSKDEBUG,
"ok\n");
397 MMechostr(0,
"_GETcaptureDeviceList\n");
402 if (devicesList.empty())
410 for (
unsigned int i = 0; i < devicesList.size(); i++)
412 if ((k = Mpushstrbloc(m,
const_cast<char*
>(devicesList[i].c_str()))))
return k;
415 if (MMpush(m, NIL))
return MERRMEM;
417 for (
unsigned int j = 0; j < devicesList.size(); j++)
419 if (MMpush(m, 2 * 2))
return MERRMEM;
420 if ((k = MBdeftab(m)))
return k;
424 MMechostr(0,
"ok\n");
441 MMechostr(MSKDEBUG,
"_SETcaptureMirror\n");
444 int mMode = MMpull(m);
445 int capture = MMget(m, 0);
446 if ((capture == NIL) || (mMode == NIL))
452 ICameraInput* CaptureOBJ = MMgetPointer<ICameraInput*>(m, MTOP(capture));
453 if (CaptureOBJ == NULL)
461 MMset(m, 0, ITOM(1));
464 MMechostr(MSKDEBUG,
"ok\n");
479 MMechostr(MSKDEBUG,
"_GETcaptureSize\n");
482 int capture = MMget(m, 0);
489 ICameraInput* CaptureOBJ = MMgetPointer<ICameraInput*>(m, MTOP(capture));
490 if (CaptureOBJ == NULL)
496 int tupleSize = MMmalloc(m, 2, TYPETAB);
497 if (tupleSize == NIL)
503 MMstore(m, tupleSize, 0, ITOM(CaptureOBJ->
GetWidth()));
504 MMstore(m, tupleSize, 1, ITOM(CaptureOBJ->
GetHeight()));
505 MMset(m, 0, PTOM(tupleSize));
508 MMechostr(MSKDEBUG,
"ok\n");
525 MMechostr(MSKDEBUG,
"_SETcaptureSize\n");
528 int mHeight = MMpull(m);
529 int mWidth = MMpull(m);
530 int capture = MMget(m, 0);
532 if ((capture == NIL) || (mHeight == NIL) || (mWidth == NIL))
538 ICameraInput* CaptureOBJ = MMgetPointer<ICameraInput*>(m, MTOP(capture));
540 if (CaptureOBJ == NULL)
548 CaptureOBJ->
SetSize(MTOI(mWidth), MTOI(mHeight));
550 catch (std::exception &)
552 MMechostr(MSKRUNTIME,
"_SETcaptureSize failed!\n");
557 MMset(m, 0, ITOM(1));
560 MMechostr(MSKDEBUG,
"ok\n");
577 MMechostr(MSKDEBUG,
"_SETcaptureFocusPoint\n");
582 int capture = MMget(m, 0);
584 if ((capture == NIL) || (mX == NIL) || (mY == NIL))
590 ICameraInput* CaptureOBJ = MMgetPointer<ICameraInput*>(m, MTOP(capture));
592 if (CaptureOBJ == NULL)
602 catch (std::exception &)
604 MMechostr(MSKRUNTIME,
"_SETcaptureFocusPoint failed!\n");
609 MMset(m, 0, ITOM(1));
612 MMechostr(MSKDEBUG,
"ok\n");
628 MMechostr(MSKDEBUG,
"_SETcaptureTorchState\n");
631 int mMode = MMpull(m);
632 int capture = MMget(m, 0);
633 if ((capture == NIL) || (mMode == NIL))
639 ICameraInput* CaptureOBJ = MMgetPointer<ICameraInput*>(m, MTOP(capture));
640 if (CaptureOBJ == NULL)
648 MMset(m, 0, ITOM(1));
651 MMechostr(MSKDEBUG,
"ok\n");
667 MMechostr(MSKDEBUG,
"_SAVEcaptureToFile\n");
669 int path = MMpull(m);
670 int capture = MMget(m, 0);
677 std::string spath(MMstartstr(m, MTOP(path)));
679 ICameraInput* CaptureOBJ = MMgetPointer<ICameraInput*>(m, MTOP(capture));
680 if (CaptureOBJ == NULL)
687 MMset(m, 0, (success) ? ITOM(1) : ITOM(0));
690 MMechostr(MSKDEBUG,
"ok\n");
705 MMechostr(MSKDEBUG,
"_AUTORENDERcapture\n");
707 int capture = MMget(m, 0);
714 ICameraInput* CaptureOBJ = MMgetPointer<ICameraInput*>(m, MTOP(capture));
715 if (CaptureOBJ == NULL)
723 MMset(m, 0, ITOM(1));
725 MMechostr(MSKDEBUG,
"_AUTORENDERcapture is not implemented on this platform\n");
726 MMset(m, 0, ITOM(0));
742static NativeDefinition sCaptkDef[] =
744 {
"ObjCapture", TYPTYPE, NULL, NULL },
745 {
"_CRcapture", 2,
"fun [Chn I] ObjCapture",
_CRcapture },
746 {
"_DScapture", 1,
"fun [ObjCapture] I",
_DScapture },
747 {
"_BLTcapture", 2,
"fun [ObjCapture ObjBitmap] ObjBitmap",
_BLTcapture },
770 MMechostr(MSKDEBUG,
" > Loading CaptureToolkit\n");
773 int k = PKhardpak2(m,
"CaptureToolkitEngine.pkg-1.0",
sizeof(sCaptkDef) /
sizeof(sCaptkDef[0]), sCaptkDef);
774 MMechostr(MSKDEBUG,
" > Successfully Loaded\n\n");
void CheckCameraPermission()
Prompts the user with a camera permission dialog if this is the first time the app is run.
int LoadCaptureToolkit(mmachine m)
int _SETcaptureSize(mmachine m)
_SETcaptureSize : This function apply a size to a capture device Prototype: fun [ObjCapture I I] I
int _SAVEcaptureToFile(mmachine m)
_SAVEcaptureToFile : This function save a capture frame into a file Prototype: fun [ObjCapture W] I
int _AUTORENDERcapture(mmachine m)
_AUTORENDERcapture : This function renders current frame on Android device Prototype: fun [ObjCapture...
int _SETcaptureMirror(mmachine m)
_SETcaptureMirror : This function change the miror mode for the capture Prototype: fun [ObjCapture I]...
int _GETcaptureDeviceList(mmachine m)
_GETcaptureDeviceList : This function list the installed video devices Prototype: fun [] [S r1]
int _GETcaptureBuffer(mmachine m)
_GETcaptureBuffer : This function return the current pixel buffer Prototype: fun [ObjCapture] ObjBuff
int _SETcaptureTorchState(mmachine m)
_SETcaptureTorchState : This function change camera torch state Prototype: fun [ObjCapture I] I
int _DScapture(mmachine m)
_DScapture : This function destroy a capture device
int _BLTcapture(mmachine m)
_BLTcapture : This function blit the device picture into a bitmap Prototype: fun [ObjCapture ObjBitma...
int _GETcaptureSize(mmachine m)
_GETcaptureSize : This function the size of a capture device Prototype: fun [ObjCapture] [I I]
int _SETcaptureFocusPoint(mmachine m)
_SETcaptureFocusPoint : This function define the focus point on a mobile camera device Prototype: fun...
int _GETcaptureBufferExt(mmachine m)
_GETcaptureBufferExt : This function return the current pixel buffer Prototype: fun [ObjCapture] [Obj...
int _CRcapture(mmachine m)
_CRcapture : This function create a new capture device from a device index