diff --git a/app/node/distort/transform/transformdistortnode.cpp b/app/node/distort/transform/transformdistortnode.cpp index 45cdd5cd8..c03a352d5 100644 --- a/app/node/distort/transform/transformdistortnode.cpp +++ b/app/node/distort/transform/transformdistortnode.cpp @@ -68,7 +68,7 @@ NodeValueTable TransformDistortNode::Value(const QString &output, NodeValueDatab if (texture) { // Adjust our matrix by the resolutions involved QVector2D sequence_res = value[QStringLiteral("global")].Get(NodeValue::kVec2, QStringLiteral("resolution")).value(); - QVector2D texture_res(texture->params().width() * texture->pixel_aspect_ratio().toDouble(), texture->params().height()); + QVector2D texture_res(texture->params().square_pixel_width(), texture->params().height()); AutoScaleType autoscale = static_cast(value[kAutoscaleInput].Get(NodeValue::kCombo).toInt()); QMatrix4x4 real_matrix = AdjustMatrixByResolutions(generated_matrix, @@ -141,7 +141,8 @@ bool TransformDistortNode::GizmoPress(NodeValueDatabase &db, const QPointF &p) } // Store texture size - QVector2D texture_sz = db[kTextureInput].Get(NodeValue::kTexture).value(); + VideoParams texture_params = db[kTextureInput].Get(NodeValue::kTexture).value(); + QVector2D texture_sz(texture_params.square_pixel_width(), texture_params.height()); gizmo_scale_anchor_ = db[kAnchorInput].Get(NodeValue::kVec2).value() + texture_sz/2; if (gizmo_scale_active[kGizmoScaleTopRight] @@ -372,7 +373,8 @@ void TransformDistortNode::DrawGizmos(NodeValueDatabase &db, QPainter *p) QPointF sequence_half_res_pt = sequence_half_res.toPointF(); // GizmoTraverser just returns the sizes of the textures and no other data - QVector2D tex_sz = db[kTextureInput].Get(NodeValue::kTexture).value(); + VideoParams tex_params = db[kTextureInput].Get(NodeValue::kTexture).value(); + QVector2D tex_sz(tex_params.square_pixel_width(), tex_params.height()); // Retrieve autoscale value AutoScaleType autoscale = static_cast(db[kAutoscaleInput].Get(NodeValue::kCombo).toInt()); diff --git a/app/node/traverser.cpp b/app/node/traverser.cpp index a80f48376..8b74399cd 100644 --- a/app/node/traverser.cpp +++ b/app/node/traverser.cpp @@ -132,10 +132,9 @@ NodeValueTable NodeTraverser::GenerateBlockTable(const Track *track, const TimeR QVariant NodeTraverser::ProcessVideoFootage(const FootageJob &stream, const rational &input_time) { - Q_UNUSED(stream) Q_UNUSED(input_time) - return QVariant(); + return QVariant::fromValue(stream.video_params()); } QVariant NodeTraverser::ProcessAudioFootage(const FootageJob& stream, const TimeRange &input_time) @@ -152,7 +151,7 @@ QVariant NodeTraverser::ProcessShader(const Node *node, const TimeRange &range, Q_UNUSED(range) Q_UNUSED(job) - return QVariant(); + return QVariant::fromValue(video_params_); } QVariant NodeTraverser::ProcessSamples(const Node *node, const TimeRange &range, const SampleJob &job) @@ -169,7 +168,7 @@ QVariant NodeTraverser::ProcessFrameGeneration(const Node *node, const GenerateJ Q_UNUSED(node) Q_UNUSED(job) - return QVariant(); + return QVariant::fromValue(video_params_); } void NodeTraverser::SaveCachedTexture(const QByteArray &hash, const QVariant &texture) @@ -196,6 +195,11 @@ void NodeTraverser::AddGlobalsToDatabase(NodeValueDatabase &db, const TimeRange& db.Insert(QStringLiteral("global"), global); } +QVector2D NodeTraverser::GenerateResolution() const +{ + return QVector2D(video_params_.square_pixel_width(), video_params_.height()); +} + void NodeTraverser::PostProcessTable(const Node *node, const QString& output, const TimeRange &range, NodeValueTable &output_params) { bool got_cached_frame = false; diff --git a/app/node/traverser.h b/app/node/traverser.h index 17100e9ee..3334e901f 100644 --- a/app/node/traverser.h +++ b/app/node/traverser.h @@ -44,6 +44,16 @@ public: NodeValueDatabase GenerateDatabase(const Node *node, const QString &output, const TimeRange &range); + const VideoParams& GetCacheVideoParams() const + { + return video_params_; + } + + void SetCacheVideoParams(const VideoParams& params) + { + video_params_ = params; + } + protected: NodeValueTable ProcessInput(const Node *node, const QString &input, const TimeRange &range); @@ -68,21 +78,15 @@ protected: return false; } - virtual VideoParams GetCacheVideoParams() - { - return VideoParams(); - } - void AddGlobalsToDatabase(NodeValueDatabase& db, const TimeRange &range) const; - virtual QVector2D GenerateResolution() const - { - return QVector2D(0, 0); - } + QVector2D GenerateResolution() const; private: void PostProcessTable(const Node *node, const QString &output, const TimeRange &range, NodeValueTable &output_params); + VideoParams video_params_; + }; } diff --git a/app/render/renderprocessor.cpp b/app/render/renderprocessor.cpp index 1c462ce22..73f64bccd 100644 --- a/app/render/renderprocessor.cpp +++ b/app/render/renderprocessor.cpp @@ -56,6 +56,7 @@ void RenderProcessor::Run() { ViewerOutput* viewer = Node::ValueToPtr(ticket_->property("viewer")); const VideoParams& video_params = ticket_->property("vparam").value(); + SetCacheVideoParams(video_params); rational time = ticket_->property("time").value(); NodeValueTable table; @@ -593,17 +594,4 @@ void RenderProcessor::SaveCachedTexture(const QByteArray &hash, const QVariant & }*/ } -VideoParams RenderProcessor::GetCacheVideoParams() -{ - return ticket_->property("vparam").value(); -} - -QVector2D RenderProcessor::GenerateResolution() const -{ - // Set resolution to the destination to the "logical" resolution of the destination - const VideoParams& video_params = ticket_->property("vparam").value(); - return QVector2D(video_params.width() * video_params.pixel_aspect_ratio().toDouble(), - video_params.height()); -} - } diff --git a/app/render/renderprocessor.h b/app/render/renderprocessor.h index e28e63474..3f8ffbeb8 100644 --- a/app/render/renderprocessor.h +++ b/app/render/renderprocessor.h @@ -59,10 +59,6 @@ protected: virtual void SaveCachedTexture(const QByteArray& hash, const QVariant& texture) override; - virtual VideoParams GetCacheVideoParams() override; - - virtual QVector2D GenerateResolution() const override; - private: RenderProcessor(RenderTicketPtr ticket, Renderer* render_ctx, StillImageCache* still_image_cache, DecoderCache* decoder_cache, ShaderCache* shader_cache, QVariant default_shader); diff --git a/app/render/videoparams.cpp b/app/render/videoparams.cpp index 5c3936a36..b1529a478 100644 --- a/app/render/videoparams.cpp +++ b/app/render/videoparams.cpp @@ -234,6 +234,7 @@ void VideoParams::calculate_effective_size() effective_width_ = GetScaledDimension(width(), divider_); effective_height_ = GetScaledDimension(height(), divider_); effective_depth_ = GetScaledDimension(depth(), divider_); + calculate_square_pixel_width(); } void VideoParams::validate_pixel_aspect_ratio() @@ -241,6 +242,7 @@ void VideoParams::validate_pixel_aspect_ratio() if (pixel_aspect_ratio_.isNull()) { pixel_aspect_ratio_ = 1; } + calculate_square_pixel_width(); } void VideoParams::set_defaults_for_footage() @@ -253,6 +255,15 @@ void VideoParams::set_defaults_for_footage() premultiplied_alpha_ = false; } +void VideoParams::calculate_square_pixel_width() +{ + if (pixel_aspect_ratio_.denominator() != 0) { + par_width_ = width_ * pixel_aspect_ratio_.numerator() / pixel_aspect_ratio_.denominator(); + } else { + par_width_ = width_; + } +} + bool VideoParams::is_valid() const { return (width() > 0 diff --git a/app/render/videoparams.h b/app/render/videoparams.h index bba7252d2..4179e7ea0 100644 --- a/app/render/videoparams.h +++ b/app/render/videoparams.h @@ -90,6 +90,14 @@ public: calculate_effective_size(); } + /** + * @brief Returns width multiplied by pixel aspect ratio where applicable + */ + int square_pixel_width() const + { + return par_width_; + } + int height() const { return height_; @@ -348,6 +356,8 @@ private: void set_defaults_for_footage(); + void calculate_square_pixel_width(); + int width_; int height_; int depth_; @@ -367,6 +377,7 @@ private: int effective_width_; int effective_height_; int effective_depth_; + int par_width_; bool enabled_; int stream_index_; diff --git a/app/widget/nodetableview/CMakeLists.txt b/app/widget/nodetableview/CMakeLists.txt index 2b4cb7162..4e4f8b2a6 100644 --- a/app/widget/nodetableview/CMakeLists.txt +++ b/app/widget/nodetableview/CMakeLists.txt @@ -16,11 +16,9 @@ set(OLIVE_SOURCES ${OLIVE_SOURCES} - widget/nodetableview/nodetabletraverser.h - widget/nodetableview/nodetabletraverser.cpp - widget/nodetableview/nodetableview.h widget/nodetableview/nodetableview.cpp - widget/nodetableview/nodetablewidget.h + widget/nodetableview/nodetableview.h widget/nodetableview/nodetablewidget.cpp + widget/nodetableview/nodetablewidget.h PARENT_SCOPE ) diff --git a/app/widget/nodetableview/nodetabletraverser.cpp b/app/widget/nodetableview/nodetabletraverser.cpp deleted file mode 100644 index e3810173c..000000000 --- a/app/widget/nodetableview/nodetabletraverser.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2021 Olive Team - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -***/ - -#include "nodetabletraverser.h" - -namespace olive { - -QVariant NodeTableTraverser::ProcessVideoFootage(const FootageJob &video_stream, const rational &input_time) -{ - return QVariant::fromValue(video_stream.video_params()); -} - -QVariant NodeTableTraverser::ProcessAudioFootage(const FootageJob &audio_stream, const TimeRange &input_time) -{ - return QVariant::fromValue(audio_stream.audio_params()); -} - -} diff --git a/app/widget/nodetableview/nodetabletraverser.h b/app/widget/nodetableview/nodetabletraverser.h deleted file mode 100644 index f7b3d0f28..000000000 --- a/app/widget/nodetableview/nodetabletraverser.h +++ /dev/null @@ -1,42 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2021 Olive Team - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -***/ - -#ifndef NODETABLETRAVERSER_H -#define NODETABLETRAVERSER_H - -#include "node/traverser.h" - -namespace olive { - -class NodeTableTraverser : public NodeTraverser -{ -public: - NodeTableTraverser() = default; - -protected: - virtual QVariant ProcessVideoFootage(const FootageJob &video_stream, const rational &input_time); - - virtual QVariant ProcessAudioFootage(const FootageJob &audio_stream, const TimeRange &input_time); - -}; - -} - -#endif // NODETABLETRAVERSER_H diff --git a/app/widget/nodetableview/nodetableview.cpp b/app/widget/nodetableview/nodetableview.cpp index 022c8cf83..313a61439 100644 --- a/app/widget/nodetableview/nodetableview.cpp +++ b/app/widget/nodetableview/nodetableview.cpp @@ -23,7 +23,7 @@ #include #include -#include "nodetabletraverser.h" +#include "node/traverser.h" namespace olive { @@ -63,10 +63,9 @@ void NodeTableView::SetTime(const rational &time) { last_time_ = time; - NodeTableTraverser traverser; + NodeTraverser traverser; - QMap::const_iterator i; - for (i=top_level_item_map_.constBegin(); i!=top_level_item_map_.constEnd(); i++) { + for (auto i=top_level_item_map_.constBegin(); i!=top_level_item_map_.constEnd(); i++) { Node* node = i.key(); QTreeWidgetItem* item = i.value(); @@ -150,7 +149,7 @@ void NodeTableView::SetTime(const rational &time) break; case NodeValue::kTexture: { - // NodeTableTraverser puts video params in here + // NodeTraverser puts video params in here for (int k=0;ksetItemWidget(sub_item, 2 + k, new QCheckBox()); } @@ -169,101 +168,4 @@ void NodeTableView::SetTime(const rational &time) } } -/* -void NodeTableView::SetNode(Node *n, const rational &time) -{ - NodeTableTraverser traverser; - NodeValueDatabase db = traverser.GenerateDatabase(n, TimeRange(time, time)); - - // Remove top items if necessary - for (int i=0;itopLevelItemCount();i++) { - if (!db.contains(this->topLevelItem(i)->data(0, Qt::UserRole).toString())) { - delete this->takeTopLevelItem(i); - i--; - } - } - - NodeValueDatabase::const_iterator i; - - for (i=db.begin(); i!=db.end(); i++) { - const NodeValueTable& table = i.value(); - - NodeInput* input = n->GetInputWithID(i.key()); - if (!input) { - // Filters out table entries that aren't inputs (like "global") - continue; - } - - QTreeWidgetItem* top_item = nullptr; - - for (int j=0;jtopLevelItemCount();j++) { - QTreeWidgetItem* compare = this->topLevelItem(j); - - if (compare->data(0, Qt::UserRole).toString() == input->id()) { - top_item = compare; - break; - } - } - - if (!top_item) { - top_item = new QTreeWidgetItem(); - top_item->setText(0, input->name()); - top_item->setData(0, Qt::UserRole, input->id()); - top_item->setFirstColumnSpanned(true); - this->addTopLevelItem(top_item); - } - - // Create children if necessary - while (top_item->childCount() < table.Count()) { - top_item->addChild(new QTreeWidgetItem()); - } - - // Remove children if necessary - while (top_item->childCount() > table.Count()) { - delete top_item->takeChild(top_item->childCount() - 1); - } - - for (int j=0;jchild(j); - - // Set data type name - sub_item->setText(0, NodeParam::GetPrettyDataTypeName(value.type())); - - // Determine source - QString source_name; - if (value.source()) { - source_name = value.source()->Name(); - } else { - source_name = tr("(unknown)"); - } - sub_item->setText(1, source_name); - - switch (value.type()) { - case NodeParam::kTexture: - { - // NodeTableTraverser puts video params in here - VideoParams p = value.data().value(); - int channel_count = PixelFormat::ChannelCount(p.format()); - - for (int k=0;ksetItemWidget(sub_item, 2 + k, new QCheckBox()); - } - break; - } - default: - { - QVector split_values = input->split_normal_value_into_track_values(value.data()); - for (int k=0;ksetText(2 + k, NodeInput::ValueToString(value.type(), split_values.at(k))); - } - } - } - } - } -} -*/ - } diff --git a/app/widget/viewer/CMakeLists.txt b/app/widget/viewer/CMakeLists.txt index 84a65e5a1..23b401cfe 100644 --- a/app/widget/viewer/CMakeLists.txt +++ b/app/widget/viewer/CMakeLists.txt @@ -16,23 +16,21 @@ set(OLIVE_SOURCES ${OLIVE_SOURCES} - widget/viewer/audiowaveformview.h widget/viewer/audiowaveformview.cpp - widget/viewer/footageviewer.h + widget/viewer/audiowaveformview.h widget/viewer/footageviewer.cpp - widget/viewer/gizmotraverser.h - widget/viewer/gizmotraverser.cpp - widget/viewer/viewer.h + widget/viewer/footageviewer.h widget/viewer/viewer.cpp - widget/viewer/viewerdisplay.h + widget/viewer/viewer.h widget/viewer/viewerdisplay.cpp - widget/viewer/viewerplaybacktimer.h + widget/viewer/viewerdisplay.h widget/viewer/viewerplaybacktimer.cpp + widget/viewer/viewerplaybacktimer.h widget/viewer/viewerqueue.h widget/viewer/viewersafemargininfo.h - widget/viewer/viewersizer.h widget/viewer/viewersizer.cpp - widget/viewer/viewerwindow.h + widget/viewer/viewersizer.h widget/viewer/viewerwindow.cpp + widget/viewer/viewerwindow.h PARENT_SCOPE ) diff --git a/app/widget/viewer/gizmotraverser.cpp b/app/widget/viewer/gizmotraverser.cpp deleted file mode 100644 index 48e13420e..000000000 --- a/app/widget/viewer/gizmotraverser.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2021 Olive Team - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -***/ - -#include "gizmotraverser.h" - -namespace olive { - -QVariant GizmoTraverser::ProcessVideoFootage(const FootageJob &ref, const rational &input_time) -{ - Q_UNUSED(input_time) - - VideoParams stream = ref.video_params(); - - return QVector2D(stream.width() * stream.pixel_aspect_ratio().toDouble(), - stream.height()); -} - -QVariant GizmoTraverser::ProcessShader(const Node *node, const TimeRange &range, const ShaderJob &job) -{ - Q_UNUSED(node) - Q_UNUSED(range) - Q_UNUSED(job) - - return GenerateResolution(); -} - -QVariant GizmoTraverser::ProcessFrameGeneration(const Node *node, const GenerateJob &job) -{ - Q_UNUSED(node) - Q_UNUSED(job) - - return GenerateResolution(); -} -} diff --git a/app/widget/viewer/gizmotraverser.h b/app/widget/viewer/gizmotraverser.h deleted file mode 100644 index 670c8fcc4..000000000 --- a/app/widget/viewer/gizmotraverser.h +++ /dev/null @@ -1,57 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2021 Olive Team - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -***/ - -#ifndef GIZMOTRAVERSER_H -#define GIZMOTRAVERSER_H - -#include "node/traverser.h" - -namespace olive { - -class GizmoTraverser : public NodeTraverser -{ -public: - GizmoTraverser(const QVector2D& sequence_resolution) : - size_(sequence_resolution) - { - } - -protected: - virtual QVariant ProcessVideoFootage(const FootageJob& stream, const rational &input_time) override; - - virtual QVariant ProcessShader(const Node *node, const TimeRange &range, const ShaderJob& job) override; - - virtual QVector2D GenerateResolution() const override - { - return size_; - } - - virtual QVariant ProcessFrameGeneration(const Node *node, const GenerateJob& job) override; - - // FIXME: Do something about audio? - -private: - QVector2D size_; - -}; - -} - -#endif // GIZMOTRAVERSER_H diff --git a/app/widget/viewer/viewerdisplay.cpp b/app/widget/viewer/viewerdisplay.cpp index cf57c2d12..7f17b11ee 100644 --- a/app/widget/viewer/viewerdisplay.cpp +++ b/app/widget/viewer/viewerdisplay.cpp @@ -33,7 +33,7 @@ #include "common/functiontimer.h" #include "config/config.h" #include "core.h" -#include "gizmotraverser.h" +#include "node/traverser.h" namespace olive { @@ -339,8 +339,8 @@ void ViewerDisplayWidget::OnPaint() // Draw gizmos if we have any if (gizmos_) { - GizmoTraverser gt(QVector2D(gizmo_params_.width() * gizmo_params_.pixel_aspect_ratio().toDouble(), - gizmo_params_.height())); + NodeTraverser gt; + gt.SetCacheVideoParams(gizmo_params_); rational node_time = GetGizmoTime();