render: remove alpha request option

This commit is contained in:
itsmattkc
2022-07-20 23:14:16 -07:00
parent 752f073136
commit 5ea97f7a64
22 changed files with 32 additions and 113 deletions
+31 -31
View File
@@ -36,8 +36,7 @@ FFmpegEncoder::FFmpegEncoder(const EncodingParams &params) :
fmt_ctx_(nullptr),
video_stream_(nullptr),
video_codec_ctx_(nullptr),
video_alpha_scale_ctx_(nullptr),
video_noalpha_scale_ctx_(nullptr),
video_scale_ctx_(nullptr),
audio_stream_(nullptr),
audio_codec_ctx_(nullptr),
audio_resample_ctx_(nullptr),
@@ -144,27 +143,32 @@ bool FFmpegEncoder::Open()
// Set up a scaling context - if the native pixel format is not equal to the encoder's, we'll need to convert it
// before encoding. Even if we don't, this may be useful for converting between linesizes, etc.
video_alpha_scale_ctx_ = sws_getContext(params().video_params().width(),
params().video_params().height(),
src_alpha_pix_fmt,
params().video_params().width(),
params().video_params().height(),
encoder_pix_fmt,
0,
nullptr,
nullptr,
nullptr);
video_scale_ctx_ = sws_getContext(params().video_params().width(),
params().video_params().height(),
src_alpha_pix_fmt,
params().video_params().width(),
params().video_params().height(),
encoder_pix_fmt,
0,
nullptr,
nullptr,
nullptr);
video_noalpha_scale_ctx_ = sws_getContext(params().video_params().width(),
params().video_params().height(),
src_noalpha_pix_fmt,
params().video_params().width(),
params().video_params().height(),
encoder_pix_fmt,
0,
nullptr,
nullptr,
nullptr);
int *inv_table;
int src_range;
int *table;
int dst_range;
int brightness;
int contrast;
int saturation;
sws_getColorspaceDetails(video_scale_ctx_, &inv_table, &src_range, &table, &dst_range, &brightness, &contrast, &saturation);
// Set swscale's dst range based on AVCodecContext's color_range. Here, 1 == JPEG range (0-255)
// and 0 == MPEG range (16-235).
dst_range = (video_codec_ctx_->color_range == AVCOL_RANGE_JPEG);
sws_setColorspaceDetails(video_scale_ctx_, inv_table, src_range, table, dst_range, brightness, contrast, saturation);
}
// Initialize an audio stream if it's enabled
@@ -242,7 +246,7 @@ bool FFmpegEncoder::WriteFrame(FramePtr frame, rational time)
input_data = frame->const_data();
input_linesize = frame->linesize_bytes();
error_code = sws_scale((frame->channel_count() == VideoParams::kRGBAChannelCount) ? video_alpha_scale_ctx_ : video_noalpha_scale_ctx_,
error_code = sws_scale(video_scale_ctx_,
reinterpret_cast<const uint8_t**>(&input_data),
&input_linesize,
0,
@@ -484,14 +488,9 @@ void FFmpegEncoder::Close()
audio_frame_ = nullptr;
}
if (video_alpha_scale_ctx_) {
sws_freeContext(video_alpha_scale_ctx_);
video_alpha_scale_ctx_ = nullptr;
}
if (video_noalpha_scale_ctx_) {
sws_freeContext(video_noalpha_scale_ctx_);
video_noalpha_scale_ctx_ = nullptr;
if (video_scale_ctx_) {
sws_freeContext(video_scale_ctx_);
video_scale_ctx_ = nullptr;
}
if (video_codec_ctx_) {
@@ -606,6 +605,7 @@ bool FFmpegEncoder::InitializeStream(AVMediaType type, AVStream** stream_ptr, AV
codec_ctx->time_base = params().video_params().frame_rate_as_time_base().toAVRational();
codec_ctx->framerate = params().video_params().frame_rate().toAVRational();
codec_ctx->pix_fmt = av_get_pix_fmt(params().video_pix_fmt().toUtf8());
codec_ctx->color_range = params().video_color_range() == EncodingParams::kYUVJPEG0_255 ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
if (params().video_params().interlacing() != VideoParams::kInterlaceNone) {
// FIXME: I actually don't know what these flags do, the documentation helpfully doesn't
+1 -2
View File
@@ -88,8 +88,7 @@ private:
AVStream* video_stream_;
AVCodecContext* video_codec_ctx_;
SwsContext* video_alpha_scale_ctx_;
SwsContext* video_noalpha_scale_ctx_;
SwsContext* video_scale_ctx_;
VideoParams::Format video_conversion_fmt_;
AVStream* audio_stream_;
@@ -53,13 +53,6 @@ ShaderCode CrossDissolveTransition::GetShaderCode(const ShaderRequest &request)
return ShaderCode(FileFunctions::ReadFileAsString(":/shaders/crossdissolve.frag"), QString());
}
void CrossDissolveTransition::ShaderJobEvent(const NodeValueRow &value, ShaderJob &job) const
{
Q_UNUSED(value)
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOn);
}
void CrossDissolveTransition::SampleJobEvent(const SampleBuffer &from_samples, const SampleBuffer &to_samples, SampleBuffer &out_samples, double time_in) const
{
for (int i=0; i<out_samples.sample_count(); i++) {
@@ -43,8 +43,6 @@ public:
virtual ShaderCode GetShaderCode(const ShaderRequest &request) const override;
protected:
virtual void ShaderJobEvent(const NodeValueRow &value, ShaderJob& job) const override;
virtual void SampleJobEvent(const SampleBuffer &from_samples, const SampleBuffer &to_samples, SampleBuffer &out_samples, double time_in) const override;
};
@@ -71,7 +71,6 @@ void CornerPinDistortNode::Value(const NodeValueRow &value, const NodeGlobals &g
{
ShaderJob job;
job.Insert(value);
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOn);
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, globals.resolution(), this));
// Convert slider values to their pixel values and then convert to clip space (-1.0 ... 1.0) for overriding the
@@ -79,7 +79,6 @@ void CropDistortNode::Value(const NodeValueRow &value, const NodeGlobals &global
{
ShaderJob job;
job.Insert(value);
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOn);
job.SetWillChangeImageSize(false);
if (TexturePtr texture = job.Get(kTextureInput).toTexture()) {
-1
View File
@@ -80,7 +80,6 @@ void MaskDistortNode::Value(const NodeValueRow &value, const NodeGlobals &global
feather.Insert(BlurFilterNode::kRadiusInput, NodeValue(NodeValue::kFloat, value[kFeatherInput].toDouble(), this));
feather.SetIterations(2, BlurFilterNode::kTextureInput);
feather.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, globals.resolution(), this));
feather.SetAlphaChannelRequired(ShaderJob::kAlphaForceOn);
merge.Insert(QStringLiteral("tex_b"), NodeValue(NodeValue::kTexture, feather, this));
} else {
@@ -103,10 +103,6 @@ void TransformDistortNode::Value(const NodeValueRow &value, const NodeGlobals &g
job.Insert(QStringLiteral("ove_mvpmat"), NodeValue(NodeValue::kMatrix, real_matrix, this));
job.SetInterpolation(QStringLiteral("ove_maintex"), static_cast<Texture::Interpolation>(value[kInterpolationInput].toInt()));
// FIXME: This should be optimized, we can use matrix math to determine if this operation will
// end up with gaps in the screen that will require an alpha channel.
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOn);
table->Push(NodeValue::kTexture, QVariant::fromValue(job), this);
pushed_job = true;
@@ -52,7 +52,6 @@ void OpacityEffect::Value(const NodeValueRow &value, const NodeGlobals &globals,
// If there's no texture, no need to run an operation
if (job.Get(kTextureInput).toTexture()) {
if (!qFuzzyCompare(job.Get(kValueInput).toDouble(), 1.0)) {
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOn);
table->Push(NodeValue::kTexture, QVariant::fromValue(job), this);
} else {
// 1.0 float is a no-op, so just push the texture
-5
View File
@@ -159,11 +159,6 @@ void BlurFilterNode::Value(const NodeValueRow &value, const NodeGlobals &globals
}
if (can_push_job) {
// If we're not repeating pixels, expect an alpha channel to appear
if (!job.Get(kRepeatEdgePixelsInput).toBool()) {
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOn);
}
table->Push(NodeValue::kTexture, QVariant::fromValue(job), this);
} else {
// If we're not performing the blur job, just push the texture
-1
View File
@@ -95,7 +95,6 @@ GenerateJob PolygonGenerator::GetGenerateJob(const NodeValueRow &value) const
job.Insert(value);
job.SetRequestedFormat(VideoParams::kFormatFloat32);
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOn);
return job;
}
-1
View File
@@ -76,7 +76,6 @@ void ShapeNode::Value(const NodeValueRow &value, const NodeGlobals &globals, Nod
job.Insert(value);
job.Insert(QStringLiteral("resolution_in"), NodeValue(NodeValue::kVec2, globals.resolution(), this));
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOn);
job.SetShaderID(QStringLiteral("shape"));
PushMergableJob(value, QVariant::fromValue(job), table);
-1
View File
@@ -94,7 +94,6 @@ void TextGeneratorV1::Value(const NodeValueRow &value, const NodeGlobals &global
{
GenerateJob job;
job.Insert(value);
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOn);
if (!job.Get(kTextInput).toString().isEmpty()) {
table->Push(NodeValue::kTexture, QVariant::fromValue(job), this);
-1
View File
@@ -97,7 +97,6 @@ void TextGeneratorV2::Value(const NodeValueRow &value, const NodeGlobals &global
{
GenerateJob job;
job.Insert(value);
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOn);
job.SetRequestedFormat(VideoParams::kFormatFloat32);
if (!job.Get(kTextInput).toString().isEmpty()) {
-1
View File
@@ -98,7 +98,6 @@ void TextGeneratorV3::Value(const NodeValueRow &value, const NodeGlobals &global
{
GenerateJob job;
job.Insert(value);
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOn);
job.SetRequestedFormat(VideoParams::kFormatUnsigned8);
if (value[kUseArgsInput].toBool()) {
-1
View File
@@ -132,7 +132,6 @@ void ChromaKeyNode::Value(const NodeValueRow &value, const NodeGlobals &globals,
ColorTransformJob job;
job.Insert(value);
job.SetAlphaChannelRequired(ColorTransformJob::kAlphaForceOn);
job.SetColorProcessor(processor());
job.SetInputTexture(value[kTextureInput].toTexture());
job.SetNeedsCustomShader(this);
@@ -95,7 +95,6 @@ void ColorDifferenceKeyNode::Value(const NodeValueRow &value, const NodeGlobals
{
ShaderJob job;
job.Insert(value);
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOn);
// If there's no texture, no need to run an operation
if (job.Get(kTextureInput).toTexture()) {
-3
View File
@@ -372,9 +372,6 @@ void MathNodeBase::ValueInternal(Operation operation, Pairing pairing, const QSt
// Replace with adjusted matrix
job.Insert(val_a.type() == NodeValue::kTexture ? param_b_in : param_a_in,
NodeValue(NodeValue::kMatrix, adjusted_matrix, this));
// It's likely an alpha channel will result from this operation
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOn);
}
}
-6
View File
@@ -90,12 +90,6 @@ void MergeNode::Value(const NodeValueRow &value, const NodeGlobals &globals, Nod
// We only have a base texture, no need to alpha over
table->Push(job.Get(kBaseIn));
} else {
// We have both textures, push the job
if (base_tex->channel_count() < VideoParams::kRGBAChannelCount) {
// Base has no alpha, therefore this merge operation will not add an alpha channel
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOff);
}
table->Push(NodeValue::kTexture, QVariant::fromValue(job), this);
}
}
-28
View File
@@ -168,34 +168,6 @@ NodeGlobals NodeTraverser::GenerateGlobals(const VideoParams &params, const Time
int NodeTraverser::GetChannelCountFromJob(const GenerateJob &job)
{
int max_channel_count = 0;
// Find maximum channel count
for (auto it=job.GetValues().cbegin(); it!=job.GetValues().cend(); it++) {
if (it.value().type() == NodeValue::kTexture) {
if (TexturePtr tex = it.value().toTexture()) {
max_channel_count = qMax(max_channel_count, tex->channel_count());
}
}
}
if (max_channel_count == 0) {
max_channel_count = VideoParams::kRGBChannelCount;
}
switch (job.GetAlphaChannelRequired()) {
case GenerateJob::kAlphaForceOn:
return VideoParams::kRGBAChannelCount;
case GenerateJob::kAlphaForceOff:
if (max_channel_count >= 1 && max_channel_count < VideoParams::kRGBChannelCount) {
return max_channel_count;
} else {
return VideoParams::kRGBChannelCount;
}
case GenerateJob::kAlphaAuto:
return max_channel_count;
}
// Default fallback, should never get here
return VideoParams::kRGBAChannelCount;
}
-13
View File
@@ -28,22 +28,11 @@ namespace olive {
class GenerateJob : public AcceleratedJob {
public:
enum AlphaChannelSetting {
kAlphaAuto,
kAlphaForceOn,
kAlphaForceOff
};
GenerateJob()
{
alpha_channel_required_ = kAlphaAuto;
requested_format_ = VideoParams::kFormatInvalid;
}
AlphaChannelSetting GetAlphaChannelRequired() const { return alpha_channel_required_; }
void SetAlphaChannelRequired(AlphaChannelSetting e) { alpha_channel_required_ = e; }
VideoParams::Format GetRequestedFormat() const { return requested_format_; }
void SetRequestedFormat(VideoParams::Format f) { requested_format_ = f; }
@@ -52,8 +41,6 @@ public:
void SetColorspace(const QString &s) { colorspace_ = s; }
private:
AlphaChannelSetting alpha_channel_required_;
VideoParams::Format requested_format_;
QString colorspace_;
-1
View File
@@ -232,7 +232,6 @@ void Renderer::BlitColorManaged(const ColorTransformJob &color_job, Texture *des
job.Insert(QStringLiteral("ove_cropmatrix"), NodeValue(NodeValue::kMatrix, color_job.GetCropMatrix().inverted()));
job.Insert(QStringLiteral("ove_maintex_alpha"), NodeValue(NodeValue::kInt, int(color_job.GetInputAlphaAssociation())));
job.Insert(color_job.GetValues());
job.SetAlphaChannelRequired(color_job.GetAlphaChannelRequired());
foreach (const ColorContext::LUT& l, color_ctx.lut3d_textures) {
job.Insert(l.name, NodeValue(NodeValue::kTexture, QVariant::fromValue(l.texture)));