mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Enable Area Selection in ScreenshotHelper class
This commit is contained in:
parent
43967f5ded
commit
63ee36ddfe
|
|
@ -32,7 +32,7 @@ void MacroActionScreenshot::CustomScreenshot(OBSWeakSource &source)
|
|||
}
|
||||
auto s = obs_weak_source_get_source(source);
|
||||
_screenshot.~ScreenshotHelper();
|
||||
new (&_screenshot) ScreenshotHelper(s, false, 0, true, _path);
|
||||
new (&_screenshot) ScreenshotHelper(s, QRect(), false, 0, true, _path);
|
||||
obs_source_release(s);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -215,8 +215,15 @@ void MacroConditionVideo::GetScreenshot(bool blocking)
|
|||
{
|
||||
auto source = obs_weak_source_get_source(_video.GetVideo());
|
||||
_screenshotData.~ScreenshotHelper();
|
||||
new (&_screenshotData)
|
||||
ScreenshotHelper(source, blocking, GetSwitcher()->interval);
|
||||
QRect screenshotArea;
|
||||
if (_areaParameters.enable && _condition != VideoCondition::NO_IMAGE) {
|
||||
screenshotArea.setRect(_areaParameters.area.x,
|
||||
_areaParameters.area.y,
|
||||
_areaParameters.area.width,
|
||||
_areaParameters.area.height);
|
||||
}
|
||||
new (&_screenshotData) ScreenshotHelper(
|
||||
source, screenshotArea, blocking, GetSwitcher()->interval);
|
||||
obs_source_release(source);
|
||||
_getNextScreenshot = false;
|
||||
}
|
||||
|
|
@ -361,13 +368,6 @@ bool MacroConditionVideo::CheckColor()
|
|||
|
||||
bool MacroConditionVideo::Compare()
|
||||
{
|
||||
if (_areaParameters.enable && _condition != VideoCondition::NO_IMAGE) {
|
||||
_screenshotData.image = _screenshotData.image.copy(
|
||||
_areaParameters.area.x, _areaParameters.area.y,
|
||||
_areaParameters.area.width,
|
||||
_areaParameters.area.height);
|
||||
}
|
||||
|
||||
if (_condition != VideoCondition::OCR) {
|
||||
SetVariableValue("");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -255,7 +255,13 @@ void PreviewImage::CreateImage(const VideoInput &video, PreviewType type,
|
|||
VideoCondition condition)
|
||||
{
|
||||
auto source = obs_weak_source_get_source(video.GetVideo());
|
||||
ScreenshotHelper screenshot(source, true);
|
||||
QRect screenshotArea;
|
||||
if (areaParams.enable && type == PreviewType::SHOW_MATCH) {
|
||||
screenshotArea.setRect(areaParams.area.x, areaParams.area.y,
|
||||
areaParams.area.width,
|
||||
areaParams.area.height);
|
||||
}
|
||||
ScreenshotHelper screenshot(source, screenshotArea, true);
|
||||
obs_source_release(source);
|
||||
|
||||
if (!video.ValidSelection() || !screenshot.done) {
|
||||
|
|
@ -274,11 +280,6 @@ void PreviewImage::CreateImage(const VideoInput &video, PreviewType type,
|
|||
|
||||
if (type == PreviewType::SHOW_MATCH) {
|
||||
std::unique_lock<std::mutex> lock(_mtx);
|
||||
if (areaParams.enable) {
|
||||
screenshot.image = screenshot.image.copy(
|
||||
areaParams.area.x, areaParams.area.y,
|
||||
areaParams.area.width, areaParams.area.height);
|
||||
}
|
||||
// Will emit status label update
|
||||
MarkMatch(screenshot.image, patternMatchParams,
|
||||
patternImageData, objDetectParams, ocrParams,
|
||||
|
|
|
|||
|
|
@ -7,10 +7,11 @@ namespace advss {
|
|||
|
||||
static void ScreenshotTick(void *param, float);
|
||||
|
||||
ScreenshotHelper::ScreenshotHelper(obs_source_t *source, bool blocking,
|
||||
int timeout, bool saveToFile,
|
||||
ScreenshotHelper::ScreenshotHelper(obs_source_t *source, const QRect &subarea,
|
||||
bool blocking, int timeout, bool saveToFile,
|
||||
std::string path)
|
||||
: weakSource(OBSGetWeakRef(source)),
|
||||
_subarea(subarea),
|
||||
_blocking(blocking),
|
||||
_saveToFile(saveToFile),
|
||||
_path(path)
|
||||
|
|
@ -62,7 +63,12 @@ void ScreenshotHelper::Screenshot()
|
|||
cy = ovi.base_height;
|
||||
}
|
||||
|
||||
if (!cx || !cy) {
|
||||
QRect renderArea(0, 0, cx, cy);
|
||||
if (!_subarea.isEmpty()) {
|
||||
renderArea &= _subarea;
|
||||
}
|
||||
|
||||
if (renderArea.isEmpty()) {
|
||||
vblog(LOG_WARNING,
|
||||
"Cannot screenshot \"%s\", invalid target size",
|
||||
obs_source_get_name(source));
|
||||
|
|
@ -71,16 +77,24 @@ void ScreenshotHelper::Screenshot()
|
|||
return;
|
||||
}
|
||||
|
||||
cx = renderArea.width();
|
||||
cy = renderArea.height();
|
||||
|
||||
texrender = gs_texrender_create(GS_RGBA, GS_ZS_NONE);
|
||||
stagesurf = gs_stagesurface_create(cx, cy, GS_RGBA);
|
||||
stagesurf = gs_stagesurface_create(renderArea.width(),
|
||||
renderArea.height(), GS_RGBA);
|
||||
|
||||
gs_texrender_reset(texrender);
|
||||
if (gs_texrender_begin(texrender, cx, cy)) {
|
||||
if (gs_texrender_begin(texrender, renderArea.width(),
|
||||
renderArea.height())) {
|
||||
vec4 zero;
|
||||
vec4_zero(&zero);
|
||||
|
||||
gs_clear(GS_CLEAR_COLOR, &zero, 0.0f, 0);
|
||||
gs_ortho(0.0f, (float)cx, 0.0f, (float)cy, -100.0f, 100.0f);
|
||||
gs_ortho((float)(renderArea.left()),
|
||||
(float)(renderArea.right() + 1),
|
||||
(float)(renderArea.top()),
|
||||
(float)(renderArea.bottom() + 1), -100.0f, 100.0f);
|
||||
|
||||
gs_blend_state_push();
|
||||
gs_blend_function(GS_BLEND_ONE, GS_BLEND_ZERO);
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ namespace advss {
|
|||
class ScreenshotHelper {
|
||||
public:
|
||||
ScreenshotHelper() = default;
|
||||
ScreenshotHelper(obs_source_t *source, bool blocking = false,
|
||||
int timeout = 1000, bool saveToFile = false,
|
||||
std::string path = "");
|
||||
ScreenshotHelper(obs_source_t *source, const QRect &subarea = QRect(),
|
||||
bool blocking = false, int timeout = 1000,
|
||||
bool saveToFile = false, std::string path = "");
|
||||
ScreenshotHelper &operator=(const ScreenshotHelper &) = delete;
|
||||
ScreenshotHelper(const ScreenshotHelper &) = delete;
|
||||
~ScreenshotHelper();
|
||||
|
|
@ -39,6 +39,7 @@ public:
|
|||
|
||||
private:
|
||||
std::atomic_bool _initDone = false;
|
||||
QRect _subarea = QRect();
|
||||
bool _blocking = false;
|
||||
std::thread _saveThread;
|
||||
bool _saveToFile = false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user