2013-10-18 12:38:09 -05:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* @brief Source file for De-interlace class
|
|
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
|
|
|
|
*
|
|
|
|
|
* @section LICENSE
|
|
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* Copyright (c) 2008-2014 OpenShot Studios, LLC
|
|
|
|
|
* <http://www.openshotstudios.com/>. This file is part of
|
|
|
|
|
* OpenShot Library (libopenshot), an open-source project dedicated to
|
|
|
|
|
* delivering high quality video editing and animation solutions to the
|
|
|
|
|
* world. For more information visit <http://www.openshot.org/>.
|
2013-10-18 12:38:09 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is free software: you can redistribute it
|
2014-07-11 16:52:14 -05:00
|
|
|
* and/or modify it under the terms of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* as published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
2013-10-18 12:38:09 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) 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
|
2014-07-11 16:52:14 -05:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-10-18 12:38:09 -05:00
|
|
|
*
|
2014-07-11 16:52:14 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
2013-10-18 12:38:09 -05:00
|
|
|
*/
|
|
|
|
|
|
2014-04-10 22:38:01 -05:00
|
|
|
#include "../../include/effects/Deinterlace.h"
|
2013-10-18 12:38:09 -05:00
|
|
|
|
|
|
|
|
using namespace openshot;
|
|
|
|
|
|
2014-01-05 22:37:11 -06:00
|
|
|
/// Blank constructor, useful when using Json to load the effect properties
|
2015-08-06 20:01:34 -05:00
|
|
|
Deinterlace::Deinterlace() : isOdd(true)
|
|
|
|
|
{
|
|
|
|
|
// Init effect properties
|
|
|
|
|
init_effect_details();
|
2014-01-05 22:37:11 -06:00
|
|
|
}
|
|
|
|
|
|
2013-10-18 12:38:09 -05:00
|
|
|
// Default constructor
|
|
|
|
|
Deinterlace::Deinterlace(bool UseOddLines) : isOdd(UseOddLines)
|
2015-08-06 20:01:34 -05:00
|
|
|
{
|
|
|
|
|
// Init effect properties
|
|
|
|
|
init_effect_details();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Init effect settings
|
|
|
|
|
void Deinterlace::init_effect_details()
|
2013-10-18 12:38:09 -05:00
|
|
|
{
|
|
|
|
|
/// Initialize the values of the EffectInfo struct.
|
|
|
|
|
InitEffectInfo();
|
|
|
|
|
|
|
|
|
|
/// Set the effect info
|
2015-08-06 20:01:34 -05:00
|
|
|
info.class_name = "Deinterlace";
|
2013-10-18 12:38:09 -05:00
|
|
|
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
|
2015-08-24 01:05:48 -05:00
|
|
|
tr1::shared_ptr<Frame> Deinterlace::GetFrame(tr1::shared_ptr<Frame> frame, long int frame_number)
|
2013-10-18 12:38:09 -05:00
|
|
|
{
|
2015-06-01 00:20:14 -07:00
|
|
|
// Get original size of frame's image
|
|
|
|
|
int original_width = frame->GetImage()->width();
|
|
|
|
|
int original_height = frame->GetImage()->height();
|
2013-10-18 12:38:09 -05:00
|
|
|
|
2015-06-01 00:20:14 -07:00
|
|
|
// Get the frame's image
|
|
|
|
|
tr1::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);
|
|
|
|
|
const unsigned char* deinterlaced_pixels = deinterlaced_image.bits();
|
|
|
|
|
|
|
|
|
|
// Loop through the scanlines of the image (even or odd)
|
|
|
|
|
int start = 0;
|
2013-10-18 12:38:09 -05:00
|
|
|
if (isOdd)
|
2015-06-01 00:20:14 -07:00
|
|
|
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();
|
|
|
|
|
}
|
2013-10-18 12:38:09 -05:00
|
|
|
|
2015-06-01 00:20:14 -07:00
|
|
|
// Resize deinterlaced image back to original size, and update frame's image
|
|
|
|
|
image = tr1::shared_ptr<QImage>(new QImage(deinterlaced_image.scaled(original_width, original_height, Qt::IgnoreAspectRatio, Qt::FastTransformation)));
|
2013-10-18 12:38:09 -05:00
|
|
|
|
2015-06-01 00:20:14 -07:00
|
|
|
// Update image on frame
|
|
|
|
|
frame->AddImage(image);
|
2013-10-18 12:38:09 -05:00
|
|
|
|
|
|
|
|
// return the modified frame
|
|
|
|
|
return frame;
|
|
|
|
|
}
|
2013-12-06 00:40:26 -06:00
|
|
|
|
2013-12-07 21:09:55 -06:00
|
|
|
// Generate JSON string of this object
|
|
|
|
|
string Deinterlace::Json() {
|
|
|
|
|
|
|
|
|
|
// Return formatted string
|
|
|
|
|
return JsonValue().toStyledString();
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-06 00:40:26 -06:00
|
|
|
// Generate Json::JsonValue for this object
|
|
|
|
|
Json::Value Deinterlace::JsonValue() {
|
|
|
|
|
|
|
|
|
|
// Create root json object
|
|
|
|
|
Json::Value root = EffectBase::JsonValue(); // get parent properties
|
2015-08-06 20:01:34 -05:00
|
|
|
root["type"] = info.class_name;
|
2013-12-06 00:40:26 -06:00
|
|
|
root["isOdd"] = isOdd;
|
|
|
|
|
|
|
|
|
|
// return JsonValue
|
|
|
|
|
return root;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-07 21:09:55 -06:00
|
|
|
// Load JSON string into this object
|
|
|
|
|
void Deinterlace::SetJson(string value) throw(InvalidJSON) {
|
|
|
|
|
|
|
|
|
|
// Parse JSON string into JSON objects
|
|
|
|
|
Json::Value root;
|
|
|
|
|
Json::Reader reader;
|
|
|
|
|
bool success = reader.parse( value, root );
|
|
|
|
|
if (!success)
|
|
|
|
|
// Raise exception
|
|
|
|
|
throw InvalidJSON("JSON could not be parsed (or is invalid)", "");
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Set all values that match
|
|
|
|
|
SetJsonValue(root);
|
|
|
|
|
}
|
|
|
|
|
catch (exception e)
|
|
|
|
|
{
|
|
|
|
|
// Error parsing JSON (or missing keys)
|
|
|
|
|
throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-06 00:40:26 -06:00
|
|
|
// Load Json::JsonValue into this object
|
2013-12-07 21:09:55 -06:00
|
|
|
void Deinterlace::SetJsonValue(Json::Value root) {
|
2013-12-06 00:40:26 -06:00
|
|
|
|
|
|
|
|
// Set parent data
|
2013-12-07 21:09:55 -06:00
|
|
|
EffectBase::SetJsonValue(root);
|
2013-12-06 00:40:26 -06:00
|
|
|
|
|
|
|
|
// Set data from Json (if key is found)
|
2014-01-08 01:43:58 -06:00
|
|
|
if (!root["isOdd"].isNull())
|
2013-12-06 00:40:26 -06:00
|
|
|
isOdd = root["isOdd"].asBool();
|
|
|
|
|
}
|
2015-02-26 00:02:06 -06:00
|
|
|
|
|
|
|
|
// Get all properties for a specific frame
|
2015-08-24 01:05:48 -05:00
|
|
|
string Deinterlace::PropertiesJSON(long int requested_frame) {
|
2015-02-26 00:02:06 -06:00
|
|
|
|
|
|
|
|
// Requested Point
|
|
|
|
|
Point requested_point(requested_frame, requested_frame);
|
|
|
|
|
|
|
|
|
|
// Generate JSON properties list
|
|
|
|
|
Json::Value root;
|
|
|
|
|
root["id"] = add_property_json("ID", 0.0, "string", Id(), false, 0, -1, -1, CONSTANT, -1, true);
|
|
|
|
|
root["position"] = add_property_json("Position", Position(), "float", "", false, 0, 0, 1000 * 60 * 30, CONSTANT, -1, false);
|
|
|
|
|
root["layer"] = add_property_json("Layer", Layer(), "int", "", false, 0, 0, 1000, CONSTANT, -1, false);
|
|
|
|
|
root["start"] = add_property_json("Start", Start(), "float", "", false, 0, 0, 1000 * 60 * 30, CONSTANT, -1, false);
|
|
|
|
|
root["end"] = add_property_json("End", End(), "float", "", false, 0, 0, 1000 * 60 * 30, CONSTANT, -1, false);
|
|
|
|
|
root["duration"] = add_property_json("Duration", Duration(), "float", "", false, 0, 0, 1000 * 60 * 30, CONSTANT, -1, true);
|
|
|
|
|
root["isOdd"] = add_property_json("Is Odd Frame", isOdd, "bool", "", false, 0, 0, 1, CONSTANT, -1, true);
|
|
|
|
|
|
|
|
|
|
// Return formatted string
|
|
|
|
|
return root.toStyledString();
|
|
|
|
|
}
|