various: moved more to core lib

This commit is contained in:
itsmattkc
2023-01-19 16:01:31 -08:00
parent dd9c52ab59
commit c1c6893713
92 changed files with 448 additions and 1558 deletions
-3
View File
@@ -16,11 +16,8 @@
set(OLIVE_SOURCES
${OLIVE_SOURCES}
common/bezier.cpp
common/bezier.h
common/cancelableobject.h
common/channellayout.h
common/clamp.h
common/commandlineparser.cpp
common/commandlineparser.h
common/crashpadinterface.cpp
-110
View File
@@ -1,110 +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 <http://www.gnu.org/licenses/>.
***/
#include "bezier.h"
#include <QtMath>
#include "common/clamp.h"
namespace olive {
Bezier::Bezier() :
x_(0),
y_(0),
cp1_x_(0),
cp1_y_(0),
cp2_x_(0),
cp2_y_(0)
{
}
Bezier::Bezier(double x, double y) :
x_(x),
y_(y),
cp1_x_(0),
cp1_y_(0),
cp2_x_(0),
cp2_y_(0)
{
}
Bezier::Bezier(double x, double y, double cp1_x, double cp1_y, double cp2_x, double cp2_y) :
x_(x),
y_(y),
cp1_x_(cp1_x),
cp1_y_(cp1_y),
cp2_x_(cp2_x),
cp2_y_(cp2_y)
{
}
double Bezier::QuadraticXtoT(double x, double a, double b, double c)
{
// Clamp to prevent infinite loop
x = clamp(x, a, c);
return CalculateTFromX(false, x, a, b, c, 0);
}
double Bezier::QuadraticTtoY(double a, double b, double c, double t)
{
return qPow(1.0 - t, 2)*a + 2*(1.0 - t)*t*b + qPow(t, 2)*c;
}
double Bezier::CubicXtoT(double x, double a, double b, double c, double d)
{
// Clamp to prevent infinite loop
x = clamp(x, a, d);
return CalculateTFromX(true, x, a, b, c, d);
}
double Bezier::CubicTtoY(double a, double b, double c, double d, double t)
{
return qPow(1.0 - t, 3)*a + 3*qPow(1.0 - t, 2)*t*b + 3*(1.0 - t)*qPow(t, 2)*c + qPow(t, 3)*d;
}
double Bezier::CalculateTFromX(bool cubic, double x, double a, double b, double c, double d)
{
double bottom = 0.0;
double top = 1.0;
while (true) {
if (bottom == top) {
return bottom;
}
double mid = (bottom + top) * 0.5;
double test = cubic ? CubicTtoY(a, b, c, d, mid) : QuadraticTtoY(a, b, c, mid);
if (qAbs(test - x) < 0.000001) {
return mid;
} else if (x > test) {
bottom = mid;
} else {
top = mid;
}
}
return qSNaN();
}
}
-103
View File
@@ -1,103 +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 <http://www.gnu.org/licenses/>.
***/
#ifndef BEZIER_H
#define BEZIER_H
#include <QPointF>
#include <QObject>
#include "common/define.h"
namespace olive {
class Bezier
{
public:
Bezier();
Bezier(double x, double y);
Bezier(double x, double y, double cp1_x, double cp1_y, double cp2_x, double cp2_y);
const double &x() const {return x_; }
const double &y() const {return y_; }
const double &cp1_x() const { return cp1_x_; }
const double &cp1_y() const { return cp1_y_; }
const double &cp2_x() const { return cp2_x_; }
const double &cp2_y() const { return cp2_y_; }
QPointF ToPointF() const
{
return QPointF(x_, y_);
}
QPointF ControlPoint1ToPointF() const
{
return QPointF(cp1_x_, cp1_y_);
}
QPointF ControlPoint2ToPointF() const
{
return QPointF(cp2_x_, cp2_y_);
}
void set_x(const double &x) { x_ = x; }
void set_y(const double &y) { y_ = y; }
void set_cp1_x(const double &cp1_x) { cp1_x_ = cp1_x; }
void set_cp1_y(const double &cp1_y) { cp1_y_ = cp1_y; }
void set_cp2_x(const double &cp2_x) { cp2_x_ = cp2_x; }
void set_cp2_y(const double &cp2_y) { cp2_y_ = cp2_y; }
static double QuadraticXtoT(double x, double a, double b, double c);
static double QuadraticTtoY(double a, double b, double c, double t);
static double QuadraticXtoY(double x, const QPointF &a, const QPointF &b, const QPointF &c)
{
return QuadraticTtoY(a.y(), b.y(), c.y(), QuadraticXtoT(x, a.x(), b.x(), c.x()));
}
static double CubicXtoT(double x, double a, double b, double c, double d);
static double CubicTtoY(double a, double b, double c, double d, double t);
static double CubicXtoY(double x, const QPointF &a, const QPointF &b, const QPointF &c, const QPointF &d)
{
return CubicTtoY(a.y(), b.y(), c.y(), d.y(), CubicXtoT(x, a.x(), b.x(), c.x(), d.x()));
}
private:
static double CalculateTFromX(bool cubic, double x, double a, double b, double c, double d);
double x_;
double y_;
double cp1_x_;
double cp1_y_;
double cp2_x_;
double cp2_y_;
};
}
Q_DECLARE_METATYPE(olive::Bezier)
#endif // BEZIER_H
-47
View File
@@ -1,47 +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 <http://www.gnu.org/licenses/>.
***/
#ifndef CLAMP_H
#define CLAMP_H
template<typename T>
/**
* @brief Clamp a value between a minimum and a maximum value
*
* Similar to using min() and max() functions, but performs both at once. If value is less than minimum, this returns
* minimum. If it is more than maximum, this returns maximum. Otherwise it returns value as-is.
*
* @return
*
* Will always return a value between minimum and maximum (inclusive).
*/
T clamp(T value, T minimum, T maximum) {
if (value < minimum) {
return minimum;
}
if (value > maximum) {
return maximum;
}
return value;
}
#endif // CLAMP_H
-30
View File
@@ -1,30 +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 <http://www.gnu.org/licenses/>.
***/
#ifndef CPUOPTIMIZE_H
#define CPUOPTIMIZE_H
#if defined(Q_PROCESSOR_X86)
#include <xmmintrin.h>
#elif defined(Q_PROCESSOR_ARM)
#include <sse2neon.h>
#endif
#endif // CPUOPTIMIZE_H
+32 -32
View File
@@ -41,70 +41,70 @@ AVPixelFormat FFmpegUtils::GetCompatiblePixelFormat(const AVPixelFormat &pix_fmt
nullptr);
}
AudioParams::Format FFmpegUtils::GetNativeSampleFormat(const AVSampleFormat &smp_fmt)
SampleFormat FFmpegUtils::GetNativeSampleFormat(const AVSampleFormat &smp_fmt)
{
switch (smp_fmt) {
case AV_SAMPLE_FMT_U8:
return AudioParams::kFormatUnsigned8Packed;
return SampleFormat::U8;
case AV_SAMPLE_FMT_S16:
return AudioParams::kFormatSigned16Packed;
return SampleFormat::S16;
case AV_SAMPLE_FMT_S32:
return AudioParams::kFormatSigned32Packed;
return SampleFormat::S32;
case AV_SAMPLE_FMT_S64:
return AudioParams::kFormatSigned64Packed;
return SampleFormat::S64;
case AV_SAMPLE_FMT_FLT:
return AudioParams::kFormatFloat32Packed;
return SampleFormat::F32;
case AV_SAMPLE_FMT_DBL:
return AudioParams::kFormatFloat64Packed;
return SampleFormat::F64;
case AV_SAMPLE_FMT_U8P :
return AudioParams::kFormatUnsigned8Planar;
return SampleFormat::U8P;
case AV_SAMPLE_FMT_S16P:
return AudioParams::kFormatSigned16Planar;
return SampleFormat::S16P;
case AV_SAMPLE_FMT_S32P:
return AudioParams::kFormatSigned32Planar;
return SampleFormat::S32P;
case AV_SAMPLE_FMT_S64P:
return AudioParams::kFormatSigned64Planar;
return SampleFormat::S64P;
case AV_SAMPLE_FMT_FLTP:
return AudioParams::kFormatFloat32Planar;
return SampleFormat::F32P;
case AV_SAMPLE_FMT_DBLP:
return AudioParams::kFormatFloat64Planar;
return SampleFormat::F64P;
case AV_SAMPLE_FMT_NONE:
case AV_SAMPLE_FMT_NB:
break;
}
return AudioParams::kFormatInvalid;
return SampleFormat::INVALID;
}
AVSampleFormat FFmpegUtils::GetFFmpegSampleFormat(const AudioParams::Format &smp_fmt)
AVSampleFormat FFmpegUtils::GetFFmpegSampleFormat(const SampleFormat &smp_fmt)
{
switch (smp_fmt) {
case AudioParams::kFormatUnsigned8Packed:
case SampleFormat::U8:
return AV_SAMPLE_FMT_U8;
case AudioParams::kFormatSigned16Packed:
case SampleFormat::S16:
return AV_SAMPLE_FMT_S16;
case AudioParams::kFormatSigned32Packed:
case SampleFormat::S32:
return AV_SAMPLE_FMT_S32;
case AudioParams::kFormatSigned64Packed:
case SampleFormat::S64:
return AV_SAMPLE_FMT_S64;
case AudioParams::kFormatFloat32Packed:
case SampleFormat::F32:
return AV_SAMPLE_FMT_FLT;
case AudioParams::kFormatFloat64Packed:
case SampleFormat::F64:
return AV_SAMPLE_FMT_DBL;
case AudioParams::kFormatUnsigned8Planar:
case SampleFormat::U8P:
return AV_SAMPLE_FMT_U8P;
case AudioParams::kFormatSigned16Planar:
case SampleFormat::S16P:
return AV_SAMPLE_FMT_S16P;
case AudioParams::kFormatSigned32Planar:
case SampleFormat::S32P:
return AV_SAMPLE_FMT_S32P;
case AudioParams::kFormatSigned64Planar:
case SampleFormat::S64P:
return AV_SAMPLE_FMT_S64P;
case AudioParams::kFormatFloat32Planar:
case SampleFormat::F32P:
return AV_SAMPLE_FMT_FLTP;
case AudioParams::kFormatFloat64Planar:
case SampleFormat::F64P:
return AV_SAMPLE_FMT_DBLP;
case AudioParams::kFormatInvalid:
case AudioParams::kFormatCount:
case SampleFormat::INVALID:
case SampleFormat::COUNT:
break;
}
@@ -159,7 +159,7 @@ AVPixelFormat FFmpegUtils::GetFFmpegPixelFormat(const PixelFormat &pix_fmt, int
case PixelFormat::F16:
case PixelFormat::F32:
case PixelFormat::INVALID:
case PixelFormat::FORMAT_COUNT:
case PixelFormat::COUNT:
break;
}
} else if (channel_layout == VideoParams::kRGBAChannelCount) {
@@ -171,7 +171,7 @@ AVPixelFormat FFmpegUtils::GetFFmpegPixelFormat(const PixelFormat &pix_fmt, int
case PixelFormat::F16:
case PixelFormat::F32:
case PixelFormat::INVALID:
case PixelFormat::FORMAT_COUNT:
case PixelFormat::COUNT:
break;
}
}
@@ -189,7 +189,7 @@ PixelFormat FFmpegUtils::GetCompatiblePixelFormat(const PixelFormat &pix_fmt)
case PixelFormat::F32:
return PixelFormat::U16;
case PixelFormat::INVALID:
case PixelFormat::FORMAT_COUNT:
case PixelFormat::COUNT:
break;
}
+6 -3
View File
@@ -27,11 +27,14 @@ extern "C" {
#include <libswscale/swscale.h>
}
#include "render/audioparams.h"
#include <olive/core/core.h>
#include "render/videoparams.h"
namespace olive {
using namespace core;
class FFmpegUtils {
public:
/**
@@ -52,12 +55,12 @@ public:
/**
* @brief Returns a native sample format type for a given AVSampleFormat
*/
static AudioParams::Format GetNativeSampleFormat(const AVSampleFormat& smp_fmt);
static SampleFormat GetNativeSampleFormat(const AVSampleFormat& smp_fmt);
/**
* @brief Returns an FFmpeg sample format type for a given native type
*/
static AVSampleFormat GetFFmpegSampleFormat(const AudioParams::Format &smp_fmt);
static AVSampleFormat GetFFmpegSampleFormat(const SampleFormat &smp_fmt);
/**
* @brief Returns an SWS_CS_* macro from an AVColorSpace enum member
+1 -1
View File
@@ -37,7 +37,7 @@ OCIO::BitDepth OCIOUtils::GetOCIOBitDepthFromPixelFormat(PixelFormat format)
return OCIO::BIT_DEPTH_F32;
break;
case PixelFormat::INVALID:
case PixelFormat::FORMAT_COUNT:
case PixelFormat::COUNT:
break;
}
+1 -1
View File
@@ -43,7 +43,7 @@ public:
case PixelFormat::F32:
return OIIO::TypeDesc::FLOAT;
case PixelFormat::INVALID:
case PixelFormat::FORMAT_COUNT:
case PixelFormat::COUNT:
break;
}
+4 -6
View File
@@ -22,8 +22,6 @@
#include <QDebug>
#include "common/clamp.h"
namespace olive {
int QtUtils::QFontMetricsWidth(QFontMetrics fm, const QString& s) {
@@ -179,10 +177,10 @@ 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));
c.setRedF(std::clamp(i.red(), 0.0f, 1.0f));
c.setGreenF(std::clamp(i.green(), 0.0f, 1.0f));
c.setBlueF(std::clamp(i.blue(), 0.0f, 1.0f));
c.setAlphaF(std::clamp(i.alpha(), 0.0f, 1.0f));
return c;
}
+3
View File
@@ -89,5 +89,8 @@ 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);
Q_DECLARE_METATYPE(olive::core::Bezier);
Q_DECLARE_METATYPE(olive::core::AudioParams);
Q_DECLARE_METATYPE(olive::core::SampleBuffer);
#endif // QTVERSIONABSTRACTION_H