Requests: Add scale.filter to Scene Item Properties

This commit is contained in:
VodBox 2021-03-03 19:43:50 +13:00
parent 6f0d056059
commit 18468c17f2
2 changed files with 49 additions and 2 deletions

View File

@ -52,6 +52,24 @@ obs_bounds_type getBoundsTypeFromName(QString name) {
return boundTypeNames.key(name);
}
const QHash<obs_scale_type, QString> scaleTypeNames = {
{ OBS_SCALE_DISABLE, "OBS_SCALE_DISABLE" },
{ OBS_SCALE_POINT, "OBS_SCALE_POINT" },
{ OBS_SCALE_BICUBIC, "OBS_SCALE_BICUBIC" },
{ OBS_SCALE_BILINEAR, "OBS_SCALE_BILINEAR" },
{ OBS_SCALE_LANCZOS, "OBS_SCALE_LANCZOS" },
{ OBS_SCALE_AREA, "OBS_SCALE_AREA" },
};
QString getScaleNameFromType(obs_scale_type type) {
QString fallback = scaleTypeNames.value(OBS_SCALE_DISABLE);
return scaleTypeNames.value(type, fallback);
}
obs_scale_type getFilterTypeFromName(QString name) {
return scaleTypeNames.key(name);
}
bool Utils::StringInStringList(char** strings, const char* string) {
if (!strings) {
return false;
@ -730,6 +748,7 @@ const char* Utils::GetCurrentRecordingFilename()
* @property {double} `rotation` The clockwise rotation of the scene item in degrees around the point of alignment.
* @property {double} `scale.x` The x-scale factor of the scene item.
* @property {double} `scale.y` The y-scale factor of the scene item.
* @property {String} `scale.filter` The scale filter of the source. Can be "OBS_SCALE_DISABLE", "OBS_SCALE_POINT", "OBS_SCALE_BICUBIC", "OBS_SCALE_BILINEAR", "OBS_SCALE_LANCZOS" or "OBS_SCALE_AREA".
* @property {int} `crop.top` The number of pixels cropped off the top of the scene item before scaling.
* @property {int} `crop.right` The number of pixels cropped off the right of the scene item before scaling.
* @property {int} `crop.bottom` The number of pixels cropped off the bottom of the scene item before scaling.
@ -773,12 +792,16 @@ obs_data_t* Utils::GetSceneItemPropertiesData(obs_sceneitem_t* sceneItem) {
uint32_t boundsAlignment = obs_sceneitem_get_bounds_alignment(sceneItem);
QString boundsTypeName = getBoundsNameFromType(boundsType);
obs_scale_type scaleFilter = obs_sceneitem_get_scale_filter(sceneItem);
QString scaleFilterName = getScaleNameFromType(scaleFilter);
OBSDataAutoRelease posData = obs_data_create();
obs_data_set_double(posData, "x", pos.x);
obs_data_set_double(posData, "y", pos.y);
obs_data_set_int(posData, "alignment", alignment);
OBSDataAutoRelease scaleData = obs_data_create();
obs_data_set_string(scaleData, "filter", scaleFilterName.toUtf8());
obs_data_set_double(scaleData, "x", scale.x);
obs_data_set_double(scaleData, "y", scale.y);

View File

@ -91,6 +91,7 @@ RpcResponse WSRequestHandler::GetSceneItemList(const RpcRequest& request) {
* @return {double} `rotation` The clockwise rotation of the item in degrees around the point of alignment.
* @return {double} `scale.x` The x-scale factor of the source.
* @return {double} `scale.y` The y-scale factor of the source.
* @return {String} `scale.filter` The scale filter of the source. Can be "OBS_SCALE_DISABLE", "OBS_SCALE_POINT", "OBS_SCALE_BICUBIC", "OBS_SCALE_BILINEAR", "OBS_SCALE_LANCZOS" or "OBS_SCALE_AREA".
* @return {int} `crop.top` The number of pixels cropped off the top of the source before scaling.
* @return {int} `crop.right` The number of pixels cropped off the right of the source before scaling.
* @return {int} `crop.bottom` The number of pixels cropped off the bottom of the source before scaling.
@ -156,6 +157,7 @@ RpcResponse WSRequestHandler::GetSceneItemProperties(const RpcRequest& request)
* @param {double (optional)} `rotation` The new clockwise rotation of the item in degrees.
* @param {double (optional)} `scale.x` The new x scale of the item.
* @param {double (optional)} `scale.y` The new y scale of the item.
* @param {String (optional)} `scale.filter` The new scale filter of the source. Can be "OBS_SCALE_DISABLE", "OBS_SCALE_POINT", "OBS_SCALE_BICUBIC", "OBS_SCALE_BILINEAR", "OBS_SCALE_LANCZOS" or "OBS_SCALE_AREA".
* @param {int (optional)} `crop.top` The new amount of pixels cropped off the top of the source before scaling.
* @param {int (optional)} `crop.bottom` The new amount of pixels cropped off the bottom of the source before scaling.
* @param {int (optional)} `crop.left` The new amount of pixels cropped off the left of the source before scaling.
@ -230,12 +232,34 @@ RpcResponse WSRequestHandler::SetSceneItemProperties(const RpcRequest& request)
}
if (request.hasField("scale")) {
OBSDataAutoRelease reqScale = obs_data_get_obj(params, "scale");
if (obs_data_has_user_value(reqScale, "filter")) {
QString newScaleFilter = obs_data_get_string(reqScale, "filter");
if (newScaleFilter == "OBS_SCALE_DISABLE") {
obs_sceneitem_set_scale_filter(sceneItem, OBS_SCALE_DISABLE);
}
else if (newScaleFilter == "OBS_SCALE_POINT") {
obs_sceneitem_set_scale_filter(sceneItem, OBS_SCALE_POINT);
}
else if (newScaleFilter == "OBS_SCALE_BICUBIC") {
obs_sceneitem_set_scale_filter(sceneItem, OBS_SCALE_BICUBIC);
}
else if (newScaleFilter == "OBS_SCALE_BILINEAR") {
obs_sceneitem_set_scale_filter(sceneItem, OBS_SCALE_BICUBIC);
}
else if (newScaleFilter == "OBS_SCALE_LANCZOS") {
obs_sceneitem_set_scale_filter(sceneItem, OBS_SCALE_LANCZOS);
}
else if (newScaleFilter == "OBS_SCALE_AREA") {
obs_sceneitem_set_scale_filter(sceneItem, OBS_SCALE_AREA);
}
}
vec2 oldScale;
obs_sceneitem_get_scale(sceneItem, &oldScale);
vec2 newScale = oldScale;
OBSDataAutoRelease reqScale = obs_data_get_obj(params, "scale");
if (obs_data_has_user_value(reqScale, "x")) {
newScale.x = obs_data_get_double(reqScale, "x");
}