From fd832f907f5c4c446f3f42bb6f8a7bcfddd94e55 Mon Sep 17 00:00:00 2001 From: scott lee Date: Mon, 10 Jul 2017 18:42:05 -0700 Subject: [PATCH] Updated mac build --- Example/Screen_Capture_Example.cpp | 10 +++++----- include/ios/CGFrameProcessor.h | 2 +- src/ios/CGFrameProcessor.cpp | 25 ++++++++++++++++++------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/Example/Screen_Capture_Example.cpp b/Example/Screen_Capture_Example.cpp index e07db4cb..94249339 100644 --- a/Example/Screen_Capture_Example.cpp +++ b/Example/Screen_Capture_Example.cpp @@ -32,12 +32,12 @@ void createframegrabber() for (auto& m : mons) { // capture just a 512x512 square... USERS SHOULD MAKE SURE bounds are // valid!!!! - - /* m.OffsetX += 512; +/* + m.OffsetX += 512; m.OffsetY += 512; m.Height = 512; - m.Width = 512;*/ - + m.Width = 512; +*/ std::cout << m << std::endl; } return mons; @@ -66,7 +66,7 @@ void createframegrabber() auto size = RowStride(img) * Height(img); //auto imgbuffer(std::make_unique(size)); // Extract(img, imgbuffer.get(), size); - //ExtractAndConvertToRGBA(img, imgbuffer.get(), size); + // ExtractAndConvertToRGBA(img, imgbuffer.get(), size); if (std::chrono::duration_cast( std::chrono::high_resolution_clock::now() - onNewFramestart) diff --git a/include/ios/CGFrameProcessor.h b/include/ios/CGFrameProcessor.h index c6a882a7..ee1ea138 100644 --- a/include/ios/CGFrameProcessor.h +++ b/include/ios/CGFrameProcessor.h @@ -9,7 +9,7 @@ namespace SL { public: DUPL_RETURN Init(std::shared_ptr data, Monitor& monitor); - DUPL_RETURN ProcessFrame(); + DUPL_RETURN ProcessFrame(const Monitor& curentmonitorinfo); }; diff --git a/src/ios/CGFrameProcessor.cpp b/src/ios/CGFrameProcessor.cpp index d4595735..efced9d8 100644 --- a/src/ios/CGFrameProcessor.cpp +++ b/src/ios/CGFrameProcessor.cpp @@ -16,19 +16,30 @@ namespace SL { // // Process a given frame and its metadata // - DUPL_RETURN CGFrameProcessor::ProcessFrame() + DUPL_RETURN CGFrameProcessor::ProcessFrame(const Monitor& curentmonitorinfo) { auto Ret = DUPL_RETURN_SUCCESS; - auto imageRef = CGDisplayCreateImage(Id(SelectedMonitor)); + + CGImageRef imageRef; + + if(Height(curentmonitorinfo) != Height(SelectedMonitor) || Width(curentmonitorinfo) != Width(SelectedMonitor)){ + CGRect rec; + rec.origin.y =OffsetY(SelectedMonitor); + rec.origin.x =OffsetX(SelectedMonitor); + rec.size.width =Width(SelectedMonitor); + rec.size.height =Height(SelectedMonitor); + + imageRef = CGDisplayCreateImageForRect(Id(SelectedMonitor), rec); + } else { + imageRef = CGDisplayCreateImage(Id(SelectedMonitor)); + } + + if(!imageRef) return DUPL_RETURN_ERROR_EXPECTED;//this happens when the monitors change. auto width = CGImageGetWidth(imageRef); auto height = CGImageGetHeight(imageRef); - if(width!= Width(SelectedMonitor) || height!= Height(SelectedMonitor)){ - CGImageRelease(imageRef); - return DUPL_RETURN_ERROR_EXPECTED;//this happens when the monitors change. - } - + auto prov = CGImageGetDataProvider(imageRef); if(!prov){ CGImageRelease(imageRef);