From 9e06287121155f1312cc64a23a5e56bf08ffcfad Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Mon, 24 Jun 2013 02:32:57 -0700 Subject: [PATCH] Windows RT sample updated. Unused scenarious removed. Grey scale convertion replaced with cv::Canny call. --- platforms/scripts/cmake_winrt.cmd | 2 +- platforms/winrt/arm.winrt.toolchain.cmake | 13 +- .../winrt/ImageManipulations/C++/AudioCapture.xaml | 62 --- .../ImageManipulations/C++/AudioCapture.xaml.cpp | 366 -------------- .../ImageManipulations/C++/AudioCapture.xaml.h | 70 --- .../winrt/ImageManipulations/C++/BasicCapture.xaml | 87 ---- .../ImageManipulations/C++/BasicCapture.xaml.cpp | 535 --------------------- .../ImageManipulations/C++/BasicCapture.xaml.h | 88 ---- samples/winrt/ImageManipulations/C++/Constants.cpp | 2 - samples/winrt/ImageManipulations/C++/Constants.h | 2 +- samples/winrt/ImageManipulations/C++/MainPage.xaml | 6 +- .../ImageManipulations/C++/MediaCapture.vcxproj | 160 +++++- .../C++/MediaCapture.vcxproj.filters | 25 +- .../C++/MediaExtensions/Grayscale/Grayscale.cpp | 250 +--------- .../C++/MediaExtensions/Grayscale/Grayscale.h | 34 +- .../MediaExtensions/Grayscale/Grayscale.vcxproj | 20 +- 16 files changed, 221 insertions(+), 1501 deletions(-) delete mode 100644 samples/winrt/ImageManipulations/C++/AudioCapture.xaml delete mode 100644 samples/winrt/ImageManipulations/C++/AudioCapture.xaml.cpp delete mode 100644 samples/winrt/ImageManipulations/C++/AudioCapture.xaml.h delete mode 100644 samples/winrt/ImageManipulations/C++/BasicCapture.xaml delete mode 100644 samples/winrt/ImageManipulations/C++/BasicCapture.xaml.cpp delete mode 100644 samples/winrt/ImageManipulations/C++/BasicCapture.xaml.h diff --git a/platforms/scripts/cmake_winrt.cmd b/platforms/scripts/cmake_winrt.cmd index aafed7d..c6d8cb8 100644 --- a/platforms/scripts/cmake_winrt.cmd +++ b/platforms/scripts/cmake_winrt.cmd @@ -3,4 +3,4 @@ cd build rem call "C:\Program Files\Microsoft Visual Studio 11.0\VC\bin\x86_arm\vcvarsx86_arm.bat" -cmake.exe -GNinja -DCMAKE_BUILD_TYPE=Release -DWITH_FFMPEG=OFF -DBUILD_opencv_gpu=OFF -DBUILD_opencv_python=OFF -DCMAKE_TOOLCHAIN_FILE=..\..\winrt\arm.winrt.toolchain.cmake ..\..\.. +cmake.exe -GNinja -DWITH_TBB=ON -DBUILD_TBB=ON -DCMAKE_BUILD_TYPE=Release -DWITH_FFMPEG=OFF -DBUILD_opencv_gpu=OFF -DBUILD_opencv_python=OFF -DCMAKE_TOOLCHAIN_FILE=..\..\winrt\arm.winrt.toolchain.cmake ..\..\.. diff --git a/platforms/winrt/arm.winrt.toolchain.cmake b/platforms/winrt/arm.winrt.toolchain.cmake index b34056c..ac9af11 100644 --- a/platforms/winrt/arm.winrt.toolchain.cmake +++ b/platforms/winrt/arm.winrt.toolchain.cmake @@ -3,4 +3,15 @@ set(CMAKE_SYSTEM_PROCESSOR "arm-v7a") set(CMAKE_FIND_ROOT_PATH "${CMAKE_SOURCE_DIR}/platforms/winrt") set(CMAKE_REQUIRED_DEFINITIONS -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE) -add_definitions(-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE) \ No newline at end of file +add_definitions(-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE) + +set(CMAKE_CXX_FLAGS "" CACHE STRING "c++ flags") +set(CMAKE_C_FLAGS "" CACHE STRING "c flags") + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ZW -EHsc -GS") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -GS") + + +set(CMAKE_SHARED_LINKER_FLAGS "/r:System.Runtime.WindowsRuntime.dll /r:System.Threading.Tasks.dll" CACHE STRING "shared linker flags") +set(CMAKE_MODULE_LINKER_FLAGS "/r:System.Runtime.WindowsRuntime.dll /r:System.Threading.Tasks.dll" CACHE STRING "module linker flags") +set(CMAKE_EXE_LINKER_FLAGS "/r:System.Runtime.WindowsRuntime.dll /r:System.Threading.Tasks.dll" CACHE STRING "executable linker flags") \ No newline at end of file diff --git a/samples/winrt/ImageManipulations/C++/AudioCapture.xaml b/samples/winrt/ImageManipulations/C++/AudioCapture.xaml deleted file mode 100644 index be65bcd..0000000 --- a/samples/winrt/ImageManipulations/C++/AudioCapture.xaml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - This scenario shows how to do an audio only capture using the default microphone. Click on StartRecord to start recording. - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/samples/winrt/ImageManipulations/C++/AudioCapture.xaml.cpp b/samples/winrt/ImageManipulations/C++/AudioCapture.xaml.cpp deleted file mode 100644 index 37fc379..0000000 --- a/samples/winrt/ImageManipulations/C++/AudioCapture.xaml.cpp +++ /dev/null @@ -1,366 +0,0 @@ -//********************************************************* -// -// Copyright (c) Microsoft. All rights reserved. -// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY -// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR -// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. -// -//********************************************************* - -// -// AudioCapture.xaml.cpp -// Implementation of the AudioCapture class -// - -#include "pch.h" -#include "AudioCapture.xaml.h" -#include -using namespace concurrency; - -using namespace SDKSample::MediaCapture; - -using namespace Windows::UI::Xaml; -using namespace Windows::UI::Xaml::Navigation; -using namespace Windows::UI::Xaml::Data; -using namespace Windows::System; -using namespace Windows::Foundation; -using namespace Platform; -using namespace Windows::UI; -using namespace Windows::UI::Core; -using namespace Windows::UI::Xaml; -using namespace Windows::UI::Xaml::Controls; -using namespace Windows::UI::Xaml::Data; -using namespace Windows::UI::Xaml::Media; -using namespace Windows::Storage; -using namespace Windows::Media::MediaProperties; -using namespace Windows::Storage::Streams; -using namespace Windows::System; -using namespace Windows::UI::Xaml::Media::Imaging; - - -AudioCapture::AudioCapture() -{ - InitializeComponent(); - ScenarioInit(); -} - -/// -/// Invoked when this page is about to be displayed in a Frame. -/// -/// Event data that describes how this page was reached. The Parameter -/// property is typically used to configure the page. -void AudioCapture::OnNavigatedTo(NavigationEventArgs^ e) -{ - // A pointer back to the main page. This is needed if you want to call methods in MainPage such - // as NotifyUser() - rootPage = MainPage::Current; - m_eventRegistrationToken = Windows::Media::MediaControl::SoundLevelChanged += ref new EventHandler(this, &AudioCapture::SoundLevelChanged); -} - -void AudioCapture::OnNavigatedFrom(NavigationEventArgs^ e) -{ - // A pointer back to the main page. This is needed if you want to call methods in MainPage such - // as NotifyUser() - Windows::Media::MediaControl::SoundLevelChanged -= m_eventRegistrationToken; -} - -void AudioCapture::ScenarioInit() -{ - try - { - rootPage = MainPage::Current; - btnStartDevice3->IsEnabled = true; - btnStartStopRecord3->IsEnabled = false; - m_bRecording = false; - playbackElement3->Source = nullptr; - m_bSuspended = false; - ShowStatusMessage(""); - } - catch (Exception ^e) - { - ShowExceptionMessage(e); - } - -} - -void AudioCapture::ScenarioReset() -{ - ScenarioInit(); -} - - -void AudioCapture::SoundLevelChanged(Object^ sender, Object^ e) -{ - create_task(Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, ref new Windows::UI::Core::DispatchedHandler([this]() - { - if(Windows::Media::MediaControl::SoundLevel != Windows::Media::SoundLevel::Muted) - { - ScenarioReset(); - } - else - { - if (m_bRecording) - { - ShowStatusMessage("Stopping Record on invisibility"); - - create_task(m_mediaCaptureMgr->StopRecordAsync()).then([this](task recordTask) - { - try - { - recordTask.get(); - m_bRecording = false; - }catch (Exception ^e) - { - ShowExceptionMessage(e); - } - }); - } - } - }))); -} - -void AudioCapture::RecordLimitationExceeded(Windows::Media::Capture::MediaCapture ^currentCaptureObject) -{ - try - { - if (m_bRecording) - { - create_task(Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, ref new Windows::UI::Core::DispatchedHandler([this](){ - try - { - ShowStatusMessage("Stopping Record on exceeding max record duration"); - EnableButton(false, "StartStopRecord"); - create_task(m_mediaCaptureMgr->StopRecordAsync()).then([this](task recordTask) - { - try - { - recordTask.get(); - m_bRecording = false; - SwitchRecordButtonContent(); - EnableButton(true, "StartStopRecord"); - ShowStatusMessage("Stopped record on exceeding max record duration:" + m_recordStorageFile->Path); - } - catch (Exception ^e) - { - ShowExceptionMessage(e); - m_bRecording = false; - SwitchRecordButtonContent(); - EnableButton(true, "StartStopRecord"); - } - }); - - } - catch (Exception ^e) - { - m_bRecording = false; - SwitchRecordButtonContent(); - EnableButton(true, "StartStopRecord"); - ShowExceptionMessage(e); - } - - }))); - } - } - catch (Exception ^e) - { - m_bRecording = false; - SwitchRecordButtonContent(); - EnableButton(true, "StartStopRecord"); - ShowExceptionMessage(e); - } -} - -void AudioCapture::Failed(Windows::Media::Capture::MediaCapture ^currentCaptureObject, Windows::Media::Capture::MediaCaptureFailedEventArgs^ currentFailure) -{ - String ^message = "Fatal error: " + currentFailure->Message; - create_task(Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, - ref new Windows::UI::Core::DispatchedHandler([this, message]() - { - ShowStatusMessage(message); - }))); -} - -void AudioCapture::btnStartDevice_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - try - { - EnableButton(false, "StartDevice"); - ShowStatusMessage("Starting device"); - auto mediaCapture = ref new Windows::Media::Capture::MediaCapture(); - m_mediaCaptureMgr = mediaCapture; - auto settings = ref new Windows::Media::Capture::MediaCaptureInitializationSettings(); - settings->StreamingCaptureMode = Windows::Media::Capture::StreamingCaptureMode::Audio; - create_task(mediaCapture->InitializeAsync()).then([this](task initTask) - { - try - { - initTask.get(); - - auto mediaCapture = m_mediaCaptureMgr.Get(); - EnableButton(true, "StartPreview"); - EnableButton(true, "StartStopRecord"); - EnableButton(true, "TakePhoto"); - ShowStatusMessage("Device initialized successful"); - mediaCapture->RecordLimitationExceeded += ref new Windows::Media::Capture::RecordLimitationExceededEventHandler(this, &AudioCapture::RecordLimitationExceeded); - mediaCapture->Failed += ref new Windows::Media::Capture::MediaCaptureFailedEventHandler(this, &AudioCapture::Failed); - } - catch (Exception ^ e) - { - ShowExceptionMessage(e); - } - }); - } - catch (Platform::Exception^ e) - { - ShowExceptionMessage(e); - } -} - -void AudioCapture::btnStartStopRecord_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - try - { - String ^fileName; - EnableButton(false, "StartStopRecord"); - - if (!m_bRecording) - { - ShowStatusMessage("Starting Record"); - - fileName = AUDIO_FILE_NAME; - - task(KnownFolders::VideosLibrary->CreateFileAsync(fileName, Windows::Storage::CreationCollisionOption::GenerateUniqueName)).then([this](task fileTask) - { - try - { - this->m_recordStorageFile = fileTask.get(); - ShowStatusMessage("Create record file successful"); - - MediaEncodingProfile^ recordProfile= nullptr; - recordProfile = MediaEncodingProfile::CreateM4a(Windows::Media::MediaProperties::AudioEncodingQuality::Auto); - - create_task(m_mediaCaptureMgr->StartRecordToStorageFileAsync(recordProfile, this->m_recordStorageFile)).then([this](task recordTask) - { - try - { - recordTask.get(); - m_bRecording = true; - SwitchRecordButtonContent(); - EnableButton(true, "StartStopRecord"); - - ShowStatusMessage("Start Record successful"); - - - }catch (Exception ^e) - { - ShowExceptionMessage(e); - m_bRecording = false; - SwitchRecordButtonContent(); - EnableButton(true, "StartStopRecord"); - } - }); - } - catch (Exception ^e) - { - m_bRecording = false; - SwitchRecordButtonContent(); - EnableButton(true, "StartStopRecord"); - ShowExceptionMessage(e); - } - } - ); - } - else - { - ShowStatusMessage("Stopping Record"); - - create_task(m_mediaCaptureMgr->StopRecordAsync()).then([this](task) - { - try - { - m_bRecording = false; - EnableButton(true, "StartStopRecord"); - SwitchRecordButtonContent(); - - ShowStatusMessage("Stop record successful"); - if (!m_bSuspended) - { - task(this->m_recordStorageFile->OpenAsync(FileAccessMode::Read)).then([this](task streamTask) - { - try - { - ShowStatusMessage("Record file opened"); - auto stream = streamTask.get(); - ShowStatusMessage(this->m_recordStorageFile->Path); - playbackElement3->AutoPlay = true; - playbackElement3->SetSource(stream, this->m_recordStorageFile->FileType); - playbackElement3->Play(); - } - catch (Exception ^e) - { - ShowExceptionMessage(e); - m_bRecording = false; - SwitchRecordButtonContent(); - EnableButton(true, "StartStopRecord"); - } - }); - } - } - catch (Exception ^e) - { - m_bRecording = false; - SwitchRecordButtonContent(); - EnableButton(true, "StartStopRecord"); - ShowExceptionMessage(e); - } - }); - } - } - catch (Platform::Exception^ e) - { - EnableButton(true, "StartStopRecord"); - ShowExceptionMessage(e); - m_bRecording = false; - SwitchRecordButtonContent(); - } -} - - -void AudioCapture::ShowStatusMessage(Platform::String^ text) -{ - rootPage->NotifyUser(text, NotifyType::StatusMessage); -} - -void AudioCapture::ShowExceptionMessage(Platform::Exception^ ex) -{ - rootPage->NotifyUser(ex->Message, NotifyType::ErrorMessage); -} - -void AudioCapture::SwitchRecordButtonContent() -{ - { - if (m_bRecording) - { - btnStartStopRecord3->Content="StopRecord"; - } - else - { - btnStartStopRecord3->Content="StartRecord"; - } - } -} -void AudioCapture::EnableButton(bool enabled, String^ name) -{ - if (name->Equals("StartDevice")) - { - btnStartDevice3->IsEnabled = enabled; - } - - else if (name->Equals("StartStopRecord")) - { - btnStartStopRecord3->IsEnabled = enabled; - } - -} - diff --git a/samples/winrt/ImageManipulations/C++/AudioCapture.xaml.h b/samples/winrt/ImageManipulations/C++/AudioCapture.xaml.h deleted file mode 100644 index b75efdc..0000000 --- a/samples/winrt/ImageManipulations/C++/AudioCapture.xaml.h +++ /dev/null @@ -1,70 +0,0 @@ -//********************************************************* -// -// Copyright (c) Microsoft. All rights reserved. -// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY -// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR -// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. -// -//********************************************************* - -// -// AudioCapture.xaml.h -// Declaration of the AudioCapture class -// - -#pragma once - -#include "pch.h" -#include "AudioCapture.g.h" -#include "MainPage.xaml.h" - -#define AUDIO_FILE_NAME "audio.mp4" - -namespace SDKSample -{ - namespace MediaCapture - { - /// - /// An empty page that can be used on its own or navigated to within a Frame. - /// - [Windows::Foundation::Metadata::WebHostHidden] - public ref class AudioCapture sealed - { - public: - AudioCapture(); - - protected: - virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override; - virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override; - private: - MainPage^ rootPage; - - void ScenarioInit(); - void ScenarioReset(); - - void SoundLevelChanged(Object^ sender, Object^ e); - void RecordLimitationExceeded(Windows::Media::Capture::MediaCapture ^ mediaCapture); - void Failed(Windows::Media::Capture::MediaCapture ^ mediaCapture, Windows::Media::Capture::MediaCaptureFailedEventArgs ^ args); - - void btnStartDevice_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - - void btnStartPreview_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - - void btnStartStopRecord_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - - void ShowStatusMessage(Platform::String^ text); - void ShowExceptionMessage(Platform::Exception^ ex); - - void EnableButton(bool enabled, Platform::String ^name); - void SwitchRecordButtonContent(); - - Platform::Agile m_mediaCaptureMgr; - Windows::Storage::StorageFile^ m_photoStorageFile; - Windows::Storage::StorageFile^ m_recordStorageFile; - bool m_bRecording; - bool m_bSuspended; - Windows::Foundation::EventRegistrationToken m_eventRegistrationToken; - }; - } -} diff --git a/samples/winrt/ImageManipulations/C++/BasicCapture.xaml b/samples/winrt/ImageManipulations/C++/BasicCapture.xaml deleted file mode 100644 index 2cc0b0a..0000000 --- a/samples/winrt/ImageManipulations/C++/BasicCapture.xaml +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - - - - - - - - - - - - This scenario demonstrates how to use the MediaCapture API to preview the camera stream, record a video, and take a picture using default initialization settings. - You can also adjust the brightness and contrast. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/samples/winrt/ImageManipulations/C++/BasicCapture.xaml.cpp b/samples/winrt/ImageManipulations/C++/BasicCapture.xaml.cpp deleted file mode 100644 index f385fa9..0000000 --- a/samples/winrt/ImageManipulations/C++/BasicCapture.xaml.cpp +++ /dev/null @@ -1,535 +0,0 @@ -//********************************************************* -// -// Copyright (c) Microsoft. All rights reserved. -// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY -// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR -// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. -// -//********************************************************* - -// -// BasicCapture.xaml.cpp -// Implementation of the BasicCapture class -// - -#include "pch.h" -#include "BasicCapture.xaml.h" -#include "ppl.h" - -using namespace Windows::System; -using namespace Windows::Foundation; -using namespace Platform; -using namespace Windows::UI; -using namespace Windows::UI::Core; -using namespace Windows::UI::Xaml; -using namespace Windows::UI::Xaml::Controls; -using namespace Windows::UI::Xaml::Navigation; -using namespace Windows::UI::Xaml::Data; -using namespace Windows::UI::Xaml::Media; -using namespace Windows::Storage; -using namespace Windows::Media::MediaProperties; -using namespace Windows::Storage::Streams; -using namespace Windows::System; -using namespace Windows::UI::Xaml::Media::Imaging; - -using namespace SDKSample::MediaCapture; -using namespace concurrency; - - -BasicCapture::BasicCapture() -{ - InitializeComponent(); - ScenarioInit(); -} - -/// -/// Invoked when this page is about to be displayed in a Frame. -/// -/// Event data that describes how this page was reached. The Parameter -/// property is typically used to configure the page. -void BasicCapture::OnNavigatedTo(NavigationEventArgs^ e) -{ - // A pointer back to the main page. This is needed if you want to call methods in MainPage such - // as NotifyUser() - rootPage = MainPage::Current; - m_eventRegistrationToken = Windows::Media::MediaControl::SoundLevelChanged += ref new EventHandler(this, &BasicCapture::SoundLevelChanged); -} - -void BasicCapture::OnNavigatedFrom(NavigationEventArgs^ e) -{ - // A pointer back to the main page. This is needed if you want to call methods in MainPage such - // as NotifyUser() - - Windows::Media::MediaControl::SoundLevelChanged -= m_eventRegistrationToken; - m_currentScenarioLoaded = false; -} - - -void BasicCapture::ScenarioInit() -{ - try - { - btnStartDevice1->IsEnabled = true; - btnStartPreview1->IsEnabled = false; - btnStartStopRecord1->IsEnabled = false; - m_bRecording = false; - m_bPreviewing = false; - btnStartStopRecord1->Content = "StartRecord"; - btnTakePhoto1->IsEnabled = false; - previewElement1->Source = nullptr; - playbackElement1->Source = nullptr; - imageElement1->Source= nullptr; - sldBrightness->IsEnabled = false; - sldContrast->IsEnabled = false; - m_bSuspended = false; - previewCanvas1->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - - } - catch (Exception ^e) - { - ShowExceptionMessage(e); - } - -} - -void BasicCapture::ScenarioReset() -{ - previewCanvas1->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - ScenarioInit(); -} - -void BasicCapture::SoundLevelChanged(Object^ sender, Object^ e) -{ - create_task(Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, ref new Windows::UI::Core::DispatchedHandler([this]() - { - if(Windows::Media::MediaControl::SoundLevel != Windows::Media::SoundLevel::Muted) - { - ScenarioReset(); - } - else - { - if (m_bRecording) - { - ShowStatusMessage("Stopping Record on invisibility"); - - create_task(m_mediaCaptureMgr->StopRecordAsync()).then([this](task recordTask) - { - m_bRecording = false; - }); - } - if (m_bPreviewing) - { - ShowStatusMessage("Stopping Preview on invisibility"); - - create_task(m_mediaCaptureMgr->StopPreviewAsync()).then([this](task previewTask) - { - try - { - previewTask.get(); - m_bPreviewing = false; - } - catch (Exception ^e) - { - ShowExceptionMessage(e); - } - }); - } - } - }))); -} - -void BasicCapture::RecordLimitationExceeded(Windows::Media::Capture::MediaCapture ^currentCaptureObject) -{ - try - { - if (m_bRecording) - { - create_task(Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, ref new Windows::UI::Core::DispatchedHandler([this](){ - try - { - ShowStatusMessage("Stopping Record on exceeding max record duration"); - EnableButton(false, "StartStopRecord"); - create_task(m_mediaCaptureMgr->StopRecordAsync()).then([this](task recordTask) - { - try - { - recordTask.get(); - m_bRecording = false; - SwitchRecordButtonContent(); - EnableButton(true, "StartStopRecord"); - ShowStatusMessage("Stopped record on exceeding max record duration:" + m_recordStorageFile->Path); - } - catch (Exception ^e) - { - ShowExceptionMessage(e); - m_bRecording = false; - SwitchRecordButtonContent(); - EnableButton(true, "StartStopRecord"); - } - }); - - } - catch (Exception ^e) - { - m_bRecording = false; - SwitchRecordButtonContent(); - EnableButton(true, "StartStopRecord"); - ShowExceptionMessage(e); - } - - }))); - } - } - catch (Exception ^e) - { - m_bRecording = false; - SwitchRecordButtonContent(); - EnableButton(true, "StartStopRecord"); - ShowExceptionMessage(e); - } -} - -void BasicCapture::Failed(Windows::Media::Capture::MediaCapture ^currentCaptureObject, Windows::Media::Capture::MediaCaptureFailedEventArgs^ currentFailure) -{ - String ^message = "Fatal error: " + currentFailure->Message; - create_task(Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, - ref new Windows::UI::Core::DispatchedHandler([this, message]() - { - ShowStatusMessage(message); - }))); -} - -void BasicCapture::btnStartDevice_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - try - { - EnableButton(false, "StartDevice"); - ShowStatusMessage("Starting device"); - auto mediaCapture = ref new Windows::Media::Capture::MediaCapture(); - m_mediaCaptureMgr = mediaCapture; - create_task(mediaCapture->InitializeAsync()).then([this](task initTask) - { - try - { - initTask.get(); - - auto mediaCapture = m_mediaCaptureMgr.Get(); - EnableButton(true, "StartPreview"); - EnableButton(true, "StartStopRecord"); - EnableButton(true, "TakePhoto"); - ShowStatusMessage("Device initialized successful"); - mediaCapture->RecordLimitationExceeded += ref new Windows::Media::Capture::RecordLimitationExceededEventHandler(this, &BasicCapture::RecordLimitationExceeded); - mediaCapture->Failed += ref new Windows::Media::Capture::MediaCaptureFailedEventHandler(this, &BasicCapture::Failed); - } - catch (Exception ^ e) - { - ShowExceptionMessage(e); - } - } - ); - } - catch (Platform::Exception^ e) - { - ShowExceptionMessage(e); - } -} - -void BasicCapture::btnStartPreview_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - m_bPreviewing = false; - try - { - ShowStatusMessage("Starting preview"); - EnableButton(false, "StartPreview"); - auto mediaCapture = m_mediaCaptureMgr.Get(); - - previewCanvas1->Visibility = Windows::UI::Xaml::Visibility::Visible; - previewElement1->Source = mediaCapture; - create_task(mediaCapture->StartPreviewAsync()).then([this](task previewTask) - { - try - { - previewTask.get(); - auto mediaCapture = m_mediaCaptureMgr.Get(); - m_bPreviewing = true; - ShowStatusMessage("Start preview successful"); - if(mediaCapture->VideoDeviceController->Brightness) - { - SetupVideoDeviceControl(mediaCapture->VideoDeviceController->Brightness, sldBrightness); - } - if(mediaCapture->VideoDeviceController->Contrast) - { - SetupVideoDeviceControl(mediaCapture->VideoDeviceController->Contrast, sldContrast); - } - - }catch (Exception ^e) - { - ShowExceptionMessage(e); - } - }); - } - catch (Platform::Exception^ e) - { - m_bPreviewing = false; - previewElement1->Source = nullptr; - EnableButton(true, "StartPreview"); - ShowExceptionMessage(e); - } -} - -void BasicCapture::btnTakePhoto_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - try - { - ShowStatusMessage("Taking photo"); - EnableButton(false, "TakePhoto"); - - task(KnownFolders::PicturesLibrary->CreateFileAsync(PHOTO_FILE_NAME, Windows::Storage::CreationCollisionOption::GenerateUniqueName)).then([this](task getFileTask) - { - try - { - this->m_photoStorageFile = getFileTask.get(); - ShowStatusMessage("Create photo file successful"); - ImageEncodingProperties^ imageProperties = ImageEncodingProperties::CreateJpeg(); - - create_task(m_mediaCaptureMgr->CapturePhotoToStorageFileAsync(imageProperties, this->m_photoStorageFile)).then([this](task photoTask) - { - try - { - photoTask.get(); - EnableButton(true, "TakePhoto"); - ShowStatusMessage("Photo taken"); - - task(this->m_photoStorageFile->OpenAsync(FileAccessMode::Read)).then([this](task getStreamTask) - { - try - { - auto photoStream = getStreamTask.get(); - ShowStatusMessage("File open successful"); - auto bmpimg = ref new BitmapImage(); - - bmpimg->SetSource(photoStream); - imageElement1->Source = bmpimg; - } - catch (Exception^ e) - { - ShowExceptionMessage(e); - EnableButton(true, "TakePhoto"); - } - }); - } - catch (Platform::Exception ^ e) - { - ShowExceptionMessage(e); - EnableButton(true, "TakePhoto"); - } - }); - } - catch (Exception^ e) - { - ShowExceptionMessage(e); - EnableButton(true, "TakePhoto"); - } - }); - } - catch (Platform::Exception^ e) - { - ShowExceptionMessage(e); - EnableButton(true, "TakePhoto"); - } -} - -void BasicCapture::btnStartStopRecord_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - try - { - String ^fileName; - EnableButton(false, "StartStopRecord"); - - if (!m_bRecording) - { - ShowStatusMessage("Starting Record"); - - fileName = VIDEO_FILE_NAME; - - task(KnownFolders::VideosLibrary->CreateFileAsync(fileName,Windows::Storage::CreationCollisionOption::GenerateUniqueName )).then([this](task fileTask) - { - try - { - this->m_recordStorageFile = fileTask.get(); - ShowStatusMessage("Create record file successful"); - - MediaEncodingProfile^ recordProfile= nullptr; - recordProfile = MediaEncodingProfile::CreateMp4(Windows::Media::MediaProperties::VideoEncodingQuality::Auto); - - create_task(m_mediaCaptureMgr->StartRecordToStorageFileAsync(recordProfile, this->m_recordStorageFile)).then([this](task recordTask) - { - try - { - recordTask.get(); - m_bRecording = true; - SwitchRecordButtonContent(); - EnableButton(true, "StartStopRecord"); - - ShowStatusMessage("Start Record successful"); - } - catch (Exception ^e) - { - ShowExceptionMessage(e); - } - }); - } - catch (Exception ^e) - { - m_bRecording = false; - SwitchRecordButtonContent(); - EnableButton(true, "StartStopRecord"); - ShowExceptionMessage(e); - } - } - ); - } - else - { - ShowStatusMessage("Stopping Record"); - - create_task(m_mediaCaptureMgr->StopRecordAsync()).then([this](task recordTask) - { - try - { - recordTask.get(); - m_bRecording = false; - EnableButton(true, "StartStopRecord"); - SwitchRecordButtonContent(); - - ShowStatusMessage("Stop record successful"); - if (!m_bSuspended) - { - task(this->m_recordStorageFile->OpenAsync(FileAccessMode::Read)).then([this](task streamTask) - { - try - { - auto stream = streamTask.get(); - ShowStatusMessage("Record file opened"); - ShowStatusMessage(this->m_recordStorageFile->Path); - playbackElement1->AutoPlay = true; - playbackElement1->SetSource(stream, this->m_recordStorageFile->FileType); - playbackElement1->Play(); - } - catch (Exception ^e) - { - ShowExceptionMessage(e); - m_bRecording = false; - EnableButton(true, "StartStopRecord"); - SwitchRecordButtonContent(); - } - }); - } - } - catch (Exception ^e) - { - m_bRecording = false; - EnableButton(true, "StartStopRecord"); - SwitchRecordButtonContent(); - ShowExceptionMessage(e); - } - }); - } - } - catch (Platform::Exception^ e) - { - EnableButton(true, "StartStopRecord"); - ShowExceptionMessage(e); - SwitchRecordButtonContent(); - m_bRecording = false; - } -} - -void BasicCapture::SetupVideoDeviceControl(Windows::Media::Devices::MediaDeviceControl^ videoDeviceControl, Slider^ slider) -{ - try - { - if ((videoDeviceControl->Capabilities)->Supported) - { - slider->IsEnabled = true; - slider->Maximum = videoDeviceControl->Capabilities->Max; - slider->Minimum = videoDeviceControl->Capabilities->Min; - slider->StepFrequency = videoDeviceControl->Capabilities->Step; - double controlValue = 0; - if (videoDeviceControl->TryGetValue(&controlValue)) - { - slider->Value = controlValue; - } - } - else - { - slider->IsEnabled = false; - } - } - catch (Platform::Exception^ e) - { - ShowExceptionMessage(e); - } -} - -// VideoDeviceControllers -void BasicCapture::sldBrightness_ValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e) -{ - bool succeeded = m_mediaCaptureMgr->VideoDeviceController->Brightness->TrySetValue(sldBrightness->Value); - if (!succeeded) - { - ShowStatusMessage("Set Brightness failed"); - } -} - -void BasicCapture::sldContrast_ValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs ^e) -{ - bool succeeded = m_mediaCaptureMgr->VideoDeviceController->Contrast->TrySetValue(sldContrast->Value); - if (!succeeded) - { - ShowStatusMessage("Set Contrast failed"); - } -} - -void BasicCapture::ShowStatusMessage(Platform::String^ text) -{ - rootPage->NotifyUser(text, NotifyType::StatusMessage); -} - -void BasicCapture::ShowExceptionMessage(Platform::Exception^ ex) -{ - rootPage->NotifyUser(ex->Message, NotifyType::ErrorMessage); -} - -void BasicCapture::SwitchRecordButtonContent() -{ - if (m_bRecording) - { - btnStartStopRecord1->Content="StopRecord"; - } - else - { - btnStartStopRecord1->Content="StartRecord"; - } -} -void BasicCapture::EnableButton(bool enabled, String^ name) -{ - if (name->Equals("StartDevice")) - { - btnStartDevice1->IsEnabled = enabled; - } - else if (name->Equals("StartPreview")) - { - btnStartPreview1->IsEnabled = enabled; - } - else if (name->Equals("StartStopRecord")) - { - btnStartStopRecord1->IsEnabled = enabled; - } - else if (name->Equals("TakePhoto")) - { - btnTakePhoto1->IsEnabled = enabled; - } -} - diff --git a/samples/winrt/ImageManipulations/C++/BasicCapture.xaml.h b/samples/winrt/ImageManipulations/C++/BasicCapture.xaml.h deleted file mode 100644 index 28129ef..0000000 --- a/samples/winrt/ImageManipulations/C++/BasicCapture.xaml.h +++ /dev/null @@ -1,88 +0,0 @@ -//********************************************************* -// -// Copyright (c) Microsoft. All rights reserved. -// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY -// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR -// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. -// -//********************************************************* - -// -// BasicCapture.xaml.h -// Declaration of the BasicCapture class -// - -#pragma once - -#include "pch.h" -#include "BasicCapture.g.h" -#include "MainPage.xaml.h" - -using namespace Windows::UI::Xaml; -using namespace Windows::UI::Xaml::Controls; -using namespace Windows::Graphics::Display; -using namespace Windows::UI::ViewManagement; -using namespace Windows::Devices::Enumeration; -#define VIDEO_FILE_NAME "video.mp4" -#define PHOTO_FILE_NAME "photo.jpg" -namespace SDKSample -{ - namespace MediaCapture - { - /// - /// An empty page that can be used on its own or navigated to within a Frame. - /// - [Windows::Foundation::Metadata::WebHostHidden] - public ref class BasicCapture sealed - { - public: - BasicCapture(); - - protected: - virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override; - virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override; - - private: - MainPage^ rootPage; - void ScenarioInit(); - void ScenarioReset(); - - void Suspending(Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e); - void Resuming(Object^ sender, Object^ e); - - void btnStartDevice_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - void SoundLevelChanged(Object^ sender, Object^ e); - void RecordLimitationExceeded(Windows::Media::Capture::MediaCapture ^ mediaCapture); - void Failed(Windows::Media::Capture::MediaCapture ^ mediaCapture, Windows::Media::Capture::MediaCaptureFailedEventArgs ^ args); - - - void btnStartPreview_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - - void btnStartStopRecord_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - - void btnTakePhoto_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); - - void SetupVideoDeviceControl(Windows::Media::Devices::MediaDeviceControl^ videoDeviceControl, Slider^ slider); - void sldBrightness_ValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e); - void sldContrast_ValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e); - - void ShowStatusMessage(Platform::String^ text); - void ShowExceptionMessage(Platform::Exception^ ex); - - void EnableButton(bool enabled, Platform::String ^name); - void SwitchRecordButtonContent(); - - Platform::Agile m_mediaCaptureMgr; - Windows::Storage::StorageFile^ m_photoStorageFile; - Windows::Storage::StorageFile^ m_recordStorageFile; - bool m_bRecording; - bool m_bEffectAdded; - bool m_bSuspended; - bool m_bPreviewing; - Windows::UI::Xaml::WindowVisibilityChangedEventHandler ^m_visbilityHandler; - Windows::Foundation::EventRegistrationToken m_eventRegistrationToken; - bool m_currentScenarioLoaded; - }; - } -} diff --git a/samples/winrt/ImageManipulations/C++/Constants.cpp b/samples/winrt/ImageManipulations/C++/Constants.cpp index 873b983..a266342 100644 --- a/samples/winrt/ImageManipulations/C++/Constants.cpp +++ b/samples/winrt/ImageManipulations/C++/Constants.cpp @@ -18,7 +18,5 @@ Platform::Array^ MainPage::scenariosInner = ref new Platform::Array - + @@ -47,7 +47,7 @@ - + @@ -92,7 +92,7 @@ - + diff --git a/samples/winrt/ImageManipulations/C++/MediaCapture.vcxproj b/samples/winrt/ImageManipulations/C++/MediaCapture.vcxproj index d2f255d..84b6d3d 100644 --- a/samples/winrt/ImageManipulations/C++/MediaCapture.vcxproj +++ b/samples/winrt/ImageManipulations/C++/MediaCapture.vcxproj @@ -101,14 +101,6 @@ AdvancedCapture.xaml Code - - AudioCapture.xaml - Code - - - BasicCapture.xaml - Code - MainPage.xaml @@ -127,12 +119,6 @@ Designer - - Designer - - - Designer - Designer @@ -156,14 +142,6 @@ App.xaml - - AudioCapture.xaml - Code - - - BasicCapture.xaml - Code - @@ -194,6 +172,144 @@ {ba69218f-da5c-4d14-a78d-21a9e4dec669} + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + + true + true + true + true + true + true + + diff --git a/samples/winrt/ImageManipulations/C++/MediaCapture.vcxproj.filters b/samples/winrt/ImageManipulations/C++/MediaCapture.vcxproj.filters index 5f6124c..403e5ea 100644 --- a/samples/winrt/ImageManipulations/C++/MediaCapture.vcxproj.filters +++ b/samples/winrt/ImageManipulations/C++/MediaCapture.vcxproj.filters @@ -40,9 +40,7 @@ Sample-Utils - - @@ -56,8 +54,6 @@ - - @@ -71,8 +67,6 @@ - - @@ -85,4 +79,23 @@ {54f287f8-e4cb-4f47-97d0-4c469de6992e} + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/winrt/ImageManipulations/C++/MediaExtensions/Grayscale/Grayscale.cpp b/samples/winrt/ImageManipulations/C++/MediaExtensions/Grayscale/Grayscale.cpp index 687386e..d41fa34 100644 --- a/samples/winrt/ImageManipulations/C++/MediaExtensions/Grayscale/Grayscale.cpp +++ b/samples/winrt/ImageManipulations/C++/MediaExtensions/Grayscale/Grayscale.cpp @@ -8,6 +8,9 @@ #include "Grayscale.h" #include "bufferlock.h" +#include "opencv2\core\core.hpp" +#include "opencv2\imgproc\imgproc.hpp" + #pragma comment(lib, "d2d1") using namespace Microsoft::WRL; @@ -80,16 +83,12 @@ NOTES ON THE MFT IMPLEMENTATION // Video FOURCC codes. -const DWORD FOURCC_YUY2 = '2YUY'; -const DWORD FOURCC_UYVY = 'YVYU'; const DWORD FOURCC_NV12 = '21VN'; // Static array of media types (preferred and accepted). const GUID g_MediaSubtypes[] = { - MFVideoFormat_NV12, - MFVideoFormat_YUY2, - MFVideoFormat_UYVY + MFVideoFormat_NV12 }; HRESULT GetImageSize(DWORD fcc, UINT32 width, UINT32 height, DWORD* pcbImage); @@ -102,27 +101,6 @@ inline T clamp(const T& val, const T& minVal, const T& maxVal) return (val < minVal ? minVal : (val > maxVal ? maxVal : val)); } - -// TransformChroma: -// Apply the transforms to calculate the output chroma values. - -void TransformChroma(const D2D1::Matrix3x2F& mat, BYTE *pu, BYTE *pv) -{ - // Normalize the chroma values to [-112, 112] range - - D2D1_POINT_2F pt = { static_cast(*pu) - 128, static_cast(*pv) - 128 }; - - pt = mat.TransformPoint(pt); - - // Clamp to valid range. - clamp(pt.x, -112.0f, 112.0f); - clamp(pt.y, -112.0f, 112.0f); - - // Map back to [16...240] range. - *pu = static_cast(pt.x + 128.0f); - *pv = static_cast(pt.y + 128.0f); -} - //------------------------------------------------------------------- // Functions to convert a YUV images to grayscale. // @@ -141,144 +119,6 @@ void TransformChroma(const D2D1::Matrix3x2F& mat, BYTE *pu, BYTE *pv) // dwHeightInPixels Frame height, in pixels. //------------------------------------------------------------------- -// Convert UYVY image. - -void TransformImage_UYVY( - const D2D1::Matrix3x2F& mat, - const D2D_RECT_U& rcDest, - _Inout_updates_(_Inexpressible_(lDestStride * dwHeightInPixels)) BYTE *pDest, - _In_ LONG lDestStride, - _In_reads_(_Inexpressible_(lSrcStride * dwHeightInPixels)) const BYTE* pSrc, - _In_ LONG lSrcStride, - _In_ DWORD dwWidthInPixels, - _In_ DWORD dwHeightInPixels) -{ - DWORD y = 0; - const DWORD y0 = min(rcDest.bottom, dwHeightInPixels); - - // Lines above the destination rectangle. - for ( ; y < rcDest.top; y++) - { - memcpy(pDest, pSrc, dwWidthInPixels * 2); - pSrc += lSrcStride; - pDest += lDestStride; - } - - // Lines within the destination rectangle. - for ( ; y < y0; y++) - { - WORD *pSrc_Pixel = (WORD*)pSrc; - WORD *pDest_Pixel = (WORD*)pDest; - - for (DWORD x = 0; (x + 1) < dwWidthInPixels; x += 2) - { - // Byte order is U0 Y0 V0 Y1 - // Each WORD is a byte pair (U/V, Y) - // Windows is little-endian so the order appears reversed. - - if (x >= rcDest.left && x < rcDest.right) - { - BYTE u = pSrc_Pixel[x] & 0x00FF; - BYTE v = pSrc_Pixel[x+1] & 0x00FF; - - TransformChroma(mat, &u, &v); - - pDest_Pixel[x] = (pSrc_Pixel[x] & 0xFF00) | u; - pDest_Pixel[x+1] = (pSrc_Pixel[x+1] & 0xFF00) | v; - } - else - { -#pragma warning(push) -#pragma warning(disable: 6385) -#pragma warning(disable: 6386) - pDest_Pixel[x] = pSrc_Pixel[x]; - pDest_Pixel[x+1] = pSrc_Pixel[x+1]; -#pragma warning(pop) - } - } - - pDest += lDestStride; - pSrc += lSrcStride; - } - - // Lines below the destination rectangle. - for ( ; y < dwHeightInPixels; y++) - { - memcpy(pDest, pSrc, dwWidthInPixels * 2); - pSrc += lSrcStride; - pDest += lDestStride; - } -} - - -// Convert YUY2 image. - -void TransformImage_YUY2( - const D2D1::Matrix3x2F& mat, - const D2D_RECT_U& rcDest, - _Inout_updates_(_Inexpressible_(lDestStride * dwHeightInPixels)) BYTE *pDest, - _In_ LONG lDestStride, - _In_reads_(_Inexpressible_(lSrcStride * dwHeightInPixels)) const BYTE* pSrc, - _In_ LONG lSrcStride, - _In_ DWORD dwWidthInPixels, - _In_ DWORD dwHeightInPixels) -{ - DWORD y = 0; - const DWORD y0 = min(rcDest.bottom, dwHeightInPixels); - - // Lines above the destination rectangle. - for ( ; y < rcDest.top; y++) - { - memcpy(pDest, pSrc, dwWidthInPixels * 2); - pSrc += lSrcStride; - pDest += lDestStride; - } - - // Lines within the destination rectangle. - for ( ; y < y0; y++) - { - WORD *pSrc_Pixel = (WORD*)pSrc; - WORD *pDest_Pixel = (WORD*)pDest; - - for (DWORD x = 0; (x + 1) < dwWidthInPixels; x += 2) - { - // Byte order is Y0 U0 Y1 V0 - // Each WORD is a byte pair (Y, U/V) - // Windows is little-endian so the order appears reversed. - - if (x >= rcDest.left && x < rcDest.right) - { - BYTE u = pSrc_Pixel[x] >> 8; - BYTE v = pSrc_Pixel[x+1] >> 8; - - TransformChroma(mat, &u, &v); - - pDest_Pixel[x] = (pSrc_Pixel[x] & 0x00FF) | (u<<8); - pDest_Pixel[x+1] = (pSrc_Pixel[x+1] & 0x00FF) | (v<<8); - } - else - { -#pragma warning(push) -#pragma warning(disable: 6385) -#pragma warning(disable: 6386) - pDest_Pixel[x] = pSrc_Pixel[x]; - pDest_Pixel[x+1] = pSrc_Pixel[x+1]; -#pragma warning(pop) - } - } - pDest += lDestStride; - pSrc += lSrcStride; - } - - // Lines below the destination rectangle. - for ( ; y < dwHeightInPixels; y++) - { - memcpy(pDest, pSrc, dwWidthInPixels * 2); - pSrc += lSrcStride; - pDest += lDestStride; - } -} - // Convert NV12 image void TransformImage_NV12( @@ -307,7 +147,8 @@ void TransformImage_NV12( // Lines above the destination rectangle. DWORD y = 0; - const DWORD y0 = min(rcDest.bottom, dwHeightInPixels); + + const DWORD y0 = rcDest.bottom < dwHeightInPixels ? rcDest.bottom : dwHeightInPixels; for ( ; y < rcDest.top/2; y++) { @@ -323,13 +164,8 @@ void TransformImage_NV12( { if (x >= rcDest.left && x < rcDest.right) { - BYTE u = pSrc[x]; - BYTE v = pSrc[x+1]; - - TransformChroma(mat, &u, &v); - - pDest[x] = u; - pDest[x+1] = v; + pDest[x] = 0; + pDest[x+1] = 0; } else { @@ -351,9 +187,9 @@ void TransformImage_NV12( } CGrayscale::CGrayscale() : - m_pSample(NULL), m_pInputType(NULL), m_pOutputType(NULL), m_pTransformFn(NULL), + m_pSample(NULL), m_pInputType(NULL), m_pOutputType(NULL), m_imageWidthInPixels(0), m_imageHeightInPixels(0), m_cbImageSize(0), - m_transform(D2D1::Matrix3x2F::Identity()), m_rcDest(D2D1::RectU()), m_bStreamingInitialized(false), + m_TransformType(Preview), m_rcDest(D2D1::RectU()), m_bStreamingInitialized(false), m_pAttributes(NULL) { InitializeCriticalSectionEx(&m_critSec, 3000, 0); @@ -1516,10 +1352,8 @@ HRESULT CGrayscale::BeginStreaming() // Get the chroma transformations. - float scale = (float)MFGetAttributeDouble(m_pAttributes, MFT_GRAYSCALE_SATURATION, 0.0f); - float angle = (float)MFGetAttributeDouble(m_pAttributes, MFT_GRAYSCALE_CHROMA_ROTATION, 0.0f); - - m_transform = D2D1::Matrix3x2F::Scale(scale, scale) * D2D1::Matrix3x2F::Rotation(angle); + // float scale = (float)MFGetAttributeDouble(m_pAttributes, MFT_GRAYSCALE_SATURATION, 0.0f); + // float angle = (float)MFGetAttributeDouble(m_pAttributes, MFT_GRAYSCALE_CHROMA_ROTATION, 0.0f); m_bStreamingInitialized = true; } @@ -1563,42 +1397,36 @@ HRESULT CGrayscale::OnProcessOutput(IMFMediaBuffer *pIn, IMFMediaBuffer *pOut) HRESULT hr = GetDefaultStride(m_pInputType, &lDefaultStride); if (FAILED(hr)) { - goto done; + return hr; } // Lock the input buffer. hr = inputLock.LockBuffer(lDefaultStride, m_imageHeightInPixels, &pSrc, &lSrcStride); if (FAILED(hr)) { - goto done; + return hr; } // Lock the output buffer. hr = outputLock.LockBuffer(lDefaultStride, m_imageHeightInPixels, &pDest, &lDestStride); if (FAILED(hr)) { - goto done; - } - - // Invoke the image transform function. - assert (m_pTransformFn != NULL); - if (m_pTransformFn) - { - (*m_pTransformFn)(m_transform, m_rcDest, pDest, lDestStride, pSrc, lSrcStride, - m_imageWidthInPixels, m_imageHeightInPixels); - } - else - { - hr = E_UNEXPECTED; - goto done; + return hr; } + //(*m_pTransformFn)(m_transform, m_rcDest, pDest, lDestStride, pSrc, lSrcStride, + // m_imageWidthInPixels, m_imageHeightInPixels); + cv::Mat InputFrame(m_imageHeightInPixels + m_imageHeightInPixels/2, m_imageWidthInPixels, CV_8UC1, pSrc, lSrcStride); + cv::Mat InputGreyScale(InputFrame, cv::Range(0, m_imageHeightInPixels), cv::Range(0, m_imageWidthInPixels)); + cv::Mat OutputFrame(m_imageHeightInPixels + m_imageHeightInPixels/2, m_imageWidthInPixels, CV_8UC1, pDest, lDestStride); + OutputFrame.setTo(cv::Scalar(128)); + cv::Mat OutputGreyScale(OutputFrame, cv::Range(0, m_imageHeightInPixels), cv::Range(0, m_imageWidthInPixels)); + cv::Canny(InputGreyScale, OutputGreyScale, 80, 90); + // Set the data size on the output buffer. hr = pOut->SetCurrentLength(m_cbImageSize); - // The VideoBufferLock class automatically unlocks the buffers. -done: return hr; } @@ -1626,8 +1454,6 @@ HRESULT CGrayscale::UpdateFormatInfo() m_imageHeightInPixels = 0; m_cbImageSize = 0; - m_pTransformFn = NULL; - if (m_pInputType != NULL) { hr = m_pInputType->GetGUID(MF_MT_SUBTYPE, &subtype); @@ -1635,19 +1461,7 @@ HRESULT CGrayscale::UpdateFormatInfo() { goto done; } - if (subtype == MFVideoFormat_YUY2) - { - m_pTransformFn = TransformImage_YUY2; - } - else if (subtype == MFVideoFormat_UYVY) - { - m_pTransformFn = TransformImage_UYVY; - } - else if (subtype == MFVideoFormat_NV12) - { - m_pTransformFn = TransformImage_NV12; - } - else + if (subtype != MFVideoFormat_NV12) { hr = E_UNEXPECTED; goto done; @@ -1678,20 +1492,6 @@ HRESULT GetImageSize(DWORD fcc, UINT32 width, UINT32 height, DWORD* pcbImage) switch (fcc) { - case FOURCC_YUY2: - case FOURCC_UYVY: - // check overflow - if ((width > MAXDWORD / 2) || (width * 2 > MAXDWORD / height)) - { - hr = E_INVALIDARG; - } - else - { - // 16 bpp - *pcbImage = width * height * 2; - } - break; - case FOURCC_NV12: // check overflow if ((height/2 > MAXDWORD - height) || ((height + height/2) > MAXDWORD / width)) diff --git a/samples/winrt/ImageManipulations/C++/MediaExtensions/Grayscale/Grayscale.h b/samples/winrt/ImageManipulations/C++/MediaExtensions/Grayscale/Grayscale.h index b83223b..96b4b1b 100644 --- a/samples/winrt/ImageManipulations/C++/MediaExtensions/Grayscale/Grayscale.h +++ b/samples/winrt/ImageManipulations/C++/MediaExtensions/Grayscale/Grayscale.h @@ -42,15 +42,14 @@ DEFINE_GUID(CLSID_GrayscaleMFT, DEFINE_GUID(MFT_GRAYSCALE_DESTINATION_RECT, 0x7bbbb051, 0x133b, 0x41f5, 0xb6, 0xaa, 0x5a, 0xff, 0x9b, 0x33, 0xa2, 0xcb); - -// {14782342-93E8-4565-872C-D9A2973D5CBF} -DEFINE_GUID(MFT_GRAYSCALE_SATURATION, -0x14782342, 0x93e8, 0x4565, 0x87, 0x2c, 0xd9, 0xa2, 0x97, 0x3d, 0x5c, 0xbf); - -// {E0BADE5D-E4B9-4689-9DBA-E2F00D9CED0E} -DEFINE_GUID(MFT_GRAYSCALE_CHROMA_ROTATION, -0xe0bade5d, 0xe4b9, 0x4689, 0x9d, 0xba, 0xe2, 0xf0, 0xd, 0x9c, 0xed, 0xe); - +enum ProcessingType +{ + Preview, + GrayScale, + Canny, + Zoom, + Sepia +}; template void SafeRelease(T **ppT) { @@ -61,18 +60,6 @@ template void SafeRelease(T **ppT) } } -// Function pointer for the function that transforms the image. -typedef void (*IMAGE_TRANSFORM_FN)( - const D2D1::Matrix3x2F& mat, // Chroma transform matrix. - const D2D_RECT_U& rcDest, // Destination rectangle for the transformation. - BYTE* pDest, // Destination buffer. - LONG lDestStride, // Destination stride. - const BYTE* pSrc, // Source buffer. - LONG lSrcStride, // Source stride. - DWORD dwWidthInPixels, // Image width in pixels. - DWORD dwHeightInPixels // Image height in pixels. - ); - // CGrayscale class: // Implements a grayscale video effect. @@ -244,7 +231,7 @@ private: CRITICAL_SECTION m_critSec; // Transformation parameters - D2D1::Matrix3x2F m_transform; // Chroma transform matrix. + ProcessingType m_TransformType; D2D_RECT_U m_rcDest; // Destination rectangle for the effect. // Streaming @@ -259,8 +246,5 @@ private: DWORD m_cbImageSize; // Image size, in bytes. IMFAttributes *m_pAttributes; - - // Image transform function. (Changes based on the media type.) - IMAGE_TRANSFORM_FN m_pTransformFn; }; #endif \ No newline at end of file diff --git a/samples/winrt/ImageManipulations/C++/MediaExtensions/Grayscale/Grayscale.vcxproj b/samples/winrt/ImageManipulations/C++/MediaExtensions/Grayscale/Grayscale.vcxproj index 8af8f2c..c7e9059 100644 --- a/samples/winrt/ImageManipulations/C++/MediaExtensions/Grayscale/Grayscale.vcxproj +++ b/samples/winrt/ImageManipulations/C++/MediaExtensions/Grayscale/Grayscale.vcxproj @@ -123,13 +123,14 @@ $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) false - $(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common; + $(OPENCV_DIR)\include;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common Console - runtimeobject.lib;%(AdditionalDependencies);mf.lib;mfuuid.lib;mfplat.lib + runtimeobject.lib;%(AdditionalDependencies);mf.lib;mfuuid.lib;mfplat.lib;opencv_core245.lib;opencv_imgproc245.lib false Grayscale.def + $(OPENCV_DIR)\lib;%(AdditionalLibraryDirectories) mdmerge -metadata_dir "$(WindowsSDK_MetadataPath)" -o "$(ProjectDir)$(Configuration)\$(MSBuildProjectName)" -i "$(MSBuildProjectDirectory)" -v -partial @@ -146,13 +147,14 @@ $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) false - $(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common; + $(OPENCV_DIR)\include;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common Console runtimeobject.lib;%(AdditionalDependencies);mf.lib;mfuuid.lib;mfplat.lib false Grayscale.def + $(OPENCV_DIR)\lib;%(AdditionalLibraryDirectories) mdmerge -metadata_dir "$(WindowsSDK_MetadataPath)" -o "$(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)" -i "$(MSBuildProjectDirectory)" -v -partial @@ -169,13 +171,14 @@ $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) false - $(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common; + $(OPENCV_DIR)\include;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common Console runtimeobject.lib;%(AdditionalDependencies);mf.lib;mfuuid.lib;mfplat.lib false Grayscale.def + $(OPENCV_DIR)\lib;%(AdditionalLibraryDirectories) mdmerge -metadata_dir "$(WindowsSDK_MetadataPath)" -o "$(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)" -i "$(MSBuildProjectDirectory)" -v -partial @@ -192,13 +195,14 @@ $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) false - $(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common; + $(OPENCV_DIR)\include;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common Console runtimeobject.lib;%(AdditionalDependencies);mf.lib;mfuuid.lib;mfplat.lib false Grayscale.def + $(OPENCV_DIR)\lib;%(AdditionalLibraryDirectories) mdmerge -metadata_dir "$(WindowsSDK_MetadataPath)" -o "$(ProjectDir)$(Configuration)\$(MSBuildProjectName)" -i "$(MSBuildProjectDirectory)" -v -partial @@ -215,13 +219,14 @@ $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) false - $(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common; + $(OPENCV_DIR)\include;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common Console runtimeobject.lib;%(AdditionalDependencies);mf.lib;mfuuid.lib;mfplat.lib false Grayscale.def + $(OPENCV_DIR)\lib;%(AdditionalLibraryDirectories) mdmerge -metadata_dir "$(WindowsSDK_MetadataPath)" -o "$(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)" -i "$(MSBuildProjectDirectory)" -v -partial @@ -238,13 +243,14 @@ $(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories) false - $(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common; + $(OPENCV_DIR)\include;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common Console runtimeobject.lib;%(AdditionalDependencies);mf.lib;mfuuid.lib;mfplat.lib false Grayscale.def + $(OPENCV_DIR)\lib;%(AdditionalLibraryDirectories) mdmerge -metadata_dir "$(WindowsSDK_MetadataPath)" -o "$(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)" -i "$(MSBuildProjectDirectory)" -v -partial -- 2.7.4