From dd9c52ab596dee05dc40b3b5dfdad1ba3aff0adf Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Thu, 19 Jan 2023 09:51:47 -0800 Subject: [PATCH] start moving core frameworks to external libraries --- CMakeLists.txt | 8 + app/audio/audioprocessor.cpp | 2 + app/audio/audioprocessor.h | 1 + app/codec/decoder.cpp | 4 +- app/codec/decoder.h | 4 +- app/codec/encoder.cpp | 19 +- app/codec/encoder.h | 7 +- app/codec/ffmpeg/ffmpegdecoder.cpp | 11 +- app/codec/ffmpeg/ffmpegdecoder.h | 2 +- app/codec/ffmpeg/ffmpegencoder.cpp | 3 +- app/codec/ffmpeg/ffmpegencoder.h | 6 +- app/codec/frame.cpp | 4 +- app/codec/frame.h | 9 +- app/codec/oiio/oiiodecoder.cpp | 2 +- app/codec/oiio/oiiodecoder.h | 2 +- app/codec/oiio/oiioencoder.h | 2 +- app/codec/samplebuffer.cpp | 2 + app/common/CMakeLists.txt | 6 - app/common/ffmpegutils.cpp | 50 +-- app/common/ffmpegutils.h | 6 +- app/common/ocioutils.cpp | 14 +- app/common/ocioutils.h | 2 +- app/common/oiioutils.cpp | 14 +- app/common/oiioutils.h | 16 +- app/common/qtutils.cpp | 30 ++ app/common/qtutils.h | 14 + app/common/ratiodialog.h | 2 - app/common/rational.cpp | 287 ------------- app/common/rational.h | 157 ------- app/common/timecodefunctions.cpp | 358 ---------------- app/common/timecodefunctions.h | 80 ---- app/common/timerange.cpp | 393 ------------------ app/common/timerange.h | 298 ------------- app/config/config.cpp | 4 +- app/config/config.h | 1 - app/core.cpp | 6 +- app/core.h | 3 +- app/dialog/color/colordialog.h | 1 - app/dialog/export/export.cpp | 2 +- app/dialog/export/exportvideotab.h | 1 - .../keyframeproperties/keyframeproperties.cpp | 1 - app/dialog/sequence/sequence.cpp | 1 - .../sequence/sequencedialogparametertab.cpp | 2 +- .../sequence/sequencedialogparametertab.h | 2 +- .../sequence/sequencedialogpresettab.cpp | 4 +- app/dialog/sequence/sequencepreset.h | 18 +- app/node/filter/stroke/stroke.cpp | 1 - app/node/generator/polygon/polygon.cpp | 2 +- app/node/generator/solid/solid.cpp | 2 - app/node/generator/text/textv2.cpp | 2 +- app/node/generator/text/textv3.cpp | 2 +- app/node/gizmo/draggable.h | 5 +- app/node/globals.h | 1 - app/node/inputdragger.h | 1 - app/node/inputimmediate.h | 1 - app/node/keyframe.h | 2 - app/node/math/math/mathbase.cpp | 1 - app/node/node.cpp | 4 +- app/node/node.h | 8 +- app/node/output/viewer/viewer.cpp | 6 +- app/node/output/viewer/viewer.h | 1 - app/node/param.cpp | 4 +- app/node/param.h | 1 - app/node/project/footage/footage.h | 2 +- .../project/serializer/serializer210528.cpp | 10 +- .../project/serializer/serializer210907.cpp | 10 +- .../project/serializer/serializer211228.cpp | 10 +- .../project/serializer/serializer220403.cpp | 20 +- app/node/value.cpp | 5 +- app/node/value.h | 6 +- app/render/CMakeLists.txt | 2 - app/render/audioparams.cpp | 4 +- app/render/audioparams.h | 5 +- app/render/audioplaybackcache.h | 1 - app/render/audiowaveformcache.cpp | 4 +- app/render/audiowaveformcache.h | 2 +- app/render/color.cpp | 300 ------------- app/render/color.h | 161 ------- app/render/colorprocessor.h | 1 - app/render/framehashcache.cpp | 22 +- app/render/framehashcache.h | 3 - app/render/job/samplejob.h | 1 - app/render/managedcolor.cpp | 2 +- app/render/managedcolor.h | 5 +- app/render/opengl/openglrenderer.cpp | 30 +- app/render/opengl/openglrenderer.h | 8 +- app/render/playbackcache.cpp | 12 +- app/render/playbackcache.h | 18 +- app/render/previewautocacher.cpp | 2 +- app/render/renderer.cpp | 4 +- app/render/renderer.h | 5 +- app/render/renderjobtracker.cpp | 2 +- app/render/renderjobtracker.h | 7 +- app/render/rendermanager.cpp | 2 +- app/render/rendermanager.h | 4 +- app/render/renderprocessor.cpp | 4 +- app/render/renderticket.h | 1 - app/render/subtitleparams.cpp | 8 +- app/render/subtitleparams.h | 3 +- app/render/texture.h | 2 +- app/render/videoparams.cpp | 71 ++-- app/render/videoparams.h | 54 +-- app/task/export/export.cpp | 1 - app/task/render/render.cpp | 5 +- app/task/render/render.h | 4 +- app/timeline/timelinecommon.h | 5 +- app/timeline/timelinecoordinate.h | 1 - app/timeline/timelinemarker.cpp | 2 +- app/timeline/timelinemarker.h | 4 +- app/timeline/timelineworkarea.h | 5 +- app/ui/colorcoding.h | 5 +- app/widget/colorbutton/colorbutton.cpp | 2 +- app/widget/colorlabelmenu/colorlabelmenu.cpp | 3 +- app/widget/colorwheel/colorgradientwidget.cpp | 2 +- app/widget/colorwheel/colorgradientwidget.h | 1 - app/widget/colorwheel/colorpreviewbox.cpp | 6 +- app/widget/colorwheel/colorpreviewbox.h | 1 - app/widget/colorwheel/colorswatchwidget.h | 1 - app/widget/colorwheel/colorvalueswidget.h | 1 - app/widget/colorwheel/colorwheelwidget.cpp | 2 +- app/widget/colorwheel/colorwheelwidget.h | 1 - app/widget/curvewidget/curvewidget.cpp | 1 - app/widget/manageddisplay/manageddisplay.cpp | 2 +- app/widget/menu/menushared.cpp | 3 +- app/widget/menu/menushared.h | 4 +- app/widget/nodeparamview/nodeparamview.cpp | 1 - app/widget/nodeview/nodeviewcontext.cpp | 6 +- app/widget/pixelsampler/pixelsampler.h | 1 - .../playbackcontrols/playbackcontrols.cpp | 6 +- .../playbackcontrols/playbackcontrols.h | 1 - .../resizabletimelinescrollbar.cpp | 2 +- app/widget/slider/rationalslider.cpp | 9 +- app/widget/slider/rationalslider.h | 4 +- app/widget/standardcombos/frameratecombobox.h | 3 +- .../standardcombos/pixelformatcombobox.h | 14 +- app/widget/taskview/elapsedcounterwidget.cpp | 9 +- app/widget/taskview/taskviewitem.cpp | 1 - app/widget/timebased/timebasedview.cpp | 1 - .../timebased/timebasedviewselectionmanager.h | 7 +- app/widget/timebased/timebasedwidget.cpp | 1 - app/widget/timebased/timescaledobject.h | 2 +- app/widget/timelinewidget/timelinewidget.cpp | 7 +- .../timelinewidget/timelinewidgetselections.h | 1 - app/widget/timelinewidget/tool/import.cpp | 6 +- app/widget/timelinewidget/tool/pointer.cpp | 9 +- app/widget/timelinewidget/tool/slip.cpp | 9 +- app/widget/timelinewidget/tool/tool.h | 1 - .../timelinewidget/view/timelineview.cpp | 9 +- app/widget/timeruler/seekablewidget.h | 1 - app/widget/timeruler/timeruler.cpp | 3 +- app/widget/timeruler/timeruler.h | 1 - app/widget/viewer/viewer.cpp | 1 - app/widget/viewer/viewer.h | 1 - app/widget/viewer/viewerdisplay.h | 1 - app/widget/viewer/viewersizer.h | 6 +- app/widget/viewer/viewerwindow.cpp | 2 - app/window/mainwindow/mainmenu.cpp | 1 - cmake/FindOlive.cmake | 55 +++ 158 files changed, 478 insertions(+), 2484 deletions(-) delete mode 100644 app/common/rational.cpp delete mode 100644 app/common/rational.h delete mode 100644 app/common/timecodefunctions.cpp delete mode 100644 app/common/timecodefunctions.h delete mode 100644 app/common/timerange.cpp delete mode 100644 app/common/timerange.h delete mode 100644 app/render/color.cpp delete mode 100644 app/render/color.h create mode 100644 cmake/FindOlive.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 04fc8ce8d..3dc95f992 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,14 @@ find_package(OpenEXR REQUIRED) list(APPEND OLIVE_LIBRARIES ${OPENEXR_LIBRARIES}) list(APPEND OLIVE_INCLUDE_DIRS ${OPENEXR_INCLUDES}) +# Link Olive +find_package(Olive REQUIRED + COMPONENTS + Core +) +list(APPEND OLIVE_LIBRARIES ${LIBOLIVE_LIBRARIES}) +list(APPEND OLIVE_INCLUDE_DIRS ${LIBOLIVE_INCLUDE_DIRS}) + # Link Qt set(QT_LIBRARIES Core diff --git a/app/audio/audioprocessor.cpp b/app/audio/audioprocessor.cpp index d73ca0931..7d451cd44 100644 --- a/app/audio/audioprocessor.cpp +++ b/app/audio/audioprocessor.cpp @@ -25,6 +25,8 @@ extern "C" { #include } +#include + #include "common/ffmpegutils.h" namespace olive { diff --git a/app/audio/audioprocessor.h b/app/audio/audioprocessor.h index d2861a3bc..d67b612cf 100644 --- a/app/audio/audioprocessor.h +++ b/app/audio/audioprocessor.h @@ -27,6 +27,7 @@ extern "C" { #include } +#include "common/define.h" #include "render/audioparams.h" namespace olive { diff --git a/app/codec/decoder.cpp b/app/codec/decoder.cpp index 6fb2a2676..f405d27de 100644 --- a/app/codec/decoder.cpp +++ b/app/codec/decoder.cpp @@ -22,13 +22,13 @@ #include #include +#include #include "codec/ffmpeg/ffmpegdecoder.h" #include "codec/planarfiledevice.h" #include "codec/oiio/oiiodecoder.h" #include "common/ffmpegutils.h" #include "common/filefunctions.h" -#include "common/timecodefunctions.h" #include "conformmanager.h" #include "node/project/project.h" #include "task/taskmanager.h" @@ -338,7 +338,7 @@ void Decoder::UpdateLastAccessed() uint qHash(Decoder::CodecStream stream, uint seed) { - return qHash(stream.filename(), seed) ^ qHash(stream.stream(), seed) ^ qHash(stream.block(), seed); + return qHash(stream.filename(), seed) ^ ::qHash(stream.stream(), seed) ^ qHash(stream.block(), seed); } } diff --git a/app/codec/decoder.h b/app/codec/decoder.h index 471958bc9..b67d22d75 100644 --- a/app/codec/decoder.h +++ b/app/codec/decoder.h @@ -32,10 +32,10 @@ extern "C" { #include #include "codec/samplebuffer.h" -#include "common/rational.h" #include "node/block/block.h" #include "node/project/footage/footagedescription.h" #include "render/cancelatom.h" +#include "render/rendermodes.h" namespace olive { @@ -160,7 +160,7 @@ public: Renderer *renderer = nullptr; rational time; int divider = 1; - VideoParams::Format maximum_format = VideoParams::kFormatInvalid; + PixelFormat maximum_format = PixelFormat::INVALID; CancelAtom *cancelled = nullptr; VideoParams::ColorRange force_range = VideoParams::kColorRangeDefault; VideoParams::Interlacing src_interlacing = VideoParams::kInterlaceNone; diff --git a/app/codec/encoder.cpp b/app/codec/encoder.cpp index 4888ed5a6..afa14bb3f 100644 --- a/app/codec/encoder.cpp +++ b/app/codec/encoder.cpp @@ -22,7 +22,6 @@ #include -#include "common/timecodefunctions.h" #include "common/xmlutils.h" #include "ffmpeg/ffmpegencoder.h" #include "oiio/oiioencoder.h" @@ -202,8 +201,8 @@ void EncodingParams::Save(QXmlStreamWriter *writer) const writer->writeTextElement(QStringLiteral("format"), QString::number(format_)); writer->writeTextElement(QStringLiteral("range"), QString::number(has_custom_range_)); - writer->writeTextElement(QStringLiteral("customrangein"), custom_range_.in().toString()); - writer->writeTextElement(QStringLiteral("customrangeout"), custom_range_.out().toString()); + writer->writeTextElement(QStringLiteral("customrangein"), QString::fromStdString(custom_range_.in().toString())); + writer->writeTextElement(QStringLiteral("customrangeout"), QString::fromStdString(custom_range_.out().toString())); writer->writeStartElement(QStringLiteral("video")); @@ -214,8 +213,8 @@ void EncodingParams::Save(QXmlStreamWriter *writer) const writer->writeTextElement(QStringLiteral("width"), QString::number(video_params_.width())); writer->writeTextElement(QStringLiteral("height"), QString::number(video_params_.height())); writer->writeTextElement(QStringLiteral("format"), QString::number(video_params_.format())); - writer->writeTextElement(QStringLiteral("pixelaspect"), video_params_.pixel_aspect_ratio().toString()); - writer->writeTextElement(QStringLiteral("timebase"), video_params_.time_base().toString()); + writer->writeTextElement(QStringLiteral("pixelaspect"), QString::fromStdString(video_params_.pixel_aspect_ratio().toString())); + writer->writeTextElement(QStringLiteral("timebase"), QString::fromStdString(video_params_.time_base().toString())); writer->writeTextElement(QStringLiteral("divider"), QString::number(video_params_.divider())); writer->writeTextElement(QStringLiteral("bitrate"), QString::number(video_bit_rate_)); writer->writeTextElement(QStringLiteral("minbitrate"), QString::number(video_min_bit_rate_)); @@ -381,9 +380,9 @@ bool EncodingParams::LoadV1(QXmlStreamReader *reader) } else if (reader->name() == QStringLiteral("range")) { has_custom_range_ = reader->readElementText().toInt(); } else if (reader->name() == QStringLiteral("customrangein")) { - custom_range_in = rational::fromString(reader->readElementText()); + custom_range_in = rational::fromString(reader->readElementText().toStdString()); } else if (reader->name() == QStringLiteral("customrangeout")) { - custom_range_out = rational::fromString(reader->readElementText()); + custom_range_out = rational::fromString(reader->readElementText().toStdString()); } else if (reader->name() == QStringLiteral("video")) { XMLAttributeLoop(reader, attr) { if (attr.name() == QStringLiteral("enabled")) { @@ -399,11 +398,11 @@ bool EncodingParams::LoadV1(QXmlStreamReader *reader) } else if (reader->name() == QStringLiteral("height")) { video_params_.set_height(reader->readElementText().toInt()); } else if (reader->name() == QStringLiteral("format")) { - video_params_.set_format(static_cast(reader->readElementText().toInt())); + video_params_.set_format(static_cast(reader->readElementText().toInt())); } else if (reader->name() == QStringLiteral("pixelaspect")) { - video_params_.set_pixel_aspect_ratio(rational::fromString(reader->readElementText())); + video_params_.set_pixel_aspect_ratio(rational::fromString(reader->readElementText().toStdString())); } else if (reader->name() == QStringLiteral("timebase")) { - video_params_.set_time_base(rational::fromString(reader->readElementText())); + video_params_.set_time_base(rational::fromString(reader->readElementText().toStdString())); } else if (reader->name() == QStringLiteral("divider")) { video_params_.set_divider(reader->readElementText().toInt()); } else if (reader->name() == QStringLiteral("bitrate")) { diff --git a/app/codec/encoder.h b/app/codec/encoder.h index e27cd1417..3e952441b 100644 --- a/app/codec/encoder.h +++ b/app/codec/encoder.h @@ -30,7 +30,6 @@ #include "codec/exportformat.h" #include "codec/frame.h" #include "codec/samplebuffer.h" -#include "common/timerange.h" #include "node/block/subtitle/subtitle.h" #include "render/audioparams.h" #include "render/colortransform.h" @@ -209,9 +208,9 @@ public: const EncodingParams& params() const; - virtual VideoParams::Format GetDesiredPixelFormat() const + virtual PixelFormat GetDesiredPixelFormat() const { - return VideoParams::kFormatInvalid; + return PixelFormat::INVALID; } const QString& GetError() const @@ -232,7 +231,7 @@ public: public slots: virtual bool Open() = 0; - virtual bool WriteFrame(olive::FramePtr frame, olive::rational time) = 0; + virtual bool WriteFrame(olive::FramePtr frame, olive::core::rational time) = 0; virtual bool WriteAudio(const olive::SampleBuffer &audio) = 0; virtual bool WriteSubtitle(const SubtitleBlock *sub_block) = 0; diff --git a/app/codec/ffmpeg/ffmpegdecoder.cpp b/app/codec/ffmpeg/ffmpegdecoder.cpp index 5e2bdddbe..8106cb0a1 100644 --- a/app/codec/ffmpeg/ffmpegdecoder.cpp +++ b/app/codec/ffmpeg/ffmpegdecoder.cpp @@ -42,7 +42,6 @@ extern "C" { #include "codec/planarfiledevice.h" #include "common/ffmpegutils.h" #include "common/filefunctions.h" -#include "common/timecodefunctions.h" #include "render/renderer.h" #include "render/subtitleparams.h" @@ -78,7 +77,7 @@ TexturePtr FFmpegDecoder::ProcessFrameIntoTexture(AVFramePtr f, const RetrieveVi { // Determine native format AVPixelFormat ideal_fmt = FFmpegUtils::GetCompatiblePixelFormat(static_cast(f->format)); - VideoParams::Format native_fmt = GetNativePixelFormat(ideal_fmt); + PixelFormat native_fmt = GetNativePixelFormat(ideal_fmt); int native_channels = GetNativeChannelCount(ideal_fmt); // Set up video params @@ -642,17 +641,17 @@ bool FFmpegDecoder::ConformAudioInternal(const QVector &filenames, cons return success; } -VideoParams::Format FFmpegDecoder::GetNativePixelFormat(AVPixelFormat pix_fmt) +PixelFormat FFmpegDecoder::GetNativePixelFormat(AVPixelFormat pix_fmt) { switch (pix_fmt) { case AV_PIX_FMT_RGB24: case AV_PIX_FMT_RGBA: - return VideoParams::kFormatUnsigned8; + return PixelFormat::U8; case AV_PIX_FMT_RGB48: case AV_PIX_FMT_RGBA64: - return VideoParams::kFormatUnsigned16; + return PixelFormat::U16; default: - return VideoParams::kFormatInvalid; + return PixelFormat::INVALID; } } diff --git a/app/codec/ffmpeg/ffmpegdecoder.h b/app/codec/ffmpeg/ffmpegdecoder.h index a695f0b31..bc3723374 100644 --- a/app/codec/ffmpeg/ffmpegdecoder.h +++ b/app/codec/ffmpeg/ffmpegdecoder.h @@ -136,7 +136,7 @@ private: void FreeScaler(); - static VideoParams::Format GetNativePixelFormat(AVPixelFormat pix_fmt); + static PixelFormat GetNativePixelFormat(AVPixelFormat pix_fmt); static int GetNativeChannelCount(AVPixelFormat pix_fmt); static uint64_t ValidateChannelLayout(AVStream *stream); diff --git a/app/codec/ffmpeg/ffmpegencoder.cpp b/app/codec/ffmpeg/ffmpegencoder.cpp index da6c8b510..c3be3c534 100644 --- a/app/codec/ffmpeg/ffmpegencoder.cpp +++ b/app/codec/ffmpeg/ffmpegencoder.cpp @@ -29,7 +29,6 @@ extern "C" { #include #include "common/ffmpegutils.h" -#include "common/timecodefunctions.h" namespace olive { @@ -130,7 +129,7 @@ bool FFmpegEncoder::Open() } // This is the format we will expect frames received in Write() to be in - VideoParams::Format native_pixel_fmt = params().video_params().format(); + PixelFormat native_pixel_fmt = params().video_params().format(); // This is the format we will need to convert the frame to for swscale to understand it video_conversion_fmt_ = FFmpegUtils::GetCompatiblePixelFormat(native_pixel_fmt); diff --git a/app/codec/ffmpeg/ffmpegencoder.h b/app/codec/ffmpeg/ffmpegencoder.h index 9a9f6cae3..18ee18923 100644 --- a/app/codec/ffmpeg/ffmpegencoder.h +++ b/app/codec/ffmpeg/ffmpegencoder.h @@ -45,7 +45,7 @@ public: virtual bool Open() override; - virtual bool WriteFrame(olive::FramePtr frame, olive::rational time) override; + virtual bool WriteFrame(olive::FramePtr frame, olive::core::rational time) override; virtual bool WriteAudio(const olive::SampleBuffer &audio) override; @@ -55,7 +55,7 @@ public: virtual void Close() override; - virtual VideoParams::Format GetDesiredPixelFormat() const override + virtual PixelFormat GetDesiredPixelFormat() const override { return video_conversion_fmt_; } @@ -91,7 +91,7 @@ private: AVFilterGraph *video_scale_ctx_; AVFilterContext *video_buffersrc_ctx_; AVFilterContext *video_buffersink_ctx_; - VideoParams::Format video_conversion_fmt_; + PixelFormat video_conversion_fmt_; AVStream* audio_stream_; AVCodecContext* audio_codec_ctx_; diff --git a/app/codec/frame.cpp b/app/codec/frame.cpp index d6899d9ff..a1342fa1e 100644 --- a/app/codec/frame.cpp +++ b/app/codec/frame.cpp @@ -84,7 +84,7 @@ FramePtr Frame::Interlace(FramePtr top, FramePtr bottom) return interlaced; } -int Frame::generate_linesize_bytes(int width, VideoParams::Format format, int channel_count) +int Frame::generate_linesize_bytes(int width, PixelFormat format, int channel_count) { // Align to 32 bytes (not sure if this is necessary?) return VideoParams::GetBytesPerPixel(format, channel_count) * ((width + 31) & ~31); @@ -146,7 +146,7 @@ void Frame::destroy() } } -FramePtr Frame::convert(VideoParams::Format format) const +FramePtr Frame::convert(PixelFormat format) const { // Create new params with destination format VideoParams params = params_; diff --git a/app/codec/frame.h b/app/codec/frame.h index 995845782..30a6ebe86 100644 --- a/app/codec/frame.h +++ b/app/codec/frame.h @@ -22,11 +22,10 @@ #define FRAME_H #include +#include #include #include "common/define.h" -#include "common/rational.h" -#include "render/color.h" #include "render/videoparams.h" namespace olive { @@ -53,7 +52,7 @@ public: static FramePtr Interlace(FramePtr top, FramePtr bottom); - static int generate_linesize_bytes(int width, VideoParams::Format format, int channel_count); + static int generate_linesize_bytes(int width, PixelFormat format, int channel_count); int linesize_pixels() const { @@ -75,7 +74,7 @@ public: return params_.effective_height(); } - VideoParams::Format format() const + PixelFormat format() const { return params_.format(); } @@ -152,7 +151,7 @@ public: return data_size_; } - FramePtr convert(VideoParams::Format format) const; + FramePtr convert(PixelFormat format) const; private: VideoParams params_; diff --git a/app/codec/oiio/oiiodecoder.cpp b/app/codec/oiio/oiiodecoder.cpp index 5593bbbe1..e3efc4108 100644 --- a/app/codec/oiio/oiiodecoder.cpp +++ b/app/codec/oiio/oiiodecoder.cpp @@ -205,7 +205,7 @@ bool OIIODecoder::OpenImageHandler(const QString &fn, int subimage) // We use RGBA frames because that tends to be the native format of GPUs pix_fmt_ = OIIOUtils::GetFormatFromOIIOBasetype(static_cast(spec.format.basetype)); - if (pix_fmt_ == VideoParams::kFormatInvalid) { + if (pix_fmt_ == PixelFormat::INVALID) { qWarning() << "Failed to convert OIIO::ImageDesc to native pixel format"; return false; } diff --git a/app/codec/oiio/oiiodecoder.h b/app/codec/oiio/oiiodecoder.h index f16e33692..ca20a8374 100644 --- a/app/codec/oiio/oiiodecoder.h +++ b/app/codec/oiio/oiiodecoder.h @@ -58,7 +58,7 @@ private: static VideoParams GetVideoParamsFromImageSpec(const OIIO::ImageSpec &spec); - VideoParams::Format pix_fmt_; + PixelFormat pix_fmt_; OIIO::TypeDesc::BASETYPE oiio_pix_fmt_; Frame buffer_; diff --git a/app/codec/oiio/oiioencoder.h b/app/codec/oiio/oiioencoder.h index 27f6ee44a..778a91474 100644 --- a/app/codec/oiio/oiioencoder.h +++ b/app/codec/oiio/oiioencoder.h @@ -34,7 +34,7 @@ public: public slots: virtual bool Open() override; - virtual bool WriteFrame(olive::FramePtr frame, olive::rational time) override; + virtual bool WriteFrame(olive::FramePtr frame, olive::core::rational time) override; virtual bool WriteAudio(const SampleBuffer &audio) override; virtual bool WriteSubtitle(const SubtitleBlock *sub_block) override; diff --git a/app/codec/samplebuffer.cpp b/app/codec/samplebuffer.cpp index c5a746387..f67c95e90 100644 --- a/app/codec/samplebuffer.cpp +++ b/app/codec/samplebuffer.cpp @@ -20,6 +20,8 @@ #include "samplebuffer.h" +#include + #include "common/cpuoptimize.h" namespace olive { diff --git a/app/common/CMakeLists.txt b/app/common/CMakeLists.txt index e3741723b..b503de134 100644 --- a/app/common/CMakeLists.txt +++ b/app/common/CMakeLists.txt @@ -50,13 +50,7 @@ set(OLIVE_SOURCES common/range.h common/ratiodialog.cpp common/ratiodialog.h - common/rational.cpp - common/rational.h common/threadsafemap.h - common/timecodefunctions.cpp - common/timecodefunctions.h - common/timerange.cpp - common/timerange.h common/tohex.h common/util.h common/xmlutils.cpp diff --git a/app/common/ffmpegutils.cpp b/app/common/ffmpegutils.cpp index 489fdf080..3ded0bbc9 100644 --- a/app/common/ffmpegutils.cpp +++ b/app/common/ffmpegutils.cpp @@ -22,13 +22,13 @@ namespace olive { -AVPixelFormat FFmpegUtils::GetCompatiblePixelFormat(const AVPixelFormat &pix_fmt, VideoParams::Format maximum) +AVPixelFormat FFmpegUtils::GetCompatiblePixelFormat(const AVPixelFormat &pix_fmt, PixelFormat maximum) { AVPixelFormat possible_pix_fmts[3]; possible_pix_fmts[0] = AV_PIX_FMT_RGBA; - if (maximum == VideoParams::kFormatUnsigned8) { + if (maximum == PixelFormat::U8) { possible_pix_fmts[1] = AV_PIX_FMT_NONE; } else { possible_pix_fmts[1] = AV_PIX_FMT_RGBA64; @@ -148,30 +148,30 @@ AVPixelFormat FFmpegUtils::ConvertJPEGSpaceToRegularSpace(AVPixelFormat f) return f; } -AVPixelFormat FFmpegUtils::GetFFmpegPixelFormat(const VideoParams::Format &pix_fmt, int channel_layout) +AVPixelFormat FFmpegUtils::GetFFmpegPixelFormat(const PixelFormat &pix_fmt, int channel_layout) { if (channel_layout == VideoParams::kRGBChannelCount) { switch (pix_fmt) { - case VideoParams::kFormatUnsigned8: + case PixelFormat::U8: return AV_PIX_FMT_RGB24; - case VideoParams::kFormatUnsigned16: + case PixelFormat::U16: return AV_PIX_FMT_RGB48; - case VideoParams::kFormatFloat16: - case VideoParams::kFormatFloat32: - case VideoParams::kFormatInvalid: - case VideoParams::kFormatCount: + case PixelFormat::F16: + case PixelFormat::F32: + case PixelFormat::INVALID: + case PixelFormat::FORMAT_COUNT: break; } } else if (channel_layout == VideoParams::kRGBAChannelCount) { switch (pix_fmt) { - case VideoParams::kFormatUnsigned8: + case PixelFormat::U8: return AV_PIX_FMT_RGBA; - case VideoParams::kFormatUnsigned16: + case PixelFormat::U16: return AV_PIX_FMT_RGBA64; - case VideoParams::kFormatFloat16: - case VideoParams::kFormatFloat32: - case VideoParams::kFormatInvalid: - case VideoParams::kFormatCount: + case PixelFormat::F16: + case PixelFormat::F32: + case PixelFormat::INVALID: + case PixelFormat::FORMAT_COUNT: break; } } @@ -179,21 +179,21 @@ AVPixelFormat FFmpegUtils::GetFFmpegPixelFormat(const VideoParams::Format &pix_f return AV_PIX_FMT_NONE; } -VideoParams::Format FFmpegUtils::GetCompatiblePixelFormat(const VideoParams::Format &pix_fmt) +PixelFormat FFmpegUtils::GetCompatiblePixelFormat(const PixelFormat &pix_fmt) { switch (pix_fmt) { - case VideoParams::kFormatUnsigned8: - return VideoParams::kFormatUnsigned8; - case VideoParams::kFormatUnsigned16: - case VideoParams::kFormatFloat16: - case VideoParams::kFormatFloat32: - return VideoParams::kFormatUnsigned16; - case VideoParams::kFormatInvalid: - case VideoParams::kFormatCount: + case PixelFormat::U8: + return PixelFormat::U8; + case PixelFormat::U16: + case PixelFormat::F16: + case PixelFormat::F32: + return PixelFormat::U16; + case PixelFormat::INVALID: + case PixelFormat::FORMAT_COUNT: break; } - return VideoParams::kFormatInvalid; + return PixelFormat::INVALID; } } diff --git a/app/common/ffmpegutils.h b/app/common/ffmpegutils.h index 66fafdd49..2f0813524 100644 --- a/app/common/ffmpegutils.h +++ b/app/common/ffmpegutils.h @@ -37,17 +37,17 @@ public: /** * @brief Returns an AVPixelFormat that can be used to convert a frame to a data type Olive supports with minimal data loss */ - static AVPixelFormat GetCompatiblePixelFormat(const AVPixelFormat& pix_fmt, VideoParams::Format maximum = VideoParams::kFormatInvalid); + static AVPixelFormat GetCompatiblePixelFormat(const AVPixelFormat& pix_fmt, PixelFormat maximum = PixelFormat::INVALID); /** * @brief Returns a native pixel format that can be used to convert from a native frame to an AVFrame with minimal data loss */ - static VideoParams::Format GetCompatiblePixelFormat(const VideoParams::Format& pix_fmt); + static PixelFormat GetCompatiblePixelFormat(const PixelFormat& pix_fmt); /** * @brief Returns an FFmpeg pixel format for a given native pixel format */ - static AVPixelFormat GetFFmpegPixelFormat(const VideoParams::Format& pix_fmt, int channel_layout); + static AVPixelFormat GetFFmpegPixelFormat(const PixelFormat& pix_fmt, int channel_layout); /** * @brief Returns a native sample format type for a given AVSampleFormat diff --git a/app/common/ocioutils.cpp b/app/common/ocioutils.cpp index 5690bab43..7b5414436 100644 --- a/app/common/ocioutils.cpp +++ b/app/common/ocioutils.cpp @@ -22,22 +22,22 @@ namespace olive { -OCIO::BitDepth OCIOUtils::GetOCIOBitDepthFromPixelFormat(VideoParams::Format format) +OCIO::BitDepth OCIOUtils::GetOCIOBitDepthFromPixelFormat(PixelFormat format) { switch (format) { - case VideoParams::kFormatUnsigned8: + case PixelFormat::U8: return OCIO::BIT_DEPTH_UINT8; - case VideoParams::kFormatUnsigned16: + case PixelFormat::U16: return OCIO::BIT_DEPTH_UINT16; break; - case VideoParams::kFormatFloat16: + case PixelFormat::F16: return OCIO::BIT_DEPTH_F16; break; - case VideoParams::kFormatFloat32: + case PixelFormat::F32: return OCIO::BIT_DEPTH_F32; break; - case VideoParams::kFormatInvalid: - case VideoParams::kFormatCount: + case PixelFormat::INVALID: + case PixelFormat::FORMAT_COUNT: break; } diff --git a/app/common/ocioutils.h b/app/common/ocioutils.h index bddafee2e..38c080077 100644 --- a/app/common/ocioutils.h +++ b/app/common/ocioutils.h @@ -31,7 +31,7 @@ namespace olive { class OCIOUtils { public: - static OCIO::BitDepth GetOCIOBitDepthFromPixelFormat(VideoParams::Format format); + static OCIO::BitDepth GetOCIOBitDepthFromPixelFormat(PixelFormat format); }; } diff --git a/app/common/oiioutils.cpp b/app/common/oiioutils.cpp index ee84de1e0..9697a2f6e 100644 --- a/app/common/oiioutils.cpp +++ b/app/common/oiioutils.cpp @@ -20,6 +20,8 @@ #include "oiioutils.h" +#include + namespace olive { void OIIOUtils::FrameToBuffer(const Frame* frame, OIIO::ImageBuf *buf) @@ -45,7 +47,7 @@ rational OIIOUtils::GetPixelAspectRatioFromOIIO(const OIIO::ImageSpec &spec) return rational::fromDouble(spec.get_float_attribute("PixelAspectRatio", 1)); } -VideoParams::Format OIIOUtils::GetFormatFromOIIOBasetype(OIIO::TypeDesc::BASETYPE type) +PixelFormat OIIOUtils::GetFormatFromOIIOBasetype(OIIO::TypeDesc::BASETYPE type) { switch (type) { case OIIO::TypeDesc::UNKNOWN: @@ -66,16 +68,16 @@ VideoParams::Format OIIOUtils::GetFormatFromOIIOBasetype(OIIO::TypeDesc::BASETYP break; case OIIO::TypeDesc::UINT8: - return VideoParams::kFormatUnsigned8; + return PixelFormat::U8; case OIIO::TypeDesc::UINT16: - return VideoParams::kFormatUnsigned16; + return PixelFormat::U16; case OIIO::TypeDesc::HALF: - return VideoParams::kFormatFloat16; + return PixelFormat::F16; case OIIO::TypeDesc::FLOAT: - return VideoParams::kFormatFloat32; + return PixelFormat::F32; } - return VideoParams::kFormatInvalid; + return PixelFormat::INVALID; } } diff --git a/app/common/oiioutils.h b/app/common/oiioutils.h index 0d7ac9a19..e606531df 100644 --- a/app/common/oiioutils.h +++ b/app/common/oiioutils.h @@ -31,19 +31,19 @@ namespace olive { class OIIOUtils { public: - static OIIO::TypeDesc::BASETYPE GetOIIOBaseTypeFromFormat(VideoParams::Format format) + static OIIO::TypeDesc::BASETYPE GetOIIOBaseTypeFromFormat(PixelFormat format) { switch (format) { - case VideoParams::kFormatUnsigned8: + case PixelFormat::U8: return OIIO::TypeDesc::UINT8; - case VideoParams::kFormatUnsigned16: + case PixelFormat::U16: return OIIO::TypeDesc::UINT16; - case VideoParams::kFormatFloat16: + case PixelFormat::F16: return OIIO::TypeDesc::HALF; - case VideoParams::kFormatFloat32: + case PixelFormat::F32: return OIIO::TypeDesc::FLOAT; - case VideoParams::kFormatInvalid: - case VideoParams::kFormatCount: + case PixelFormat::INVALID: + case PixelFormat::FORMAT_COUNT: break; } @@ -54,7 +54,7 @@ public: static void BufferToFrame(OIIO::ImageBuf* buf, Frame* frame); - static VideoParams::Format GetFormatFromOIIOBasetype(OIIO::TypeDesc::BASETYPE type); + static PixelFormat GetFormatFromOIIOBasetype(OIIO::TypeDesc::BASETYPE type); static rational GetPixelAspectRatioFromOIIO(const OIIO::ImageSpec& spec); diff --git a/app/common/qtutils.cpp b/app/common/qtutils.cpp index 46ee40172..12935e350 100644 --- a/app/common/qtutils.cpp +++ b/app/common/qtutils.cpp @@ -22,6 +22,8 @@ #include +#include "common/clamp.h" + namespace olive { int QtUtils::QFontMetricsWidth(QFontMetrics fm, const QString& s) { @@ -172,4 +174,32 @@ void QtUtils::SetComboBoxData(QComboBox *cb, int data) } } +QColor QtUtils::toQColor(const core::Color &i) +{ + QColor c; + + // QColor only supports values from 0.0 to 1.0 and are only used for UI representations + c.setRedF(clamp(i.red(), 0.0f, 1.0f)); + c.setGreenF(clamp(i.green(), 0.0f, 1.0f)); + c.setBlueF(clamp(i.blue(), 0.0f, 1.0f)); + c.setAlphaF(clamp(i.alpha(), 0.0f, 1.0f)); + + return c; +} + +namespace core { + +uint qHash(const core::rational &r, uint seed) +{ + return ::qHash(r.toDouble(), seed); +} + +uint qHash(const core::TimeRange &r, uint seed) +{ + return qHash(r.in(), seed) ^ qHash(r.out(), seed); +} + + +} + } diff --git a/app/common/qtutils.h b/app/common/qtutils.h index 60190b072..cd6c0fcd4 100644 --- a/app/common/qtutils.h +++ b/app/common/qtutils.h @@ -21,6 +21,7 @@ #ifndef QTVERSIONABSTRACTION_H #define QTVERSIONABSTRACTION_H +#include #include #include #include @@ -72,8 +73,21 @@ public: return nullptr; } + static QColor toQColor(const core::Color &c); + }; +namespace core { + +uint qHash(const core::rational& r, uint seed = 0); +uint qHash(const core::TimeRange& r, uint seed = 0); + } +} + +Q_DECLARE_METATYPE(olive::core::rational); +Q_DECLARE_METATYPE(olive::core::Color); +Q_DECLARE_METATYPE(olive::core::TimeRange); + #endif // QTVERSIONABSTRACTION_H diff --git a/app/common/ratiodialog.h b/app/common/ratiodialog.h index 5eacd9de1..b7b5debd0 100644 --- a/app/common/ratiodialog.h +++ b/app/common/ratiodialog.h @@ -23,8 +23,6 @@ #include -#include "common/rational.h" - namespace olive { double GetFloatRatioFromUser(QWidget* parent, diff --git a/app/common/rational.cpp b/app/common/rational.cpp deleted file mode 100644 index 0f9039e7c..000000000 --- a/app/common/rational.cpp +++ /dev/null @@ -1,287 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2022 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 "rational.h" - -namespace olive { - -const rational rational::NaN = rational(0, 0); - -rational rational::fromDouble(const double &flt, bool* ok) -{ - if (qIsNaN(flt)) { - // Return NaN rational - if (ok) *ok = false; - return NaN; - } - - // Use FFmpeg function for the time being - AVRational r = av_d2q(flt, INT_MAX); - - if (r.den == 0) { - // If den == 0, we were unable to convert to a rational - if (ok) { - *ok = false; - } - } else { - // Otherwise, assume we received a real rational - if (ok) { - *ok = true; - } - } - - return r; -} - -rational rational::fromString(const QString &str, bool* ok) -{ - QStringList elements = str.split('/'); - - switch (elements.size()) { - case 1: - return rational(elements.first().toInt(ok)); - case 2: - return rational(elements.at(0).toInt(ok), elements.at(1).toInt(ok)); - default: - // Returns NaN with ok set to false - if (ok) { - *ok = false; - } - return NaN; - } -} - -//Function: convert to double - -double rational::toDouble() const -{ - if (r_.den != 0) { - return av_q2d(r_); - } else { - return qSNaN(); - } -} - -AVRational rational::toAVRational() const -{ - return r_; -} - -#ifdef USE_OTIO -opentime::RationalTime rational::toRationalTime(double framerate) const -{ - // Is this the best way of doing this? - // Olive can store rationals as 0/0 which causes errors in OTIO - opentime::RationalTime time = opentime::RationalTime(r_.num, r_.den == 0 ? 1 : r_.den); - return time.rescaled_to(framerate); -} -#endif - -rational rational::flipped() const -{ - rational r = *this; - r.flip(); - return r; -} - -void rational::flip() -{ - if (!isNull()) { - std::swap(r_.den, r_.num); - FixSigns(); - } -} - -QString rational::toString() const -{ - return QStringLiteral("%1/%2").arg(QString::number(r_.num), QString::number(r_.den)); -} - -void rational::FixSigns() -{ - if (r_.den < 0) { - // Normalize so that denominator is always positive - r_.den = -r_.den; - r_.num = -r_.num; - } else if (r_.den == 0) { - // Normalize to 0/0 (aka NaN) if denominator is zero - r_.num = 0; - } else if (r_.num == 0) { - // Normalize to 0/1 if numerator is zero - r_.den = 1; - } -} - -void rational::Reduce() -{ - av_reduce(&r_.num, &r_.den, r_.num, r_.den, INT_MAX); -} - -//Assignment Operators - -const rational& rational::operator=(const rational &rhs) -{ - r_ = rhs.r_; - return *this; -} - -const rational& rational::operator+=(const rational &rhs) -{ - Q_ASSERT(*this != RATIONAL_MIN && *this != RATIONAL_MAX && rhs != RATIONAL_MIN && rhs != RATIONAL_MAX); - - if (!isNaN()) { - if (rhs.isNaN()) { - *this = NaN; - } else { - r_ = av_add_q(r_, rhs.r_); - FixSigns(); - } - } - - return *this; -} - -const rational& rational::operator-=(const rational &rhs) -{ - Q_ASSERT(*this != RATIONAL_MIN && *this != RATIONAL_MAX && rhs != RATIONAL_MIN && rhs != RATIONAL_MAX); - - if (!isNaN()) { - if (rhs.isNaN()) { - *this = NaN; - } else { - r_ = av_sub_q(r_, rhs.r_); - FixSigns(); - } - } - - return *this; -} - -const rational& rational::operator*=(const rational &rhs) -{ - Q_ASSERT(*this != RATIONAL_MIN && *this != RATIONAL_MAX && rhs != RATIONAL_MIN && rhs != RATIONAL_MAX); - - if (!isNaN()) { - if (rhs.isNaN()) { - *this = NaN; - } else { - r_ = av_mul_q(r_, rhs.r_); - FixSigns(); - } - } - - return *this; -} - -const rational& rational::operator/=(const rational &rhs) -{ - Q_ASSERT(*this != RATIONAL_MIN && *this != RATIONAL_MAX && rhs != RATIONAL_MIN && rhs != RATIONAL_MAX); - - if (!isNaN()) { - if (rhs.isNaN()) { - *this = NaN; - } else { - r_ = av_div_q(r_, rhs.r_); - FixSigns(); - } - } - - return *this; -} - -//Binary math operators - -rational rational::operator+(const rational &rhs) const -{ - rational answer(*this); - answer += rhs; - return answer; -} - -rational rational::operator-(const rational &rhs) const -{ - rational answer(*this); - answer -= rhs; - return answer; -} - -rational rational::operator/(const rational &rhs) const -{ - rational answer(*this); - answer /= rhs; - return answer; -} - -rational rational::operator*(const rational &rhs) const -{ - rational answer(*this); - answer *= rhs; - return answer; -} - -//Relational and equality operators - -bool rational::operator<(const rational &rhs) const -{ - return av_cmp_q(r_, rhs.r_) == -1; -} - -bool rational::operator<=(const rational &rhs) const -{ - int cmp = av_cmp_q(r_, rhs.r_); - return cmp == 0 || cmp == -1; -} - -bool rational::operator>(const rational &rhs) const -{ - return av_cmp_q(r_, rhs.r_) == 1; -} - -bool rational::operator>=(const rational &rhs) const -{ - int cmp = av_cmp_q(r_, rhs.r_); - return cmp == 0 || cmp == 1; -} - -bool rational::operator==(const rational &rhs) const -{ - return av_cmp_q(r_, rhs.r_) == 0; -} - -bool rational::operator!=(const rational &rhs) const -{ - return !(*this == rhs); -} - -uint qHash(const rational &r, uint seed) -{ - return ::qHash(r.toDouble(), seed); -} - -} - -QDebug operator<<(QDebug debug, const olive::rational &r) -{ - if (r.isNaN()) { - return debug.space() << "NaN"; - } else { - return debug.space() << r.toDouble(); - } -} diff --git a/app/common/rational.h b/app/common/rational.h deleted file mode 100644 index e4d0ba9fb..000000000 --- a/app/common/rational.h +++ /dev/null @@ -1,157 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2022 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 RATIONAL_H -#define RATIONAL_H - -extern "C" { -#include -} - -#include -#include -#include - -#ifdef USE_OTIO -#include -#endif - -#include "common/define.h" - -namespace olive { - -class rational -{ -public: - rational(const int &numerator = 0) - { - r_.num = numerator; - r_.den = 1; - } - - rational(const int &numerator, const int &denominator) - { - r_.num = numerator; - r_.den = denominator; - - FixSigns(); - Reduce(); - } - - rational(const rational &rhs) = default; - - rational(const AVRational& r) - { - r_ = r; - - FixSigns(); - } - - static rational fromDouble(const double& flt, bool *ok = nullptr); - static rational fromString(const QString& str, bool* ok = nullptr); - - static const rational NaN; - - //Assignment Operators - const rational& operator=(const rational &rhs); - const rational& operator+=(const rational &rhs); - const rational& operator-=(const rational &rhs); - const rational& operator/=(const rational &rhs); - const rational& operator*=(const rational &rhs); - - //Binary math operators - rational operator+(const rational &rhs) const; - rational operator-(const rational &rhs) const; - rational operator/(const rational &rhs) const; - rational operator*(const rational &rhs) const; - - //Relational and equality operators - bool operator<(const rational &rhs) const; - bool operator<=(const rational &rhs) const; - bool operator>(const rational &rhs) const; - bool operator>=(const rational &rhs) const; - bool operator==(const rational &rhs) const; - bool operator!=(const rational &rhs) const; - - //Unary operators - const rational& operator+() const { return *this; } - rational operator-() const { return rational(r_.num, -r_.den); } - bool operator!() const { return !r_.num; } - - //Function: convert to double - double toDouble() const; - - AVRational toAVRational() const; - -#ifdef USE_OTIO - static rational fromRationalTime(const opentime::RationalTime &t) - { - // Is this the best way to do this? - return fromDouble(t.to_seconds()); - } - - // Convert Olive rationals to opentime rationals with the given framerate (defaults to 24) - opentime::RationalTime toRationalTime(double framerate = 24) const; -#endif - - // Produce "flipped" version - rational flipped() const; - void flip(); - - // Returns whether the rational is valid but equal to zero or not - // - // A NaN is always a null, but a null is not always a NaN - bool isNull() const { return r_.num == 0; } - - // Returns whether this rational is not a valid number (denominator == 0) - bool isNaN() const { return r_.den == 0; } - - const int& numerator() const { return r_.num; } - const int& denominator() const { return r_.den; } - - QString toString() const; - - friend std::ostream& operator<<(std::ostream &out, const rational &value) - { - out << value.r_.num << '/' << value.r_.den; - - return out; - } - -private: - void FixSigns(); - void Reduce(); - - AVRational r_; - -}; - -#define RATIONAL_MIN rational(INT_MIN) -#define RATIONAL_MAX rational(INT_MAX) - -uint qHash(const rational& r, uint seed = 0); - -} - -QDebug operator<<(QDebug debug, const olive::rational& r); - -Q_DECLARE_METATYPE(olive::rational) - -#endif // RATIONAL_H diff --git a/app/common/timecodefunctions.cpp b/app/common/timecodefunctions.cpp deleted file mode 100644 index ca6e8503e..000000000 --- a/app/common/timecodefunctions.cpp +++ /dev/null @@ -1,358 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2022 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 "timecodefunctions.h" - -extern "C" { -#include -} - -#include -#include - -#include "config/config.h" - -namespace olive { - -QString padded(int64_t arg, int padding) { - return QStringLiteral("%1").arg(arg, padding, 10, QChar('0')); -} - -QString Timecode::time_to_timecode(const rational &time, const rational &timebase, const Timecode::Display &display, bool show_plus_if_positive) -{ - if (timebase.isNull()) { - return QStringLiteral("INVALID TIMEBASE"); - } - - double time_dbl = time.toDouble(); - - switch (display) { - case kTimecodeNonDropFrame: - case kTimecodeDropFrame: - case kTimecodeSeconds: - { - QString prefix; - - if (time_dbl < 0) { - prefix = "-"; - } else if (show_plus_if_positive) { - prefix = "+"; - } - - if (display == kTimecodeSeconds) { - time_dbl = qAbs(time_dbl); - - int64_t total_seconds = qFloor(time_dbl); - - int64_t hours = total_seconds / 3600; - int64_t mins = total_seconds / 60 - hours * 60; - int64_t secs = total_seconds - mins * 60; - int64_t fraction = qRound64((time_dbl - static_cast(total_seconds)) * 1000); - - return QStringLiteral("%1%2:%3:%4.%5").arg(prefix, - padded(hours, 2), - padded(mins, 2), - padded(secs, 2), - padded(fraction, 3)); - } else { - // Determine what symbol to separate frames (";" is used for drop frame, ":" is non-drop frame) - QString frame_token; - double frame_rate = timebase.flipped().toDouble(); - int rounded_frame_rate = qRound(frame_rate); - int64_t frames, secs, mins, hours; - int64_t f = qAbs(time_to_timestamp(time, timebase)); - - if (display == kTimecodeDropFrame && TimebaseIsDropFrame(timebase)) { - frame_token = ";"; - - /** - * CONVERT A FRAME NUMBER TO DROP FRAME TIMECODE - * - * Code by David Heidelberger, adapted from Andrew Duncan, further adapted for Olive by Olive Team - * Given an int called framenumber and a double called framerate - * Framerate should be 29.97, 59.94, or 23.976, otherwise the calculations will be off. - */ - - // If frame number is greater than 24 hrs, next operation will rollover clock - f %= (qRound(frame_rate*3600)*24); - - // Number of frames per ten minutes - int64_t framesPer10Minutes = qRound(frame_rate * 600); - int64_t d = f / framesPer10Minutes; - int64_t m = f % framesPer10Minutes; - - // Number of frames to drop on the minute marks is the nearest integer to 6% of the framerate - int64_t dropFrames = qRound(frame_rate * (2.0/30.0)); - - // Number of frames per minute is the round of the framerate * 60 minus the number of dropped frames - f += dropFrames*9*d; - if (m > dropFrames) { - f += dropFrames * ((m - dropFrames) / (qRound(frame_rate)*60 - dropFrames)); - } - } else { - frame_token = ":"; - } - - // non-drop timecode - hours = f / (3600*rounded_frame_rate); - mins = f / (60*rounded_frame_rate) % 60; - secs = f / rounded_frame_rate % 60; - frames = f % rounded_frame_rate; - - return QStringLiteral("%1%2:%3:%4%5%6").arg(prefix, - padded(hours, 2), - padded(mins, 2), - padded(secs, 2), - frame_token, - padded(frames, 2)); - } - } - case kFrames: - return QString::number(time_to_timestamp(time, timebase)); - case kMilliseconds: - return QString::number(qRound(time_dbl * 1000)); - } - - return QStringLiteral("INVALID TIMECODE MODE"); -} - -int64_t StrToInt64EmptyTolerant(const QString &s, bool *ok) -{ - if (s.isEmpty()) { - if (ok) *ok = true; - return 0; - } else { - return s.toLongLong(ok); - } -} - -double StrToDoubleEmptyTolerant(const QString &s, bool *ok) -{ - if (s.isEmpty()) { - if (ok) *ok = true; - return 0; - } else { - return s.toDouble(ok); - } -} - -rational Timecode::timecode_to_time(const QString &timecode, const rational &timebase, const Timecode::Display &display, bool *ok) -{ - if (timecode.isEmpty()) { - goto err_fatal; - } - - switch (display) { - case kTimecodeNonDropFrame: - case kTimecodeDropFrame: - case kTimecodeSeconds: - { - QStringList timecode_split = timecode.split(QRegularExpression("(:)|(;)")); - - const int element_count = display == kTimecodeSeconds ? 3 : 4; - - // Remove excess tokens (we're only interested in HH:MM:SS.FF) - while (timecode_split.size() > element_count) { - timecode_split.removeLast(); - } - - // For easier index calculations, ensure minimum size - while (timecode_split.size() < element_count) { - timecode_split.prepend(QString()); - } - - bool negative = timecode.trimmed().startsWith('-'); - - double frame_rate = timebase.flipped().toDouble(); - int rounded_frame_rate = qRound(frame_rate); - - bool valid; - rational time; - - int64_t hours = StrToInt64EmptyTolerant(timecode_split.at(0), &valid); - if (!valid) goto err_fatal; - int64_t mins = StrToInt64EmptyTolerant(timecode_split.at(1), &valid); - if (!valid) goto err_fatal; - - if (display == kTimecodeSeconds) { - double secs = StrToDoubleEmptyTolerant(timecode_split.at(2), &valid); - if (!valid) goto err_fatal; - - time = rational::fromDouble(hours * 3600 + mins * 60 + secs); - } else { - int64_t secs = StrToInt64EmptyTolerant(timecode_split.at(2), &valid); - if (!valid) goto err_fatal; - int64_t frames = StrToInt64EmptyTolerant(timecode_split.at(3), &valid); - if (!valid) goto err_fatal; - - int64_t sec_count = (hours*3600 + mins*60 + secs); - int64_t frame_count = sec_count*rounded_frame_rate + frames; - - if (display == kTimecodeDropFrame && TimebaseIsDropFrame(timebase)) { - - // Number of frames to drop on the minute marks is the nearest integer to 6% of the framerate - int64_t dropFrames = qRound64(frame_rate * (2.0/30.0)); - - // d and m need to be calculated from - int64_t real_fr_ts = qRound64(static_cast(sec_count)*frame_rate) + frames; - - int64_t framesPer10Minutes = qRound(frame_rate * 600); - int64_t d = real_fr_ts / framesPer10Minutes; - int64_t m = real_fr_ts % framesPer10Minutes; - - if (m > dropFrames) { - frame_count -= dropFrames * ((m - dropFrames) / (qRound(frame_rate)*60 - dropFrames)); - } - frame_count -= dropFrames*9*d; - } - - time = timestamp_to_time(frame_count, timebase); - } - - if (ok) *ok = true; - - if (negative) time = -time; - - return time; - } - case kMilliseconds: - { - bool valid; - double timecode_secs = timecode.toDouble(&valid); - - if (valid) { - // Convert milliseconds to seconds - timecode_secs *= 0.001; - - // Convert seconds to rational - return rational::fromDouble(timecode_secs, ok); - } else { - goto err_fatal; - } - } - case kFrames: - { - bool valid; - int64_t ts = timecode.toLongLong(&valid); - if (!valid) { - goto err_fatal; - } - - if (ok) *ok = true; - return timestamp_to_time(ts, timebase); - } - } - -err_fatal: - if (ok) *ok = false; - return 0; -} - -rational Timecode::snap_time_to_timebase(const rational &time, const rational &timebase, Rounding floor) -{ - // Just convert to a timestamp in timebase units and back - int64_t timestamp = time_to_timestamp(time, timebase, floor); - - return timestamp_to_time(timestamp, timebase); -} - -rational Timecode::timestamp_to_time(const int64_t ×tamp, const rational &timebase) -{ - int64_t num = int64_t(timebase.numerator()) * timestamp; - int64_t den = timebase.denominator(); - - int num_r, den_r; - - av_reduce(&num_r, &den_r, num, den, INT_MAX); - - return rational(num_r, den_r); -} - -bool Timecode::TimebaseIsDropFrame(const rational &timebase) -{ - return (timebase.numerator() != 1); -} - -QString Timecode::TimeToString(int64_t ms) -{ - int64_t total_seconds = ms / 1000; - int64_t ss = total_seconds % 60; - int64_t mm = (total_seconds / 60) % 60; - int64_t hh = total_seconds / 3600; - - return QStringLiteral("%1:%2:%3") - .arg(hh, 2, 10, QChar('0')) - .arg(mm, 2, 10, QChar('0')) - .arg(ss, 2, 10, QChar('0')); -} - -int64_t Timecode::time_to_timestamp(const rational &time, const rational &timebase, Rounding floor) -{ - return time_to_timestamp(time.toDouble(), timebase, floor); -} - -int64_t Timecode::time_to_timestamp(const double &time, const rational &timebase, Rounding floor) -{ - const double d = time * timebase.flipped().toDouble(); - - if (std::isnan(d)) { - return 0; - } - - const double eps = 0.000000000001; - - switch (floor) { - case kRound: - default: - return qRound64(d); - case kFloor: - if (d > qCeil(d)-eps) { - return qCeil(d); - } else { - return qFloor(d); - } - case kCeil: - if (d < qFloor(d)+eps) { - return qFloor(d); - } else { - return qCeil(d); - } - } -} - -int64_t Timecode::rescale_timestamp(const int64_t &ts, const rational &source, const rational &dest) -{ - if (source == dest) { - return ts; - } - - return av_rescale_q(ts, source.toAVRational(), dest.toAVRational()); -} - -int64_t Timecode::rescale_timestamp_ceil(const int64_t &ts, const rational &source, const rational &dest) -{ - if (source == dest) { - return ts; - } - - return av_rescale_q_rnd(ts, source.toAVRational(), dest.toAVRational(), AV_ROUND_UP); -} - -} diff --git a/app/common/timecodefunctions.h b/app/common/timecodefunctions.h deleted file mode 100644 index 0cdabd242..000000000 --- a/app/common/timecodefunctions.h +++ /dev/null @@ -1,80 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2022 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 TIMECODEFUNCTIONS_H -#define TIMECODEFUNCTIONS_H - -#include - -#include "common/rational.h" - -namespace olive { - -/** - * @brief Functions for converting times/timecodes/timestamps - * - * Olive uses the following terminology through its code: - * - * `time` - time in seconds presented in a rational form - * `timebase` - the base time unit of an audio/video stream in seconds - * `timestamp` - an integer representation of a time in timebase units (in many cases is used like a frame number) - * `timecode` a user-friendly string representation of a time according to Timecode::Display - */ -class Timecode { -public: - enum Display { - kTimecodeDropFrame, - kTimecodeNonDropFrame, - kTimecodeSeconds, - kFrames, - kMilliseconds - }; - - enum Rounding { - kCeil, - kFloor, - kRound - }; - - /** - * @brief Convert a timestamp (according to a rational timebase) to a user-friendly string representation - */ - static QString time_to_timecode(const rational& time, const rational& timebase, const Display &display, bool show_plus_if_positive = false); - static rational timecode_to_time(const QString& timecode, const rational& timebase, const Display& display, bool *ok = nullptr); - - static rational snap_time_to_timebase(const rational& time, const rational& timebase, Rounding floor = kRound); - - static int64_t time_to_timestamp(const rational& time, const rational& timebase, Rounding floor = kRound); - static int64_t time_to_timestamp(const double& time, const rational& timebase, Rounding floor = kRound); - - static int64_t rescale_timestamp(const int64_t& ts, const rational& source, const rational& dest); - static int64_t rescale_timestamp_ceil(const int64_t& ts, const rational& source, const rational& dest); - - static rational timestamp_to_time(const int64_t& timestamp, const rational& timebase); - - static bool TimebaseIsDropFrame(const rational& timebase); - - static QString TimeToString(int64_t ms); - -}; - -} - -#endif // TIMECODEFUNCTIONS_H diff --git a/app/common/timerange.cpp b/app/common/timerange.cpp deleted file mode 100644 index 8a8b45e5c..000000000 --- a/app/common/timerange.cpp +++ /dev/null @@ -1,393 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2022 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 "timerange.h" - -#include -#include - -namespace olive { - -TimeRange::TimeRange(const rational &in, const rational &out) : - in_(in), - out_(out) -{ - normalize(); -} - -const rational &TimeRange::in() const -{ - return in_; -} - -const rational &TimeRange::out() const -{ - return out_; -} - -const rational &TimeRange::length() const -{ - Q_ASSERT(!length_.isNaN()); - return length_; -} - -void TimeRange::set_in(const rational &in) -{ - in_ = in; - normalize(); -} - -void TimeRange::set_out(const rational &out) -{ - out_ = out; - normalize(); -} - -void TimeRange::set_range(const rational &in, const rational &out) -{ - in_ = in; - out_ = out; - normalize(); -} - -bool TimeRange::operator==(const TimeRange &r) const -{ - return in() == r.in() && out() == r.out(); -} - -bool TimeRange::operator!=(const TimeRange &r) const -{ - return in() != r.in() || out() != r.out(); -} - -bool TimeRange::OverlapsWith(const TimeRange &a, bool in_inclusive, bool out_inclusive) const -{ - bool doesnt_overlap_in = (in_inclusive) ? (a.out() < in()) : (a.out() <= in()); - - bool doesnt_overlap_out = (out_inclusive) ? (a.in() > out()) : (a.in() >= out()); - - return !doesnt_overlap_in && !doesnt_overlap_out; -} - -TimeRange TimeRange::Combined(const TimeRange &a) const -{ - return Combine(a, *this); -} - -bool TimeRange::Contains(const TimeRange &compare, bool in_inclusive, bool out_inclusive) const -{ - bool contains_in = (in_inclusive) ? (compare.in() >= in()) : (compare.in() > in()); - - bool contains_out = (out_inclusive) ? (compare.out() <= out()) : (compare.out() < out()); - - return contains_in && contains_out; -} - -bool TimeRange::Contains(const rational &r) const -{ - return r >= in_ && r < out_; -} - -TimeRange TimeRange::Combine(const TimeRange &a, const TimeRange &b) -{ - return TimeRange(qMin(a.in(), b.in()), - qMax(a.out(), b.out())); -} - -TimeRange TimeRange::Intersected(const TimeRange &a) const -{ - return Intersect(a, *this); -} - -TimeRange TimeRange::Intersect(const TimeRange &a, const TimeRange &b) -{ - return TimeRange(qMax(a.in(), b.in()), - qMin(a.out(), b.out())); -} - -TimeRange TimeRange::operator+(const rational &rhs) const -{ - TimeRange answer(*this); - answer += rhs; - return answer; -} - -TimeRange TimeRange::operator-(const rational &rhs) const -{ - TimeRange answer(*this); - answer -= rhs; - return answer; -} - -const TimeRange &TimeRange::operator+=(const rational &rhs) -{ - set_range(in_ + rhs, out_ + rhs); - - return *this; -} - -const TimeRange &TimeRange::operator-=(const rational &rhs) -{ - set_range(in_ - rhs, out_ - rhs); - - return *this; -} - -std::list TimeRange::Split(const int &chunk_size) const -{ - std::list split_ranges; - - int start_time = qFloor(this->in().toDouble() / static_cast(chunk_size)) * chunk_size; - int end_time = qCeil(this->out().toDouble() / static_cast(chunk_size)) * chunk_size; - - for (int i=start_time; iin(), rational(i)), - qMin(this->out(), rational(i + chunk_size)))); - } - - return split_ranges; -} - -void TimeRange::normalize() -{ - // If `out` is earlier than `in`, swap them - if (out_ < in_) - { - std::swap(out_, in_); - } - - // Calculate length - if (out_ == RATIONAL_MIN || out_ == RATIONAL_MAX || in_ == RATIONAL_MIN || in_ == RATIONAL_MAX) { - length_ = rational::NaN; - } else { - length_ = out_ - in_; - } -} - -void TimeRangeList::insert(const TimeRangeList &list_to_add) -{ - for (auto it=list_to_add.cbegin(); it!=list_to_add.cend(); it++) { - insert(*it); - } -} - -void TimeRangeList::insert(TimeRange range_to_add) -{ - // See if list contains this range - if (contains(range_to_add)) { - return; - } - - // Does not contain range, so we'll almost certainly be adding it in some way - for (int i=0;i= range.out()) { - // No intersect - continue; - } else { - // Crop the time range to the range and add it to the list - TimeRange cropped(qMax(range.in(), compare.in()), - qMin(range.out(), compare.out())); - - intersect_list.insert(cropped); - } - } - - return intersect_list; -} - -uint qHash(const TimeRange &r, uint seed) -{ - return qHash(r.in(), seed) ^ qHash(r.out(), seed); -} - -TimeRangeListFrameIterator::TimeRangeListFrameIterator() : - TimeRangeListFrameIterator(TimeRangeList(), rational::NaN) -{ -} - -TimeRangeListFrameIterator::TimeRangeListFrameIterator(const TimeRangeList &list, const rational &timebase) : - list_(list), - timebase_(timebase), - range_index_(-1), - size_(-1), - frame_index_(0), - custom_range_(false) -{ - if (!list_.isEmpty() && timebase_.isNull()) { - qCritical() << "TimeRangeListFrameIterator created with null timebase but non-empty list, this will likely lead to infinite loops"; - } - - UpdateIndexIfNecessary(); -} - -rational TimeRangeListFrameIterator::Snap(const rational &r) const -{ - return Timecode::snap_time_to_timebase(r, timebase_, Timecode::kFloor); -} - -bool TimeRangeListFrameIterator::GetNext(rational *out) -{ - if (!HasNext()) { - return false; - } - - // Output current value - *out = current_; - - // Determine next value by adding timebase - current_ += timebase_; - - // If this time is outside the current range, jump to the next one - UpdateIndexIfNecessary(); - - // Increment frame index - frame_index_++; - - return true; -} - -bool TimeRangeListFrameIterator::HasNext() const -{ - return range_index_ < list_.size(); -} - -int TimeRangeListFrameIterator::size() -{ - if (size_ == -1) { - // Size isn't calculated automatically for optimization, so we'll calculate it now - size_ = 0; - - foreach (const TimeRange &range, list_) { - rational start = Snap(range.in()); - rational end = Timecode::snap_time_to_timebase(range.out(), timebase_, Timecode::kFloor); - - if (end == range.out()) { - end -= timebase_; - } - - int64_t start_ts = Timecode::time_to_timestamp(start, timebase_); - int64_t end_ts = Timecode::time_to_timestamp(end, timebase_); - - size_ += 1 + (end_ts - start_ts); - } - } - - return size_; -} - -void TimeRangeListFrameIterator::UpdateIndexIfNecessary() -{ - while (range_index_ < list_.size() && (range_index_ == -1 || current_ >= list_.at(range_index_).out())) { - range_index_++; - - if (range_index_ < list_.size()) { - current_ = Snap(list_.at(range_index_).in()); - } - } -} - -} - -QDebug operator<<(QDebug debug, const olive::TimeRange &r) -{ - debug.nospace() << r.in().toDouble() << " - " << r.out().toDouble(); - return debug.space(); -} - -QDebug operator<<(QDebug debug, const olive::TimeRangeList &r) -{ - debug << r.internal_array(); - return debug.space(); -} diff --git a/app/common/timerange.h b/app/common/timerange.h deleted file mode 100644 index 8fc55872e..000000000 --- a/app/common/timerange.h +++ /dev/null @@ -1,298 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2022 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 TIMERANGE_H -#define TIMERANGE_H - -#include "rational.h" -#include "timecodefunctions.h" - -namespace olive { - -class TimeRange { -public: - TimeRange() = default; - TimeRange(const rational& in, const rational& out); - - const rational& in() const; - const rational& out() const; - const rational& length() const; - - void set_in(const rational& in); - void set_out(const rational& out); - void set_range(const rational& in, const rational& out); - - bool operator==(const TimeRange& r) const; - bool operator!=(const TimeRange& r) const; - - bool OverlapsWith(const TimeRange& a, bool in_inclusive = true, bool out_inclusive = true) const; - bool Contains(const TimeRange& a, bool in_inclusive = true, bool out_inclusive = true) const; - bool Contains(const rational& r) const; - - TimeRange Combined(const TimeRange& a) const; - static TimeRange Combine(const TimeRange &a, const TimeRange &b); - TimeRange Intersected(const TimeRange& a) const; - static TimeRange Intersect(const TimeRange &a, const TimeRange &b); - - TimeRange operator+(const rational& rhs) const; - TimeRange operator-(const rational& rhs) const; - - const TimeRange& operator+=(const rational &rhs); - const TimeRange& operator-=(const rational &rhs); - - std::list Split(const int &chunk_size) const; - -private: - void normalize(); - - rational in_; - rational out_; - rational length_; - -}; - -class TimeRangeList { -public: - TimeRangeList() = default; - - TimeRangeList(std::initializer_list r) : - array_(r) - { - } - - void insert(const TimeRangeList &list_to_add); - void insert(TimeRange range_to_add); - - void remove(const TimeRange& remove); - void remove(const TimeRangeList &list); - - template - static void util_remove(QVector *list, const TimeRange &remove) - { - int sz = list->size(); - - for (int i=0;iremoveAt(i); - i--; - sz--; - } else if (compare.Contains(remove, false, false)) { - // The remove range is within this element, only choice is to split the element into two - T new_range = compare; - new_range.set_in(remove.out()); - compare.set_out(remove.in()); - list->append(new_range); - break; - } else if (compare.in() < remove.in() && compare.out() > remove.in()) { - // This element's out point overlaps the range's in, we'll trim it - compare.set_out(remove.in()); - } else if (compare.in() < remove.out() && compare.out() > remove.out()) { - // This element's in point overlaps the range's out, we'll trim it - compare.set_in(remove.out()); - } - } - } - - bool contains(const TimeRange& range, bool in_inclusive = true, bool out_inclusive = true) const; - - bool contains(const rational &r) const - { - for (const TimeRange &range : array_) { - if (range.Contains(r)) { - return true; - } - } - - return false; - } - - bool OverlapsWith(const TimeRange& r, bool in_inclusive = true, bool out_inclusive = true) const - { - for (const TimeRange &range : array_) { - if (range.OverlapsWith(r, in_inclusive, out_inclusive)) { - return true; - } - } - - return false; - } - - bool isEmpty() const - { - return array_.isEmpty(); - } - - void clear() - { - array_.clear(); - } - - int size() const - { - return array_.size(); - } - - void shift(const rational& diff); - - void trim_in(const rational& diff); - - void trim_out(const rational& diff); - - TimeRangeList Intersects(const TimeRange& range) const; - - using const_iterator = QVector::const_iterator; - - const_iterator begin() const - { - return array_.constBegin(); - } - - const_iterator end() const - { - return array_.constEnd(); - } - - const_iterator cbegin() const - { - return begin(); - } - - const_iterator cend() const - { - return end(); - } - - const TimeRange& first() const - { - return array_.first(); - } - - const TimeRange& last() const - { - return array_.last(); - } - - const TimeRange& at(int index) const - { - return array_.at(index); - } - - const QVector& internal_array() const - { - return array_; - } - - bool operator==(const TimeRangeList &rhs) const - { - return array_ == rhs.array_; - } - -private: - QVector array_; - -}; - -class TimeRangeListFrameIterator -{ -public: - TimeRangeListFrameIterator(); - TimeRangeListFrameIterator(const TimeRangeList &list, const rational &timebase); - - rational Snap(const rational &r) const; - - bool GetNext(rational *out); - - bool HasNext() const; - - QVector ToVector() const - { - TimeRangeListFrameIterator copy(list_, timebase_); - QVector times; - rational r; - while (copy.GetNext(&r)) { - times.append(r); - } - return times; - } - - int size(); - - void reset() - { - *this = TimeRangeListFrameIterator(); - } - - void insert(const TimeRange &range) - { - list_.insert(range); - } - - void insert(const TimeRangeList &list) - { - list_.insert(list); - } - - bool IsCustomRange() const - { - return custom_range_; - } - - void SetCustomRange(bool e) - { - custom_range_ = e; - } - - int frame_index() const - { - return frame_index_; - } - -private: - void UpdateIndexIfNecessary(); - - TimeRangeList list_; - - rational timebase_; - - rational current_; - - int range_index_; - - int size_; - - int frame_index_; - - bool custom_range_; - -}; - -uint qHash(const TimeRange& r, uint seed = 0); - -} - -QDebug operator<<(QDebug debug, const olive::TimeRange& r); -QDebug operator<<(QDebug debug, const olive::TimeRangeList& r); - -Q_DECLARE_METATYPE(olive::TimeRange) - -#endif // TIMERANGE_H diff --git a/app/config/config.cpp b/app/config/config.cpp index 82d358a28..51d97eb2b 100644 --- a/app/config/config.cpp +++ b/app/config/config.cpp @@ -160,8 +160,8 @@ void Config::SetDefaults() SetEntryInternal(QStringLiteral("DefaultSequenceAudioLayout"), NodeValue::kInt, QVariant::fromValue(static_cast(AV_CH_LAYOUT_STEREO))); // Online/offline settings - SetEntryInternal(QStringLiteral("OnlinePixelFormat"), NodeValue::kInt, VideoParams::kFormatFloat32); - SetEntryInternal(QStringLiteral("OfflinePixelFormat"), NodeValue::kInt, VideoParams::kFormatFloat16); + SetEntryInternal(QStringLiteral("OnlinePixelFormat"), NodeValue::kInt, PixelFormat::F32); + SetEntryInternal(QStringLiteral("OfflinePixelFormat"), NodeValue::kInt, PixelFormat::F16); SetEntryInternal(QStringLiteral("MarkerColor"), NodeValue::kInt, ColorCoding::kLime); } diff --git a/app/config/config.h b/app/config/config.h index c3c9d2d04..4179858dc 100644 --- a/app/config/config.h +++ b/app/config/config.h @@ -25,7 +25,6 @@ #include #include -#include "common/timecodefunctions.h" #include "node/value.h" namespace olive { diff --git a/app/core.cpp b/app/core.cpp index 72d84f5f5..81c4f2b48 100644 --- a/app/core.cpp +++ b/app/core.cpp @@ -105,7 +105,7 @@ Core *Core::instance() void Core::DeclareTypesForQt() { - qRegisterMetaType(); + qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); @@ -114,8 +114,8 @@ void Core::DeclareTypesForQt() qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); diff --git a/app/core.h b/app/core.h index 297db9a47..6ac219940 100644 --- a/app/core.h +++ b/app/core.h @@ -21,13 +21,12 @@ #ifndef CORE_H #define CORE_H +#include #include #include #include #include -#include "common/rational.h" -#include "common/timecodefunctions.h" #include "node/project/footage/footage.h" #include "node/project/project.h" #include "node/project/projectviewmodel.h" diff --git a/app/dialog/color/colordialog.h b/app/dialog/color/colordialog.h index bdd517e50..00edb730b 100644 --- a/app/dialog/color/colordialog.h +++ b/app/dialog/color/colordialog.h @@ -24,7 +24,6 @@ #include #include "node/color/colormanager/colormanager.h" -#include "render/color.h" #include "render/managedcolor.h" #include "widget/colorwheel/colorgradientwidget.h" #include "widget/colorwheel/colorspacechooser.h" diff --git a/app/dialog/export/export.cpp b/app/dialog/export/export.cpp index 46f74eb7c..d98935e01 100644 --- a/app/dialog/export/export.cpp +++ b/app/dialog/export/export.cpp @@ -626,7 +626,7 @@ void ExportDialog::SetDefaults() video_tab_->height_slider()->SetDefaultValue(vp.height()); video_tab_->SetSelectedFrameRate(vp.frame_rate()); video_tab_->pixel_aspect_combobox()->SetPixelAspectRatio(vp.pixel_aspect_ratio()); - video_tab_->pixel_format_field()->SetPixelFormat(static_cast(OLIVE_CONFIG("OnlinePixelFormat").toInt())); + video_tab_->pixel_format_field()->SetPixelFormat(static_cast(OLIVE_CONFIG("OnlinePixelFormat").toInt())); video_tab_->interlaced_combobox()->SetInterlaceMode(vp.interlacing()); audio_tab_->sample_rate_combobox()->SetSampleRate(ap.sample_rate()); audio_tab_->sample_format_combobox()->SetAttemptToRestoreFormat(false); diff --git a/app/dialog/export/exportvideotab.h b/app/dialog/export/exportvideotab.h index c401721e9..061dea64f 100644 --- a/app/dialog/export/exportvideotab.h +++ b/app/dialog/export/exportvideotab.h @@ -26,7 +26,6 @@ #include #include "common/qtutils.h" -#include "common/rational.h" #include "dialog/export/codec/cineformsection.h" #include "dialog/export/codec/codecstack.h" #include "dialog/export/codec/h264section.h" diff --git a/app/dialog/keyframeproperties/keyframeproperties.cpp b/app/dialog/keyframeproperties/keyframeproperties.cpp index 37edfe771..53d7558c2 100644 --- a/app/dialog/keyframeproperties/keyframeproperties.cpp +++ b/app/dialog/keyframeproperties/keyframeproperties.cpp @@ -24,7 +24,6 @@ #include #include "core.h" -#include "common/timecodefunctions.h" #include "widget/keyframeview/keyframeviewundo.h" #include "widget/nodeparamview/nodeparamviewundo.h" diff --git a/app/dialog/sequence/sequence.cpp b/app/dialog/sequence/sequence.cpp index 3f78e570c..18b509311 100644 --- a/app/dialog/sequence/sequence.cpp +++ b/app/dialog/sequence/sequence.cpp @@ -33,7 +33,6 @@ #include "core.h" #include "common/channellayout.h" #include "common/qtutils.h" -#include "common/rational.h" #include "undo/undostack.h" namespace olive { diff --git a/app/dialog/sequence/sequencedialogparametertab.cpp b/app/dialog/sequence/sequencedialogparametertab.cpp index a277717ac..9022c3543 100644 --- a/app/dialog/sequence/sequencedialogparametertab.cpp +++ b/app/dialog/sequence/sequencedialogparametertab.cpp @@ -141,7 +141,7 @@ void SequenceDialogParameterTab::UpdatePreviewResolutionLabel() { VideoParams test_param(GetSelectedVideoWidth(), GetSelectedVideoHeight(), - VideoParams::kFormatInvalid, + PixelFormat::INVALID, VideoParams::kInternalChannelCount, rational(1), VideoParams::kInterlaceNone, diff --git a/app/dialog/sequence/sequencedialogparametertab.h b/app/dialog/sequence/sequencedialogparametertab.h index 97a5f24a7..0efef7e7c 100644 --- a/app/dialog/sequence/sequencedialogparametertab.h +++ b/app/dialog/sequence/sequencedialogparametertab.h @@ -59,7 +59,7 @@ public: return preview_resolution_field_->GetDivider(); } - VideoParams::Format GetSelectedPreviewFormat() const + PixelFormat GetSelectedPreviewFormat() const { return preview_format_field_->GetPixelFormat(); } diff --git a/app/dialog/sequence/sequencedialogpresettab.cpp b/app/dialog/sequence/sequencedialogpresettab.cpp index 68446fd16..e3a572936 100644 --- a/app/dialog/sequence/sequencedialogpresettab.cpp +++ b/app/dialog/sequence/sequencedialogpresettab.cpp @@ -100,7 +100,7 @@ QTreeWidgetItem* SequenceDialogPresetTab::CreateFolder(const QString &name) QTreeWidgetItem *SequenceDialogPresetTab::CreateHDPresetFolder(const QString &name, int width, int height, int divider) { - const VideoParams::Format default_format = static_cast(OLIVE_CONFIG("OfflinePixelFormat").toInt()); + const PixelFormat default_format = static_cast(OLIVE_CONFIG("OfflinePixelFormat").toInt()); const bool default_autocache = false; QTreeWidgetItem* parent = CreateFolder(name); AddStandardItem(parent, std::make_shared(tr("%1 23.976 FPS").arg(name), @@ -163,7 +163,7 @@ QTreeWidgetItem *SequenceDialogPresetTab::CreateHDPresetFolder(const QString &na QTreeWidgetItem *SequenceDialogPresetTab::CreateSDPresetFolder(const QString &name, int width, int height, const rational& frame_rate, const rational &standard_par, const rational &wide_par, int divider) { - const VideoParams::Format default_format = static_cast(OLIVE_CONFIG("OfflinePixelFormat").toInt()); + const PixelFormat default_format = static_cast(OLIVE_CONFIG("OfflinePixelFormat").toInt()); const bool default_autocache = false; QTreeWidgetItem* parent = CreateFolder(name); preset_tree_->addTopLevelItem(parent); diff --git a/app/dialog/sequence/sequencepreset.h b/app/dialog/sequence/sequencepreset.h index e8657812f..2a2f5699b 100644 --- a/app/dialog/sequence/sequencepreset.h +++ b/app/dialog/sequence/sequencepreset.h @@ -21,9 +21,9 @@ #ifndef SEQUENCEPARAM_H #define SEQUENCEPARAM_H +#include #include -#include "common/rational.h" #include "common/xmlutils.h" #include "dialog/sequence/presetmanager.h" #include "render/videoparams.h" @@ -43,7 +43,7 @@ public: int sample_rate, uint64_t channel_layout, int preview_divider, - VideoParams::Format preview_format, + PixelFormat preview_format, bool preview_autocache) : width_(width), height_(height), @@ -69,9 +69,9 @@ public: } else if (reader->name() == QStringLiteral("height")) { height_ = reader->readElementText().toInt(); } else if (reader->name() == QStringLiteral("framerate")) { - frame_rate_ = rational::fromString(reader->readElementText()); + frame_rate_ = rational::fromString(reader->readElementText().toStdString()); } else if (reader->name() == QStringLiteral("pixelaspect")) { - pixel_aspect_ = rational::fromString(reader->readElementText()); + pixel_aspect_ = rational::fromString(reader->readElementText().toStdString()); } else if (reader->name() == QStringLiteral("interlacing")) { interlacing_ = static_cast(reader->readElementText().toInt()); } else if (reader->name() == QStringLiteral("samplerate")) { @@ -81,7 +81,7 @@ public: } else if (reader->name() == QStringLiteral("divider")) { preview_divider_ = reader->readElementText().toInt(); } else if (reader->name() == QStringLiteral("format")) { - preview_format_ = static_cast(reader->readElementText().toInt()); + preview_format_ = static_cast(reader->readElementText().toInt()); } else if (reader->name() == QStringLiteral("autocache")) { preview_autocache_ = reader->readElementText().toInt(); } else { @@ -95,8 +95,8 @@ public: writer->writeTextElement(QStringLiteral("name"), GetName()); writer->writeTextElement(QStringLiteral("width"), QString::number(width_)); writer->writeTextElement(QStringLiteral("height"), QString::number(height_)); - writer->writeTextElement(QStringLiteral("framerate"), frame_rate_.toString()); - writer->writeTextElement(QStringLiteral("pixelaspect"), pixel_aspect_.toString()); + writer->writeTextElement(QStringLiteral("framerate"), QString::fromStdString(frame_rate_.toString())); + writer->writeTextElement(QStringLiteral("pixelaspect"), QString::fromStdString(pixel_aspect_.toString())); writer->writeTextElement(QStringLiteral("interlacing_"), QString::number(interlacing_)); writer->writeTextElement(QStringLiteral("samplerate"), QString::number(sample_rate_)); writer->writeTextElement(QStringLiteral("chlayout"), QString::number(channel_layout_)); @@ -145,7 +145,7 @@ public: return preview_divider_; } - VideoParams::Format preview_format() const + PixelFormat preview_format() const { return preview_format_; } @@ -164,7 +164,7 @@ private: int sample_rate_; uint64_t channel_layout_; int preview_divider_; - VideoParams::Format preview_format_; + PixelFormat preview_format_; bool preview_autocache_; }; diff --git a/app/node/filter/stroke/stroke.cpp b/app/node/filter/stroke/stroke.cpp index 389edb53b..858f26102 100644 --- a/app/node/filter/stroke/stroke.cpp +++ b/app/node/filter/stroke/stroke.cpp @@ -20,7 +20,6 @@ #include "stroke.h" -#include "render/color.h" #include "widget/slider/floatslider.h" namespace olive { diff --git a/app/node/generator/polygon/polygon.cpp b/app/node/generator/polygon/polygon.cpp index b482392d6..4f71f3336 100644 --- a/app/node/generator/polygon/polygon.cpp +++ b/app/node/generator/polygon/polygon.cpp @@ -90,7 +90,7 @@ void PolygonGenerator::Retranslate() ShaderJob PolygonGenerator::GetGenerateJob(const NodeValueRow &value, const VideoParams ¶ms) const { VideoParams p = params; - p.set_format(VideoParams::kFormatUnsigned8); + p.set_format(PixelFormat::U8); auto job = Texture::Job(p, GenerateJob(value)); // Conversion to RGB diff --git a/app/node/generator/solid/solid.cpp b/app/node/generator/solid/solid.cpp index d485a48f9..4674ab893 100644 --- a/app/node/generator/solid/solid.cpp +++ b/app/node/generator/solid/solid.cpp @@ -20,8 +20,6 @@ #include "solid.h" -#include "render/color.h" - namespace olive { const QString SolidGenerator::kColorInput = QStringLiteral("color_in"); diff --git a/app/node/generator/text/textv2.cpp b/app/node/generator/text/textv2.cpp index 7cf82cd83..5689b342a 100644 --- a/app/node/generator/text/textv2.cpp +++ b/app/node/generator/text/textv2.cpp @@ -97,7 +97,7 @@ void TextGeneratorV2::Value(const NodeValueRow &value, const NodeGlobals &global if (!value[kTextInput].toString().isEmpty()) { GenerateJob job(value); auto text_params = globals.vparams(); - text_params.set_format(VideoParams::kFormatFloat32); + text_params.set_format(PixelFormat::F32); table->Push(NodeValue::kTexture, Texture::Job(text_params, job), this); } } diff --git a/app/node/generator/text/textv3.cpp b/app/node/generator/text/textv3.cpp index 1964f8cb0..6d776f462 100644 --- a/app/node/generator/text/textv3.cpp +++ b/app/node/generator/text/textv3.cpp @@ -117,7 +117,7 @@ void TextGeneratorV3::Value(const NodeValueRow &value, const NodeGlobals &global TexturePtr base = value[kTextInput].toTexture(); VideoParams text_params = base ? base->params() : globals.vparams(); - text_params.set_format(VideoParams::kFormatUnsigned8); + text_params.set_format(PixelFormat::U8); text_params.set_colorspace(project()->color_manager()->GetDefaultInputColorSpace()); GenerateJob job(value); diff --git a/app/node/gizmo/draggable.h b/app/node/gizmo/draggable.h index cee0a3790..560f1a50b 100644 --- a/app/node/gizmo/draggable.h +++ b/app/node/gizmo/draggable.h @@ -21,7 +21,6 @@ #ifndef DRAGGABLEGIZMO_H #define DRAGGABLEGIZMO_H -#include "common/rational.h" #include "gizmo.h" #include "node/inputdragger.h" #include "undo/undocommand.h" @@ -46,7 +45,7 @@ public: explicit DraggableGizmo(QObject *parent = nullptr); - void DragStart(const NodeValueRow &row, double abs_x, double abs_y, const olive::rational &time); + void DragStart(const NodeValueRow &row, double abs_x, double abs_y, const olive::core::rational &time); void DragMove(double x, double y, const Qt::KeyboardModifiers &modifiers); @@ -67,7 +66,7 @@ public: void SetDragValueBehavior(DragValueBehavior d) { drag_value_behavior_ = d; } signals: - void HandleStart(const olive::NodeValueRow &row, double x, double y, const olive::rational &time); + void HandleStart(const olive::NodeValueRow &row, double x, double y, const olive::core::rational &time); void HandleMovement(double x, double y, const Qt::KeyboardModifiers &modifiers); diff --git a/app/node/globals.h b/app/node/globals.h index 9c8eb26a9..73ff8c00d 100644 --- a/app/node/globals.h +++ b/app/node/globals.h @@ -23,7 +23,6 @@ #include -#include "common/timerange.h" #include "render/audioparams.h" #include "render/loopmode.h" #include "render/videoparams.h" diff --git a/app/node/inputdragger.h b/app/node/inputdragger.h index d30bb35ab..7bdab1472 100644 --- a/app/node/inputdragger.h +++ b/app/node/inputdragger.h @@ -21,7 +21,6 @@ #ifndef NODEINPUTDRAGGER_H #define NODEINPUTDRAGGER_H -#include "common/rational.h" #include "node/keyframe.h" #include "node/param.h" #include "undo/undocommand.h" diff --git a/app/node/inputimmediate.h b/app/node/inputimmediate.h index dc1aee59c..06c3fad06 100644 --- a/app/node/inputimmediate.h +++ b/app/node/inputimmediate.h @@ -21,7 +21,6 @@ #ifndef NODEINPUTIMMEDIATE_H #define NODEINPUTIMMEDIATE_H -#include "common/timerange.h" #include "common/xmlutils.h" #include "node/keyframe.h" #include "node/value.h" diff --git a/app/node/keyframe.h b/app/node/keyframe.h index e81de91f6..eaff4d491 100644 --- a/app/node/keyframe.h +++ b/app/node/keyframe.h @@ -25,8 +25,6 @@ #include #include -#include "common/rational.h" -#include "common/timerange.h" #include "node/param.h" namespace olive { diff --git a/app/node/math/math/mathbase.cpp b/app/node/math/math/mathbase.cpp index 2ae9594ae..1c6c979e2 100644 --- a/app/node/math/math/mathbase.cpp +++ b/app/node/math/math/mathbase.cpp @@ -26,7 +26,6 @@ #include "common/cpuoptimize.h" #include "common/tohex.h" #include "node/distort/transform/transformdistortnode.h" -#include "render/color.h" namespace olive { diff --git a/app/node/node.cpp b/app/node/node.cpp index b26a95d93..2ebef9b30 100644 --- a/app/node/node.cpp +++ b/app/node/node.cpp @@ -163,7 +163,7 @@ QLinearGradient Node::gradient_color(qreal top, qreal bottom) const grad.setStart(0, top); grad.setFinalStop(0, bottom); - QColor c = color().toQColor(); + QColor c = QtUtils::toQColor(color()); grad.setColorAt(0.0, c.lighter()); grad.setColorAt(1.0, c); @@ -176,7 +176,7 @@ QBrush Node::brush(qreal top, qreal bottom) const if (OLIVE_CONFIG("UseGradients").toBool()) { return gradient_color(top, bottom); } else { - return color().toQColor(); + return QtUtils::toQColor(color()); } } diff --git a/app/node/node.h b/app/node/node.h index 8fa933979..108a137cf 100644 --- a/app/node/node.h +++ b/app/node/node.h @@ -30,8 +30,6 @@ #include "codec/frame.h" #include "codec/samplebuffer.h" -#include "common/rational.h" -#include "common/timerange.h" #include "common/xmlutils.h" #include "node/gizmo/draggable.h" #include "node/globals.h" @@ -1229,7 +1227,7 @@ protected: } protected slots: - virtual void GizmoDragStart(const olive::NodeValueRow &row, double x, double y, const olive::rational &time){} + virtual void GizmoDragStart(const olive::NodeValueRow &row, double x, double y, const olive::core::rational &time){} virtual void GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers){} @@ -1379,8 +1377,8 @@ private: QVector GetDependenciesInternal(bool traverse, bool exclusive_only) const; - void ParameterValueChanged(const QString &input, int element, const olive::TimeRange &range); - void ParameterValueChanged(const NodeInput& input, const olive::TimeRange &range) + void ParameterValueChanged(const QString &input, int element, const olive::core::TimeRange &range); + void ParameterValueChanged(const NodeInput& input, const olive::core::TimeRange &range) { ParameterValueChanged(input.input(), input.element(), range); } diff --git a/app/node/output/viewer/viewer.cpp b/app/node/output/viewer/viewer.cpp index fc8490a2a..2bc405bb8 100644 --- a/app/node/output/viewer/viewer.cpp +++ b/app/node/output/viewer/viewer.cpp @@ -116,7 +116,7 @@ QString ViewerOutput::duration() const return QString(); } else { // Return time transformed to timecode - return Timecode::time_to_timecode(GetLength(), using_timebase, using_display); + return QString::fromStdString(Timecode::time_to_timecode(GetLength(), using_timebase, using_display)); } } @@ -206,7 +206,7 @@ void ViewerOutput::set_default_parameters() width, height, OLIVE_CONFIG("DefaultSequenceFrameRate").value(), - static_cast(OLIVE_CONFIG("OfflinePixelFormat").toInt()), + static_cast(OLIVE_CONFIG("OfflinePixelFormat").toInt()), VideoParams::kInternalChannelCount, OLIVE_CONFIG("DefaultSequencePixelAspect").value(), OLIVE_CONFIG("DefaultSequenceInterlacing").value(), @@ -505,7 +505,7 @@ void ViewerOutput::set_parameters_from_footage(const QVector foo SetVideoParams(VideoParams(s.width(), s.height(), using_timebase, - static_cast(OLIVE_CONFIG("OfflinePixelFormat").toInt()), + static_cast(OLIVE_CONFIG("OfflinePixelFormat").toInt()), VideoParams::kInternalChannelCount, s.pixel_aspect_ratio(), s.interlacing(), diff --git a/app/node/output/viewer/viewer.h b/app/node/output/viewer/viewer.h index 93df8d46b..e7802472d 100644 --- a/app/node/output/viewer/viewer.h +++ b/app/node/output/viewer/viewer.h @@ -22,7 +22,6 @@ #define VIEWER_H #include "codec/encoder.h" -#include "common/rational.h" #include "node/node.h" #include "node/output/track/track.h" #include "render/audioparams.h" diff --git a/app/node/param.cpp b/app/node/param.cpp index 34eb9d382..431ce31ff 100644 --- a/app/node/param.cpp +++ b/app/node/param.cpp @@ -170,12 +170,12 @@ int NodeInput::GetArraySize() const uint qHash(const NodeInput &i) { - return qHash(i.node()) ^ qHash(i.input()) ^ qHash(i.element()); + return qHash(i.node()) ^ qHash(i.input()) ^ ::qHash(i.element()); } uint qHash(const NodeKeyframeTrackReference &i) { - return qHash(i.input()) & qHash(i.track()); + return qHash(i.input()) & ::qHash(i.track()); } uint qHash(const NodeInputPair &i) diff --git a/app/node/param.h b/app/node/param.h index 41bfc6736..683d6a2fa 100644 --- a/app/node/param.h +++ b/app/node/param.h @@ -23,7 +23,6 @@ #include -#include "common/rational.h" #include "value.h" namespace olive { diff --git a/app/node/project/footage/footage.h b/app/node/project/footage/footage.h index 321afa829..1c6e24dc4 100644 --- a/app/node/project/footage/footage.h +++ b/app/node/project/footage/footage.h @@ -21,11 +21,11 @@ #ifndef FOOTAGE_H #define FOOTAGE_H +#include #include #include #include "codec/decoder.h" -#include "common/rational.h" #include "footagedescription.h" #include "node/output/viewer/viewer.h" #include "render/audioparams.h" diff --git a/app/node/project/serializer/serializer210528.cpp b/app/node/project/serializer/serializer210528.cpp index ea30b7578..f79eb5c2c 100644 --- a/app/node/project/serializer/serializer210528.cpp +++ b/app/node/project/serializer/serializer210528.cpp @@ -378,7 +378,7 @@ void ProjectSerializer210528::LoadImmediate(QXmlStreamReader *reader, Node *node if (attr.name() == QStringLiteral("input")) { key_input = attr.value().toString(); } else if (attr.name() == QStringLiteral("time")) { - key_time = rational::fromString(attr.value().toString()); + key_time = rational::fromString(attr.value().toString().toStdString()); } else if (attr.name() == QStringLiteral("type")) { key_type = static_cast(attr.value().toInt()); } else if (attr.name() == QStringLiteral("inhandlex")) { @@ -575,9 +575,9 @@ void ProjectSerializer210528::LoadWorkArea(QXmlStreamReader *reader, TimelineWor if (attr.name() == QStringLiteral("enabled")) { workarea->set_enabled(attr.value() != QStringLiteral("0")); } else if (attr.name() == QStringLiteral("in")) { - range_in = rational::fromString(attr.value().toString()); + range_in = rational::fromString(attr.value().toString().toStdString()); } else if (attr.name() == QStringLiteral("out")) { - range_out = rational::fromString(attr.value().toString()); + range_out = rational::fromString(attr.value().toString().toStdString()); } } @@ -601,9 +601,9 @@ void ProjectSerializer210528::LoadMarkerList(QXmlStreamReader *reader, TimelineM if (attr.name() == QStringLiteral("name")) { name = attr.value().toString(); } else if (attr.name() == QStringLiteral("in")) { - in = rational::fromString(attr.value().toString()); + in = rational::fromString(attr.value().toString().toStdString()); } else if (attr.name() == QStringLiteral("out")) { - out = rational::fromString(attr.value().toString()); + out = rational::fromString(attr.value().toString().toStdString()); } } diff --git a/app/node/project/serializer/serializer210907.cpp b/app/node/project/serializer/serializer210907.cpp index dc5e127e7..ad180f9e0 100644 --- a/app/node/project/serializer/serializer210907.cpp +++ b/app/node/project/serializer/serializer210907.cpp @@ -375,7 +375,7 @@ void ProjectSerializer210907::LoadImmediate(QXmlStreamReader *reader, Node *node if (attr.name() == QStringLiteral("input")) { key_input = attr.value().toString(); } else if (attr.name() == QStringLiteral("time")) { - key_time = rational::fromString(attr.value().toString()); + key_time = rational::fromString(attr.value().toString().toStdString()); } else if (attr.name() == QStringLiteral("type")) { key_type = static_cast(attr.value().toInt()); } else if (attr.name() == QStringLiteral("inhandlex")) { @@ -567,9 +567,9 @@ void ProjectSerializer210907::LoadWorkArea(QXmlStreamReader *reader, TimelineWor if (attr.name() == QStringLiteral("enabled")) { workarea->set_enabled(attr.value() != QStringLiteral("0")); } else if (attr.name() == QStringLiteral("in")) { - range_in = rational::fromString(attr.value().toString()); + range_in = rational::fromString(attr.value().toString().toStdString()); } else if (attr.name() == QStringLiteral("out")) { - range_out = rational::fromString(attr.value().toString()); + range_out = rational::fromString(attr.value().toString().toStdString()); } } @@ -593,9 +593,9 @@ void ProjectSerializer210907::LoadMarkerList(QXmlStreamReader *reader, TimelineM if (attr.name() == QStringLiteral("name")) { name = attr.value().toString(); } else if (attr.name() == QStringLiteral("in")) { - in = rational::fromString(attr.value().toString()); + in = rational::fromString(attr.value().toString().toStdString()); } else if (attr.name() == QStringLiteral("out")) { - out = rational::fromString(attr.value().toString()); + out = rational::fromString(attr.value().toString().toStdString()); } } diff --git a/app/node/project/serializer/serializer211228.cpp b/app/node/project/serializer/serializer211228.cpp index 94a6ce1ed..a4a114a83 100644 --- a/app/node/project/serializer/serializer211228.cpp +++ b/app/node/project/serializer/serializer211228.cpp @@ -425,7 +425,7 @@ void ProjectSerializer211228::LoadImmediate(QXmlStreamReader *reader, Node *node if (attr.name() == QStringLiteral("input")) { key_input = attr.value().toString(); } else if (attr.name() == QStringLiteral("time")) { - key_time = rational::fromString(attr.value().toString()); + key_time = rational::fromString(attr.value().toString().toStdString()); } else if (attr.name() == QStringLiteral("type")) { key_type = static_cast(attr.value().toInt()); } else if (attr.name() == QStringLiteral("inhandlex")) { @@ -617,9 +617,9 @@ void ProjectSerializer211228::LoadWorkArea(QXmlStreamReader *reader, TimelineWor if (attr.name() == QStringLiteral("enabled")) { workarea->set_enabled(attr.value() != QStringLiteral("0")); } else if (attr.name() == QStringLiteral("in")) { - range_in = rational::fromString(attr.value().toString()); + range_in = rational::fromString(attr.value().toString().toStdString()); } else if (attr.name() == QStringLiteral("out")) { - range_out = rational::fromString(attr.value().toString()); + range_out = rational::fromString(attr.value().toString().toStdString()); } } @@ -643,9 +643,9 @@ void ProjectSerializer211228::LoadMarkerList(QXmlStreamReader *reader, TimelineM if (attr.name() == QStringLiteral("name")) { name = attr.value().toString(); } else if (attr.name() == QStringLiteral("in")) { - in = rational::fromString(attr.value().toString()); + in = rational::fromString(attr.value().toString().toStdString()); } else if (attr.name() == QStringLiteral("out")) { - out = rational::fromString(attr.value().toString()); + out = rational::fromString(attr.value().toString().toStdString()); } } diff --git a/app/node/project/serializer/serializer220403.cpp b/app/node/project/serializer/serializer220403.cpp index 6708911df..41daded68 100644 --- a/app/node/project/serializer/serializer220403.cpp +++ b/app/node/project/serializer/serializer220403.cpp @@ -909,7 +909,7 @@ void ProjectSerializer220403::LoadKeyframe(QXmlStreamReader *reader, NodeKeyfram if (attr.name() == QStringLiteral("input")) { key_input = attr.value().toString(); } else if (attr.name() == QStringLiteral("time")) { - key->set_time(rational::fromString(attr.value().toString())); + key->set_time(rational::fromString(attr.value().toString().toStdString())); } else if (attr.name() == QStringLiteral("type")) { key->set_type_no_bezier_adj(static_cast(attr.value().toInt())); } else if (attr.name() == QStringLiteral("inhandlex")) { @@ -932,7 +932,7 @@ void ProjectSerializer220403::LoadKeyframe(QXmlStreamReader *reader, NodeKeyfram void ProjectSerializer220403::SaveKeyframe(QXmlStreamWriter *writer, NodeKeyframe *key, NodeValue::Type data_type) const { writer->writeAttribute(QStringLiteral("input"), key->input()); - writer->writeAttribute(QStringLiteral("time"), key->time().toString()); + writer->writeAttribute(QStringLiteral("time"), QString::fromStdString(key->time().toString())); writer->writeAttribute(QStringLiteral("type"), QString::number(key->type())); writer->writeAttribute(QStringLiteral("inhandlex"), QString::number(key->bezier_control_in().x())); writer->writeAttribute(QStringLiteral("inhandley"), QString::number(key->bezier_control_in().y())); @@ -1214,9 +1214,9 @@ void ProjectSerializer220403::LoadMarker(QXmlStreamReader *reader, TimelineMarke if (attr.name() == QStringLiteral("name")) { marker->set_name(attr.value().toString()); } else if (attr.name() == QStringLiteral("in")) { - in = rational::fromString(attr.value().toString()); + in = rational::fromString(attr.value().toString().toStdString()); } else if (attr.name() == QStringLiteral("out")) { - out = rational::fromString(attr.value().toString()); + out = rational::fromString(attr.value().toString().toStdString()); } else if (attr.name() == QStringLiteral("color")) { marker->set_color(attr.value().toInt()); } @@ -1231,8 +1231,8 @@ void ProjectSerializer220403::LoadMarker(QXmlStreamReader *reader, TimelineMarke void ProjectSerializer220403::SaveMarker(QXmlStreamWriter *writer, TimelineMarker *marker) const { writer->writeAttribute(QStringLiteral("name"), marker->name()); - writer->writeAttribute(QStringLiteral("in"), marker->time().in().toString()); - writer->writeAttribute(QStringLiteral("out"), marker->time().out().toString()); + writer->writeAttribute(QStringLiteral("in"), QString::fromStdString(marker->time().in().toString())); + writer->writeAttribute(QStringLiteral("out"), QString::fromStdString(marker->time().out().toString())); writer->writeAttribute(QStringLiteral("color"), QString::number(marker->color())); } @@ -1245,9 +1245,9 @@ void ProjectSerializer220403::LoadWorkArea(QXmlStreamReader *reader, TimelineWor if (attr.name() == QStringLiteral("enabled")) { workarea->set_enabled(attr.value() != QStringLiteral("0")); } else if (attr.name() == QStringLiteral("in")) { - range_in = rational::fromString(attr.value().toString()); + range_in = rational::fromString(attr.value().toString().toStdString()); } else if (attr.name() == QStringLiteral("out")) { - range_out = rational::fromString(attr.value().toString()); + range_out = rational::fromString(attr.value().toString().toStdString()); } } @@ -1263,8 +1263,8 @@ void ProjectSerializer220403::LoadWorkArea(QXmlStreamReader *reader, TimelineWor void ProjectSerializer220403::SaveWorkArea(QXmlStreamWriter *writer, TimelineWorkArea *workarea) const { writer->writeAttribute(QStringLiteral("enabled"), QString::number(workarea->enabled())); - writer->writeAttribute(QStringLiteral("in"), workarea->in().toString()); - writer->writeAttribute(QStringLiteral("out"), workarea->out().toString()); + writer->writeAttribute(QStringLiteral("in"), QString::fromStdString(workarea->in().toString())); + writer->writeAttribute(QStringLiteral("out"), QString::fromStdString(workarea->out().toString())); } void ProjectSerializer220403::LoadMarkerList(QXmlStreamReader *reader, TimelineMarkerList *markers) const diff --git a/app/node/value.cpp b/app/node/value.cpp index 7a2d875bf..6d40d621b 100644 --- a/app/node/value.cpp +++ b/app/node/value.cpp @@ -31,7 +31,6 @@ #include "render/audioparams.h" #include "render/subtitleparams.h" #include "render/videoparams.h" -#include "render/color.h" namespace olive { @@ -72,7 +71,7 @@ QString NodeValue::ValueToString(Type data_type, const QVariant &value, bool val QString::number(b.cp2_x()), QString::number(b.cp2_y())); } else if (data_type == kRational) { - return value.value().toString(); + return QString::fromStdString(value.value().toString()); } else if (data_type == kTexture || data_type == kSamples || data_type == kNone) { @@ -245,7 +244,7 @@ QVariant NodeValue::StringToValue(Type data_type, const QString &string, bool va } else if (data_type == kInt) { return QVariant::fromValue(string.toLongLong()); } else if (data_type == kRational) { - return QVariant::fromValue(rational::fromString(string)); + return QVariant::fromValue(rational::fromString(string.toStdString())); } else { return string; } diff --git a/app/node/value.h b/app/node/value.h index 3a3f75501..11223e62b 100644 --- a/app/node/value.h +++ b/app/node/value.h @@ -28,8 +28,8 @@ #include "codec/samplebuffer.h" #include "common/bezier.h" +#include "common/qtutils.h" #include "node/splitvalue.h" -#include "render/color.h" #include "render/texture.h" namespace olive { @@ -338,9 +338,9 @@ public: bool toBool() const { return value(); } double toDouble() const { return value(); } int64_t toInt() const { return value(); } - rational toRational() const { return value(); } + rational toRational() const { return value(); } QString toString() const { return value(); } - Color toColor() const { return value(); } + Color toColor() const { return value(); } QMatrix4x4 toMatrix() const { return value(); } VideoParams toVideoParams() const { return value(); } AudioParams toAudioParams() const { return value(); } diff --git a/app/render/CMakeLists.txt b/app/render/CMakeLists.txt index e2e310fcc..fcbc45750 100644 --- a/app/render/CMakeLists.txt +++ b/app/render/CMakeLists.txt @@ -27,8 +27,6 @@ set(OLIVE_SOURCES render/audiowaveformcache.cpp render/audiowaveformcache.h render/cancelatom.h - render/color.cpp - render/color.h render/colorprocessor.cpp render/colorprocessor.h render/colorprocessorcache.h diff --git a/app/render/audioparams.cpp b/app/render/audioparams.cpp index 3712f8cde..63d1b52e5 100644 --- a/app/render/audioparams.cpp +++ b/app/render/audioparams.cpp @@ -203,7 +203,7 @@ void AudioParams::Load(QXmlStreamReader *reader) } else if (reader->name() == QStringLiteral("duration")) { set_duration(reader->readElementText().toLongLong()); } else if (reader->name() == QStringLiteral("timebase")) { - set_time_base(rational::fromString(reader->readElementText())); + set_time_base(rational::fromString(reader->readElementText().toStdString())); } else { reader->skipCurrentElement(); } @@ -218,7 +218,7 @@ void AudioParams::Save(QXmlStreamWriter *writer) const writer->writeTextElement(QStringLiteral("enabled"), QString::number(enabled_)); writer->writeTextElement(QStringLiteral("streamindex"), QString::number(stream_index_)); writer->writeTextElement(QStringLiteral("duration"), QString::number(duration_)); - writer->writeTextElement(QStringLiteral("timebase"), timebase_.toString()); + writer->writeTextElement(QStringLiteral("timebase"), QString::fromStdString(timebase_.toString())); } QString AudioParams::SampleRateToString(const int &sample_rate) diff --git a/app/render/audioparams.h b/app/render/audioparams.h index aff223239..edbcc50a9 100644 --- a/app/render/audioparams.h +++ b/app/render/audioparams.h @@ -25,14 +25,15 @@ extern "C" { #include } +#include #include #include #include -#include "common/rational.h" - namespace olive { +using namespace core; + class AudioParams { public: // Only append to this list (never insert) because indexes are used in serialized files diff --git a/app/render/audioplaybackcache.h b/app/render/audioplaybackcache.h index 6a7949482..5297a3acd 100644 --- a/app/render/audioplaybackcache.h +++ b/app/render/audioplaybackcache.h @@ -22,7 +22,6 @@ #define AUDIOPLAYBACKCACHE_H #include "audio/audiovisualwaveform.h" -#include "common/timerange.h" #include "codec/samplebuffer.h" #include "render/playbackcache.h" diff --git a/app/render/audiowaveformcache.cpp b/app/render/audiowaveformcache.cpp index 4f9870759..0b33ceb87 100644 --- a/app/render/audiowaveformcache.cpp +++ b/app/render/audiowaveformcache.cpp @@ -97,9 +97,9 @@ void AudioWaveformCache::SetPassthrough(PlaybackCache *cache) for (const TimeRange &r : c->GetValidatedRanges()) { WaveformPassthrough t = r; t.waveform = c->waveforms_; - passthroughs_.append(t); + passthroughs_.push_back(t); } - passthroughs_.append(c->passthroughs_); + passthroughs_.insert(passthroughs_.end(), c->passthroughs_.begin(), c->passthroughs_.end()); SetParameters(c->GetParameters()); SetSavingEnabled(c->IsSavingEnabled()); diff --git a/app/render/audiowaveformcache.h b/app/render/audiowaveformcache.h index 95a498d4f..3557c64e3 100644 --- a/app/render/audiowaveformcache.h +++ b/app/render/audiowaveformcache.h @@ -69,7 +69,7 @@ private: WaveformPtr waveform; }; - QVector passthroughs_; + std::vector passthroughs_; }; diff --git a/app/render/color.cpp b/app/render/color.cpp deleted file mode 100644 index a840244e0..000000000 --- a/app/render/color.cpp +++ /dev/null @@ -1,300 +0,0 @@ -/*** - - Olive - Non-Linear Video Editor - Copyright (C) 2022 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 "color.h" - -#include - -#include "common/clamp.h" -#include "common/oiioutils.h" - -namespace olive { - -Color Color::fromHsv(const DataType &h, const DataType &s, const DataType &v) -{ - DataType C = s * v; - DataType X = C * (1.0 - abs(fmod(h / 60.0, 2.0) - 1.0)); - DataType m = v - C; - DataType Rs, Gs, Bs; - - if(h >= 0.0 && h < 60.0) { - Rs = C; - Gs = X; - Bs = 0.0; - } - else if(h >= 60.0 && h < 120.0) { - Rs = X; - Gs = C; - Bs = 0.0; - } - else if(h >= 120.0 && h < 180.0) { - Rs = 0.0; - Gs = C; - Bs = X; - } - else if(h >= 180.0 && h < 240.0) { - Rs = 0.0; - Gs = X; - Bs = C; - } - else if(h >= 240.0 && h < 300.0) { - Rs = X; - Gs = 0.0; - Bs = C; - } - else { - Rs = C; - Gs = 0.0; - Bs = X; - } - - return Color(Rs + m, Gs + m, Bs + m); -} - -Color::Color(const char *data, const VideoParams::Format &format, int ch_layout) -{ - *this = fromData(data, format, ch_layout); -} - -Color::Color(const QColor &c) -{ - set_red(c.redF()); - set_green(c.greenF()); - set_blue(c.blueF()); - set_alpha(c.alphaF()); -} - -void Color::toHsv(DataType *hue, DataType *sat, DataType *val) const -{ - DataType fCMax = qMax(qMax(red(), green()), blue()); - DataType fCMin = qMin(qMin(red(), green()), blue()); - DataType fDelta = fCMax - fCMin; - - if(fDelta > 0) { - if(fCMax == red()) { - *hue = 60 * (fmod(((green() - blue()) / fDelta), 6)); - } else if(fCMax == green()) { - *hue = 60 * (((blue() - red()) / fDelta) + 2); - } else if(fCMax == blue()) { - *hue = 60 * (((red() - green()) / fDelta) + 4); - } - - if(fCMax > 0) { - *sat = fDelta / fCMax; - } else { - *sat = 0; - } - - *val = fCMax; - } else { - *hue = 0; - *sat = 0; - *val = fCMax; - } - - if(*hue < 0) { - *hue = 360 + *hue; - } -} - -Color::DataType Color::hsv_hue() const -{ - DataType h, s, v; - toHsv(&h, &s, &v); - return h; -} - -Color::DataType Color::hsv_saturation() const -{ - DataType h, s, v; - toHsv(&h, &s, &v); - return s; -} - -Color::DataType Color::value() const -{ - DataType h, s, v; - toHsv(&h, &s, &v); - return v; -} - -void Color::toHsl(DataType *hue, DataType *sat, DataType *lightness) const -{ - DataType fCMin = qMin(red(), qMin(green(), blue())); - DataType fCMax = qMax(red(), qMax(green(), blue())); - - *lightness = 0.5 * (fCMin + fCMax); - - if (fCMin == fCMax) - { - *sat = 0; - *hue = 0; - return; - - } - else if (*lightness < 0.5) - { - *sat = (fCMax - fCMin) / (fCMax + fCMin); - } - else - { - *sat = (fCMax - fCMin) / (2.0 - fCMax - fCMin); - } - - if (fCMax == red()) - { - *hue = 60 * (green() - blue()) / (fCMax - fCMin); - } - if (fCMax == green()) - { - *hue = 60 * (blue() - red()) / (fCMax - fCMin) + 120; - } - if (fCMax == blue()) - { - *hue = 60 * (red() - green()) / (fCMax - fCMin) + 240; - } - if (*hue < 0) - { - *hue = *hue + 360; - } -} - -Color::DataType Color::hsl_hue() const -{ - DataType h, s, l; - toHsl(&h, &s, &l); - return h; -} - -Color::DataType Color::hsl_saturation() const -{ - DataType h, s, l; - toHsl(&h, &s, &l); - return s; -} - -Color::DataType Color::lightness() const -{ - DataType h, s, l; - toHsl(&h, &s, &l); - return l; -} - -void Color::toData(char *data, const VideoParams::Format &format, int ch_layout) const -{ - OIIO::convert_pixel_values(OIIO::TypeDesc::FLOAT, - data_, - OIIOUtils::GetOIIOBaseTypeFromFormat(format), - data, - ch_layout); -} - -Color Color::fromData(const char *data, const VideoParams::Format &format, int ch_layout) -{ - Color c; - - OIIO::convert_pixel_values(OIIOUtils::GetOIIOBaseTypeFromFormat(format), - data, - OIIO::TypeDesc::FLOAT, - c.data_, - ch_layout); - - return c; -} - -QColor Color::toQColor() const -{ - QColor c; - - // QColor only supports values from 0.0 to 1.0 and are only used for UI representations - c.setRedF(clamp(red(), 0.0f, 1.0f)); - c.setGreenF(clamp(green(), 0.0f, 1.0f)); - c.setBlueF(clamp(blue(), 0.0f, 1.0f)); - c.setAlphaF(clamp(alpha(), 0.0f, 1.0f)); - - return c; -} - -Color::DataType Color::GetRoughLuminance() const -{ - return (2*red()+blue()+3*green())/6.0; -} - -Color &Color::operator+=(const Color &rhs) -{ - for (int i=0;i. - -***/ - -#ifndef COLOR_H -#define COLOR_H - -#include -#include - -#include "common/define.h" -#include "render/videoparams.h" - -namespace olive { - -/** - * @brief High precision 32-bit DataType based RGBA color value - */ -class Color -{ -public: - using DataType = float; - - Color() - { - for (int i=0;i(file.header()["oliveDivider"]).value()); - VideoParams::Format image_format; + PixelFormat image_format; if (pix_type == Imf::HALF) { - image_format = VideoParams::kFormatFloat16; + image_format = PixelFormat::F16; } else { - image_format = VideoParams::kFormatFloat32; + image_format = PixelFormat::F32; } int channel_count = has_alpha ? VideoParams::kRGBAChannelCount : VideoParams::kRGBChannelCount; @@ -202,7 +202,7 @@ FramePtr FrameHashCache::LoadCacheFrame(const QString &fn) // FIXME: Hardcoded const int div = 1; - const VideoParams::Format image_format = VideoParams::kFormatUnsigned8; + const PixelFormat image_format = PixelFormat::U8; const int channel_count = 4; const rational par(1, 1); @@ -343,7 +343,7 @@ bool FrameHashCache::SaveCacheFrame(const QString &filename, const FramePtr fram // Floating point types are stored in EXR Imf::PixelType pix_type; - if (frame->format() == VideoParams::kFormatFloat16) { + if (frame->format() == PixelFormat::F16) { pix_type = Imf::HALF; } else { pix_type = Imf::FLOAT; @@ -392,22 +392,22 @@ bool FrameHashCache::SaveCacheFrame(const QString &filename, const FramePtr fram QImage::Format fmt = QImage::Format_Invalid; switch (frame->format()) { - case VideoParams::kFormatUnsigned8: + case PixelFormat::U8: if (frame->channel_count() == VideoParams::kRGBAChannelCount){ fmt = QImage::Format_RGBA8888_Premultiplied; } else if (frame->channel_count() == VideoParams::kRGBChannelCount){ fmt = QImage::Format_RGB888; } break; - case VideoParams::kFormatUnsigned16: + case PixelFormat::U16: if (frame->channel_count() == VideoParams::kRGBAChannelCount){ fmt = QImage::Format_RGBA64_Premultiplied; } break; - case VideoParams::kFormatFloat16: - case VideoParams::kFormatFloat32: - case VideoParams::kFormatCount: - case VideoParams::kFormatInvalid: + case PixelFormat::F16: + case PixelFormat::F32: + case PixelFormat::FORMAT_COUNT: + case PixelFormat::INVALID: break; } diff --git a/app/render/framehashcache.h b/app/render/framehashcache.h index 378e1a02a..cb7ddcd3b 100644 --- a/app/render/framehashcache.h +++ b/app/render/framehashcache.h @@ -21,9 +21,6 @@ #ifndef VIDEORENDERFRAMECACHE_H #define VIDEORENDERFRAMECACHE_H -#include "common/rational.h" -#include "common/timecodefunctions.h" -#include "common/timerange.h" #include "codec/frame.h" #include "render/playbackcache.h" #include "render/videoparams.h" diff --git a/app/render/job/samplejob.h b/app/render/job/samplejob.h index f5602a8ba..8cf37e542 100644 --- a/app/render/job/samplejob.h +++ b/app/render/job/samplejob.h @@ -23,7 +23,6 @@ #include "acceleratedjob.h" #include "codec/samplebuffer.h" -#include "common/timerange.h" namespace olive { diff --git a/app/render/managedcolor.cpp b/app/render/managedcolor.cpp index 6a6862cde..cf5577701 100644 --- a/app/render/managedcolor.cpp +++ b/app/render/managedcolor.cpp @@ -31,7 +31,7 @@ ManagedColor::ManagedColor(const double &r, const double &g, const double &b, co { } -ManagedColor::ManagedColor(const char *data, const VideoParams::Format &format, int channel_layout) : +ManagedColor::ManagedColor(const char *data, const PixelFormat &format, int channel_layout) : Color(data, format, channel_layout) { } diff --git a/app/render/managedcolor.h b/app/render/managedcolor.h index 3b3dd275b..93411425a 100644 --- a/app/render/managedcolor.h +++ b/app/render/managedcolor.h @@ -21,7 +21,8 @@ #ifndef MANAGEDCOLOR_H #define MANAGEDCOLOR_H -#include "color.h" +#include + #include "colortransform.h" namespace olive { @@ -31,7 +32,7 @@ class ManagedColor : public Color public: ManagedColor(); ManagedColor(const double& r, const double& g, const double& b, const double& a = 1.0); - ManagedColor(const char *data, const VideoParams::Format &format, int channel_layout); + ManagedColor(const char *data, const PixelFormat &format, int channel_layout); ManagedColor(const Color& c); const QString& color_input() const; diff --git a/app/render/opengl/openglrenderer.cpp b/app/render/opengl/openglrenderer.cpp index 3340c64d4..9237c9e36 100644 --- a/app/render/opengl/openglrenderer.cpp +++ b/app/render/opengl/openglrenderer.cpp @@ -189,7 +189,7 @@ void OpenGLRenderer::ClearDestination(Texture *texture, double r, double g, doub } } -QVariant OpenGLRenderer::CreateNativeTexture(int width, int height, int depth, VideoParams::Format format, int channel_count, const void *data, int linesize) +QVariant OpenGLRenderer::CreateNativeTexture(int width, int height, int depth, PixelFormat format, int channel_count, const void *data, int linesize) { GL_PREAMBLE; @@ -673,10 +673,10 @@ void OpenGLRenderer::Blit(QVariant s, ShaderJob job, Texture *destination, Video vao_.destroy(); } -GLint OpenGLRenderer::GetInternalFormat(VideoParams::Format format, int channel_layout) +GLint OpenGLRenderer::GetInternalFormat(PixelFormat format, int channel_layout) { switch (format) { - case VideoParams::kFormatUnsigned8: + case PixelFormat::U8: switch (channel_layout) { case 1: return GL_R8; @@ -688,7 +688,7 @@ GLint OpenGLRenderer::GetInternalFormat(VideoParams::Format format, int channel_ return GL_RGBA8; } break; - case VideoParams::kFormatUnsigned16: + case PixelFormat::U16: switch (channel_layout) { case 1: return GL_R16; @@ -700,7 +700,7 @@ GLint OpenGLRenderer::GetInternalFormat(VideoParams::Format format, int channel_ return GL_RGBA16; } break; - case VideoParams::kFormatFloat16: + case PixelFormat::F16: switch (channel_layout) { case 1: return GL_R16F; @@ -712,7 +712,7 @@ GLint OpenGLRenderer::GetInternalFormat(VideoParams::Format format, int channel_ return GL_RGBA16F; } break; - case VideoParams::kFormatFloat32: + case PixelFormat::F32: switch (channel_layout) { case 1: return GL_R32F; @@ -724,28 +724,28 @@ GLint OpenGLRenderer::GetInternalFormat(VideoParams::Format format, int channel_ return GL_RGBA32F; } break; - case VideoParams::kFormatInvalid: - case VideoParams::kFormatCount: + case PixelFormat::INVALID: + case PixelFormat::FORMAT_COUNT: break; } return GL_INVALID_VALUE; } -GLenum OpenGLRenderer::GetPixelType(VideoParams::Format format) +GLenum OpenGLRenderer::GetPixelType(PixelFormat format) { switch (format) { - case VideoParams::kFormatUnsigned8: + case PixelFormat::U8: return GL_UNSIGNED_BYTE; - case VideoParams::kFormatUnsigned16: + case PixelFormat::U16: return GL_UNSIGNED_SHORT; - case VideoParams::kFormatFloat16: + case PixelFormat::F16: return GL_HALF_FLOAT; - case VideoParams::kFormatFloat32: + case PixelFormat::F32: return GL_FLOAT; - case VideoParams::kFormatInvalid: - case VideoParams::kFormatCount: + case PixelFormat::INVALID: + case PixelFormat::FORMAT_COUNT: break; } diff --git a/app/render/opengl/openglrenderer.h b/app/render/opengl/openglrenderer.h index fe7f0098a..acd869ea0 100644 --- a/app/render/opengl/openglrenderer.h +++ b/app/render/opengl/openglrenderer.h @@ -70,16 +70,16 @@ protected: olive::VideoParams destination_params, bool clear_destination) override; - virtual QVariant CreateNativeTexture(int width, int height, int depth, olive::VideoParams::Format format, int channel_count, const void* data = nullptr, int linesize = 0) override; + virtual QVariant CreateNativeTexture(int width, int height, int depth, PixelFormat format, int channel_count, const void* data = nullptr, int linesize = 0) override; virtual void DestroyNativeTexture(QVariant texture) override; virtual void DestroyInternal() override; private: - static GLint GetInternalFormat(VideoParams::Format format, int channel_layout); + static GLint GetInternalFormat(PixelFormat format, int channel_layout); - static GLenum GetPixelType(VideoParams::Format format); + static GLenum GetPixelType(PixelFormat format); static GLenum GetPixelFormat(int channel_count); @@ -105,7 +105,7 @@ private: int width; int height; int depth; - VideoParams::Format format; + PixelFormat format; int channel_count; bool operator==(const TextureCacheKey &rhs) const diff --git a/app/render/playbackcache.cpp b/app/render/playbackcache.cpp index 7cc89d473..cc61c1761 100644 --- a/app/render/playbackcache.cpp +++ b/app/render/playbackcache.cpp @@ -115,7 +115,7 @@ void PlaybackCache::LoadState() Passthrough p = TimeRange(rational(in_num, in_den), rational(out_num, out_den)); p.cache = id; - passthroughs_.append(p); + passthroughs_.push_back(p); } break; @@ -136,7 +136,7 @@ void PlaybackCache::SaveState() QDir cache_dir = GetThisCacheDirectory(); QFile f(cache_dir.filePath(QStringLiteral("state"))); - if (validated_.isEmpty() && passthroughs_.isEmpty()) { + if (validated_.isEmpty() && passthroughs_.empty()) { if (f.exists()) { f.remove(); } @@ -150,7 +150,8 @@ void PlaybackCache::SaveState() SaveStateEvent(s); - s << validated_.size(); + // Using "int" for backwards compatibility with when we used QVector, could potentially overflow + s << int(validated_.size()); for (const TimeRange &r : validated_) { s << r.in().numerator(); @@ -159,7 +160,8 @@ void PlaybackCache::SaveState() s << r.out().denominator(); } - s << passthroughs_.size(); + // Using "int" for backwards compatibility with when we used QVector, could potentially overflow + s << int(passthroughs_.size()); for (const Passthrough &p : passthroughs_) { s << p.in().numerator(); @@ -211,7 +213,7 @@ void PlaybackCache::SetPassthrough(PlaybackCache *cache) passthroughs_.push_back(p); } - passthroughs_.append(cache->GetPassthroughs()); + passthroughs_.insert(passthroughs_.end(), cache->GetPassthroughs().begin(), cache->GetPassthroughs().end()); if (saving_enabled_) { SaveState(); diff --git a/app/render/playbackcache.h b/app/render/playbackcache.h index 8f483d1c5..6b4537c0c 100644 --- a/app/render/playbackcache.h +++ b/app/render/playbackcache.h @@ -21,6 +21,7 @@ #ifndef PLAYBACKCACHE_H #define PLAYBACKCACHE_H +#include #include #include #include @@ -28,7 +29,8 @@ #include #include "common/jobtime.h" -#include "common/timerange.h" + +using namespace olive::core; namespace olive { @@ -96,9 +98,9 @@ public: QUuid cache; }; - const QVector &GetPassthroughs() const { return passthroughs_; } + const std::vector &GetPassthroughs() const { return passthroughs_; } - void ClearRequestRange(const olive::TimeRange &r) + void ClearRequestRange(const TimeRange &r) { requested_.remove(r); } @@ -113,14 +115,14 @@ public: public slots: void InvalidateAll(); - void Request(const olive::TimeRange &r); + void Request(const TimeRange &r); signals: - void Invalidated(const olive::TimeRange& r); + void Invalidated(const TimeRange& r); - void Validated(const olive::TimeRange& r); + void Validated(const TimeRange& r); - void Requested(const olive::TimeRange& r); + void Requested(const TimeRange& r); void CancelAll(); @@ -146,7 +148,7 @@ private: QMutex mutex_; - QVector passthroughs_; + std::vector passthroughs_; qint64 last_loaded_state_; diff --git a/app/render/previewautocacher.cpp b/app/render/previewautocacher.cpp index 827b02c98..1e6bcfbf6 100644 --- a/app/render/previewautocacher.cpp +++ b/app/render/previewautocacher.cpp @@ -589,7 +589,7 @@ RenderTicketWatcher* PreviewAutoCacher::RenderFrame(Node *node, const rational& if (ThumbnailCache *wave_cache = dynamic_cast(cache)) { rvp.video_params.set_divider(VideoParams::GetDividerForTargetResolution(rvp.video_params.width(), rvp.video_params.height(), 160, 120)); rvp.force_color_output = display_color_processor_; - rvp.force_format = VideoParams::kFormatUnsigned8; + rvp.force_format = PixelFormat::U8; } else { frame_cache->SetTimebase(viewer_node_->GetVideoParams().frame_rate_as_time_base()); } diff --git a/app/render/renderer.cpp b/app/render/renderer.cpp index a5a3aaedb..9e3c1fd9c 100644 --- a/app/render/renderer.cpp +++ b/app/render/renderer.cpp @@ -229,7 +229,7 @@ bool Renderer::GetColorContext(const ColorTransformJob &color_job, Renderer::Col } // Allocate 3D LUT - color_ctx.lut3d_textures[i].texture = CreateTexture(VideoParams(edge_len, edge_len, edge_len, VideoParams::kFormatFloat32, VideoParams::kRGBChannelCount), values); + color_ctx.lut3d_textures[i].texture = CreateTexture(VideoParams(edge_len, edge_len, edge_len, PixelFormat::F32, VideoParams::kRGBChannelCount), values); color_ctx.lut3d_textures[i].name = sampler_name; color_ctx.lut3d_textures[i].interpolation = (interpolation == OCIO::INTERP_NEAREST) ? Texture::kNearest : Texture::kLinear; } @@ -259,7 +259,7 @@ bool Renderer::GetColorContext(const ColorTransformJob &color_job, Renderer::Col } // Allocate 1D LUT - color_ctx.lut1d_textures[i].texture = CreateTexture(VideoParams(width, height, VideoParams::kFormatFloat32, (channel == OCIO::GpuShaderDesc::TEXTURE_RED_CHANNEL) ? 1 : VideoParams::kRGBChannelCount), values); + color_ctx.lut1d_textures[i].texture = CreateTexture(VideoParams(width, height, PixelFormat::F32, (channel == OCIO::GpuShaderDesc::TEXTURE_RED_CHANNEL) ? 1 : VideoParams::kRGBChannelCount), values); color_ctx.lut1d_textures[i].name = sampler_name; color_ctx.lut1d_textures[i].interpolation = (interpolation == OCIO::INTERP_NEAREST) ? Texture::kNearest : Texture::kLinear; } diff --git a/app/render/renderer.h b/app/render/renderer.h index 76651c05c..24bbfa3f1 100644 --- a/app/render/renderer.h +++ b/app/render/renderer.h @@ -26,7 +26,6 @@ #include #include "common/define.h" -#include "common/timerange.h" #include "node/node.h" #include "render/colorprocessor.h" #include "render/job/colortransformjob.h" @@ -106,7 +105,7 @@ protected: olive::VideoParams destination_params, bool clear_destination) = 0; - virtual QVariant CreateNativeTexture(int width, int height, int depth, olive::VideoParams::Format format, int channel_count, const void* data = nullptr, int linesize = 0) = 0; + virtual QVariant CreateNativeTexture(int width, int height, int depth, PixelFormat format, int channel_count, const void* data = nullptr, int linesize = 0) = 0; virtual void DestroyNativeTexture(QVariant texture) = 0; @@ -139,7 +138,7 @@ private: int width; int height; int depth; - VideoParams::Format format; + PixelFormat format; int channel_count; QVariant handle; qint64 accessed; diff --git a/app/render/renderjobtracker.cpp b/app/render/renderjobtracker.cpp index 7d8154f82..5dee38e50 100644 --- a/app/render/renderjobtracker.cpp +++ b/app/render/renderjobtracker.cpp @@ -29,7 +29,7 @@ void RenderJobTracker::insert(const TimeRange &range, JobTime job_time) // Now append the job TimeRangeWithJob job(range, job_time); - jobs_.append(job); + jobs_.push_back(job); } void RenderJobTracker::insert(const TimeRangeList &ranges, JobTime job_time) diff --git a/app/render/renderjobtracker.h b/app/render/renderjobtracker.h index 178c01ecc..d475818a7 100644 --- a/app/render/renderjobtracker.h +++ b/app/render/renderjobtracker.h @@ -21,11 +21,14 @@ #ifndef RENDERJOBTRACKER_H #define RENDERJOBTRACKER_H +#include + #include "common/jobtime.h" -#include "common/timerange.h" namespace olive { +using namespace core; + class RenderJobTracker { public: @@ -59,7 +62,7 @@ private: }; - QVector jobs_; + std::vector jobs_; }; diff --git a/app/render/rendermanager.cpp b/app/render/rendermanager.cpp index 32b1a9574..48bc29c2d 100644 --- a/app/render/rendermanager.cpp +++ b/app/render/rendermanager.cpp @@ -101,7 +101,7 @@ RenderTicketPtr RenderManager::RenderFrame(const RenderVideoParams ¶ms) ticket->setProperty("time", QVariant::fromValue(params.time)); ticket->setProperty("size", params.force_size); ticket->setProperty("matrix", params.force_matrix); - ticket->setProperty("format", params.force_format); + ticket->setProperty("format", static_cast(params.force_format)); ticket->setProperty("usecache", params.use_cache); ticket->setProperty("channelcount", params.force_channel_count); ticket->setProperty("mode", params.mode); diff --git a/app/render/rendermanager.h b/app/render/rendermanager.h index 25dbae894..1faaee37b 100644 --- a/app/render/rendermanager.h +++ b/app/render/rendermanager.h @@ -112,7 +112,7 @@ public: color_manager = colorman; use_cache = false; return_type = kFrame; - force_format = VideoParams::kFormatInvalid; + force_format = PixelFormat::INVALID; force_color_output = nullptr; force_size = QSize(0, 0); force_channel_count = 0; @@ -144,7 +144,7 @@ public: QSize force_size; int force_channel_count; QMatrix4x4 force_matrix; - VideoParams::Format force_format; + PixelFormat force_format; ColorProcessorPtr force_color_output; }; diff --git a/app/render/renderprocessor.cpp b/app/render/renderprocessor.cpp index d723d54e7..7d146ae9b 100644 --- a/app/render/renderprocessor.cpp +++ b/app/render/renderprocessor.cpp @@ -70,8 +70,8 @@ FramePtr RenderProcessor::GenerateFrame(TexturePtr texture, const rational& time frame_params.set_height(frame_size.height()); } - VideoParams::Format frame_format = static_cast(ticket_->property("format").toInt()); - if (frame_format != VideoParams::kFormatInvalid) { + PixelFormat frame_format = static_cast(ticket_->property("format").toInt()); + if (frame_format != PixelFormat::INVALID) { frame_params.set_format(frame_format); } diff --git a/app/render/renderticket.h b/app/render/renderticket.h index 700053653..77a246c58 100644 --- a/app/render/renderticket.h +++ b/app/render/renderticket.h @@ -28,7 +28,6 @@ #include "codec/frame.h" #include "codec/samplebuffer.h" #include "common/cancelableobject.h" -#include "common/timerange.h" #include "node/output/viewer/viewer.h" namespace olive { diff --git a/app/render/subtitleparams.cpp b/app/render/subtitleparams.cpp index 442fa3994..ecf985a8c 100644 --- a/app/render/subtitleparams.cpp +++ b/app/render/subtitleparams.cpp @@ -125,9 +125,9 @@ void SubtitleParams::Load(QXmlStreamReader *reader) XMLAttributeLoop(reader, attr) { if (attr.name() == QStringLiteral("in")) { - in = rational::fromString(attr.value().toString()); + in = rational::fromString(attr.value().toString().toStdString()); } else if (attr.name() == QStringLiteral("out")) { - out = rational::fromString(attr.value().toString()); + out = rational::fromString(attr.value().toString().toStdString()); } } @@ -152,8 +152,8 @@ void SubtitleParams::Save(QXmlStreamWriter *writer) const writer->writeStartElement(QStringLiteral("subtitles")); for (auto it=this->cbegin(); it!=this->cend(); it++) { writer->writeStartElement(QStringLiteral("subtitle")); - writer->writeAttribute(QStringLiteral("in"), it->time().in().toString()); - writer->writeAttribute(QStringLiteral("out"), it->time().out().toString()); + writer->writeAttribute(QStringLiteral("in"), QString::fromStdString(it->time().in().toString())); + writer->writeAttribute(QStringLiteral("out"), QString::fromStdString(it->time().out().toString())); writer->writeCharacters(it->text()); writer->writeEndElement(); // subtitle } diff --git a/app/render/subtitleparams.h b/app/render/subtitleparams.h index 2e9d86c8e..7d82273e7 100644 --- a/app/render/subtitleparams.h +++ b/app/render/subtitleparams.h @@ -21,12 +21,13 @@ #ifndef SUBTITLEPARAMS_H #define SUBTITLEPARAMS_H +#include #include #include #include #include -#include "common/timerange.h" +using namespace olive::core; namespace olive { diff --git a/app/render/texture.h b/app/render/texture.h index a184edb15..42fa1d3fc 100644 --- a/app/render/texture.h +++ b/app/render/texture.h @@ -121,7 +121,7 @@ public: return QVector2D(params_.square_pixel_width(), params_.height()); } - VideoParams::Format format() const + PixelFormat format() const { return params_.format(); } diff --git a/app/render/videoparams.cpp b/app/render/videoparams.cpp index 77d785d24..0eb4edd7c 100644 --- a/app/render/videoparams.cpp +++ b/app/render/videoparams.cpp @@ -24,6 +24,7 @@ extern "C" { #include } +#include #include #include "core.h" @@ -69,7 +70,7 @@ VideoParams::VideoParams() : width_(0), height_(0), depth_(0), - format_(kFormatInvalid), + format_(PixelFormat::INVALID), channel_count_(0), interlacing_(Interlacing::kInterlaceNone), divider_(1) @@ -77,7 +78,7 @@ VideoParams::VideoParams() : set_defaults_for_footage(); } -VideoParams::VideoParams(int width, int height, Format format, int nb_channels, const rational& pixel_aspect_ratio, Interlacing interlacing, int divider) : +VideoParams::VideoParams(int width, int height, PixelFormat format, int nb_channels, const rational& pixel_aspect_ratio, Interlacing interlacing, int divider) : width_(width), height_(height), depth_(1), @@ -92,7 +93,7 @@ VideoParams::VideoParams(int width, int height, Format format, int nb_channels, set_defaults_for_footage(); } -VideoParams::VideoParams(int width, int height, int depth, Format format, int nb_channels, const rational &pixel_aspect_ratio, VideoParams::Interlacing interlacing, int divider) : +VideoParams::VideoParams(int width, int height, int depth, PixelFormat format, int nb_channels, const rational &pixel_aspect_ratio, VideoParams::Interlacing interlacing, int divider) : width_(width), height_(height), depth_(depth), @@ -107,7 +108,7 @@ VideoParams::VideoParams(int width, int height, int depth, Format format, int nb set_defaults_for_footage(); } -VideoParams::VideoParams(int width, int height, const rational &time_base, Format format, int nb_channels, const rational& pixel_aspect_ratio, Interlacing interlacing, int divider) : +VideoParams::VideoParams(int width, int height, const rational &time_base, PixelFormat format, int nb_channels, const rational& pixel_aspect_ratio, Interlacing interlacing, int divider) : width_(width), height_(height), depth_(1), @@ -177,25 +178,25 @@ bool VideoParams::operator!=(const VideoParams &rhs) const return !(*this == rhs); } -int VideoParams::GetBytesPerChannel(VideoParams::Format format) +int VideoParams::GetBytesPerChannel(PixelFormat format) { switch (format) { - case kFormatInvalid: - case kFormatCount: + case PixelFormat::INVALID: + case PixelFormat::FORMAT_COUNT: break; - case kFormatUnsigned8: + case PixelFormat::U8: return 1; - case kFormatUnsigned16: - case kFormatFloat16: + case PixelFormat::U16: + case PixelFormat::F16: return 2; - case kFormatFloat32: + case PixelFormat::F32: return 4; } return 0; } -int VideoParams::GetBytesPerPixel(VideoParams::Format format, int channels) +int VideoParams::GetBytesPerPixel(PixelFormat format, int channels) { return GetBytesPerChannel(format) * channels; } @@ -209,35 +210,19 @@ QString VideoParams::GetNameForDivider(int div) } } -bool VideoParams::FormatIsFloat(VideoParams::Format format) +QString VideoParams::GetFormatName(PixelFormat format) { switch (format) { - case kFormatFloat16: - case kFormatFloat32: - return true; - case kFormatUnsigned8: - case kFormatUnsigned16: - case kFormatInvalid: - case kFormatCount: - break; - } - - return false; -} - -QString VideoParams::GetFormatName(VideoParams::Format format) -{ - switch (format) { - case kFormatUnsigned8: + case PixelFormat::U8: return QCoreApplication::translate("VideoParams", "8-bit"); - case kFormatUnsigned16: + case PixelFormat::U16: return QCoreApplication::translate("VideoParams", "16-bit Integer"); - case kFormatFloat16: + case PixelFormat::F16: return QCoreApplication::translate("VideoParams", "Half-Float (16-bit)"); - case kFormatFloat32: + case PixelFormat::F32: return QCoreApplication::translate("VideoParams", "Full-Float (32-bit)"); - case kFormatInvalid: - case kFormatCount: + case PixelFormat::INVALID: + case PixelFormat::FORMAT_COUNT: break; } @@ -302,7 +287,7 @@ bool VideoParams::is_valid() const return (width() > 0 && height() > 0 && !pixel_aspect_ratio_.isNull() - && format_ > kFormatInvalid && format_ < kFormatCount + && format_ > PixelFormat::INVALID && format_ < PixelFormat::FORMAT_COUNT && channel_count_ > 0); } @@ -359,13 +344,13 @@ void VideoParams::Load(QXmlStreamReader *reader) } else if (reader->name() == QStringLiteral("depth")) { set_depth(reader->readElementText().toInt()); } else if (reader->name() == QStringLiteral("timebase")) { - set_time_base(rational::fromString(reader->readElementText())); + set_time_base(rational::fromString(reader->readElementText().toStdString())); } else if (reader->name() == QStringLiteral("format")) { - set_format(static_cast(reader->readElementText().toInt())); + set_format(static_cast(reader->readElementText().toInt())); } else if (reader->name() == QStringLiteral("channelcount")) { set_channel_count(reader->readElementText().toInt()); } else if (reader->name() == QStringLiteral("pixelaspectratio")) { - set_pixel_aspect_ratio(rational::fromString(reader->readElementText())); + set_pixel_aspect_ratio(rational::fromString(reader->readElementText().toStdString())); } else if (reader->name() == QStringLiteral("interlacing")) { set_interlacing(static_cast(reader->readElementText().toInt())); } else if (reader->name() == QStringLiteral("divider")) { @@ -381,7 +366,7 @@ void VideoParams::Load(QXmlStreamReader *reader) } else if (reader->name() == QStringLiteral("videotype")) { set_video_type(static_cast(reader->readElementText().toInt())); } else if (reader->name() == QStringLiteral("framerate")) { - set_frame_rate(rational::fromString(reader->readElementText())); + set_frame_rate(rational::fromString(reader->readElementText().toStdString())); } else if (reader->name() == QStringLiteral("starttime")) { set_start_time(reader->readElementText().toLongLong()); } else if (reader->name() == QStringLiteral("duration")) { @@ -403,10 +388,10 @@ void VideoParams::Save(QXmlStreamWriter *writer) const writer->writeTextElement(QStringLiteral("width"), QString::number(width_)); writer->writeTextElement(QStringLiteral("height"), QString::number(height_)); writer->writeTextElement(QStringLiteral("depth"), QString::number(depth_)); - writer->writeTextElement(QStringLiteral("timebase"), time_base_.toString()); + writer->writeTextElement(QStringLiteral("timebase"), QString::fromStdString(time_base_.toString())); writer->writeTextElement(QStringLiteral("format"), QString::number(format_)); writer->writeTextElement(QStringLiteral("channelcount"), QString::number(channel_count_)); - writer->writeTextElement(QStringLiteral("pixelaspectratio"), pixel_aspect_ratio_.toString()); + writer->writeTextElement(QStringLiteral("pixelaspectratio"), QString::fromStdString(pixel_aspect_ratio_.toString())); writer->writeTextElement(QStringLiteral("interlacing"), QString::number(interlacing_)); writer->writeTextElement(QStringLiteral("divider"), QString::number(divider_)); writer->writeTextElement(QStringLiteral("enabled"), QString::number(enabled_)); @@ -414,7 +399,7 @@ void VideoParams::Save(QXmlStreamWriter *writer) const writer->writeTextElement(QStringLiteral("y"), QString::number(y_)); writer->writeTextElement(QStringLiteral("streamindex"), QString::number(stream_index_)); writer->writeTextElement(QStringLiteral("videotype"), QString::number(video_type_)); - writer->writeTextElement(QStringLiteral("framerate"), frame_rate_.toString()); + writer->writeTextElement(QStringLiteral("framerate"), QString::fromStdString(frame_rate_.toString())); writer->writeTextElement(QStringLiteral("starttime"), QString::number(start_time_)); writer->writeTextElement(QStringLiteral("duration"), QString::number(duration_)); writer->writeTextElement(QStringLiteral("premultipliedalpha"), QString::number(premultiplied_alpha_)); diff --git a/app/render/videoparams.h b/app/render/videoparams.h index e7cbcb883..84ae67b60 100644 --- a/app/render/videoparams.h +++ b/app/render/videoparams.h @@ -21,40 +21,17 @@ #ifndef VIDEOPARAMS_H #define VIDEOPARAMS_H +#include #include #include #include -#include "common/rational.h" -#include "rendermodes.h" - namespace olive { +using namespace core; + class VideoParams { public: - enum Format { - /// Invalid or no format - kFormatInvalid = -1, - - /// 8-bit unsigned integer - kFormatUnsigned8, - - /// 16-bit unsigned integer - kFormatUnsigned16, - - /// 16-bit half float - kFormatFloat16, - - /// 32-bit full float - kFormatFloat32, - - /// 64-bit double float - disabled since very, very few libs support 64-bit buffers - //kFormatFloat64, - - /// Total format count - kFormatCount - }; - enum Interlacing { kInterlaceNone, kInterlacedTopFirst, @@ -76,15 +53,15 @@ public: VideoParams(); - VideoParams(int width, int height, Format format, int nb_channels, + VideoParams(int width, int height, PixelFormat format, int nb_channels, const rational& pixel_aspect_ratio = 1, Interlacing interlacing = kInterlaceNone, int divider = 1); VideoParams(int width, int height, int depth, - Format format, int nb_channels, + PixelFormat format, int nb_channels, const rational& pixel_aspect_ratio = 1, Interlacing interlacing = kInterlaceNone, int divider = 1); VideoParams(int width, int height, const rational& time_base, - Format format, int nb_channels, + PixelFormat format, int nb_channels, const rational& pixel_aspect_ratio = 1, Interlacing interlacing = kInterlaceNone, int divider = 1); @@ -182,12 +159,12 @@ public: return effective_depth_; } - Format format() const + PixelFormat format() const { return format_; } - void set_format(Format f) + void set_format(PixelFormat f) { format_ = f; } @@ -230,19 +207,19 @@ public: bool operator==(const VideoParams& rhs) const; bool operator!=(const VideoParams& rhs) const; - static int GetBytesPerChannel(Format format); + static int GetBytesPerChannel(PixelFormat format); int GetBytesPerChannel() const { return GetBytesPerChannel(format_); } - static int GetBytesPerPixel(Format format, int channels); + static int GetBytesPerPixel(PixelFormat format, int channels); int GetBytesPerPixel() const { return GetBytesPerPixel(format_, channel_count_); } - static int GetBufferSize(int width, int height, Format format, int channels) + static int GetBufferSize(int width, int height, PixelFormat format, int channels) { return width * height * GetBytesPerPixel(format, channels); } @@ -253,9 +230,12 @@ public: static QString GetNameForDivider(int div); - static bool FormatIsFloat(Format format); + static bool FormatIsFloat(PixelFormat format) + { + return format.is_float(); + } - static QString GetFormatName(Format format); + static QString GetFormatName(PixelFormat format); static int GetDividerForTargetResolution(int src_width, int src_height, int dst_width, int dst_height); @@ -395,7 +375,7 @@ private: int depth_; rational time_base_; - Format format_; + PixelFormat format_; int channel_count_; diff --git a/app/task/export/export.cpp b/app/task/export/export.cpp index 397a0eda8..12ebf2ba6 100644 --- a/app/task/export/export.cpp +++ b/app/task/export/export.cpp @@ -20,7 +20,6 @@ #include "export.h" -#include "common/timecodefunctions.h" #include "node/color/colormanager/colormanager.h" namespace olive { diff --git a/app/task/render/render.cpp b/app/task/render/render.cpp index b3bfca484..0dfdfcc8b 100644 --- a/app/task/render/render.cpp +++ b/app/task/render/render.cpp @@ -20,7 +20,6 @@ #include "render.h" -#include "common/timecodefunctions.h" #include "node/project/sequence/sequence.h" #include "render/rendermanager.h" @@ -41,7 +40,7 @@ bool RenderTask::Render(ColorManager* manager, const TimeRangeList &audio_range, const TimeRange &subtitle_range, RenderMode::Mode mode, FrameHashCache* cache, const QSize &force_size, - const QMatrix4x4 &force_matrix, VideoParams::Format force_format, + const QMatrix4x4 &force_matrix, PixelFormat force_format, int force_channel_count, ColorProcessorPtr force_color_output) { QMetaObject::invokeMethod(RenderManager::instance(), "SetAggressiveGarbageCollection", Q_ARG(bool, true)); @@ -279,7 +278,7 @@ void RenderTask::IncrementRunningTickets() void RenderTask::StartTicket(QThread* watcher_thread, ColorManager* manager, const rational& time, RenderMode::Mode mode, FrameHashCache* cache, const QSize &force_size, const QMatrix4x4 &force_matrix, - VideoParams::Format force_format, int force_channel_count, + PixelFormat force_format, int force_channel_count, ColorProcessorPtr force_color_output) { RenderManager::RenderVideoParams rvp(viewer_->GetConnectedTextureOutput(), video_params_, audio_params_, diff --git a/app/task/render/render.h b/app/task/render/render.h index a9313e738..03340e3de 100644 --- a/app/task/render/render.h +++ b/app/task/render/render.h @@ -45,7 +45,7 @@ protected: RenderMode::Mode mode, FrameHashCache *cache, const QSize& force_size = QSize(0, 0), const QMatrix4x4& force_matrix = QMatrix4x4(), - VideoParams::Format force_format = VideoParams::kFormatInvalid, + PixelFormat force_format = PixelFormat::INVALID, int force_channel_count = 0, ColorProcessorPtr force_color_output = nullptr); virtual bool DownloadFrame(QThread* thread, FramePtr frame, const rational &time); @@ -116,7 +116,7 @@ private: void IncrementRunningTickets(); - void StartTicket(QThread *watcher_thread, ColorManager *manager, const rational &time, RenderMode::Mode mode, FrameHashCache *cache, const QSize &force_size, const QMatrix4x4 &force_matrix, VideoParams::Format force_format, int force_channel_count, ColorProcessorPtr force_color_output); + void StartTicket(QThread *watcher_thread, ColorManager *manager, const rational &time, RenderMode::Mode mode, FrameHashCache *cache, const QSize &force_size, const QMatrix4x4 &force_matrix, PixelFormat force_format, int force_channel_count, ColorProcessorPtr force_color_output); ViewerOutput* viewer_; diff --git a/app/timeline/timelinecommon.h b/app/timeline/timelinecommon.h index cdc513149..0bafa466e 100644 --- a/app/timeline/timelinecommon.h +++ b/app/timeline/timelinecommon.h @@ -21,8 +21,11 @@ #ifndef TIMELINECOMMON_H #define TIMELINECOMMON_H +#include + #include "common/define.h" -#include "common/rational.h" + +using namespace olive::core; namespace olive { diff --git a/app/timeline/timelinecoordinate.h b/app/timeline/timelinecoordinate.h index 9e572cca1..70aec2a08 100644 --- a/app/timeline/timelinecoordinate.h +++ b/app/timeline/timelinecoordinate.h @@ -21,7 +21,6 @@ #ifndef TIMELINECOORDINATE_H #define TIMELINECOORDINATE_H -#include "common/rational.h" #include "node/output/track/track.h" namespace olive { diff --git a/app/timeline/timelinemarker.cpp b/app/timeline/timelinemarker.cpp index a9753b2e5..7c72faad3 100644 --- a/app/timeline/timelinemarker.cpp +++ b/app/timeline/timelinemarker.cpp @@ -87,7 +87,7 @@ QRect TimelineMarker::Draw(QPainter *p, const QPoint &pt, int max_right, double int half_width = marker_width / 2; - QColor c = ColorCoding::GetColor(color()).toQColor(); + QColor c = QtUtils::toQColor(ColorCoding::GetColor(color())); if (selected) { p->setPen(Qt::white); p->setBrush(c.lighter()); diff --git a/app/timeline/timelinemarker.h b/app/timeline/timelinemarker.h index 47773d237..f6c65dfd2 100644 --- a/app/timeline/timelinemarker.h +++ b/app/timeline/timelinemarker.h @@ -21,14 +21,16 @@ #ifndef TIMELINEMARKER_H #define TIMELINEMARKER_H +#include #include #include #include #include -#include "common/timerange.h" #include "undo/undocommand.h" +using namespace olive::core; + namespace olive { class TimelineMarker : public QObject diff --git a/app/timeline/timelineworkarea.h b/app/timeline/timelineworkarea.h index f100d8856..2036ac857 100644 --- a/app/timeline/timelineworkarea.h +++ b/app/timeline/timelineworkarea.h @@ -21,14 +21,15 @@ #ifndef TIMELINEWORKAREA_H #define TIMELINEWORKAREA_H +#include #include #include #include -#include "common/timerange.h" - namespace olive { +using namespace core; + class TimelineWorkArea : public QObject { Q_OBJECT diff --git a/app/ui/colorcoding.h b/app/ui/colorcoding.h index 4e8393c12..5cc16d58c 100644 --- a/app/ui/colorcoding.h +++ b/app/ui/colorcoding.h @@ -21,10 +21,13 @@ #ifndef COLORCODING_H #define COLORCODING_H -#include "render/color.h" +#include +#include namespace olive { +using namespace core; + class ColorCoding : public QObject { Q_OBJECT diff --git a/app/widget/colorbutton/colorbutton.cpp b/app/widget/colorbutton/colorbutton.cpp index 0e1a9cf14..f6a3cf3fd 100644 --- a/app/widget/colorbutton/colorbutton.cpp +++ b/app/widget/colorbutton/colorbutton.cpp @@ -83,7 +83,7 @@ void ColorButton::UpdateColor() color_.color_input(), color_.color_output()); - QColor managed = color_processor_->ConvertColor(color_).toQColor(); + QColor managed = QtUtils::toQColor(color_processor_->ConvertColor(color_)); setStyleSheet(QStringLiteral("%1--ColorButton {background: %2;}").arg(MACRO_VAL_AS_STR(olive), managed.name())); } diff --git a/app/widget/colorlabelmenu/colorlabelmenu.cpp b/app/widget/colorlabelmenu/colorlabelmenu.cpp index cbd36186b..4071d5f29 100644 --- a/app/widget/colorlabelmenu/colorlabelmenu.cpp +++ b/app/widget/colorlabelmenu/colorlabelmenu.cpp @@ -24,6 +24,7 @@ #include #include +#include "common/qtutils.h" #include "ui/colorcoding.h" namespace olive { @@ -40,7 +41,7 @@ ColorLabelMenu::ColorLabelMenu(QWidget *parent) : QPainter painter(&p); painter.setPen(Qt::black); - painter.setBrush(ColorCoding::standard_colors().at(i).toQColor()); + painter.setBrush(QtUtils::toQColor(ColorCoding::standard_colors().at(i))); painter.drawRect(p.rect().adjusted(0, 0, -1, -1)); QAction *a = AddItem(QStringLiteral("colorlabel%1").arg(i), this, &ColorLabelMenu::ActionTriggered); diff --git a/app/widget/colorwheel/colorgradientwidget.cpp b/app/widget/colorwheel/colorgradientwidget.cpp index a9a093a68..5972565de 100644 --- a/app/widget/colorwheel/colorgradientwidget.cpp +++ b/app/widget/colorwheel/colorgradientwidget.cpp @@ -62,7 +62,7 @@ void ColorGradientWidget::paintEvent(QPaintEvent *e) } for (int i=0;i +#include "common/qtutils.h" + namespace olive { ColorPreviewBox::ColorPreviewBox(QWidget *parent) : @@ -53,9 +55,9 @@ void ColorPreviewBox::paintEvent(QPaintEvent *e) // Color management if (to_ref_processor_ && to_display_processor_) { - c = to_display_processor_->ConvertColor(to_ref_processor_->ConvertColor(color_)).toQColor(); + c = QtUtils::toQColor(to_display_processor_->ConvertColor(to_ref_processor_->ConvertColor(color_))); } else { - c = color_.toQColor(); + c = QtUtils::toQColor(color_); } QPainter p(this); diff --git a/app/widget/colorwheel/colorpreviewbox.h b/app/widget/colorwheel/colorpreviewbox.h index f222219ac..bd1fee452 100644 --- a/app/widget/colorwheel/colorpreviewbox.h +++ b/app/widget/colorwheel/colorpreviewbox.h @@ -23,7 +23,6 @@ #include -#include "render/color.h" #include "render/colorprocessor.h" namespace olive { diff --git a/app/widget/colorwheel/colorswatchwidget.h b/app/widget/colorwheel/colorswatchwidget.h index 0c68ae50b..8b7bb9f3a 100644 --- a/app/widget/colorwheel/colorswatchwidget.h +++ b/app/widget/colorwheel/colorswatchwidget.h @@ -23,7 +23,6 @@ #include -#include "render/color.h" #include "render/colorprocessor.h" namespace olive { diff --git a/app/widget/colorwheel/colorvalueswidget.h b/app/widget/colorwheel/colorvalueswidget.h index 5c0607043..f234a03c5 100644 --- a/app/widget/colorwheel/colorvalueswidget.h +++ b/app/widget/colorwheel/colorvalueswidget.h @@ -27,7 +27,6 @@ #include "colorpreviewbox.h" #include "node/color/colormanager/colormanager.h" -#include "render/color.h" #include "widget/slider/floatslider.h" #include "widget/slider/stringslider.h" diff --git a/app/widget/colorwheel/colorwheelwidget.cpp b/app/widget/colorwheel/colorwheelwidget.cpp index 954a905ee..78b19e85a 100644 --- a/app/widget/colorwheel/colorwheelwidget.cpp +++ b/app/widget/colorwheel/colorwheelwidget.cpp @@ -73,7 +73,7 @@ void ColorWheelWidget::paintEvent(QPaintEvent *e) if (tri.hypotenuse <= radius) { Color managed = GetManagedColor(GetColorFromTriangle(tri)); - QColor c = managed.toQColor(); + QColor c = QtUtils::toQColor(managed); // Very basic antialiasing around the edges of the wheel qreal alpha = qMin(1.0, radius - tri.hypotenuse); diff --git a/app/widget/colorwheel/colorwheelwidget.h b/app/widget/colorwheel/colorwheelwidget.h index 2860b14bc..9a6be3ec0 100644 --- a/app/widget/colorwheel/colorwheelwidget.h +++ b/app/widget/colorwheel/colorwheelwidget.h @@ -24,7 +24,6 @@ #include #include "colorswatchwidget.h" -#include "render/color.h" namespace olive { diff --git a/app/widget/curvewidget/curvewidget.cpp b/app/widget/curvewidget/curvewidget.cpp index ed5a1b79c..ca69773ec 100644 --- a/app/widget/curvewidget/curvewidget.cpp +++ b/app/widget/curvewidget/curvewidget.cpp @@ -28,7 +28,6 @@ #include "core.h" #include "common/qtutils.h" -#include "common/timecodefunctions.h" #include "node/node.h" #include "widget/keyframeview/keyframeviewundo.h" #include "widget/timeruler/timeruler.h" diff --git a/app/widget/manageddisplay/manageddisplay.cpp b/app/widget/manageddisplay/manageddisplay.cpp index 6a7886242..abbf0b223 100644 --- a/app/widget/manageddisplay/manageddisplay.cpp +++ b/app/widget/manageddisplay/manageddisplay.cpp @@ -279,7 +279,7 @@ VideoParams ManagedDisplayWidget::GetViewportParams() const { int device_width = width() * devicePixelRatioF(); int device_height = height() * devicePixelRatioF(); - VideoParams::Format device_format = static_cast(OLIVE_CONFIG("OfflinePixelFormat").toInt()); + PixelFormat device_format = static_cast(OLIVE_CONFIG("OfflinePixelFormat").toInt()); return VideoParams(device_width, device_height, device_format, VideoParams::kInternalChannelCount); } diff --git a/app/widget/menu/menushared.cpp b/app/widget/menu/menushared.cpp index 7e6ee594f..8ff97d204 100644 --- a/app/widget/menu/menushared.cpp +++ b/app/widget/menu/menushared.cpp @@ -23,7 +23,6 @@ #include #include "core.h" -#include "common/timecodefunctions.h" #include "panel/panelmanager.h" #include "panel/timeline/timeline.h" #include "window/mainwindow/mainwindow.h" @@ -189,7 +188,7 @@ void MenuShared::AboutToShowTimeRulerActions(const rational& timebase) Timecode::Display current_timecode_display = Core::instance()->GetTimecodeDisplay(); // Only show the drop-frame option if the timebase is drop-frame - view_timecode_view_dropframe_item_->setVisible(!timebase.isNull() && Timecode::TimebaseIsDropFrame(timebase)); + view_timecode_view_dropframe_item_->setVisible(!timebase.isNull() && Timecode::timebase_is_drop_frame(timebase)); if (!view_timecode_view_dropframe_item_->isVisible() && current_timecode_display == Timecode::kTimecodeDropFrame) { // If the current setting is drop-frame, correct to non-drop frame diff --git a/app/widget/menu/menushared.h b/app/widget/menu/menushared.h index 61a544e53..398d40e44 100644 --- a/app/widget/menu/menushared.h +++ b/app/widget/menu/menushared.h @@ -21,12 +21,14 @@ #ifndef MENUSHARED_H #define MENUSHARED_H -#include "common/rational.h" +#include #include "widget/colorlabelmenu/colorlabelmenu.h" #include "widget/menu/menu.h" namespace olive { +using namespace core; + /** * @brief A static object that provides various "stock" menus for use throughout the application */ diff --git a/app/widget/nodeparamview/nodeparamview.cpp b/app/widget/nodeparamview/nodeparamview.cpp index c734af945..da5519964 100644 --- a/app/widget/nodeparamview/nodeparamview.cpp +++ b/app/widget/nodeparamview/nodeparamview.cpp @@ -26,7 +26,6 @@ #include #include -#include "common/timecodefunctions.h" #include "node/output/viewer/viewer.h" #include "widget/nodeparamview/nodeparamviewundo.h" #include "widget/nodeview/nodeviewundo.h" diff --git a/app/widget/nodeview/nodeviewcontext.cpp b/app/widget/nodeview/nodeviewcontext.cpp index 32e63a17b..4f0be5acf 100644 --- a/app/widget/nodeview/nodeviewcontext.cpp +++ b/app/widget/nodeview/nodeviewcontext.cpp @@ -29,8 +29,8 @@ NodeViewContext::NodeViewContext(Node *context, QGraphicsItem *item) : lbl_ = QCoreApplication::translate("NodeViewContext", "%1 [%2] :: %3 - %4").arg(block->GetLabelAndName(), Track::Reference::TypeToTranslatedString(block->track()->type()), - Timecode::time_to_timecode(block->in(), timebase, Core::instance()->GetTimecodeDisplay()), - Timecode::time_to_timecode(block->out(), timebase, Core::instance()->GetTimecodeDisplay())); + QString::fromStdString(Timecode::time_to_timecode(block->in(), timebase, Core::instance()->GetTimecodeDisplay())), + QString::fromStdString(Timecode::time_to_timecode(block->out(), timebase, Core::instance()->GetTimecodeDisplay()))); } else { lbl_ = context_->GetLabelAndName(); } @@ -244,7 +244,7 @@ void NodeViewContext::paint(QPainter *painter, const QStyleOptionGraphicsItem *o { // Set pen and brush Color color = context_->color(); - QColor c = color.toQColor(); + QColor c = QtUtils::toQColor(color); QPen pen(c, 2); if (option->state & QStyle::State_Selected) { pen.setStyle(Qt::DotLine); diff --git a/app/widget/pixelsampler/pixelsampler.h b/app/widget/pixelsampler/pixelsampler.h index 42884c28c..f0d53bf23 100644 --- a/app/widget/pixelsampler/pixelsampler.h +++ b/app/widget/pixelsampler/pixelsampler.h @@ -25,7 +25,6 @@ #include #include -#include "render/color.h" #include "widget/colorwheel/colorpreviewbox.h" namespace olive { diff --git a/app/widget/playbackcontrols/playbackcontrols.cpp b/app/widget/playbackcontrols/playbackcontrols.cpp index a87904e9e..1f9e0b8ff 100644 --- a/app/widget/playbackcontrols/playbackcontrols.cpp +++ b/app/widget/playbackcontrols/playbackcontrols.cpp @@ -198,9 +198,9 @@ void PlaybackControls::SetEndTime(const rational &r) end_time_ = r; - end_tc_lbl_->setText(Timecode::time_to_timecode(end_time_, - time_base_, - Core::instance()->GetTimecodeDisplay())); + end_tc_lbl_->setText(QString::fromStdString(Timecode::time_to_timecode(end_time_, + time_base_, + Core::instance()->GetTimecodeDisplay()))); } void PlaybackControls::ShowPauseButton() diff --git a/app/widget/playbackcontrols/playbackcontrols.h b/app/widget/playbackcontrols/playbackcontrols.h index 53ea4ce5d..826839f76 100644 --- a/app/widget/playbackcontrols/playbackcontrols.h +++ b/app/widget/playbackcontrols/playbackcontrols.h @@ -26,7 +26,6 @@ #include #include -#include "common/rational.h" #include "dragbutton.h" #include "widget/slider/rationalslider.h" diff --git a/app/widget/resizablescrollbar/resizabletimelinescrollbar.cpp b/app/widget/resizablescrollbar/resizabletimelinescrollbar.cpp index 2d4f98ea2..a1648f50b 100644 --- a/app/widget/resizablescrollbar/resizabletimelinescrollbar.cpp +++ b/app/widget/resizablescrollbar/resizabletimelinescrollbar.cpp @@ -131,7 +131,7 @@ void ResizableTimelineScrollBar::paintEvent(QPaintEvent *event) for (auto it=markers_->cbegin(); it!=markers_->cend(); it++) { TimelineMarker* marker = *it; - QColor marker_color = ColorCoding::GetColor(marker->color()).toQColor(); + QColor marker_color = QtUtils::toQColor(ColorCoding::GetColor(marker->color())); int64_t in = qRound64(ratio * TimeToScene(marker->time().in())); int64_t out = qRound64(ratio * TimeToScene(marker->time().out())); int64_t length = qMax(int64_t(1), out-in); diff --git a/app/widget/slider/rationalslider.cpp b/app/widget/slider/rationalslider.cpp index 8ac41bf0d..bcad1f493 100644 --- a/app/widget/slider/rationalslider.cpp +++ b/app/widget/slider/rationalslider.cpp @@ -20,7 +20,6 @@ #include "rationalslider.h" -#include "common/timecodefunctions.h" #include "core.h" #include "widget/menu/menu.h" #include "widget/menu/menushared.h" @@ -107,11 +106,11 @@ QString RationalSlider::ValueToString(const QVariant &v) const switch (display_type_) { case kTime: - return Timecode::time_to_timecode(r, timebase_, Core::instance()->GetTimecodeDisplay()); + return QString::fromStdString(Timecode::time_to_timecode(r, timebase_, Core::instance()->GetTimecodeDisplay())); case kFloat: return FloatToString(val, GetDecimalPlaces(), GetAutoTrimDecimalPlaces()); case kRational: - return v.value().toString(); + return QString::fromStdString(v.value().toString()); } return v.toString(); @@ -126,7 +125,7 @@ QVariant RationalSlider::StringToValue(const QString &s, bool *ok) const switch (display_type_) { case kTime: { - r = Timecode::timecode_to_time(s, timebase_, Core::instance()->GetTimecodeDisplay(), ok); + r = Timecode::timecode_to_time(s.toStdString(), timebase_, Core::instance()->GetTimecodeDisplay(), ok); break; } case kFloat: @@ -142,7 +141,7 @@ QVariant RationalSlider::StringToValue(const QString &s, bool *ok) const break; } case kRational: - r = rational::fromString(s, ok); + r = rational::fromString(s.toStdString(), ok); break; } diff --git a/app/widget/slider/rationalslider.h b/app/widget/slider/rationalslider.h index 090bff099..4da25b96a 100644 --- a/app/widget/slider/rationalslider.h +++ b/app/widget/slider/rationalslider.h @@ -21,13 +21,15 @@ #ifndef RATIONALSLIDER_H #define RATIONALSLIDER_H +#include #include #include "base/decimalsliderbase.h" -#include "common/rational.h" namespace olive { +using namespace core; + /** * @brief A olive::rational based slider * diff --git a/app/widget/standardcombos/frameratecombobox.h b/app/widget/standardcombos/frameratecombobox.h index ddd12d47a..c0d63d24d 100644 --- a/app/widget/standardcombos/frameratecombobox.h +++ b/app/widget/standardcombos/frameratecombobox.h @@ -27,7 +27,6 @@ #include #include -#include "common/rational.h" #include "render/videoparams.h" namespace olive { @@ -121,7 +120,7 @@ private slots: r = rational::fromDouble(d, &ok); } else { // Try converting to rational in case someone formatted that way - r = rational::fromString(s, &ok); + r = rational::fromString(s.toStdString(), &ok); } if (ok) { diff --git a/app/widget/standardcombos/pixelformatcombobox.h b/app/widget/standardcombos/pixelformatcombobox.h index 1e7fda24b..46fc31312 100644 --- a/app/widget/standardcombos/pixelformatcombobox.h +++ b/app/widget/standardcombos/pixelformatcombobox.h @@ -35,21 +35,21 @@ public: QComboBox(parent) { // Set up preview formats - for (int i=0;i(i); + for (int i=0;i(i); - if (!float_only || VideoParams::FormatIsFloat(pix_fmt)) { - this->addItem(VideoParams::GetFormatName(pix_fmt), pix_fmt); + if (!float_only || pix_fmt.is_float()) { + this->addItem(VideoParams::GetFormatName(pix_fmt), static_cast(pix_fmt)); } } } - VideoParams::Format GetPixelFormat() const + PixelFormat GetPixelFormat() const { - return static_cast(this->currentData().toInt()); + return static_cast(this->currentData().toInt()); } - void SetPixelFormat(VideoParams::Format fmt) + void SetPixelFormat(PixelFormat fmt) { for (int i=0; icount(); i++) { if (this->itemData(i).toInt() == fmt) { diff --git a/app/widget/taskview/elapsedcounterwidget.cpp b/app/widget/taskview/elapsedcounterwidget.cpp index 8300be9f4..4c7a4788c 100644 --- a/app/widget/taskview/elapsedcounterwidget.cpp +++ b/app/widget/taskview/elapsedcounterwidget.cpp @@ -20,14 +20,15 @@ #include "elapsedcounterwidget.h" +#include #include #include #include -#include "common/timecodefunctions.h" - namespace olive { +using namespace core; + ElapsedCounterWidget::ElapsedCounterWidget(QWidget* parent) : QWidget(parent), last_progress_(0), @@ -87,8 +88,8 @@ void ElapsedCounterWidget::UpdateTimers() remaining_ms = 0; } - elapsed_lbl_->setText(tr("Elapsed: %1").arg(Timecode::TimeToString(elapsed_ms))); - remaining_lbl_->setText(tr("Remaining: %1").arg(Timecode::TimeToString(remaining_ms))); + elapsed_lbl_->setText(tr("Elapsed: %1").arg(QString::fromStdString(Timecode::time_to_string(elapsed_ms)))); + remaining_lbl_->setText(tr("Remaining: %1").arg(QString::fromStdString(Timecode::time_to_string(remaining_ms)))); } } diff --git a/app/widget/taskview/taskviewitem.cpp b/app/widget/taskview/taskviewitem.cpp index eaa7f04e0..406be48bc 100644 --- a/app/widget/taskview/taskviewitem.cpp +++ b/app/widget/taskview/taskviewitem.cpp @@ -23,7 +23,6 @@ #include #include -#include "common/timecodefunctions.h" #include "ui/icons/icons.h" namespace olive { diff --git a/app/widget/timebased/timebasedview.cpp b/app/widget/timebased/timebasedview.cpp index 869bc6d78..6576cf4b3 100644 --- a/app/widget/timebased/timebasedview.cpp +++ b/app/widget/timebased/timebasedview.cpp @@ -25,7 +25,6 @@ #include #include -#include "common/timecodefunctions.h" #include "widget/timebased/timebasedwidget.h" namespace olive { diff --git a/app/widget/timebased/timebasedviewselectionmanager.h b/app/widget/timebased/timebasedviewselectionmanager.h index f9ac6faf9..2169170b2 100644 --- a/app/widget/timebased/timebasedviewselectionmanager.h +++ b/app/widget/timebased/timebasedviewselectionmanager.h @@ -27,8 +27,6 @@ #include #include "common/qtutils.h" -#include "common/rational.h" -#include "common/timecodefunctions.h" #include "timebasedview.h" #include "timebasedwidget.h" #include "widget/timetarget/timetarget.h" @@ -309,8 +307,9 @@ public: display_time = initial_drag_item_->time(); } - QString tip = Timecode::time_to_timecode(display_time, timebase_, - Core::instance()->GetTimecodeDisplay(), false); + QString tip = QString::fromStdString(Timecode::time_to_timecode( + display_time, timebase_, + Core::instance()->GetTimecodeDisplay(), false)); if (!tip_format.isEmpty()) { tip = tip_format.arg(tip); diff --git a/app/widget/timebased/timebasedwidget.cpp b/app/widget/timebased/timebasedwidget.cpp index a87b6dbbb..15145f999 100644 --- a/app/widget/timebased/timebasedwidget.cpp +++ b/app/widget/timebased/timebasedwidget.cpp @@ -24,7 +24,6 @@ #include "common/autoscroll.h" #include "common/range.h" -#include "common/timecodefunctions.h" #include "config/config.h" #include "core.h" #include "dialog/markerproperties/markerpropertiesdialog.h" diff --git a/app/widget/timebased/timescaledobject.h b/app/widget/timebased/timescaledobject.h index 6fb237682..ca4a59765 100644 --- a/app/widget/timebased/timescaledobject.h +++ b/app/widget/timebased/timescaledobject.h @@ -21,9 +21,9 @@ #ifndef TIMELINESCALEDOBJECT_H #define TIMELINESCALEDOBJECT_H +#include #include -#include "common/rational.h" #include "node/block/block.h" namespace olive { diff --git a/app/widget/timelinewidget/timelinewidget.cpp b/app/widget/timelinewidget/timelinewidget.cpp index 1ca6e3569..f609d1da9 100644 --- a/app/widget/timelinewidget/timelinewidget.cpp +++ b/app/widget/timelinewidget/timelinewidget.cpp @@ -27,7 +27,6 @@ #include "core.h" #include "common/range.h" -#include "common/timecodefunctions.h" #include "dialog/sequence/sequence.h" #include "dialog/speedduration/speeddurationdialog.h" #include "node/block/transition/transition.h" @@ -660,7 +659,7 @@ bool TimelineWidget::CopySelected(bool cut) } foreach (Block* block, selected_blocks_) { - properties[block][QStringLiteral("in")] = (block->in() - earliest_in).toString(); + properties[block][QStringLiteral("in")] = QString::fromStdString((block->in() - earliest_in).toString()); properties[block][QStringLiteral("track")] = block->track()->ToReference().ToString(); } @@ -1978,7 +1977,7 @@ bool TimelineWidget::PasteInternal(bool insert) for (auto it=res.GetLoadData().properties.cbegin(); it!=res.GetLoadData().properties.cend(); it++) { rational length = static_cast(it.key())->length(); - rational in = rational::fromString(it.value()[QStringLiteral("in")]); + rational in = rational::fromString(it.value()[QStringLiteral("in")].toStdString()); paste_end = qMax(paste_end, paste_start + in + length); } @@ -1990,7 +1989,7 @@ bool TimelineWidget::PasteInternal(bool insert) for (auto it=res.GetLoadData().properties.cbegin(); it!=res.GetLoadData().properties.cend(); it++) { Block *block = static_cast(it.key()); - rational in = rational::fromString(it.value()[QStringLiteral("in")]); + rational in = rational::fromString(it.value()[QStringLiteral("in")].toStdString()); Track::Reference track = Track::Reference::FromString(it.value()[QStringLiteral("track")]); command->add_child(new TrackPlaceBlockCommand(sequence()->track_list(track.type()), diff --git a/app/widget/timelinewidget/timelinewidgetselections.h b/app/widget/timelinewidget/timelinewidgetselections.h index 8bd216f66..df579de25 100644 --- a/app/widget/timelinewidget/timelinewidgetselections.h +++ b/app/widget/timelinewidget/timelinewidgetselections.h @@ -23,7 +23,6 @@ #include -#include "common/timerange.h" #include "node/output/track/track.h" namespace olive { diff --git a/app/widget/timelinewidget/tool/import.cpp b/app/widget/timelinewidget/tool/import.cpp index 214056f2c..b09e66752 100644 --- a/app/widget/timelinewidget/tool/import.cpp +++ b/app/widget/timelinewidget/tool/import.cpp @@ -150,9 +150,9 @@ void ImportTool::DragMove(TimelineViewMouseEvent *event) // Generate tooltip (showing earliest in point of imported clip) rational tooltip_timebase = parent()->GetTimebaseForTrackType(event->GetTrack().type()); - QString tooltip_text = Timecode::time_to_timecode(earliest_ghost, - tooltip_timebase, - Core::instance()->GetTimecodeDisplay()); + QString tooltip_text = QString::fromStdString(Timecode::time_to_timecode(earliest_ghost, + tooltip_timebase, + Core::instance()->GetTimecodeDisplay())); // Force tooltip to update (otherwise the tooltip won't move as written in the documentation, and could get in the way // of the cursor) diff --git a/app/widget/timelinewidget/tool/pointer.cpp b/app/widget/timelinewidget/tool/pointer.cpp index 91595afa2..eca7470a6 100644 --- a/app/widget/timelinewidget/tool/pointer.cpp +++ b/app/widget/timelinewidget/tool/pointer.cpp @@ -26,7 +26,6 @@ #include "common/clamp.h" #include "common/qtutils.h" #include "common/range.h" -#include "common/timecodefunctions.h" #include "config/config.h" #include "core.h" #include "node/block/gap/gap.h" @@ -596,10 +595,10 @@ void PointerTool::ProcessDrag(const TimelineCoordinate &mouse_pos) rational tooltip_timebase = parent()->GetTimebaseForTrackType(drag_start_.GetTrack().type()); QToolTip::hideText(); QToolTip::showText(QCursor::pos(), - Timecode::time_to_timecode(time_movement, - tooltip_timebase, - Core::instance()->GetTimecodeDisplay(), - true), + QString::fromStdString(Timecode::time_to_timecode(time_movement, + tooltip_timebase, + Core::instance()->GetTimecodeDisplay(), + true)), parent()); } diff --git a/app/widget/timelinewidget/tool/slip.cpp b/app/widget/timelinewidget/tool/slip.cpp index 86550fcbc..94337928f 100644 --- a/app/widget/timelinewidget/tool/slip.cpp +++ b/app/widget/timelinewidget/tool/slip.cpp @@ -22,7 +22,6 @@ #include -#include "common/timecodefunctions.h" #include "config/config.h" #include "slip.h" #include "widget/timelinewidget/undo/timelineundogeneral.h" @@ -58,10 +57,10 @@ void SlipTool::ProcessDrag(const TimelineCoordinate &mouse_pos) rational tooltip_timebase = parent()->GetTimebaseForTrackType(drag_start_.GetTrack().type()); QToolTip::hideText(); QToolTip::showText(QCursor::pos(), - Timecode::time_to_timecode(time_movement, - tooltip_timebase, - Core::instance()->GetTimecodeDisplay(), - true), + QString::fromStdString(Timecode::time_to_timecode(time_movement, + tooltip_timebase, + Core::instance()->GetTimecodeDisplay(), + true)), parent()); } diff --git a/app/widget/timelinewidget/tool/tool.h b/app/widget/timelinewidget/tool/tool.h index 37a5a6841..450e39060 100644 --- a/app/widget/timelinewidget/tool/tool.h +++ b/app/widget/timelinewidget/tool/tool.h @@ -23,7 +23,6 @@ #include -#include "common/rational.h" #include "widget/nodeview/nodeviewundo.h" #include "widget/timelinewidget/view/timelineviewghostitem.h" #include "widget/timelinewidget/view/timelineviewmouseevent.h" diff --git a/app/widget/timelinewidget/view/timelineview.cpp b/app/widget/timelinewidget/view/timelineview.cpp index d086fb657..2062b1c2e 100644 --- a/app/widget/timelinewidget/view/timelineview.cpp +++ b/app/widget/timelinewidget/view/timelineview.cpp @@ -29,7 +29,6 @@ #include "config/config.h" #include "common/qtutils.h" -#include "common/timecodefunctions.h" #include "node/project/footage/footage.h" #include "panel/panelmanager.h" #include "panel/timeline/timeline.h" @@ -106,9 +105,9 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) Block* b = GetItemAtScenePos(timeline_event.GetFrame(), timeline_event.GetTrack().index()); if (b) { setToolTip(tr("In: %1\nOut: %2\nDuration: %3").arg( - Timecode::time_to_timecode(b->in(), timebase(), Core::instance()->GetTimecodeDisplay()), - Timecode::time_to_timecode(b->out(), timebase(), Core::instance()->GetTimecodeDisplay()), - Timecode::time_to_timecode(b->length(), timebase(), Core::instance()->GetTimecodeDisplay()) + QString::fromStdString(Timecode::time_to_timecode(b->in(), timebase(), Core::instance()->GetTimecodeDisplay())), + QString::fromStdString(Timecode::time_to_timecode(b->out(), timebase(), Core::instance()->GetTimecodeDisplay())), + QString::fromStdString(Timecode::time_to_timecode(b->length(), timebase(), Core::instance()->GetTimecodeDisplay())) )); } else { setToolTip(QString()); @@ -416,7 +415,7 @@ void TimelineView::DrawBlock(QPainter *painter, bool foreground, Block *block, q block_right - block_left, block_height); - QColor shadow_color = block->is_enabled() ? block->color().toQColor().darker() : QColor(Qt::darkGray).darker(); + QColor shadow_color = block->is_enabled() ? QtUtils::toQColor(block->color()).darker() : QColor(Qt::darkGray).darker(); const qreal MINIMUM_RECT_WIDTH = 2; const qreal MINIMUM_DETAIL_WIDTH = 8; diff --git a/app/widget/timeruler/seekablewidget.h b/app/widget/timeruler/seekablewidget.h index 47e730542..bf0b248a6 100644 --- a/app/widget/timeruler/seekablewidget.h +++ b/app/widget/timeruler/seekablewidget.h @@ -24,7 +24,6 @@ #include #include -#include "common/rational.h" #include "widget/menu/menu.h" #include "widget/timebased/timebasedviewselectionmanager.h" diff --git a/app/widget/timeruler/timeruler.cpp b/app/widget/timeruler/timeruler.cpp index 3d3a00808..1fa74f9d3 100644 --- a/app/widget/timeruler/timeruler.cpp +++ b/app/widget/timeruler/timeruler.cpp @@ -23,7 +23,6 @@ #include #include -#include "common/timecodefunctions.h" #include "common/qtutils.h" #include "config/config.h" #include "core.h" @@ -206,7 +205,7 @@ void TimeRuler::drawForeground(QPainter *p, const QRectF &rect) if (text_visible_) { QRect text_rect; Qt::Alignment text_align; - QString timecode_str = Timecode::time_to_timecode(SceneToTime(i), timebase(), Core::instance()->GetTimecodeDisplay()); + QString timecode_str = QString::fromStdString(Timecode::time_to_timecode(SceneToTime(i), timebase(), Core::instance()->GetTimecodeDisplay())); int timecode_width = QtUtils::QFontMetricsWidth(fm, timecode_str); int timecode_left; diff --git a/app/widget/timeruler/timeruler.h b/app/widget/timeruler/timeruler.h index f23571634..f7855060c 100644 --- a/app/widget/timeruler/timeruler.h +++ b/app/widget/timeruler/timeruler.h @@ -24,7 +24,6 @@ #include #include -#include "common/timerange.h" #include "seekablewidget.h" #include "render/playbackcache.h" diff --git a/app/widget/viewer/viewer.cpp b/app/widget/viewer/viewer.cpp index 294a98c87..0c8e91b33 100644 --- a/app/widget/viewer/viewer.cpp +++ b/app/widget/viewer/viewer.cpp @@ -34,7 +34,6 @@ #include "audio/audiomanager.h" #include "common/clamp.h" #include "common/ratiodialog.h" -#include "common/timecodefunctions.h" #include "config/config.h" #include "core.h" #include "node/block/gap/gap.h" diff --git a/app/widget/viewer/viewer.h b/app/widget/viewer/viewer.h index 203a03801..006d0aad4 100644 --- a/app/widget/viewer/viewer.h +++ b/app/widget/viewer/viewer.h @@ -30,7 +30,6 @@ #include "audio/audioprocessor.h" #include "audiowaveformview.h" -#include "common/rational.h" #include "node/output/viewer/viewer.h" #include "render/previewaudiodevice.h" #include "render/previewautocacher.h" diff --git a/app/widget/viewer/viewerdisplay.h b/app/widget/viewer/viewerdisplay.h index 37567dabc..2672b1b67 100644 --- a/app/widget/viewer/viewerdisplay.h +++ b/app/widget/viewer/viewerdisplay.h @@ -29,7 +29,6 @@ #include "node/node.h" #include "node/output/track/tracklist.h" #include "node/traverser.h" -#include "render/color.h" #include "tool/tool.h" #include "viewerplaybacktimer.h" #include "viewerqueue.h" diff --git a/app/widget/viewer/viewersizer.h b/app/widget/viewer/viewersizer.h index 21cb532f1..90157be6d 100644 --- a/app/widget/viewer/viewersizer.h +++ b/app/widget/viewer/viewersizer.h @@ -21,14 +21,14 @@ #ifndef VIEWERSIZER_H #define VIEWERSIZER_H +#include #include #include -#include "common/define.h" -#include "common/rational.h" - namespace olive { +using namespace core; + /** * @brief A container widget that enforces the aspect ratio of a child widget * diff --git a/app/widget/viewer/viewerwindow.cpp b/app/widget/viewer/viewerwindow.cpp index 41e43462f..b4bbcfa63 100644 --- a/app/widget/viewer/viewerwindow.cpp +++ b/app/widget/viewer/viewerwindow.cpp @@ -23,8 +23,6 @@ #include #include -#include "common/timecodefunctions.h" - namespace olive { ViewerWindow::ViewerWindow(QWidget *parent) : diff --git a/app/window/mainwindow/mainmenu.cpp b/app/window/mainwindow/mainmenu.cpp index 6d5daa527..3b8e86fbb 100644 --- a/app/window/mainwindow/mainmenu.cpp +++ b/app/window/mainwindow/mainmenu.cpp @@ -25,7 +25,6 @@ #include #include -#include "common/timecodefunctions.h" #include "config/config.h" #include "core.h" #include "dialog/actionsearch/actionsearch.h" diff --git a/cmake/FindOlive.cmake b/cmake/FindOlive.cmake new file mode 100644 index 000000000..20b34f5f4 --- /dev/null +++ b/cmake/FindOlive.cmake @@ -0,0 +1,55 @@ +# Olive - Non-Linear Video Editor +# Copyright (C) 2023 Olive Studios LLC +# +# 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 . + +set(LIBOLIVE_COMPONENTS + Core + #Codec +) + +foreach (COMPONENT ${LIBOLIVE_COMPONENTS}) + string(TOLOWER ${COMPONENT} LOWER_COMPONENT) + string(TOUPPER ${COMPONENT} UPPER_COMPONENT) + + # Find include directory for this component + find_path(LIBOLIVE_${UPPER_COMPONENT}_INCLUDEDIR + olive/${LOWER_COMPONENT}/${LOWER_COMPONENT}.h + HINTS + "${LIBOLIVE_LOCATION}" + "$ENV{LIBOLIVE_LOCATION}" + PATH_SUFFIXES + include/ + ) + + find_library(LIBOLIVE_${UPPER_COMPONENT}_LIBRARY + olivecore + HINTS + "${LIBOLIVE_LOCATION}" + "$ENV{LIBOLIVE_LOCATION}" + PATH_SUFFIXES + lib/ + ) + + list(APPEND LIBOLIVE_LIBRARIES ${LIBOLIVE_${UPPER_COMPONENT}_LIBRARY}) + list(APPEND LIBOLIVE_INCLUDE_DIRS ${LIBOLIVE_${UPPER_COMPONENT}_INCLUDEDIR}) +endforeach() + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(Olive + REQUIRED_VARS + LIBOLIVE_LIBRARIES + LIBOLIVE_INCLUDE_DIRS +)