nodevalue: begin abstracting qvariant

This commit is contained in:
itsmattkc
2022-05-09 13:07:34 -07:00
parent 839f63d78f
commit 58c4600d04
36 changed files with 235 additions and 229 deletions
@@ -94,16 +94,16 @@ void CornerPinDistortNode::Value(const NodeValueRow &value, const NodeGlobals &g
job.SetVertexCoordinates(adjusted_vertices);
// If no texture do nothing
if (!job.GetValue(kTextureInput).data().isNull()) {
if (job.GetValue(kTextureInput).toTexture()) {
// In the special case that all sliders are in their default position just
// push the texture.
if (!(job.GetValue(kTopLeftInput).data().value<QVector2D>().isNull()
&& job.GetValue(kTopRightInput).data().value<QVector2D>().isNull() &&
job.GetValue(kBottomRightInput).data().value<QVector2D>().isNull() &&
job.GetValue(kBottomLeftInput).data().value<QVector2D>().isNull())) {
if (!(job.GetValue(kTopLeftInput).toVec2().isNull()
&& job.GetValue(kTopRightInput).toVec2().isNull() &&
job.GetValue(kBottomRightInput).toVec2().isNull() &&
job.GetValue(kBottomLeftInput).toVec2().isNull())) {
table->Push(NodeValue::kTexture, QVariant::fromValue(job), this);
} else {
table->Push(NodeValue::kTexture, job.GetValue(kTextureInput).data(), this);
table->Push(job.GetValue(kTextureInput));
}
}
}
@@ -119,25 +119,24 @@ ShaderCode CornerPinDistortNode::GetShaderCode(const ShaderRequest &request) con
QPointF CornerPinDistortNode::ValueToPixel(int value, const NodeValueRow& row, const QVector2D &resolution) const
{
Q_ASSERT(value >= 0 && value <= 3);
QVector2D v;
switch (value) {
case 0: // Top left
return QPointF(row[kTopLeftInput].data().value<QVector2D>().x(),
row[kTopLeftInput].data().value<QVector2D>().y());
break;
case 1: // Top right
return QPointF(resolution.x() + row[kTopRightInput].data().value<QVector2D>().x(),
row[kTopRightInput].data().value<QVector2D>().y());
break;
case 2: // Bottom right
return QPointF(resolution.x() + row[kBottomRightInput].data().value<QVector2D>().x(),
resolution.y() + row[kBottomRightInput].data().value<QVector2D>().y());
break;
case 3: //Bottom left
return QPointF(row[kBottomLeftInput].data().value<QVector2D>().x(),
row[kBottomLeftInput].data().value<QVector2D>().y() + resolution.y());
break;
default: // We should never get here
return QPointF();
case 0: // Top left
v = row[kTopLeftInput].toVec2();
return QPointF(v.x(), v.y());
case 1: // Top right
v = row[kTopRightInput].toVec2();
return QPointF(resolution.x() + v.x(), v.y());
case 2: // Bottom right
v = row[kBottomRightInput].toVec2();
return QPointF(resolution.x() + v.x(), resolution.y() + v.y());
case 3: //Bottom left
v = row[kBottomLeftInput].toVec2();
return QPointF(v.x(), v.y() + resolution.y());
default: // We should never get here
return QPointF();
}
}
+10 -10
View File
@@ -82,14 +82,14 @@ void CropDistortNode::Value(const NodeValueRow &value, const NodeGlobals &global
job.InsertValue(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, globals.resolution(), this));
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOn);
if (!job.GetValue(kTextureInput).data().isNull()) {
if (!qIsNull(job.GetValue(kLeftInput).data().toDouble())
|| !qIsNull(job.GetValue(kRightInput).data().toDouble())
|| !qIsNull(job.GetValue(kTopInput).data().toDouble())
|| !qIsNull(job.GetValue(kBottomInput).data().toDouble())) {
if (job.GetValue(kTextureInput).toTexture()) {
if (!qIsNull(job.GetValue(kLeftInput).toDouble())
|| !qIsNull(job.GetValue(kRightInput).toDouble())
|| !qIsNull(job.GetValue(kTopInput).toDouble())
|| !qIsNull(job.GetValue(kBottomInput).toDouble())) {
table->Push(NodeValue::kTexture, QVariant::fromValue(job), this);
} else {
table->Push(NodeValue::kTexture, job.GetValue(kTextureInput).data(), this);
table->Push(job.GetValue(kTextureInput));
}
}
}
@@ -104,10 +104,10 @@ void CropDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGl
{
const QVector2D &resolution = globals.resolution();
double left_pt = resolution.x() * row[kLeftInput].data().toDouble();
double top_pt = resolution.y() * row[kTopInput].data().toDouble();
double right_pt = resolution.x() * (1.0 - row[kRightInput].data().toDouble());
double bottom_pt = resolution.y() * (1.0 - row[kBottomInput].data().toDouble());
double left_pt = resolution.x() * row[kLeftInput].toDouble();
double top_pt = resolution.y() * row[kTopInput].toDouble();
double right_pt = resolution.x() * (1.0 - row[kRightInput].toDouble());
double bottom_pt = resolution.y() * (1.0 - row[kBottomInput].toDouble());
double center_x_pt = mid(left_pt, right_pt);
double center_y_pt = mid(top_pt, bottom_pt);
+2 -2
View File
@@ -82,9 +82,9 @@ void FlipDistortNode::Value(const NodeValueRow &value, const NodeGlobals &global
job.InsertValue(value);
// If there's no texture, no need to run an operation
if (!job.GetValue(kTextureInput).data().isNull()) {
if (job.GetValue(kTextureInput).toTexture()) {
// Only run shader if at least one of flip or flop are selected
if (job.GetValue(kHorizontalInput).data().toBool() || job.GetValue(kVerticalInput).data().toBool()) {
if (job.GetValue(kHorizontalInput).toBool() || job.GetValue(kVerticalInput).toBool()) {
table->Push(NodeValue::kTexture, QVariant::fromValue(job), this);
} else {
// If we're not flipping or flopping just push the texture
+1 -1
View File
@@ -47,7 +47,7 @@ void MaskDistortNode::Value(const NodeValueRow &value, const NodeGlobals &global
{
GenerateJob job = GetGenerateJob(value);
if (!value[kBaseInput].data().isNull()) {
if (value[kBaseInput].toTexture()) {
// Push as merge node
ShaderJob merge;
@@ -92,7 +92,7 @@ void TransformDistortNode::Value(const NodeValueRow &value, const NodeGlobals &g
bool pushed_job = false;
// If we have a texture, generate a matrix and make it happen
if (TexturePtr texture = texture_meta.data().value<TexturePtr>()) {
if (TexturePtr texture = texture_meta.toTexture()) {
// Adjust our matrix by the resolutions involved
QMatrix4x4 real_matrix = GenerateAutoScaledMatrix(generated_matrix, value, globals, texture->params());
@@ -101,7 +101,7 @@ void TransformDistortNode::Value(const NodeValueRow &value, const NodeGlobals &g
ShaderJob job;
job.InsertValue(QStringLiteral("ove_maintex"), NodeValue(NodeValue::kTexture, QVariant::fromValue(texture), this));
job.InsertValue(QStringLiteral("ove_mvpmat"), NodeValue(NodeValue::kMatrix, real_matrix, this));
job.SetInterpolation(QStringLiteral("ove_maintex"), static_cast<Texture::Interpolation>(value[kInterpolationInput].data().toInt()));
job.SetInterpolation(QStringLiteral("ove_maintex"), static_cast<Texture::Interpolation>(value[kInterpolationInput].toInt()));
// FIXME: This should be optimized, we can use matrix math to determine if this operation will
// end up with gaps in the screen that will require an alpha channel.
@@ -140,7 +140,7 @@ void TransformDistortNode::Hash(QCryptographicHash &hash, const NodeGlobals &glo
traverser.SetCacheVideoParams(video_params);
NodeValueRow db = traverser.GenerateRow(this, globals.time());
TexturePtr tex = db[kTextureInput].data().value<TexturePtr>();
TexturePtr tex = db[kTextureInput].toTexture();
if (tex) {
VideoParams tex_params = tex->params();
QMatrix4x4 matrix = GenerateMatrix(db, true, false, false, false);
@@ -167,13 +167,13 @@ void TransformDistortNode::GizmoDragStart(const NodeValueRow &row, double x, dou
} else if (IsAScaleGizmo(gizmo)) {
// Dragging scale handle
TexturePtr tex = row[kTextureInput].data().value<TexturePtr>();
TexturePtr tex = row[kTextureInput].toTexture();
if (!tex) {
return;
}
gizmo_scale_uniform_ = row[kUniformScaleInput].data().toBool();
gizmo_anchor_pt_ = (row[kAnchorInput].data().value<QVector2D>() + gizmo->GetGlobals().resolution()/2).toPointF();
gizmo_scale_uniform_ = row[kUniformScaleInput].toBool();
gizmo_anchor_pt_ = (row[kAnchorInput].toVec2() + gizmo->GetGlobals().resolution()/2).toPointF();
if (gizmo == point_gizmo_[kGizmoScaleTopLeft] || gizmo == point_gizmo_[kGizmoScaleTopRight]
|| gizmo == point_gizmo_[kGizmoScaleBottomLeft] || gizmo == point_gizmo_[kGizmoScaleBottomRight]) {
@@ -187,7 +187,7 @@ void TransformDistortNode::GizmoDragStart(const NodeValueRow &row, double x, dou
// Store texture size
VideoParams texture_params = tex->params();
QVector2D texture_sz(texture_params.square_pixel_width(), texture_params.height());
gizmo_scale_anchor_ = row[kAnchorInput].data().value<QVector2D>() + texture_sz/2;
gizmo_scale_anchor_ = row[kAnchorInput].toVec2() + texture_sz/2;
if (gizmo == point_gizmo_[kGizmoScaleTopRight]
|| gizmo == point_gizmo_[kGizmoScaleBottomRight]
@@ -208,7 +208,7 @@ void TransformDistortNode::GizmoDragStart(const NodeValueRow &row, double x, dou
} else if (gizmo == rotation_gizmo_) {
gizmo_anchor_pt_ = (row[kAnchorInput].data().value<QVector2D>() + gizmo->GetGlobals().resolution()/2).toPointF();
gizmo_anchor_pt_ = (row[kAnchorInput].toVec2() + gizmo->GetGlobals().resolution()/2).toPointF();
gizmo_start_angle_ = qAtan2(y - gizmo_anchor_pt_.y(), x - gizmo_anchor_pt_.x());
gizmo_last_angle_ = gizmo_start_angle_;
gizmo_last_alt_angle_ = qAtan2(x - gizmo_anchor_pt_.x(), y - gizmo_anchor_pt_.y());
@@ -368,7 +368,7 @@ QMatrix4x4 TransformDistortNode::AdjustMatrixByResolutions(const QMatrix4x4 &mat
void TransformDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals)
{
TexturePtr tex = row[kTextureInput].data().value<TexturePtr>();
TexturePtr tex = row[kTextureInput].toTexture();
if (!tex) {
return;
}
@@ -384,7 +384,7 @@ void TransformDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const N
QVector2D tex_offset = tex_params.offset();
// Retrieve autoscale value
AutoScaleType autoscale = static_cast<AutoScaleType>(row[kAutoscaleInput].data().toInt());
AutoScaleType autoscale = static_cast<AutoScaleType>(row[kAutoscaleInput].toInt());
// Fold values into a matrix for the rectangle
QMatrix4x4 rectangle_matrix;
@@ -441,7 +441,7 @@ QMatrix4x4 TransformDistortNode::GenerateAutoScaledMatrix(const QMatrix4x4& gene
{
const QVector2D &sequence_res = globals.resolution();
QVector2D texture_res(texture_params.square_pixel_width(), texture_params.height());
AutoScaleType autoscale = static_cast<AutoScaleType>(value[kAutoscaleInput].data().toInt());
AutoScaleType autoscale = static_cast<AutoScaleType>(value[kAutoscaleInput].toInt());
return AdjustMatrixByResolutions(generated_matrix,
sequence_res,