Skip to content

Commit 3a5317a

Browse files
authored
Merge pull request #129 from smasherprog/Exampleupdate
example update
2 parents 7a36dfa + c509a89 commit 3a5317a

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

Example_CPP/Screen_Capture_Example.cpp

+33-21
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void ExtractAndConvertToRGBA(const SL::Screen_Capture::Image &img, unsigned char
106106
{
107107
assert(dst_size >= static_cast<size_t>(SL::Screen_Capture::Width(img) * SL::Screen_Capture::Height(img) * sizeof(SL::Screen_Capture::ImageBGRA)));
108108
auto imgsrc = StartSrc(img);
109-
auto imgdist = dst;
109+
auto imgdist = dst;
110110
for (auto h = 0; h < Height(img); h++) {
111111
auto startimgsrc = imgsrc;
112112
for (auto w = 0; w < Width(img); w++) {
@@ -165,12 +165,12 @@ void createframegrabber()
165165
->onNewFrame([&](const SL::Screen_Capture::Image &img, const SL::Screen_Capture::Monitor &monitor) {
166166
// Uncomment the below code to write the image to disk for debugging
167167

168-
//auto r = realcounter.fetch_add(1);
169-
//auto s = std::to_string(r) + std::string("MONITORNEW_") + std::string(".jpg");
170-
//auto size = Width(img) * Height(img) * sizeof(SL::Screen_Capture::ImageBGRA);
171-
//auto imgbuffer(std::make_unique<unsigned char[]>(size));
172-
//ExtractAndConvertToRGBA(img, imgbuffer.get(), size);
173-
//tje_encode_to_file(s.c_str(), Width(img), Height(img), 4, (const unsigned char *)imgbuffer.get());
168+
// auto r = realcounter.fetch_add(1);
169+
// auto s = std::to_string(r) + std::string("MONITORNEW_") + std::string(".jpg");
170+
// auto size = Width(img) * Height(img) * sizeof(SL::Screen_Capture::ImageBGRA);
171+
// auto imgbuffer(std::make_unique<unsigned char[]>(size));
172+
// ExtractAndConvertToRGBA(img, imgbuffer.get(), size);
173+
// tje_encode_to_file(s.c_str(), Width(img), Height(img), 4, (const unsigned char *)imgbuffer.get());
174174

175175
if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - onNewFramestart).count() >=
176176
1000) {
@@ -281,27 +281,39 @@ void createpartialframegrabber()
281281
framgrabber->setMouseChangeInterval(std::chrono::milliseconds(100));
282282
}
283283

284+
285+
auto getWindowToCapture(std::string window_to_search_for = "blizzard")
286+
{
287+
auto windows = SL::Screen_Capture::GetWindows();
288+
// convert to lower case for easier comparisons
289+
std::transform(window_to_search_for.begin(), window_to_search_for.end(), window_to_search_for.begin(),
290+
[](char c) { return std::tolower(c, std::locale()); });
291+
decltype(windows) filtereditems;
292+
for (auto &a : windows) {
293+
std::string name = a.Name;
294+
std::transform(name.begin(), name.end(), name.begin(), [](char c) { return std::tolower(c, std::locale()); });
295+
if (name.find(window_to_search_for) != std::string::npos) {
296+
filtereditems.push_back(a);
297+
std::cout << "ADDING WINDOW Height " << a.Size.y << " Width " << a.Size.x << " " << a.Name << std::endl;
298+
}
299+
}
300+
301+
return filtereditems;
302+
}
303+
284304
void createwindowgrabber()
285305
{
306+
auto w = getWindowToCapture();
307+
if (w.empty()) {
308+
std::cout << "In order to test window capturing, you must modify the getWindowToCapture() function to search for a window that actually exists!" << std::endl;
309+
return;
310+
}
286311
realcounter = 0;
287312
onNewFramecounter = 0;
288313
framgrabber = nullptr;
289314
framgrabber =
290315
SL::Screen_Capture::CreateCaptureConfiguration([]() {
291-
auto windows = SL::Screen_Capture::GetWindows();
292-
std::string srchterm = "blizzard";
293-
// convert to lower case for easier comparisons
294-
std::transform(srchterm.begin(), srchterm.end(), srchterm.begin(), [](char c) { return std::tolower(c, std::locale()); });
295-
decltype(windows) filtereditems;
296-
for (auto &a : windows) {
297-
std::string name = a.Name;
298-
std::transform(name.begin(), name.end(), name.begin(), [](char c) { return std::tolower(c, std::locale()); });
299-
if (name.find(srchterm) != std::string::npos) {
300-
filtereditems.push_back(a);
301-
std::cout << "ADDING WINDOW Height " << a.Size.y << " Width " << a.Size.x << " " << a.Name << std::endl;
302-
}
303-
}
304-
316+
auto filtereditems = getWindowToCapture();
305317
return filtereditems;
306318
})
307319

0 commit comments

Comments
 (0)