Loading...
Searching...
No Matches
Deinterlace.cpp
Go to the documentation of this file.
// Copyright (c) 2008-2019 OpenShot Studios, LLC
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "Deinterlace.h"
#include "Exceptions.h"
using namespace openshot;
Deinterlace::Deinterlace() : isOdd(true)
{
// Init effect properties
init_effect_details();
}
// Default constructor
Deinterlace::Deinterlace(bool UseOddLines) : isOdd(UseOddLines)
{
// Init effect properties
init_effect_details();
}
// Init effect settings
void Deinterlace::init_effect_details()
{
InitEffectInfo();
info.class_name = "Deinterlace";
info.name = "Deinterlace";
info.description = "Remove interlacing from a video (i.e. even or odd horizontal lines)";
info.has_audio = false;
info.has_video = true;
}
// This method is required for all derived classes of EffectBase, and returns a
// modified openshot::Frame object
std::shared_ptr<openshot::Frame> Deinterlace::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number)
{
// Get original size of frame's image
int original_width = frame->GetImage()->width();
int original_height = frame->GetImage()->height();
// Get the frame's image
std::shared_ptr<QImage> image = frame->GetImage();
const unsigned char* pixels = image->bits();
// Create a smaller, new image
QImage deinterlaced_image(image->width(), image->height() / 2, QImage::Format_RGBA8888_Premultiplied);
const unsigned char* deinterlaced_pixels = deinterlaced_image.bits();
// Loop through the scanlines of the image (even or odd)
int start = 0;
if (isOdd)
start = 1;
for (int row = start; row < image->height(); row += 2) {
memcpy((unsigned char*)deinterlaced_pixels, pixels + (row * image->bytesPerLine()), image->bytesPerLine());
deinterlaced_pixels += image->bytesPerLine();
}
// Resize deinterlaced image back to original size, and update frame's image
image = std::make_shared<QImage>(deinterlaced_image.scaled(
original_width, original_height,
Qt::IgnoreAspectRatio, Qt::FastTransformation));
// Update image on frame
frame->AddImage(image);
// return the modified frame
return frame;
}
// Generate JSON string of this object
std::string Deinterlace::Json() const {
// Return formatted string
return JsonValue().toStyledString();
}
// Generate Json::Value for this object
Json::Value Deinterlace::JsonValue() const {
// Create root json object
Json::Value root = EffectBase::JsonValue(); // get parent properties
root["type"] = info.class_name;
root["isOdd"] = isOdd;
// return JsonValue
return root;
}
// Load JSON string into this object
void Deinterlace::SetJson(const std::string value) {
// Parse JSON string into JSON objects
try
{
const Json::Value root = openshot::stringToJson(value);
// Set all values that match
SetJsonValue(root);
}
catch (const std::exception& e)
{
// Error parsing JSON (or missing keys)
throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
}
}
// Load Json::Value into this object
void Deinterlace::SetJsonValue(const Json::Value root) {
// Set parent data
EffectBase::SetJsonValue(root);
// Set data from Json (if key is found)
if (!root["isOdd"].isNull())
isOdd = root["isOdd"].asBool();
}
// Get all properties for a specific frame
std::string Deinterlace::PropertiesJSON(int64_t requested_frame) const {
// Generate JSON properties list
Json::Value root = BasePropertiesJSON(requested_frame);
// Add Is Odd Frame choices (dropdown style)
root["isOdd"] = add_property_json("Is Odd Frame", isOdd, "bool", "", NULL, 0, 1, true, requested_frame);
root["isOdd"]["choices"].append(add_property_choice_json("Yes", true, isOdd));
root["isOdd"]["choices"].append(add_property_choice_json("No", false, isOdd));
// Return formatted string
return root.toStyledString();
}
Deinterlace.h
Header file for De-interlace class.
Exceptions.h
Header file for all Exception classes.
openshot::ClipBase::start
float start
The position in seconds to start playing (used to trim the beginning of a clip)
Definition ClipBase.h:38
openshot::ClipBase::add_property_choice_json
Json::Value add_property_choice_json(std::string name, int value, int selected_value) const
Generate JSON choice for a property (dropdown properties)
Definition ClipBase.cpp:132
openshot::ClipBase::add_property_json
Json::Value add_property_json(std::string name, float value, std::string type, std::string memo, const Keyframe *keyframe, float min_value, float max_value, bool readonly, int64_t requested_frame) const
Generate JSON for a property.
Definition ClipBase.cpp:96
openshot::Deinterlace::Json
std::string Json() const override
Generate JSON string of this object.
Definition Deinterlace.cpp:84
openshot::Deinterlace::SetJsonValue
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition Deinterlace.cpp:120
openshot::Deinterlace::Deinterlace
Deinterlace()
Default constructor, useful when using Json to load the effect properties.
Definition Deinterlace.cpp:19
openshot::Deinterlace::GetFrame
std::shared_ptr< openshot::Frame > GetFrame(int64_t frame_number) override
This method is required for all derived classes of ClipBase, and returns a new openshot::Frame object...
Definition Deinterlace.h:56
openshot::Deinterlace::SetJson
void SetJson(const std::string value) override
Load JSON string into this object.
Definition Deinterlace.cpp:103
openshot::Deinterlace::PropertiesJSON
std::string PropertiesJSON(int64_t requested_frame) const override
Definition Deinterlace.cpp:131
openshot::Deinterlace::JsonValue
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition Deinterlace.cpp:91
openshot::EffectBase::JsonValue
virtual Json::Value JsonValue() const
Generate Json::Value for this object.
Definition EffectBase.cpp:79
openshot::EffectBase::InitEffectInfo
void InitEffectInfo()
Definition EffectBase.cpp:24
openshot::EffectBase::BasePropertiesJSON
Json::Value BasePropertiesJSON(int64_t requested_frame) const
Generate JSON object of base properties (recommended to be used by all effects)
Definition EffectBase.cpp:179
openshot::EffectBase::SetJsonValue
virtual void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition EffectBase.cpp:115
openshot::EffectBase::info
EffectInfoStruct info
Information about the current effect.
Definition EffectBase.h:69
openshot::InvalidJSON
Exception for invalid JSON.
Definition Exceptions.h:218
openshot
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
openshot::stringToJson
const Json::Value stringToJson(const std::string value)
Definition Json.cpp:16
openshot::EffectInfoStruct::has_video
bool has_video
Determines if this effect manipulates the image of a frame.
Definition EffectBase.h:40
openshot::EffectInfoStruct::has_audio
bool has_audio
Determines if this effect manipulates the audio of a frame.
Definition EffectBase.h:41
openshot::EffectInfoStruct::class_name
std::string class_name
The class name of the effect.
Definition EffectBase.h:36
openshot::EffectInfoStruct::name
std::string name
The name of the effect.
Definition EffectBase.h:37
openshot::EffectInfoStruct::description
std::string description
The description of this effect and what it does.
Definition EffectBase.h:38