diff --git a/include/Clip.h b/include/Clip.h index a9a70c71..7c44b617 100644 --- a/include/Clip.h +++ b/include/Clip.h @@ -181,8 +181,11 @@ namespace openshot { float End() throw(ReaderClosed); ///< Get end position (in seconds) of clip (trim end of video), which can be affected by the time curve. void End(float value) { end = value; } ///< Set end position (in seconds) of clip (trim end of video) - /// Generate JSON of clip data - string Json(); + /// Get and Set JSON methods + string Json(); ///< Generate JSON string of this object + Json::Value JsonValue(); ///< Generate Json::JsonValue for this object + void Json(string value) throw(InvalidJSON); ///< Load JSON string into this object + void Json(Json::Value root); ///< Load Json::JsonValue into this object /// Waveform property bool Waveform() { return waveform; } ///< Get the waveform property of this clip diff --git a/include/ClipBase.h b/include/ClipBase.h index 46ba21fa..7d0df0bf 100644 --- a/include/ClipBase.h +++ b/include/ClipBase.h @@ -34,6 +34,8 @@ #endif #include +#include "Exceptions.h" +#include "Json.h" using namespace std; @@ -73,6 +75,12 @@ namespace openshot { void Start(float value) { start = value; } ///< Set start position (in seconds) of clip (trim start of video) void End(float value) { end = value; } ///< Set end position (in seconds) of clip (trim end of video) + /// Get and Set JSON methods + string Json(); ///< Generate JSON string of this object + Json::Value JsonValue(); ///< Generate Json::JsonValue for this object + void Json(string value) throw(InvalidJSON); ///< Load JSON string into this object + void Json(Json::Value root); ///< Load Json::JsonValue into this object + }; diff --git a/include/Color.h b/include/Color.h index dc7aada7..916deeb6 100644 --- a/include/Color.h +++ b/include/Color.h @@ -42,6 +42,12 @@ namespace openshot { Keyframe red; /// -#include "../include/Fraction.h" +#include "Exceptions.h" +#include "Fraction.h" +#include "Json.h" + +using namespace std; namespace openshot { @@ -85,6 +89,12 @@ namespace openshot { /// Get the delta / difference between previous coordinate value (used internally on the timeline, to track changes to coordinates) float Delta() { return delta; } + + /// Get and Set JSON methods + string Json(); ///< Generate JSON string of this object + Json::Value JsonValue(); ///< Generate Json::JsonValue for this object + void Json(string value) throw(InvalidJSON); ///< Load JSON string into this object + void Json(Json::Value root); ///< Load Json::JsonValue into this object }; } diff --git a/include/EffectBase.h b/include/EffectBase.h index 55f65aad..e9633da3 100644 --- a/include/EffectBase.h +++ b/include/EffectBase.h @@ -33,6 +33,7 @@ #include #include "ClipBase.h" #include "Frame.h" +#include "Json.h" using namespace std; @@ -87,6 +88,12 @@ namespace openshot /// this method, or the EffectInfo struct values will not be initialized. void InitEffectInfo(); + /// Get and Set JSON methods + string Json(); ///< Generate JSON string of this object + Json::Value JsonValue(); ///< Generate Json::JsonValue for this object + void Json(string value) throw(InvalidJSON); ///< Load JSON string into this object + void Json(Json::Value root); ///< Load Json::JsonValue into this object + /// Get the order that this effect should be executed. int Order() { return order; } diff --git a/include/Exceptions.h b/include/Exceptions.h index 94c9d7d3..bae491e8 100644 --- a/include/Exceptions.h +++ b/include/Exceptions.h @@ -28,8 +28,7 @@ #ifndef OPENSHOT_EXCEPTIONS_H #define OPENSHOT_EXCEPTIONS_H -#include - +#include using namespace std; namespace openshot { diff --git a/include/KeyFrame.h b/include/KeyFrame.h index c5cf8da7..23dbb087 100644 --- a/include/KeyFrame.h +++ b/include/KeyFrame.h @@ -134,8 +134,11 @@ namespace openshot { /// Get the direction of the curve at a specific index (increasing or decreasing) bool IsIncreasing(int index); - /// Generate JSON of keyframe data - string Json(); + /// Get and Set JSON methods + string Json(); ///< Generate JSON string of this object + Json::Value JsonValue(); ///< Generate Json::JsonValue for this object + void Json(string value) throw(InvalidJSON); ///< Load JSON string into this object + void Json(Json::Value root); ///< Load Json::JsonValue into this object /** * @brief Calculate all of the values for this keyframe. diff --git a/include/OpenShot.h b/include/OpenShot.h index 08a4c0a2..f837bc13 100644 --- a/include/OpenShot.h +++ b/include/OpenShot.h @@ -98,6 +98,7 @@ #include "ChunkReader.h" #include "ChunkWriter.h" #include "Clip.h" +#include "ClipBase.h" #include "Coordinate.h" #ifdef USE_BLACKMAGIC #include "DecklinkReader.h" diff --git a/include/Point.h b/include/Point.h index 5e0feae4..c4c57216 100644 --- a/include/Point.h +++ b/include/Point.h @@ -29,6 +29,10 @@ #define OPENSHOT_POINT_H #include "Coordinate.h" +#include "Exceptions.h" +#include "Json.h" + +using namespace std; namespace openshot { @@ -110,6 +114,12 @@ namespace openshot */ void Initialize_Handles(float Offset = 0.0f); + /// Get and Set JSON methods + string Json(); ///< Generate JSON string of this object + Json::Value JsonValue(); ///< Generate Json::JsonValue for this object + void Json(string value) throw(InvalidJSON); ///< Load JSON string into this object + void Json(Json::Value root); ///< Load Json::JsonValue into this object + }; } diff --git a/include/effects/ChromaKey.h b/include/effects/ChromaKey.h index d207c5f3..0e9d016c 100644 --- a/include/effects/ChromaKey.h +++ b/include/effects/ChromaKey.h @@ -78,6 +78,12 @@ namespace openshot /// @param frame The frame object that needs the effect applied to it /// @param frame_number The frame number (starting at 1) of the effect on the timeline. tr1::shared_ptr GetFrame(tr1::shared_ptr frame, int frame_number); + + /// Get and Set JSON methods + string Json(); ///< Generate JSON string of this object + Json::Value JsonValue(); ///< Generate Json::JsonValue for this object + void Json(string value) throw(InvalidJSON); ///< Load JSON string into this object + void Json(Json::Value root); ///< Load Json::JsonValue into this object }; } diff --git a/include/effects/Deinterlace.h b/include/effects/Deinterlace.h index 248db5c3..9bbaa49d 100644 --- a/include/effects/Deinterlace.h +++ b/include/effects/Deinterlace.h @@ -25,8 +25,8 @@ * along with OpenShot Library. If not, see . */ -#ifndef OPENSHOT_NEGATE_EFFECT_H -#define OPENSHOT_NEGATE_EFFECT_H +#ifndef OPENSHOT_DEINTERLACE_EFFECT_H +#define OPENSHOT_DEINTERLACE_EFFECT_H #include "../EffectBase.h" @@ -39,6 +39,7 @@ #include "Magick++.h" #include "../Color.h" #include "../Exceptions.h" +#include "../Json.h" #include "../KeyFrame.h" using namespace std; @@ -73,6 +74,12 @@ namespace openshot /// @param frame The frame object that needs the effect applied to it /// @param frame_number The frame number (starting at 1) of the effect on the timeline. tr1::shared_ptr GetFrame(tr1::shared_ptr frame, int frame_number); + + /// Get and Set JSON methods + string Json(); ///< Generate JSON string of this object + Json::Value JsonValue(); ///< Generate Json::JsonValue for this object + void Json(string value) throw(InvalidJSON); ///< Load JSON string into this object + void Json(Json::Value root); ///< Load Json::JsonValue into this object }; } diff --git a/include/effects/Mask.h b/include/effects/Mask.h index 6e6e4d24..084c8617 100644 --- a/include/effects/Mask.h +++ b/include/effects/Mask.h @@ -39,6 +39,7 @@ #include "Magick++.h" #include "../Color.h" #include "../Exceptions.h" +#include "../Json.h" #include "../KeyFrame.h" #include "../ReaderBase.h" @@ -86,6 +87,12 @@ namespace openshot /// @param frame The frame object that needs the effect applied to it /// @param frame_number The frame number (starting at 1) of the effect on the timeline. tr1::shared_ptr GetFrame(tr1::shared_ptr frame, int frame_number); + + /// Get and Set JSON methods + string Json(); ///< Generate JSON string of this object + Json::Value JsonValue(); ///< Generate Json::JsonValue for this object + void Json(string value) throw(InvalidJSON); ///< Load JSON string into this object + void Json(Json::Value root); ///< Load Json::JsonValue into this object }; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d52e33c7..5b0d1ed6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -128,7 +128,9 @@ SET ( OPENSHOT_SOURCE_FILES Cache.cpp ChunkReader.cpp ChunkWriter.cpp + Color.cpp Clip.cpp + ClipBase.cpp Coordinate.cpp DummyReader.cpp ReaderBase.cpp diff --git a/src/Clip.cpp b/src/Clip.cpp index 4be580f1..341bc71f 100644 --- a/src/Clip.cpp +++ b/src/Clip.cpp @@ -536,23 +536,63 @@ int Clip::GetSamplesPerFrame(int frame_number, Fraction rate) throw(ReaderClosed return samples_per_frame; } -// Generate JSON of clip data +// Generate JSON string of this object string Clip::Json() { + // Return formatted string + return JsonValue().toStyledString(); +} + +// Generate Json::JsonValue for this object +Json::Value Clip::JsonValue() { + // Create root json object - Json::Value root; - root["position"] = Position(); - root["layer"] = Layer(); - root["start"] = Start(); - root["end"] = End(); + Json::Value root = ClipBase::JsonValue(); // get parent properties root["gravity"] = gravity; root["scale"] = scale; root["anchor"] = anchor; root["waveform"] = waveform; - // return formatted json string - return root.toStyledString(); - + // return JsonValue + return root; } +// Load JSON string into this object +void Clip::Json(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 + Json(root); + } + catch (exception e) + { + // Error parsing JSON (or missing keys) + throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); + } +} + +// Load Json::JsonValue into this object +void Clip::Json(Json::Value root) { + + // Set parent data + ClipBase::Json(root); + + // Set data from Json (if key is found) + if (root["gravity"] != Json::nullValue) + gravity = (GravityType) root["gravity"].asInt(); + if (root["scale"] != Json::nullValue) + scale = (ScaleType) root["scale"].asInt(); + if (root["anchor"] != Json::nullValue) + anchor = (AnchorType) root["anchor"].asInt(); + if (root["waveform"] != Json::nullValue) + waveform = root["waveform"].asBool(); +} diff --git a/src/ClipBase.cpp b/src/ClipBase.cpp new file mode 100644 index 00000000..0ca2d177 --- /dev/null +++ b/src/ClipBase.cpp @@ -0,0 +1,88 @@ +/** + * @file + * @brief Source file for EffectBase class + * @author Jonathan Thomas + * + * @section LICENSE + * + * Copyright (c) 2008-2013 OpenShot Studios, LLC + * (http://www.openshotstudios.com). This file is part of + * OpenShot Library (http://www.openshot.org), an open-source project + * dedicated to delivering high quality video editing and animation solutions + * to the world. + * + * OpenShot Library 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. + * + * OpenShot Library 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 OpenShot Library. If not, see . + */ + +#include "../include/ClipBase.h" + +using namespace openshot; + +// Generate JSON string of this object +string ClipBase::Json() { + + // Return formatted string + return JsonValue().toStyledString(); +} + +// Generate Json::JsonValue for this object +Json::Value ClipBase::JsonValue() { + + // Create root json object + Json::Value root; + root["position"] = Position(); + root["layer"] = Layer(); + root["start"] = Start(); + root["end"] = End(); + + // return JsonValue + return root; +} + +// Load JSON string into this object +void ClipBase::Json(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 + Json(root); + } + catch (exception e) + { + // Error parsing JSON (or missing keys) + throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); + } +} + +// Load Json::JsonValue into this object +void ClipBase::Json(Json::Value root) { + + // Set data from Json (if key is found) + if (root["position"] != Json::nullValue) + Position(root["position"].asDouble()); + if (root["layer"] != Json::nullValue) + Layer(root["layer"].asInt()); + if (root["start"] != Json::nullValue) + Start(root["start"].asDouble()); + if (root["end"] != Json::nullValue) + End(root["end"].asDouble()); +} diff --git a/src/Color.cpp b/src/Color.cpp new file mode 100644 index 00000000..2a208b29 --- /dev/null +++ b/src/Color.cpp @@ -0,0 +1,85 @@ +/** + * @file + * @brief Source file for EffectBase class + * @author Jonathan Thomas + * + * @section LICENSE + * + * Copyright (c) 2008-2013 OpenShot Studios, LLC + * (http://www.openshotstudios.com). This file is part of + * OpenShot Library (http://www.openshot.org), an open-source project + * dedicated to delivering high quality video editing and animation solutions + * to the world. + * + * OpenShot Library 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. + * + * OpenShot Library 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 OpenShot Library. If not, see . + */ + +#include "../include/Color.h" + +using namespace openshot; + +// Generate JSON string of this object +string Color::Json() { + + // Return formatted string + return JsonValue().toStyledString(); +} + +// Generate Json::JsonValue for this object +Json::Value Color::JsonValue() { + + // Create root json object + Json::Value root; + root["red"] = red.JsonValue(); + root["green"] = green.JsonValue(); + root["blue"] = blue.JsonValue(); + + // return JsonValue + return root; +} + +// Load JSON string into this object +void Color::Json(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 + Json(root); + } + catch (exception e) + { + // Error parsing JSON (or missing keys) + throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); + } +} + +// Load Json::JsonValue into this object +void Color::Json(Json::Value root) { + + // Set data from Json (if key is found) + if (root["red"] != Json::nullValue) + red.Json(root["red"]); + if (root["green"] != Json::nullValue) + green.Json(root["green"]); + if (root["blue"] != Json::nullValue) + blue.Json(root["blue"]); +} diff --git a/src/Coordinate.cpp b/src/Coordinate.cpp index b8bb28d1..edd812dc 100644 --- a/src/Coordinate.cpp +++ b/src/Coordinate.cpp @@ -39,3 +39,70 @@ Coordinate::Coordinate() : Coordinate::Coordinate(float x, float y) : X(x), Y(y), increasing(true), repeated(1,1), delta(0.0) { } + + +// Generate JSON string of this object +string Coordinate::Json() { + + // Return formatted string + return JsonValue().toStyledString(); +} + +// Generate Json::JsonValue for this object +Json::Value Coordinate::JsonValue() { + + // Create root json object + Json::Value root; + root["X"] = X; + root["Y"] = Y; + root["increasing"] = increasing; + root["repeated"] = Json::Value(Json::objectValue); + root["repeated"]["num"] = repeated.num; + root["repeated"]["den"] = repeated.den; + root["delta"] = delta; + + // return JsonValue + return root; +} + +// Load JSON string into this object +void Coordinate::Json(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 + Json(root); + } + catch (exception e) + { + // Error parsing JSON (or missing keys) + throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); + } +} + +// Load Json::JsonValue into this object +void Coordinate::Json(Json::Value root) { + + // Set data from Json (if key is found) + if (root["X"] != Json::nullValue) + X = root["X"].asDouble(); + if (root["Y"] != Json::nullValue) + Y = root["Y"].asDouble(); + if (root["increasing"] != Json::nullValue) + increasing = root["increasing"].asBool(); + if (root["repeated"] != Json::nullValue) + { + repeated.num = root["repeated"]["num"].asInt(); + repeated.den = root["repeated"]["den"].asInt(); + } + if (root["delta"] != Json::nullValue) + delta = root["delta"].asDouble(); +} diff --git a/src/EffectBase.cpp b/src/EffectBase.cpp index ac728fe9..119cff62 100644 --- a/src/EffectBase.cpp +++ b/src/EffectBase.cpp @@ -58,3 +58,54 @@ void EffectBase::DisplayInfo() { cout << "----------------------------" << endl; } +// Generate JSON string of this object +string EffectBase::Json() { + + // Return formatted string + return JsonValue().toStyledString(); +} + +// Generate Json::JsonValue for this object +Json::Value EffectBase::JsonValue() { + + // Create root json object + Json::Value root = ClipBase::JsonValue(); // get parent properties + root["order"] = Order(); + + // return JsonValue + return root; +} + +// Load JSON string into this object +void EffectBase::Json(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 + Json(root); + } + catch (exception e) + { + // Error parsing JSON (or missing keys) + throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); + } +} + +// Load Json::JsonValue into this object +void EffectBase::Json(Json::Value root) { + + // Set parent data + ClipBase::Json(root); + + // Set data from Json (if key is found) + if (root["order"] != Json::nullValue) + Order(root["order"].asInt()); +} diff --git a/src/KeyFrame.cpp b/src/KeyFrame.cpp index d51b255c..1f1f1580 100644 --- a/src/KeyFrame.cpp +++ b/src/KeyFrame.cpp @@ -237,44 +237,82 @@ bool Keyframe::IsIncreasing(int index) return true; } -// Generate JSON of keyframe data +// Generate JSON string of this object string Keyframe::Json() { - // Check if it needs to be processed - if (needs_update) - Process(); + // Return formatted string + return JsonValue().toStyledString(); +} + +// Generate Json::JsonValue for this object +Json::Value Keyframe::JsonValue() { // Create root json object - Json::Value root = Json::Value(Json::arrayValue); + Json::Value root; + root["Points"] = Json::Value(Json::arrayValue); // loop through points, and find a matching coordinate for (int x = 0; x < Points.size(); x++) { // Get each point Point existing_point = Points[x]; - - // Create new point object - Json::Value point = Json::Value(Json::objectValue); - point["interpolation"] = existing_point.interpolation; - point["handle_type"] = existing_point.handle_type; - point["co"] = Json::Value(Json::objectValue); - point["co"]["X"] = existing_point.co.X; - point["co"]["Y"] = existing_point.co.Y; - - point["left"] = Json::Value(Json::objectValue); - point["left"]["X"] = existing_point.handle_left.X; - point["left"]["Y"] = existing_point.handle_left.Y; - - point["right"] = Json::Value(Json::objectValue); - point["right"]["X"] = existing_point.handle_right.X; - point["right"]["Y"] = existing_point.handle_right.Y; - - // Append point to array - root.append(point); - + root["Points"].append(existing_point.JsonValue()); } + root["Auto_Handle_Percentage"] = Auto_Handle_Percentage; - // return formatted json string - return root.toStyledString(); + // return JsonValue + return root; +} + +// Load JSON string into this object +void Keyframe::Json(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 + Json(root); + } + catch (exception e) + { + // Error parsing JSON (or missing keys) + throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); + } +} + +// Load Json::JsonValue into this object +void Keyframe::Json(Json::Value root) { + + // mark as dirty + needs_update = true; + + // Clear existing points + Points.clear(); + + if (root["Points"] != Json::nullValue) + // loop through points, and find a matching coordinate + for (int x = 0; x < root["Points"].size(); x++) { + // Get each point + Json::Value existing_point = root["Points"][x]; + + // Create Point + Point p; + + // Load Json into Point + p.Json(existing_point); + + // Add Point to Keyframe + AddPoint(p); + } + + if (root["Auto_Handle_Percentage"] != Json::nullValue) + Auto_Handle_Percentage = root["Auto_Handle_Percentage"].asBool(); } diff --git a/src/Main.cpp b/src/Main.cpp index 67c54163..8ea8a68d 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -41,6 +41,10 @@ using namespace tr1; int main(int argc, char* argv[]) { + Color c; + std::string a; + a = "{\"blue\":{\"Auto_Handle_Percentage\":0.4000000059604645,\"Points\":[]},\"red\":{\"Auto_Handle_Percentage\":0.4000000059604645,\"Points\":[{\"co\":{\"X\":0,\"Y\":243,\"delta\":0,\"increasing\":true,\"repeated\":{\"den\":1,\"num\":1}},\"handle_left\":{\"X\":0,\"Y\":243,\"delta\":0,\"increasing\":true,\"repeated\":{\"den\":1,\"num\":1}},\"handle_right\":{\"X\":0,\"Y\":243,\"delta\":0,\"increasing\":true,\"repeated\":{\"den\":1,\"num\":1}},\"handle_type\":0,\"interpolation\":0}]}}"; + c.Json(a); // FFmpegReader r2("/home/jonathan/Videos/sintel_trailer-720p.mp4"); // r2.Open(); diff --git a/src/Point.cpp b/src/Point.cpp index 21527036..fe371b8e 100644 --- a/src/Point.cpp +++ b/src/Point.cpp @@ -92,3 +92,64 @@ void Point::Initialize_Handles(float Offset) { handle_left = Coordinate(co.X - Offset, co.Y); handle_right = Coordinate(co.X + Offset, co.Y); } + +// Generate JSON string of this object +string Point::Json() { + + // Return formatted string + return JsonValue().toStyledString(); +} + +// Generate Json::JsonValue for this object +Json::Value Point::JsonValue() { + + // Create root json object + Json::Value root; + root["co"] = co.JsonValue(); + root["handle_left"] = handle_left.JsonValue(); + root["handle_right"] = handle_right.JsonValue(); + root["interpolation"] = interpolation; + root["handle_type"] = handle_type; + + // return JsonValue + return root; +} + +// Load JSON string into this object +void Point::Json(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 + Json(root); + } + catch (exception e) + { + // Error parsing JSON (or missing keys) + throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); + } +} + +// Load Json::JsonValue into this object +void Point::Json(Json::Value root) { + + if (root["co"] != Json::nullValue) + co.Json(root["co"]); // update coordinate + if (root["handle_left"] != Json::nullValue) + handle_left.Json(root["handle_left"]); // update coordinate + if (root["handle_right"] != Json::nullValue) + handle_right.Json(root["handle_right"]); // update coordinate + if (root["interpolation"] != Json::nullValue) + interpolation = (InterpolationType) root["interpolation"].asInt(); + if (root["handle_type"] != Json::nullValue) + handle_type = (HandleType) root["handle_type"].asInt(); + +} diff --git a/src/effects/ChromaKey.cpp b/src/effects/ChromaKey.cpp index d1a48ed6..a9f1b0cf 100644 --- a/src/effects/ChromaKey.cpp +++ b/src/effects/ChromaKey.cpp @@ -55,3 +55,58 @@ tr1::shared_ptr ChromaKey::GetFrame(tr1::shared_ptr frame, int fra // return the modified frame return frame; } + +// Generate JSON string of this object +string ChromaKey::Json() { + + // Return formatted string + return JsonValue().toStyledString(); +} + +// Generate Json::JsonValue for this object +Json::Value ChromaKey::JsonValue() { + + // Create root json object + Json::Value root = EffectBase::JsonValue(); // get parent properties + root["color"] = color.JsonValue(); + root["fuzz"] = fuzz.JsonValue(); + + // return JsonValue + return root; +} + +// Load JSON string into this object +void ChromaKey::Json(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 + Json(root); + } + catch (exception e) + { + // Error parsing JSON (or missing keys) + throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); + } +} + +// Load Json::JsonValue into this object +void ChromaKey::Json(Json::Value root) { + + // Set parent data + EffectBase::Json(root); + + // Set data from Json (if key is found) + if (root["color"] != Json::nullValue) + color.Json(root["color"]); + if (root["fuzz"] != Json::nullValue) + fuzz.Json(root["fuzz"]); +} diff --git a/src/effects/Deinterlace.cpp b/src/effects/Deinterlace.cpp index 54067a9b..33ff8622 100644 --- a/src/effects/Deinterlace.cpp +++ b/src/effects/Deinterlace.cpp @@ -65,3 +65,55 @@ tr1::shared_ptr Deinterlace::GetFrame(tr1::shared_ptr frame, int f // return the modified frame return frame; } + +// Generate JSON string of this object +string Deinterlace::Json() { + + // Return formatted string + return JsonValue().toStyledString(); +} + +// Generate Json::JsonValue for this object +Json::Value Deinterlace::JsonValue() { + + // Create root json object + Json::Value root = EffectBase::JsonValue(); // get parent properties + root["isOdd"] = isOdd; + + // return JsonValue + return root; +} + +// Load JSON string into this object +void Deinterlace::Json(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 + Json(root); + } + catch (exception e) + { + // Error parsing JSON (or missing keys) + throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); + } +} + +// Load Json::JsonValue into this object +void Deinterlace::Json(Json::Value root) { + + // Set parent data + EffectBase::Json(root); + + // Set data from Json (if key is found) + if (root["isOdd"] != Json::nullValue) + isOdd = root["isOdd"].asBool(); +} diff --git a/src/effects/Mask.cpp b/src/effects/Mask.cpp index fcd2887a..67783f48 100644 --- a/src/effects/Mask.cpp +++ b/src/effects/Mask.cpp @@ -121,3 +121,60 @@ tr1::shared_ptr Mask::GetFrame(tr1::shared_ptr frame, int frame_nu // return the modified frame return frame; } + +// Generate JSON string of this object +string Mask::Json() { + + // Return formatted string + return JsonValue().toStyledString(); +} + +// Generate Json::JsonValue for this object +Json::Value Mask::JsonValue() { + + // Create root json object + Json::Value root = EffectBase::JsonValue(); // get parent properties + root["brightness"] = brightness.JsonValue(); + root["contrast"] = contrast.JsonValue(); + //root["reader"] = reader.JsonValue(); + + // return JsonValue + return root; +} + +// Load JSON string into this object +void Mask::Json(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 + Json(root); + } + catch (exception e) + { + // Error parsing JSON (or missing keys) + throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); + } +} + +// Load Json::JsonValue into this object +void Mask::Json(Json::Value root) { + + // Set parent data + EffectBase::Json(root); + + // Set data from Json (if key is found) + if (root["brightness"] != Json::nullValue) + brightness.Json(root["brightness"]); + if (root["contrast"] != Json::nullValue) + contrast.Json(root["contrast"]); +} +