diff --git a/samples/winrt/ImageManipulations/MediaExtensions/OcvTransform/OcvTransform.cpp b/samples/winrt/ImageManipulations/MediaExtensions/OcvTransform/OcvTransform.cpp index 438b2c6d138c5476ca1d7b0d89ad605ea35f9823..56193c1cbb8fc79d427d372036e01d4e51cad753 100644 --- a/samples/winrt/ImageManipulations/MediaExtensions/OcvTransform/OcvTransform.cpp +++ b/samples/winrt/ImageManipulations/MediaExtensions/OcvTransform/OcvTransform.cpp @@ -120,13 +120,24 @@ HRESULT OcvImageManipulations::SetProperties(ABI::Windows::Foundation::Collectio if (found) { - IInspectable* value; - spSetting->Lookup(key, &value); + Microsoft::WRL::ComPtr spPropVal; + Microsoft::WRL::ComPtr spInsp; + + spSetting->Lookup(key, spInsp.ReleaseAndGetAddressOf()); + + hr = spInsp.As(&spPropVal); + if (hr != S_OK) + { + return hr; + } + + INT32 effect; + hr = spPropVal->GetInt32(&effect); + if (hr != S_OK) + { + return hr; + } - Microsoft::WRL::ComPtr> ref; - hr = value->QueryInterface(IID_PPV_ARGS(&ref)); - int effect = InvalidEffect; - hr = ref->get_Value(&effect); if ((effect >= 0) && (effect < InvalidEffect)) { m_TransformType = (ProcessingType)effect; diff --git a/samples/winrt/JavaScript/MediaCaptureJavaScript.jsproj b/samples/winrt/JavaScript/MediaCaptureJavaScript.jsproj new file mode 100644 index 0000000000000000000000000000000000000000..8bf1b03d942014ad70e8c98c926e780f0965b6dc --- /dev/null +++ b/samples/winrt/JavaScript/MediaCaptureJavaScript.jsproj @@ -0,0 +1,115 @@ + + + + + Debug + AnyCPU + + + Debug + ARM + + + Debug + x64 + + + Debug + x86 + + + Release + AnyCPU + + + Release + ARM + + + Release + x64 + + + Release + x86 + + + + d70a3790-48ce-4e58-af60-ebefc22e9c7a + + + + 12.0 + + + + + Windows + 8.1 + 8.1 + $(VersionNumberMajor).$(VersionNumberMinor) + en-US + MediaCaptureJavaScript_TemporaryKey.pfx + + + + Designer + + + + + + + + + + + + + + + + + + + + + + + + + + + $(OPENCV_WINRT_INSTALL_DIR)WS\8.1\$(PlatformTarget)\$(PlatformTarget)\vc12\bin\ + $(OPENCV_WINRT_INSTALL_DIR)WS\8.1\$(PlatformTarget)\$(PlatformTarget)\vc12\lib\ + $(OPENCV_WINRT_INSTALL_DIR)WS\8.1\$(PlatformTarget)\include\ + + d + + + + + + + PreserveNewest + + + PreserveNewest + + + + + + + + \ No newline at end of file diff --git a/samples/winrt/JavaScript/MediaCaptureJavaScript.sln b/samples/winrt/JavaScript/MediaCaptureJavaScript.sln new file mode 100644 index 0000000000000000000000000000000000000000..cb5c347fa4064c2a8ee5c7cea7b5cd00a3d44328 --- /dev/null +++ b/samples/winrt/JavaScript/MediaCaptureJavaScript.sln @@ -0,0 +1,84 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OcvTransform", "..\ImageManipulations\MediaExtensions\OcvTransform\OcvTransform.vcxproj", "{BA69218F-DA5C-4D14-A78D-21A9E4DEC669}" +EndProject +Project("{262852C6-CD72-467D-83FE-5EEB1973A190}") = "MediaCaptureJavaScript", "MediaCaptureJavaScript.jsproj", "{D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|ARM = Debug|ARM + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|ARM = Release|ARM + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|ARM.ActiveCfg = Debug|ARM + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|ARM.Build.0 = Debug|ARM + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|ARM.Deploy.0 = Debug|ARM + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|Win32.ActiveCfg = Debug|Win32 + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|Win32.Build.0 = Debug|Win32 + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|Win32.Deploy.0 = Debug|Win32 + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|x64.ActiveCfg = Debug|x64 + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|x64.Build.0 = Debug|x64 + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Debug|x64.Deploy.0 = Debug|x64 + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|Any CPU.ActiveCfg = Release|Win32 + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|ARM.ActiveCfg = Release|ARM + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|ARM.Build.0 = Release|ARM + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|ARM.Deploy.0 = Release|ARM + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|Win32.ActiveCfg = Release|Win32 + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|Win32.Build.0 = Release|Win32 + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|Win32.Deploy.0 = Release|Win32 + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|x64.ActiveCfg = Release|x64 + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|x64.Build.0 = Release|x64 + {C5B886A7-8300-46FF-B533-9613DE2AF637}.Release|x64.Deploy.0 = Release|x64 + {BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Debug|ARM.ActiveCfg = Debug|ARM + {BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Debug|ARM.Build.0 = Debug|ARM + {BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Debug|Win32.ActiveCfg = Debug|Win32 + {BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Debug|Win32.Build.0 = Debug|Win32 + {BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Debug|x64.ActiveCfg = Debug|x64 + {BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Debug|x64.Build.0 = Debug|x64 + {BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Release|Any CPU.ActiveCfg = Release|Win32 + {BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Release|ARM.ActiveCfg = Release|ARM + {BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Release|ARM.Build.0 = Release|ARM + {BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Release|Win32.ActiveCfg = Release|Win32 + {BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Release|Win32.Build.0 = Release|Win32 + {BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Release|x64.ActiveCfg = Release|x64 + {BA69218F-DA5C-4D14-A78D-21A9E4DEC669}.Release|x64.Build.0 = Release|x64 + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Debug|ARM.ActiveCfg = Debug|ARM + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Debug|ARM.Build.0 = Debug|ARM + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Debug|ARM.Deploy.0 = Debug|ARM + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Debug|Win32.ActiveCfg = Debug|x86 + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Debug|Win32.Build.0 = Debug|x86 + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Debug|Win32.Deploy.0 = Debug|x86 + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Debug|x64.ActiveCfg = Debug|x64 + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Debug|x64.Build.0 = Debug|x64 + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Debug|x64.Deploy.0 = Debug|x64 + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Release|Any CPU.Build.0 = Release|Any CPU + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Release|Any CPU.Deploy.0 = Release|Any CPU + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Release|ARM.ActiveCfg = Release|ARM + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Release|ARM.Build.0 = Release|ARM + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Release|ARM.Deploy.0 = Release|ARM + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Release|Win32.ActiveCfg = Release|x86 + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Release|Win32.Build.0 = Release|x86 + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Release|Win32.Deploy.0 = Release|x86 + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Release|x64.ActiveCfg = Release|x64 + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Release|x64.Build.0 = Release|x64 + {D70A3790-48CE-4E58-AF60-EBEFC22E9C7A}.Release|x64.Deploy.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/samples/winrt/JavaScript/MediaCaptureJavaScript_TemporaryKey.pfx b/samples/winrt/JavaScript/MediaCaptureJavaScript_TemporaryKey.pfx new file mode 100644 index 0000000000000000000000000000000000000000..242376d0edd4a63294d20055556a3b41ea2f632b Binary files /dev/null and b/samples/winrt/JavaScript/MediaCaptureJavaScript_TemporaryKey.pfx differ diff --git a/samples/winrt/JavaScript/css/default.css b/samples/winrt/JavaScript/css/default.css new file mode 100644 index 0000000000000000000000000000000000000000..e47ef40285c4012a52fcba14100ab6e7fa1ce8f3 --- /dev/null +++ b/samples/winrt/JavaScript/css/default.css @@ -0,0 +1,6 @@ +/* styles */ + +#featureLabel +{ + padding-top: 50px; +} \ No newline at end of file diff --git a/samples/winrt/JavaScript/default.html b/samples/winrt/JavaScript/default.html new file mode 100644 index 0000000000000000000000000000000000000000..b229ddaf4a6df35d97206f6eb92c81f024679c85 --- /dev/null +++ b/samples/winrt/JavaScript/default.html @@ -0,0 +1,31 @@ + + + + + + OpenCV for Windows RT + + + + + + + + + + + + + +
+
+

+ + OpenCV for Windows RT +

+

+
+
+
+ + diff --git a/samples/winrt/JavaScript/html/AdvancedCapture.html b/samples/winrt/JavaScript/html/AdvancedCapture.html new file mode 100644 index 0000000000000000000000000000000000000000..4523992968569cf709ccf78c9b840162a43e5520 --- /dev/null +++ b/samples/winrt/JavaScript/html/AdvancedCapture.html @@ -0,0 +1,40 @@ + + + + + + + + +
+

+ This scenario shows how to enumerate cameras in the system. + Choose a camera from the list to start previewing from that camera. You can add additional effect + using the dropdown provided. +

+ + + + +
+
+ + + + + + + +
Preview
+ +
+
+ + diff --git a/samples/winrt/JavaScript/images/logo.scale-100.png b/samples/winrt/JavaScript/images/logo.scale-100.png new file mode 100644 index 0000000000000000000000000000000000000000..ea685d651ace9ce7ed2463b84bbff6ea2d891f9c Binary files /dev/null and b/samples/winrt/JavaScript/images/logo.scale-100.png differ diff --git a/samples/winrt/JavaScript/images/microsoft-sdk.png b/samples/winrt/JavaScript/images/microsoft-sdk.png new file mode 100644 index 0000000000000000000000000000000000000000..380a0102660b7ad3a9ba5418dd1bb81da99bce2b Binary files /dev/null and b/samples/winrt/JavaScript/images/microsoft-sdk.png differ diff --git a/samples/winrt/JavaScript/images/smallTile-sdk.png b/samples/winrt/JavaScript/images/smallTile-sdk.png new file mode 100644 index 0000000000000000000000000000000000000000..5546e8b24a69738114bc17b2b2d493a6872d67ad Binary files /dev/null and b/samples/winrt/JavaScript/images/smallTile-sdk.png differ diff --git a/samples/winrt/JavaScript/images/smalllogo.scale-100.png b/samples/winrt/JavaScript/images/smalllogo.scale-100.png new file mode 100644 index 0000000000000000000000000000000000000000..efaf5468a19d1fd00f0aa95a51b47f849408fbba Binary files /dev/null and b/samples/winrt/JavaScript/images/smalllogo.scale-100.png differ diff --git a/samples/winrt/JavaScript/images/splash-sdk.png b/samples/winrt/JavaScript/images/splash-sdk.png new file mode 100644 index 0000000000000000000000000000000000000000..901c3b085a091e7ccd47f98062443553e73909ed Binary files /dev/null and b/samples/winrt/JavaScript/images/splash-sdk.png differ diff --git a/samples/winrt/JavaScript/images/splashscreen.scale-100.png b/samples/winrt/JavaScript/images/splashscreen.scale-100.png new file mode 100644 index 0000000000000000000000000000000000000000..c951e031bdfa0d4ebe68d52647f14caf710ca471 Binary files /dev/null and b/samples/winrt/JavaScript/images/splashscreen.scale-100.png differ diff --git a/samples/winrt/JavaScript/images/squareTile-sdk.png b/samples/winrt/JavaScript/images/squareTile-sdk.png new file mode 100644 index 0000000000000000000000000000000000000000..126cf70d83e3973f6a4b040fb4af58f546692252 Binary files /dev/null and b/samples/winrt/JavaScript/images/squareTile-sdk.png differ diff --git a/samples/winrt/JavaScript/images/storeLogo-sdk.png b/samples/winrt/JavaScript/images/storeLogo-sdk.png new file mode 100644 index 0000000000000000000000000000000000000000..2133f177d172d4c79ef1ffaa8088f786a2bdbe8f Binary files /dev/null and b/samples/winrt/JavaScript/images/storeLogo-sdk.png differ diff --git a/samples/winrt/JavaScript/images/storelogo.scale-100.png b/samples/winrt/JavaScript/images/storelogo.scale-100.png new file mode 100644 index 0000000000000000000000000000000000000000..dcb672712c6823a0c91548ded70a8acb85536b4d Binary files /dev/null and b/samples/winrt/JavaScript/images/storelogo.scale-100.png differ diff --git a/samples/winrt/JavaScript/images/tile-sdk.png b/samples/winrt/JavaScript/images/tile-sdk.png new file mode 100644 index 0000000000000000000000000000000000000000..cdec0dbdccad7ae5dd0e92e3c3015449fffb7450 Binary files /dev/null and b/samples/winrt/JavaScript/images/tile-sdk.png differ diff --git a/samples/winrt/JavaScript/images/windows-sdk.png b/samples/winrt/JavaScript/images/windows-sdk.png new file mode 100644 index 0000000000000000000000000000000000000000..af64bf00ad4a8bfec7ee89ab8a7b61d55988dfd6 Binary files /dev/null and b/samples/winrt/JavaScript/images/windows-sdk.png differ diff --git a/samples/winrt/JavaScript/js/AdvancedCapture.js b/samples/winrt/JavaScript/js/AdvancedCapture.js new file mode 100644 index 0000000000000000000000000000000000000000..211e1cd3b118137eef3c603d17c94c592aefc8df --- /dev/null +++ b/samples/winrt/JavaScript/js/AdvancedCapture.js @@ -0,0 +1,161 @@ +//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO +//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +//// PARTICULAR PURPOSE. +//// +//// Copyright (c) Microsoft Corporation. All rights reserved + +(function () { + "use strict"; + + var cameraList = null; + var mediaCaptureMgr = null; + var captureInitSettings = null; + + var page = WinJS.UI.Pages.define("/html/AdvancedCapture.html", { + + ready: function (element, options) { + scenarioInitialize(); + }, + + unload: function (element, options) { + // release resources + releaseMediaCapture(); + } + }); + + function scenarioInitialize() { + // Initialize the UI elements + id("btnStartDevice").disabled = false; + id("btnStartDevice").addEventListener("click", startDevice, false); + id("btnStartPreview").disabled = true; + id("videoEffect").disabled = true; + id("btnStartPreview").addEventListener("click", startPreview, false); + id("cameraSelect").addEventListener("change", onDeviceChange, false); + + id("videoEffect").addEventListener('change', addEffectToImageStream, false); + + enumerateCameras(); + } + + function initCameraSettings() { + captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings(); + captureInitSettings.streamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.video + + // If the user chose another capture device, use it by default + var selectedIndex = id("cameraSelect").selectedIndex; + var deviceInfo = cameraList[selectedIndex]; + captureInitSettings.videoDeviceId = deviceInfo.id; + } + + // this function takes care of releasing the resources associated with media capturing + function releaseMediaCapture() { + if (mediaCaptureMgr) { + mediaCaptureMgr.close(); + mediaCaptureMgr = null; + } + } + + //Initialize media capture with the current settings + function startDevice() { + displayStatus("Starting device"); + releaseMediaCapture(); + initCameraSettings(); + + mediaCaptureMgr = new Windows.Media.Capture.MediaCapture(); + mediaCaptureMgr.initializeAsync(captureInitSettings).done(function (result) { + // Update the UI + id("btnStartPreview").disabled = false; + id("btnStartDevice").disabled = true; + displayStatus("Device started"); + }); + } + + function startPreview() { + displayStatus("Starting preview"); + id("btnStartPreview").disabled = true; + id("videoEffect").disabled = false; + var video = id("previewVideo"); + video.src = URL.createObjectURL(mediaCaptureMgr, { oneTimeOnly: true }); + video.play(); + displayStatus("Preview started"); + } + + function addEffectToImageStream() { + var effectId = id("videoEffect").selectedIndex; + var props = new Windows.Foundation.Collections.PropertySet(); + props.insert("{698649BE-8EAE-4551-A4CB-3EC98FBD3D86}", effectId); + + mediaCaptureMgr.clearEffectsAsync(Windows.Media.Capture.MediaStreamType.videoPreview).then(function () { + return mediaCaptureMgr.addEffectAsync(Windows.Media.Capture.MediaStreamType.videoPreview, 'OcvTransform.OcvImageManipulations', props); + }).then(function () { + displayStatus('Effect has been successfully added'); + }, errorHandler); + } + + function enumerateCameras() { + displayStatus("Enumerating capture devices"); + var cameraSelect = id("cameraSelect"); + cameraList = null; + cameraList = new Array(); + + // Clear the previous list of capture devices if any + while (cameraSelect.length > 0) { + cameraSelect.remove(0); + } + + // Enumerate cameras and add them to the list + var deviceInfo = Windows.Devices.Enumeration.DeviceInformation; + deviceInfo.findAllAsync(Windows.Devices.Enumeration.DeviceClass.videoCapture).done(function (cameras) { + if (cameras.length === 0) { + cameraSelect.disabled = true; + displayError("No camera was found"); + id("btnStartDevice").disabled = true; + cameraSelect.add(new Option("No cameras available")); + } else { + cameras.forEach(function (camera) { + cameraList.push(camera); + cameraSelect.add(new Option(camera.name)); + }); + } + }, errorHandler); + } + + function onDeviceChange() { + releaseMediaCapture(); + id("btnStartDevice").disabled = false; + id("btnStartPreview").disabled = true; + id("videoEffect").disabled = true; + displayStatus(""); + } + + function suspendingHandler(suspendArg) { + displayStatus("Suspended"); + releaseMediaCapture(); + } + + function resumingHandler(resumeArg) { + displayStatus("Resumed"); + scenarioInitialize(); + } + + function errorHandler(err) { + displayError(err.message); + } + + function failedEventHandler(e) { + displayError("Fatal error", e.message); + } + + function displayStatus(statusText) { + SdkSample.displayStatus(statusText); + } + + function displayError(error) { + SdkSample.displayError(error); + } + + function id(elementId) { + return document.getElementById(elementId); + } +})(); diff --git a/samples/winrt/JavaScript/js/default.js b/samples/winrt/JavaScript/js/default.js new file mode 100644 index 0000000000000000000000000000000000000000..4aa17a3d6045a394af11937a1d41f81e65605e79 --- /dev/null +++ b/samples/winrt/JavaScript/js/default.js @@ -0,0 +1,74 @@ +//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO +//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +//// PARTICULAR PURPOSE. +//// +//// Copyright (c) Microsoft Corporation. All rights reserved + + +(function () { + "use strict"; + + var sampleTitle = "OpenCV Image Manipulations sample"; + + var scenarios = [ + { url: "/html/AdvancedCapture.html", title: "Enumerate cameras and add a video effect" }, + ]; + + function activated(eventObject) { + if (eventObject.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) { + // Use setPromise to indicate to the system that the splash screen must not be torn down + // until after processAll and navigate complete asynchronously. + eventObject.setPromise(WinJS.UI.processAll().then(function () { + // Navigate to either the first scenario or to the last running scenario + // before suspension or termination. + var url = WinJS.Application.sessionState.lastUrl || scenarios[0].url; + return WinJS.Navigation.navigate(url); + })); + } + } + + WinJS.Navigation.addEventListener("navigated", function (eventObject) { + var url = eventObject.detail.location; + var host = document.getElementById("contentHost"); + // Call unload method on current scenario, if there is one + host.winControl && host.winControl.unload && host.winControl.unload(); + WinJS.Utilities.empty(host); + eventObject.detail.setPromise(WinJS.UI.Pages.render(url, host, eventObject.detail.state).then(function () { + WinJS.Application.sessionState.lastUrl = url; + })); + }); + + WinJS.Namespace.define("SdkSample", { + sampleTitle: sampleTitle, + scenarios: scenarios, + mediaCaptureMgr: null, + photoFile: "photo.jpg", + deviceList: null, + recordState: null, + captureInitSettings: null, + encodingProfile: null, + storageFile: null, + photoStorage: null, + cameraControlSliders: null, + + + displayStatus: function (statusText) { + WinJS.log && WinJS.log(statusText, "MediaCapture", "status"); + }, + + displayError: function (error) { + WinJS.log && WinJS.log(error, "MediaCapture", "error"); + }, + + id: function (elementId) { + return document.getElementById(elementId); + }, + + }); + + WinJS.Application.addEventListener("activated", activated, false); + WinJS.Application.start(); + Windows.UI.WebUI.WebUIApplication.addEventListener("suspending", SdkSample.suspendingHandler, false); + Windows.UI.WebUI.WebUIApplication.addEventListener("resuming", SdkSample.resumingHandler, false); +})(); diff --git a/samples/winrt/JavaScript/package.appxmanifest b/samples/winrt/JavaScript/package.appxmanifest new file mode 100644 index 0000000000000000000000000000000000000000..aa4526c2a409f668f29cec1917d7ce51a638919d --- /dev/null +++ b/samples/winrt/JavaScript/package.appxmanifest @@ -0,0 +1,35 @@ + + + + + MediaCaptureJavaScript + Sergei + images\storelogo.png + + + 6.3.0 + 6.3.0 + + + + + + + + + + + + + + + + + + + OcvTransform.dll + + + + + \ No newline at end of file diff --git a/samples/winrt/JavaScript/sample-utils/sample-utils.css b/samples/winrt/JavaScript/sample-utils/sample-utils.css new file mode 100644 index 0000000000000000000000000000000000000000..d209fafbb8003eae930466da2fb5ef20eff3a817 --- /dev/null +++ b/samples/winrt/JavaScript/sample-utils/sample-utils.css @@ -0,0 +1,213 @@ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +html +{ + cursor: default; +} + +#featureLabel +{ + font: 20pt/24pt "Segoe UI Semilight"; + margin:0; + padding:5px 0 10px 0; + font-weight: normal; +} + +#inputLabel, #outputLabel +{ + font: 11pt/15pt "Segoe UI"; + margin:0; + padding:0; + font-weight: normal; +} + +#listLabel, #descLabel +{ + font: 11pt/15pt "Segoe UI Semilight"; + font-weight:normal; +} + +#rootGrid +{ + width: 100%; + height: 100%; + display: -ms-grid; + -ms-grid-columns: 100px 1fr 100px; + -ms-grid-rows: 20px auto 1fr auto 20px; +} + +#header +{ + -ms-grid-column: 2; + -ms-grid-row: 2; +} + +#content +{ + padding-right:20px; + padding-bottom:20px; + overflow:auto; + display:-ms-grid; + -ms-grid-columns:1fr; + -ms-grid-rows: auto 1fr; + -ms-grid-column: 2; + -ms-grid-row: 3; +} + +#footer +{ + -ms-grid-column: 2; + -ms-grid-row: 4; + padding-bottom:10px; +} + +#featureLabel +{ + -ms-grid-row: 1; +} + +#contentHost +{ + display:-ms-grid; + -ms-grid-columns:1fr; + -ms-grid-rows: auto auto auto 1fr; + -ms-grid-row: 2; +} + +#inputLabel +{ + -ms-grid-row: 1; +} + + +#input +{ + -ms-grid-row: 2; + display: -ms-grid; + -ms-grid-columns: auto auto; + -ms-grid-rows: auto; + margin-top:10px; +} + +#outputLabel +{ + -ms-grid-row: 3; + padding-top:10px; + padding-bottom:10px; +} + +#output +{ + height:100%; + -ms-grid-row: 4; + -ms-grid-row-align:stretch; +} + +.clear +{ + clear:both; +} + + +#footer span +{ + font-size:12px; +} + +#footer .company +{ + float:left; +} + +#footer .links +{ + float:right; +} + +#footer .links a +{ + font-size:12px; + margin-left:8px; + text-decoration:none; +} + +#footer .links .pipe +{ + font-size:9px; + margin-left:8px; +} + +#statusMessage +{ + margin-bottom:5px; +} + +#input .options +{ + -ms-grid-row: 1; + -ms-grid-column: 1; +} + +#input .details +{ + -ms-grid-row: 1; + -ms-grid-column: 2; + cursor:text; +} + +.imageHolder +{ + max-width:382px; +} + +.imageHolder.withText +{ + float:left; + margin-right:10px; +} + +#scenarios +{ + margin-right:20px; +} + + + +@media screen and (min-width: 800px) and (max-width: 1024px) +{ + #rootGrid + { + -ms-grid-columns: 40px 1fr 40px; + } +} + +@media screen and (max-width: 799px) +{ + #rootGrid + { + -ms-grid-columns: 20px 1fr 20px; + } + + #output + { + padding-bottom:20px; + } + + #input + { + -ms-grid-columns: auto; + -ms-grid-rows: auto auto; + } + + #input .options + { + -ms-grid-row: 1; + -ms-grid-column: 1; + margin-bottom:10px; + } + + #input .details + { + -ms-grid-row: 2; + -ms-grid-column: 1; + } +} \ No newline at end of file diff --git a/samples/winrt/JavaScript/sample-utils/sample-utils.js b/samples/winrt/JavaScript/sample-utils/sample-utils.js new file mode 100644 index 0000000000000000000000000000000000000000..ad2834d8c8ea4b568584c4b578272718083c572c --- /dev/null +++ b/samples/winrt/JavaScript/sample-utils/sample-utils.js @@ -0,0 +1,204 @@ +//// Copyright (c) Microsoft Corporation. All rights reserved + +// This file is a part of the SDK sample framework. For code demonstrating scenarios in this particular sample, +// please see the html, css and js folders. + +(function () { + + // + // Helper controls used in the sample pages + // + + // The ScenarioInput control inserts the appropriate markup to get labels & controls + // hooked into the input section of a scenario page so that it's not repeated in + // every one. + + var lastError = ""; + var lastStatus = ""; + var ScenarioInput = WinJS.Class.define( + function (element, options) { + element.winControl = this; + this.element = element; + + new WinJS.Utilities.QueryCollection(element) + .setAttribute("role", "main") + .setAttribute("aria-labelledby", "inputLabel"); + element.id = "input"; + + this.addInputLabel(element); + this.addDetailsElement(element); + this.addScenariosPicker(element); + }, { + addInputLabel: function (element) { + var label = document.createElement("h2"); + label.textContent = "Input"; + label.id = "inputLabel"; + element.parentNode.insertBefore(label, element); + }, + addScenariosPicker: function (parentElement) { + var scenarios = document.createElement("div"); + scenarios.id = "scenarios"; + var control = new ScenarioSelect(scenarios); + + parentElement.insertBefore(scenarios, parentElement.childNodes[0]); + }, + + addDetailsElement: function (sourceElement) { + var detailsDiv = this._createDetailsDiv(); + while (sourceElement.childNodes.length > 0) { + detailsDiv.appendChild(sourceElement.removeChild(sourceElement.childNodes[0])); + } + sourceElement.appendChild(detailsDiv); + }, + _createDetailsDiv: function () { + var detailsDiv = document.createElement("div"); + + new WinJS.Utilities.QueryCollection(detailsDiv) + .addClass("details") + .setAttribute("role", "region") + .setAttribute("aria-labelledby", "descLabel") + .setAttribute("aria-live", "assertive"); + + var label = document.createElement("h3"); + label.textContent = "Description"; + label.id = "descLabel"; + + detailsDiv.appendChild(label); + return detailsDiv; + }, + } + ); + + // The ScenarioOutput control inserts the appropriate markup to get labels & controls + // hooked into the output section of a scenario page so that it's not repeated in + // every one. + + var ScenarioOutput = WinJS.Class.define( + function (element, options) { + element.winControl = this; + this.element = element; + new WinJS.Utilities.QueryCollection(element) + .setAttribute("role", "region") + .setAttribute("aria-labelledby", "outputLabel") + .setAttribute("aria-live", "assertive"); + element.id = "output"; + + this._addOutputLabel(element); + this._addStatusOutput(element); + }, { + _addOutputLabel: function (element) { + var label = document.createElement("h2"); + label.id = "outputLabel"; + label.textContent = "Output"; + element.parentNode.insertBefore(label, element); + }, + _addStatusOutput: function (element) { + var statusDiv = document.createElement("div"); + statusDiv.id = "statusMessage"; + statusDiv.setAttribute("role", "textbox"); + element.insertBefore(statusDiv, element.childNodes[0]); + } + } + ); + + + // Sample infrastructure internals + + var currentScenarioUrl = null; + + WinJS.Navigation.addEventListener("navigating", function (evt) { + currentScenarioUrl = evt.detail.location; + }); + + WinJS.log = function (message, tag, type) { + var isError = (type === "error"); + var isStatus = (type === "status"); + + if (isError || isStatus) { + var statusDiv = /* @type(HTMLElement) */ document.getElementById("statusMessage"); + if (statusDiv) { + statusDiv.innerText = message; + if (isError) { + lastError = message; + statusDiv.style.color = "blue"; + } else if (isStatus) { + lastStatus = message; + statusDiv.style.color = "green"; + } + } + } + }; + + // Control that populates and runs the scenario selector + + var ScenarioSelect = WinJS.UI.Pages.define("/sample-utils/scenario-select.html", { + ready: function (element, options) { + var that = this; + var selectElement = WinJS.Utilities.query("#scenarioSelect", element); + this._selectElement = selectElement[0]; + + SdkSample.scenarios.forEach(function (s, index) { + that._addScenario(index, s); + }); + + selectElement.listen("change", function (evt) { + var select = evt.target; + if (select.selectedIndex >= 0) { + var newUrl = select.options[select.selectedIndex].value; + WinJS.Navigation.navigate(newUrl); + } + }); + selectElement[0].size = (SdkSample.scenarios.length > 5 ? 5 : SdkSample.scenarios.length); + if (SdkSample.scenarios.length === 1) { + // Avoid showing down arrow when there is only one scenario + selectElement[0].setAttribute("multiple", "multiple"); + } + + // Use setImmediate to ensure that the select element is set as active only after + // the scenario page has been constructed. + setImmediate(function () { + that._selectElement.setActive(); + }); + }, + + _addScenario: function (index, info) { + var option = document.createElement("option"); + if (info.url === currentScenarioUrl) { + option.selected = "selected"; + } + option.text = (index + 1) + ") " + info.title; + option.value = info.url; + this._selectElement.appendChild(option); + } + }); + + function activated(e) { + WinJS.Utilities.query("#featureLabel")[0].textContent = SdkSample.sampleTitle; + } + + WinJS.Application.addEventListener("activated", activated, false); + + // Export public methods & controls + WinJS.Namespace.define("SdkSample", { + ScenarioInput: ScenarioInput, + ScenarioOutput: ScenarioOutput + }); + + // SDK Sample Test helper + document.TestSdkSample = { + getLastError: function () { + return lastError; + }, + + getLastStatus: function () { + return lastStatus; + }, + + selectScenario: function (scenarioID) { + scenarioID = scenarioID >> 0; + var select = document.getElementById("scenarioSelect"); + var newUrl = select.options[scenarioID - 1].value; + WinJS.Navigation.navigate(newUrl); + } + }; +})(); diff --git a/samples/winrt/JavaScript/sample-utils/scenario-select.html b/samples/winrt/JavaScript/sample-utils/scenario-select.html new file mode 100644 index 0000000000000000000000000000000000000000..011fabee605281195684314de05b10c37d7fe648 --- /dev/null +++ b/samples/winrt/JavaScript/sample-utils/scenario-select.html @@ -0,0 +1,15 @@ + + + + + + + +
+

Select scenario:

+ +
+ +