2019-12-28 12:27:58 -05:00
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* @brief Unit tests for openshot::Frame
|
|
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
|
|
|
|
* @author FeRD (Frank Dana) <ferdnyc@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* @ref License
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-16 01:26:26 -04:00
|
|
|
// Copyright (c) 2008-2019 OpenShot Studios, LLC
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
2019-12-28 12:27:58 -05:00
|
|
|
|
2020-12-26 06:03:30 -05:00
|
|
|
#include <sstream>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2019-12-28 12:27:58 -05:00
|
|
|
#include <QImage>
|
|
|
|
|
|
2020-12-26 06:03:30 -05:00
|
|
|
#ifdef USE_OPENCV
|
2021-04-09 04:09:36 -04:00
|
|
|
#define int64 opencv_broken_int
|
|
|
|
|
#define uint64 opencv_broken_uint
|
|
|
|
|
#include <opencv2/opencv.hpp>
|
|
|
|
|
#undef int64
|
|
|
|
|
#undef uint64
|
2020-12-26 06:03:30 -05:00
|
|
|
#endif
|
|
|
|
|
|
2022-06-17 15:07:16 -04:00
|
|
|
#include "openshot_catch.h"
|
2021-04-09 04:09:36 -04:00
|
|
|
|
|
|
|
|
#include "Clip.h"
|
|
|
|
|
#include "Fraction.h"
|
|
|
|
|
#include "Frame.h"
|
|
|
|
|
|
2019-12-28 12:27:58 -05:00
|
|
|
using namespace openshot;
|
|
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
TEST_CASE( "Default_Constructor", "[libopenshot][frame]" )
|
2019-12-28 12:27:58 -05:00
|
|
|
{
|
|
|
|
|
// Create a "blank" default Frame
|
|
|
|
|
std::shared_ptr<Frame> f1(new Frame());
|
|
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
REQUIRE(f1 != nullptr); // Test aborts here if we didn't get a Frame
|
2019-12-28 12:27:58 -05:00
|
|
|
|
|
|
|
|
// Check basic default parameters
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK(f1->GetHeight() == 1);
|
|
|
|
|
CHECK(f1->GetWidth() == 1);
|
|
|
|
|
CHECK(f1->SampleRate() == 44100);
|
|
|
|
|
CHECK(f1->GetAudioChannelsCount() == 2);
|
2019-12-28 12:27:58 -05:00
|
|
|
|
|
|
|
|
// Should be false until we load or create contents
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK(f1->has_image_data == false);
|
|
|
|
|
CHECK(f1->has_audio_data == false);
|
2019-12-28 12:27:58 -05:00
|
|
|
|
|
|
|
|
// Calling GetImage() paints a blank frame, by default
|
|
|
|
|
std::shared_ptr<QImage> i1 = f1->GetImage();
|
|
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
REQUIRE(i1 != nullptr);
|
2019-12-28 12:27:58 -05:00
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK(f1->has_image_data == true);
|
|
|
|
|
CHECK(f1->has_audio_data == false);
|
2019-12-28 12:27:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
TEST_CASE( "Data_Access", "[libopenshot][frame]" )
|
2019-12-28 12:27:58 -05:00
|
|
|
{
|
|
|
|
|
// Create a video clip
|
|
|
|
|
std::stringstream path;
|
|
|
|
|
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
|
|
|
|
|
Clip c1(path.str());
|
|
|
|
|
c1.Open();
|
|
|
|
|
|
|
|
|
|
// Get first frame
|
|
|
|
|
std::shared_ptr<Frame> f1 = c1.GetFrame(1);
|
|
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
REQUIRE(f1 != nullptr);
|
2019-12-28 12:27:58 -05:00
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK(f1->number == 1);
|
|
|
|
|
CHECK(f1->GetWidth() == 1280);
|
|
|
|
|
CHECK(f1->GetHeight() == 720);
|
2019-12-28 12:27:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
TEST_CASE( "AddImage_QImage", "[libopenshot][frame]" )
|
2019-12-28 12:27:58 -05:00
|
|
|
{
|
|
|
|
|
// Create a "blank" default Frame
|
|
|
|
|
std::shared_ptr<Frame> f1(new Frame());
|
|
|
|
|
|
|
|
|
|
// Load an image
|
|
|
|
|
std::stringstream path;
|
|
|
|
|
path << TEST_MEDIA_PATH << "front.png";
|
2021-04-09 04:09:36 -04:00
|
|
|
auto i1 = std::make_shared<QImage>(QString::fromStdString(path.str()));
|
2019-12-28 12:27:58 -05:00
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
REQUIRE(f1 != nullptr); // Test aborts here if we didn't get a Frame
|
|
|
|
|
CHECK(i1->isNull() == false);
|
2019-12-28 12:27:58 -05:00
|
|
|
|
|
|
|
|
f1->AddImage(i1);
|
|
|
|
|
|
|
|
|
|
// Check loaded image parameters
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK(f1->GetHeight() == i1->height());
|
|
|
|
|
CHECK(f1->GetWidth() == i1->width());
|
|
|
|
|
CHECK(f1->has_image_data == true);
|
2019-12-28 12:27:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
TEST_CASE( "Copy_Constructor", "[libopenshot][frame]" )
|
2019-12-28 12:27:58 -05:00
|
|
|
{
|
|
|
|
|
// Create a dummy Frame
|
|
|
|
|
openshot::Frame f1(1, 800, 600, "#000000");
|
|
|
|
|
|
|
|
|
|
// Load an image
|
|
|
|
|
std::stringstream path;
|
|
|
|
|
path << TEST_MEDIA_PATH << "front.png";
|
2021-04-09 04:09:36 -04:00
|
|
|
auto i1 = std::make_shared<QImage>(QString::fromStdString(path.str()));
|
2019-12-28 12:27:58 -05:00
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK(i1->isNull() == false);
|
2019-12-28 12:27:58 -05:00
|
|
|
|
|
|
|
|
// Add image to f1, then copy f1 to f2
|
|
|
|
|
f1.AddImage(i1);
|
|
|
|
|
|
|
|
|
|
Frame f2 = f1;
|
|
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK(f1.GetHeight() == f2.GetHeight());
|
|
|
|
|
CHECK(f1.GetWidth() == f2.GetWidth());
|
2019-12-28 12:27:58 -05:00
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK(f1.has_image_data == f2.has_image_data);
|
|
|
|
|
CHECK(f1.has_audio_data == f2.has_audio_data);
|
2019-12-28 12:27:58 -05:00
|
|
|
|
|
|
|
|
Fraction par1 = f1.GetPixelRatio();
|
|
|
|
|
Fraction par2 = f2.GetPixelRatio();
|
|
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK(par1.num == par2.num);
|
|
|
|
|
CHECK(par1.den == par2.den);
|
2019-12-28 12:27:58 -05:00
|
|
|
|
|
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK(f1.SampleRate() == f2.SampleRate());
|
|
|
|
|
CHECK(f1.GetAudioChannelsCount() == f2.GetAudioChannelsCount());
|
|
|
|
|
CHECK(f1.ChannelsLayout() == f2.ChannelsLayout());
|
2019-12-28 12:27:58 -05:00
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK(f1.GetBytes() == f2.GetBytes());
|
|
|
|
|
CHECK(f1.GetAudioSamplesCount() == f2.GetAudioSamplesCount());
|
2019-12-28 12:27:58 -05:00
|
|
|
}
|
|
|
|
|
|
2020-07-04 19:20:54 -03:00
|
|
|
#ifdef USE_OPENCV
|
2021-04-09 04:09:36 -04:00
|
|
|
TEST_CASE( "Convert_Image", "[libopenshot][opencv][frame]" )
|
2020-06-28 16:54:11 -03:00
|
|
|
{
|
|
|
|
|
// Create a video clip
|
|
|
|
|
std::stringstream path;
|
|
|
|
|
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
|
|
|
|
|
Clip c1(path.str());
|
|
|
|
|
c1.Open();
|
|
|
|
|
|
|
|
|
|
// Get first frame
|
2020-11-05 12:23:08 -03:00
|
|
|
auto f1 = c1.GetFrame(1);
|
2020-06-28 16:54:11 -03:00
|
|
|
|
|
|
|
|
// Get first Mat image
|
|
|
|
|
cv::Mat cvimage = f1->GetImageCV();
|
|
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK_FALSE(cvimage.empty());
|
2020-06-28 16:54:11 -03:00
|
|
|
|
2021-04-09 04:09:36 -04:00
|
|
|
CHECK(f1->number == 1);
|
|
|
|
|
CHECK(f1->GetWidth() == cvimage.cols);
|
|
|
|
|
CHECK(f1->GetHeight() == cvimage.rows);
|
|
|
|
|
CHECK(cvimage.channels() == 3);
|
2020-06-28 16:54:11 -03:00
|
|
|
}
|
2020-07-04 19:20:54 -03:00
|
|
|
#endif
|