diff --git a/src/ImageReader.cpp b/src/ImageReader.cpp index 1b7c1af0..ad21be15 100644 --- a/src/ImageReader.cpp +++ b/src/ImageReader.cpp @@ -35,14 +35,7 @@ using namespace openshot; -ImageReader::ImageReader(std::string path) : path(path), is_open(false) -{ - // Open and Close the reader, to populate its attributes (such as height, width, etc...) - Open(); - Close(); -} - -ImageReader::ImageReader(std::string path, bool inspect_reader) : path(path), is_open(false) +ImageReader::ImageReader(const std::string& path, bool inspect_reader) : path(path), is_open(false) { // Open and Close the reader, to populate its attributes (such as height, width, etc...) if (inspect_reader) { diff --git a/src/ImageReader.h b/src/ImageReader.h index 5aafcc8f..aa96272f 100644 --- a/src/ImageReader.h +++ b/src/ImageReader.h @@ -76,15 +76,15 @@ namespace openshot bool is_open; public: - - /// Constructor for ImageReader. This automatically opens the media file and loads - /// frame 1, or it throws one of the following exceptions. - ImageReader(std::string path); - - /// Constructor for ImageReader. This only opens the media file to inspect its properties - /// if inspect_reader=true. When not inspecting the media file, it's much faster, and useful - /// when you are inflating the object using JSON after instantiating it. - ImageReader(std::string path, bool inspect_reader); + /// @brief Constructor for ImageReader. + /// + /// Opens the media file to inspect its properties and loads frame 1, + /// iff inspect_reader == true (the default). Pass a false value in + /// the optional parameter to defer this initial Open()/Close() cycle. + /// + /// When not inspecting the media file, it's much faster, and useful + /// when you are inflating the object using JSON after instantiation. + ImageReader(const std::string& path, bool inspect_reader=true); /// Close File void Close() override; diff --git a/src/QtImageReader.cpp b/src/QtImageReader.cpp index 281cb363..f24c7ef4 100644 --- a/src/QtImageReader.cpp +++ b/src/QtImageReader.cpp @@ -44,13 +44,6 @@ using namespace openshot; -QtImageReader::QtImageReader(std::string path) : path{QString::fromStdString(path)}, is_open(false) -{ - // Open and Close the reader, to populate its attributes (such as height, width, etc...) - Open(); - Close(); -} - QtImageReader::QtImageReader(std::string path, bool inspect_reader) : path{QString::fromStdString(path)}, is_open(false) { // Open and Close the reader, to populate its attributes (such as height, width, etc...) diff --git a/src/QtImageReader.h b/src/QtImageReader.h index 3848065a..5162b8f4 100644 --- a/src/QtImageReader.h +++ b/src/QtImageReader.h @@ -72,15 +72,15 @@ namespace openshot QSize max_size; ///> Current max_size as calculated with Clip properties public: - - /// Constructor for QtImageReader. This automatically opens the media file and loads - /// frame 1, or it throws one of the following exceptions. - QtImageReader(std::string path); - - /// Constructor for QtImageReader. This only opens the media file to inspect its properties - /// if inspect_reader=true. When not inspecting the media file, it's much faster, and useful - /// when you are inflating the object using JSON after instantiating it. - QtImageReader(std::string path, bool inspect_reader); + /// @brief Constructor for QtImageReader. + /// + /// Opens the media file to inspect its properties and loads frame 1, + /// iff inspect_reader == true (the default). Pass a false value in + /// the optional parameter to defer this initial Open()/Close() cycle. + /// + /// When not inspecting the media file, it's much faster, and useful + /// when you are inflating the object using JSON after instantiation. + QtImageReader(std::string path, bool inspect_reader=true); virtual ~QtImageReader(); diff --git a/tests/ImageWriter_Tests.cpp b/tests/ImageWriter_Tests.cpp index a9b9e07d..d74907bf 100644 --- a/tests/ImageWriter_Tests.cpp +++ b/tests/ImageWriter_Tests.cpp @@ -37,17 +37,35 @@ using namespace std; using namespace openshot; #ifdef USE_IMAGEMAGICK -TEST(ImageWriter_Test_Gif) +SUITE(ImageWriter) { - // Reader + +TEST(Gif) +{ + // Reader --------------- + + // Bad path + FFmpegReader bad_r("/tmp/bleeblorp.xls", false); + CHECK_THROW(bad_r.Open(), InvalidFile); + + // Good path stringstream path; path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4"; FFmpegReader r(path.str()); + + // Read-before-open error + CHECK_THROW(r.GetFrame(1), ReaderClosed); + r.Open(); /* WRITER ---------------- */ ImageWriter w("output1.gif"); + CHECK_EQUAL(false, w.IsOpen()); + + // Check for exception on write-before-open + CHECK_THROW(w.WriteFrame(&r, 500, 504), WriterClosed); + // Set the image output settings (format, fps, width, height, quality, loops, combine) w.SetVideoOptions("GIF", r.info.fps, r.info.width, r.info.height, 70, 1, true); @@ -63,7 +81,16 @@ TEST(ImageWriter_Test_Gif) // Open up the 5th frame from the newly created GIF ImageReader r1("output1.gif[4]"); + + // Basic Reader state queries + CHECK_EQUAL("ImageReader", r1.Name()); + + CacheMemory* c = r1.GetCache(); + CHECK_EQUAL(true, c == nullptr); + + CHECK_EQUAL(false, r1.IsOpen()); r1.Open(); + CHECK_EQUAL(true, r1.IsOpen()); // Verify various settings CHECK_EQUAL(r.info.width, r1.info.width); @@ -82,4 +109,6 @@ TEST(ImageWriter_Test_Gif) CHECK_CLOSE(11, (int)pixels[pixel_index + 2], 5); CHECK_CLOSE(255, (int)pixels[pixel_index + 3], 5); } + +} // SUITE #endif