revised text node

Fixes #1684
This commit is contained in:
itsmattkc
2021-10-25 15:46:06 -07:00
parent 6543512d00
commit dc79a6a5d9
16 changed files with 351 additions and 96 deletions
+35 -35
View File
@@ -27,12 +27,12 @@
namespace olive {
Color Color::fromHsv(const double &h, const double &s, const double &v)
Color Color::fromHsv(const float &h, const float &s, const float &v)
{
double C = s * v;
double X = C * (1.0 - abs(fmod(h / 60.0, 2.0) - 1.0));
double m = v - C;
double Rs, Gs, Bs;
float C = s * v;
float X = C * (1.0 - abs(fmod(h / 60.0, 2.0) - 1.0));
float m = v - C;
float Rs, Gs, Bs;
if(h >= 0.0 && h < 60.0) {
Rs = C;
@@ -81,11 +81,11 @@ Color::Color(const QColor &c)
set_alpha(c.alphaF());
}
void Color::toHsv(double *hue, double *sat, double *val) const
void Color::toHsv(float *hue, float *sat, float *val) const
{
double fCMax = qMax(qMax(red(), green()), blue());
double fCMin = qMin(qMin(red(), green()), blue());
double fDelta = fCMax - fCMin;
float fCMax = qMax(qMax(red(), green()), blue());
float fCMin = qMin(qMin(red(), green()), blue());
float fDelta = fCMax - fCMin;
if(fDelta > 0) {
if(fCMax == red()) {
@@ -114,31 +114,31 @@ void Color::toHsv(double *hue, double *sat, double *val) const
}
}
double Color::hsv_hue() const
float Color::hsv_hue() const
{
double h, s, v;
float h, s, v;
toHsv(&h, &s, &v);
return h;
}
double Color::hsv_saturation() const
float Color::hsv_saturation() const
{
double h, s, v;
float h, s, v;
toHsv(&h, &s, &v);
return s;
}
double Color::value() const
float Color::value() const
{
double h, s, v;
float h, s, v;
toHsv(&h, &s, &v);
return v;
}
void Color::toHsl(double *hue, double *sat, double *lightness) const
void Color::toHsl(float *hue, float *sat, float *lightness) const
{
double fCMin = qMin(red(), qMin(green(), blue()));
double fCMax = qMax(red(), qMax(green(), blue()));
float fCMin = qMin(red(), qMin(green(), blue()));
float fCMax = qMax(red(), qMax(green(), blue()));
*lightness = 0.5 * (fCMin + fCMax);
@@ -176,30 +176,30 @@ void Color::toHsl(double *hue, double *sat, double *lightness) const
}
}
double Color::hsl_hue() const
float Color::hsl_hue() const
{
double h, s, l;
float h, s, l;
toHsl(&h, &s, &l);
return h;
}
double Color::hsl_saturation() const
float Color::hsl_saturation() const
{
double h, s, l;
float h, s, l;
toHsl(&h, &s, &l);
return s;
}
double Color::lightness() const
float Color::lightness() const
{
double h, s, l;
float 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::DOUBLE,
OIIO::convert_pixel_values(OIIO::TypeDesc::FLOAT,
data_,
OIIOUtils::GetOIIOBaseTypeFromFormat(format),
data,
@@ -212,7 +212,7 @@ Color Color::fromData(const char *data, const VideoParams::Format &format, int c
OIIO::convert_pixel_values(OIIOUtils::GetOIIOBaseTypeFromFormat(format),
data,
OIIO::TypeDesc::DOUBLE,
OIIO::TypeDesc::FLOAT,
c.data_,
ch_layout);
@@ -224,15 +224,15 @@ 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.0, 1.0));
c.setGreenF(clamp(green(), 0.0, 1.0));
c.setBlueF(clamp(blue(), 0.0, 1.0));
c.setAlphaF(clamp(alpha(), 0.0, 1.0));
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;
}
double Color::GetRoughLuminance() const
float Color::GetRoughLuminance() const
{
return (2*red()+blue()+3*green())/6.0;
}
@@ -255,7 +255,7 @@ const Color &Color::operator-=(const Color &rhs)
return *this;
}
const Color &Color::operator*=(const double &rhs)
const Color &Color::operator*=(const float &rhs)
{
for (int i=0;i<VideoParams::kRGBAChannelCount;i++) {
data_[i] *= rhs;
@@ -264,7 +264,7 @@ const Color &Color::operator*=(const double &rhs)
return *this;
}
const Color &Color::operator/=(const double &rhs)
const Color &Color::operator/=(const float &rhs)
{
for (int i=0;i<VideoParams::kRGBAChannelCount;i++) {
data_[i] /= rhs;
@@ -287,14 +287,14 @@ Color Color::operator-(const Color &rhs) const
return c;
}
Color Color::operator*(const double &rhs) const
Color Color::operator*(const float &rhs) const
{
Color c(*this);
c *= rhs;
return c;
}
Color Color::operator/(const double &rhs) const
Color Color::operator/(const float &rhs) const
{
Color c(*this);
c /= rhs;
+27 -27
View File
@@ -30,7 +30,7 @@
namespace olive {
/**
* @brief High precision 64-bit float based RGBA color value
* @brief High precision 32-bit float based RGBA color value
*/
class Color
{
@@ -42,7 +42,7 @@ public:
}
}
Color(const double& r, const double& g, const double& b, const double& a = 1.0)
Color(const float& r, const float& g, const float& b, const float& a = 1.0f)
{
data_[0] = r;
data_[1] = g;
@@ -59,30 +59,30 @@ public:
*
* Hue expects a value between 0.0 and 360.0. Saturation and Value expect a value between 0.0 and 1.0.
*/
static Color fromHsv(const double& h, const double& s, const double &v);
static Color fromHsv(const float& h, const float& s, const float &v);
const double& red() const {return data_[0];}
const double& green() const {return data_[1];}
const double& blue() const {return data_[2];}
const double& alpha() const {return data_[3];}
const float& red() const {return data_[0];}
const float& green() const {return data_[1];}
const float& blue() const {return data_[2];}
const float& alpha() const {return data_[3];}
void toHsv(double* hue, double* sat, double* val) const;
double hsv_hue() const;
double hsv_saturation() const;
double value() const;
void toHsv(float* hue, float* sat, float* val) const;
float hsv_hue() const;
float hsv_saturation() const;
float value() const;
void toHsl(double* hue, double* sat, double* lightness) const;
double hsl_hue() const;
double hsl_saturation() const;
double lightness() const;
void toHsl(float* hue, float* sat, float* lightness) const;
float hsl_hue() const;
float hsl_saturation() const;
float lightness() const;
void set_red(const double& red) {data_[0] = red;}
void set_green(const double& green) {data_[1] = green;}
void set_blue(const double& blue) {data_[2] = blue;}
void set_alpha(const double& alpha) {data_[3] = alpha;}
void set_red(const float& red) {data_[0] = red;}
void set_green(const float& green) {data_[1] = green;}
void set_blue(const float& blue) {data_[2] = blue;}
void set_alpha(const float& alpha) {data_[3] = alpha;}
double* data() {return data_;}
const double* data() const {return data_;}
float* data() {return data_;}
const float* data() const {return data_;}
void toData(char* data, const VideoParams::Format& format, int ch_layout) const;
@@ -92,22 +92,22 @@ public:
// Suuuuper rough luminance value mostly used for UI (determining whether to overlay with black
// or white text)
double GetRoughLuminance() const;
float GetRoughLuminance() const;
// Assignment math operators
const Color& operator+=(const Color& rhs);
const Color& operator-=(const Color& rhs);
const Color& operator*=(const double& rhs);
const Color& operator/=(const double& rhs);
const Color& operator*=(const float& rhs);
const Color& operator/=(const float& rhs);
// Binary math operators
Color operator+(const Color& rhs) const;
Color operator-(const Color& rhs) const;
Color operator*(const double& rhs) const;
Color operator/(const double& rhs) const;
Color operator*(const float& rhs) const;
Color operator/(const float& rhs) const;
private:
double data_[VideoParams::kRGBAChannelCount];
float data_[VideoParams::kRGBAChannelCount];
};
+10 -8
View File
@@ -22,6 +22,7 @@
#define GENERATEJOB_H
#include "acceleratedjob.h"
#include "render/videoparams.h"
namespace olive {
@@ -36,21 +37,22 @@ public:
GenerateJob()
{
alpha_channel_required_ = kAlphaAuto;
requested_format_ = VideoParams::kFormatInvalid;
}
AlphaChannelSetting GetAlphaChannelRequired() const
{
return alpha_channel_required_;
}
AlphaChannelSetting GetAlphaChannelRequired() const { return alpha_channel_required_; }
void SetAlphaChannelRequired(AlphaChannelSetting e)
{
alpha_channel_required_ = e;
}
void SetAlphaChannelRequired(AlphaChannelSetting e) { alpha_channel_required_ = e; }
VideoParams::Format GetRequestedFormat() const { return requested_format_; }
void SetRequestedFormat(VideoParams::Format f) { requested_format_ = f; }
private:
AlphaChannelSetting alpha_channel_required_;
VideoParams::Format requested_format_;
};
}
+4
View File
@@ -533,6 +533,10 @@ TexturePtr RenderProcessor::ProcessFrameGeneration(const Node *node, const Gener
VideoParams frame_params = GetCacheVideoParams();
frame_params.set_channel_count(GetChannelCountFromJob(job));
if (job.GetRequestedFormat() != VideoParams::kFormatInvalid) {
frame_params.set_format(job.GetRequestedFormat());
}
frame->set_video_params(frame_params);
frame->allocate();