style: reformat C/C++ sources and headers with clang-format

Run clang-format over all project C/C++ source and header files
(.c, .cpp, .cc, .h, .hpp, .hh, .m, .mm) under app/ and tests/.
Non-source files (svg, qm, qrc, etc.) were not touched.
This commit is contained in:
2026-07-13 15:34:11 +08:00
parent 6a696bc234
commit f03b6b58ff
61 changed files with 2873 additions and 2740 deletions
+129 -109
View File
@@ -27,22 +27,26 @@ extern "C" {
#include "render/texture.h"
#include "render/videoparams.h"
namespace olive {
namespace plugin {
namespace test {
namespace olive
{
namespace plugin
{
namespace test
{
namespace {
namespace
{
// Helper to create a test texture with solid color
// For U8: fill_value is 0-255
// For U16: fill_value is 0-65535
// For Float: fill_value is 0.0-1.0 mapped to bytes
template<typename T>
template <typename T>
TexturePtr CreateSolidTextureT(const VideoParams &params, T fill_value)
{
AVFramePtr frame = CreateAVFramePtr();
frame->format = FFmpegUtils::GetFFmpegPixelFormat(
params.format(), params.channel_count());
frame->format = FFmpegUtils::GetFFmpegPixelFormat(params.format(),
params.channel_count());
frame->width = params.width();
frame->height = params.height();
if (frame->format == AV_PIX_FMT_NONE) {
@@ -57,7 +61,7 @@ TexturePtr CreateSolidTextureT(const VideoParams &params, T fill_value)
const int linesize = frame->linesize[0];
for (int y = 0; y < frame->height; ++y) {
T *row = reinterpret_cast<T*>(frame->data[0] + y * linesize);
T *row = reinterpret_cast<T *>(frame->data[0] + y * linesize);
for (int x = 0; x < frame->width * params.channel_count(); ++x) {
row[x] = fill_value;
}
@@ -68,17 +72,21 @@ TexturePtr CreateSolidTextureT(const VideoParams &params, T fill_value)
return texture;
}
TexturePtr CreateSolidTexture(const VideoParams &params, uint32_t fill_value = 0x7f)
TexturePtr CreateSolidTexture(const VideoParams &params,
uint32_t fill_value = 0x7f)
{
// Choose type based on pixel format
switch (params.format()) {
case core::PixelFormat::U8:
return CreateSolidTextureT<uint8_t>(params, static_cast<uint8_t>(fill_value));
return CreateSolidTextureT<uint8_t>(params,
static_cast<uint8_t>(fill_value));
case core::PixelFormat::U16:
return CreateSolidTextureT<uint16_t>(params, static_cast<uint16_t>(fill_value));
return CreateSolidTextureT<uint16_t>(params,
static_cast<uint16_t>(fill_value));
case core::PixelFormat::F16:
case core::PixelFormat::F32:
return CreateSolidTextureT<float>(params, static_cast<float>(fill_value) / 255.0f);
return CreateSolidTextureT<float>(
params, static_cast<float>(fill_value) / 255.0f);
default:
return nullptr;
}
@@ -87,12 +95,12 @@ TexturePtr CreateSolidTexture(const VideoParams &params, uint32_t fill_value = 0
// Helper to create a gradient texture
// For U8: gradient is 0-255 per byte
// For Float: gradient is 0.0-1.0 per component
template<typename T>
template <typename T>
TexturePtr CreateGradientTextureT(const VideoParams &params, float scale)
{
AVFramePtr frame = CreateAVFramePtr();
frame->format = FFmpegUtils::GetFFmpegPixelFormat(
params.format(), params.channel_count());
frame->format = FFmpegUtils::GetFFmpegPixelFormat(params.format(),
params.channel_count());
frame->width = params.width();
frame->height = params.height();
if (frame->format == AV_PIX_FMT_NONE) {
@@ -107,7 +115,7 @@ TexturePtr CreateGradientTextureT(const VideoParams &params, float scale)
const int linesize = frame->linesize[0];
for (int y = 0; y < frame->height; ++y) {
T *row = reinterpret_cast<T*>(frame->data[0] + y * linesize);
T *row = reinterpret_cast<T *>(frame->data[0] + y * linesize);
T value = static_cast<T>((y * scale) / frame->height);
for (int x = 0; x < frame->width * params.channel_count(); ++x) {
row[x] = value;
@@ -135,17 +143,16 @@ TexturePtr CreateGradientTexture(const VideoParams &params)
}
// Helper function to find and render a plugin
bool RenderPlugin(const std::string &plugin_id,
const VideoParams &params,
const NodeValueRow &inputs,
bool verbose = false)
bool RenderPlugin(const std::string &plugin_id, const VideoParams &params,
const NodeValueRow &inputs, bool verbose = false)
{
auto *cache = OFX::Host::PluginCache::getPluginCache();
if (!cache) {
if (verbose) std::cerr << "Plugin cache not available" << std::endl;
if (verbose)
std::cerr << "Plugin cache not available" << std::endl;
return false;
}
OFX::Host::Plugin *found = nullptr;
for (auto *plug : cache->getPlugins()) {
if (plug && plug->getIdentifier() == plugin_id) {
@@ -153,66 +160,72 @@ bool RenderPlugin(const std::string &plugin_id,
break;
}
}
if (!found) {
if (verbose) std::cerr << "Plugin not found: " << plugin_id << std::endl;
if (verbose)
std::cerr << "Plugin not found: " << plugin_id << std::endl;
return false;
}
auto *image_effect = dynamic_cast<OFX::Host::ImageEffect::ImageEffectPlugin *>(found);
auto *image_effect =
dynamic_cast<OFX::Host::ImageEffect::ImageEffectPlugin *>(found);
if (!image_effect) {
if (verbose) std::cerr << "Not an image effect plugin" << std::endl;
if (verbose)
std::cerr << "Not an image effect plugin" << std::endl;
return false;
}
const auto &contexts = image_effect->getContexts();
std::string context = kOfxImageEffectContextFilter;
if (!contexts.empty() &&
contexts.find(kOfxImageEffectContextFilter) == contexts.end()) {
context = *contexts.begin();
}
OFX::Host::ImageEffect::Instance *instance =
image_effect->createInstance(context, nullptr);
if (!instance) {
if (verbose) std::cerr << "Failed to create instance" << std::endl;
if (verbose)
std::cerr << "Failed to create instance" << std::endl;
return false;
}
auto *olive_instance = dynamic_cast<OlivePluginInstance *>(instance);
if (!olive_instance) {
if (verbose) std::cerr << "Not an OlivePluginInstance" << std::endl;
if (verbose)
std::cerr << "Not an OlivePluginInstance" << std::endl;
return false;
}
olive_instance->setVideoParam(params);
PluginJob job(instance, nullptr, inputs);
TexturePtr output = std::make_shared<Texture>(params);
PluginRenderer renderer(nullptr);
renderer.RenderPlugin(nullptr, job, output, params, true, false);
bool has_frame = output->frame() != nullptr;
if (!has_frame && verbose) {
std::cerr << "Render produced no output frame" << std::endl;
}
return has_frame;
}
// Skip check function
bool ShouldSkipTest() {
bool ShouldSkipTest()
{
const char *itest = std::getenv("OAK_OFX_ITEST");
if (!itest || std::string(itest) != "1") {
return true;
}
const char *path = std::getenv("OAK_OFX_PLUGIN_PATH");
if (!path || std::string(path).empty()) {
return true;
}
static bool plugins_loaded = false;
if (!plugins_loaded) {
QString raw = QString::fromUtf8(path);
@@ -223,7 +236,7 @@ bool ShouldSkipTest() {
}
plugins_loaded = true;
}
return false;
}
@@ -238,16 +251,16 @@ TEST(PluginMisc, MirrorHorizontal)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
// Mirror plugin typically works with 8-bit
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr input = CreateGradientTexture(params);
ASSERT_NE(input, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, input));
bool result = RenderPlugin("net.sf.openfx.Mirror", params, row, true);
EXPECT_TRUE(result) << "Mirror plugin should produce output";
}
@@ -261,16 +274,17 @@ TEST(PluginMisc, TransformTranslate)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr input = CreateSolidTexture(params, 0x80);
ASSERT_NE(input, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, input));
bool result = RenderPlugin("net.sf.openfx.TransformPlugin", params, row, true);
bool result =
RenderPlugin("net.sf.openfx.TransformPlugin", params, row, true);
EXPECT_TRUE(result) << "Transform plugin should produce output";
}
@@ -283,16 +297,17 @@ TEST(PluginMisc, ColorCorrect)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr input = CreateSolidTexture(params, 0x80);
ASSERT_NE(input, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, input));
bool result = RenderPlugin("net.sf.openfx.ColorCorrectPlugin", params, row, true);
bool result =
RenderPlugin("net.sf.openfx.ColorCorrectPlugin", params, row, true);
EXPECT_TRUE(result) << "ColorCorrect plugin should produce output";
}
@@ -301,16 +316,17 @@ TEST(PluginMisc, Saturation)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr input = CreateSolidTexture(params, 0x80);
ASSERT_NE(input, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, input));
bool result = RenderPlugin("net.sf.openfx.SaturationPlugin", params, row, true);
bool result =
RenderPlugin("net.sf.openfx.SaturationPlugin", params, row, true);
EXPECT_TRUE(result) << "Saturation plugin should produce output";
}
@@ -323,15 +339,15 @@ TEST(PluginMisc, GaussianBlur)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr input = CreateSolidTexture(params, 0x80);
ASSERT_NE(input, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, input));
// Use CImgBlur from the available plugin list
bool result = RenderPlugin("net.sf.cimg.CImgBlur", params, row, true);
EXPECT_TRUE(result) << "GaussianBlur plugin should produce output";
@@ -346,15 +362,15 @@ TEST(PluginMisc, Crop)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr input = CreateSolidTexture(params, 0x80);
ASSERT_NE(input, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, input));
bool result = RenderPlugin("net.sf.openfx.CropPlugin", params, row, true);
EXPECT_TRUE(result) << "Crop plugin should produce output";
}
@@ -364,15 +380,15 @@ TEST(PluginMisc, Grade)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr input = CreateSolidTexture(params, 0x80);
ASSERT_NE(input, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, input));
bool result = RenderPlugin("net.sf.openfx.GradePlugin", params, row, true);
EXPECT_TRUE(result) << "Grade plugin should produce output";
}
@@ -386,16 +402,17 @@ TEST(PluginMisc, NonExistentPlugin)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr input = CreateSolidTexture(params, 0x80);
ASSERT_NE(input, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, input));
bool result = RenderPlugin("net.sf.openfx.NonExistentPlugin", params, row, true);
bool result =
RenderPlugin("net.sf.openfx.NonExistentPlugin", params, row, true);
EXPECT_FALSE(result) << "Non-existent plugin should fail gracefully";
}
@@ -408,15 +425,15 @@ TEST(PluginMisc, CImgSharpen)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr input = CreateSolidTexture(params, 0x80);
ASSERT_NE(input, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, input));
bool result = RenderPlugin("net.sf.cimg.CImgSharpen", params, row, true);
EXPECT_TRUE(result) << "CImgSharpen plugin should produce output";
}
@@ -426,15 +443,15 @@ TEST(PluginMisc, CImgDenoise)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr input = CreateSolidTexture(params, 0x80);
ASSERT_NE(input, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, input));
bool result = RenderPlugin("net.sf.cimg.CImgDenoise", params, row, true);
EXPECT_TRUE(result) << "CImgDenoise plugin should produce output";
}
@@ -444,15 +461,15 @@ TEST(PluginMisc, CImgBilateral)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr input = CreateSolidTexture(params, 0x80);
ASSERT_NE(input, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, input));
bool result = RenderPlugin("net.sf.cimg.CImgBilateral", params, row, true);
EXPECT_TRUE(result) << "CImgBilateral plugin should produce output";
}
@@ -466,17 +483,16 @@ TEST(PluginMisc, MergeOver)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr input = CreateSolidTexture(params, 0x80);
ASSERT_NE(input, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, input));
row.insert(QStringLiteral("Bg"),
NodeValue(NodeValue::kTexture, input));
row.insert(QStringLiteral("Bg"), NodeValue(NodeValue::kTexture, input));
bool result = RenderPlugin("net.sf.openfx.MergePlugin", params, row, true);
EXPECT_TRUE(result) << "Merge plugin should produce output";
}
@@ -490,15 +506,15 @@ TEST(PluginMisc, Keyer)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr input = CreateSolidTexture(params, 0x80);
ASSERT_NE(input, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, input));
bool result = RenderPlugin("net.sf.openfx.KeyerPlugin", params, row, true);
EXPECT_TRUE(result) << "Keyer plugin should produce output";
}
@@ -512,16 +528,17 @@ TEST(PluginMisc, CornerPin)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr input = CreateSolidTexture(params, 0x80);
ASSERT_NE(input, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, input));
bool result = RenderPlugin("net.sf.openfx.CornerPinPlugin", params, row, true);
bool result =
RenderPlugin("net.sf.openfx.CornerPinPlugin", params, row, true);
EXPECT_TRUE(result) << "CornerPin plugin should produce output";
}
@@ -530,16 +547,17 @@ TEST(PluginMisc, LensDistortion)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr input = CreateSolidTexture(params, 0x80);
ASSERT_NE(input, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, input));
bool result = RenderPlugin("net.sf.openfx.LensDistortion", params, row, true);
bool result =
RenderPlugin("net.sf.openfx.LensDistortion", params, row, true);
EXPECT_TRUE(result) << "LensDistortion plugin should produce output";
}
@@ -552,15 +570,15 @@ TEST(PluginMisc, Invert)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr input = CreateSolidTexture(params, 0x80);
ASSERT_NE(input, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, input));
bool result = RenderPlugin("net.sf.openfx.Invert", params, row, true);
EXPECT_TRUE(result) << "Invert plugin should produce output";
}
@@ -570,15 +588,15 @@ TEST(PluginMisc, Gamma)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr input = CreateSolidTexture(params, 0x80);
ASSERT_NE(input, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, input));
bool result = RenderPlugin("net.sf.openfx.GammaPlugin", params, row, true);
EXPECT_TRUE(result) << "Gamma plugin should produce output";
}
@@ -592,12 +610,12 @@ TEST(PluginMisc, ListAvailablePlugins)
if (ShouldSkipTest()) {
GTEST_SKIP() << "OFX integration test not enabled";
}
auto *cache = OFX::Host::PluginCache::getPluginCache();
if (!cache) {
GTEST_SKIP() << "Plugin cache not available";
}
std::cout << "\nAvailable OFX plugins:\n";
for (auto *plug : cache->getPlugins()) {
if (plug) {
@@ -605,29 +623,31 @@ TEST(PluginMisc, ListAvailablePlugins)
}
}
std::cout << std::endl;
SUCCEED();
}
TEST(PluginMisc, CImgBilateralGuided_MultiInput)
{
if (ShouldSkipTest()) GTEST_SKIP() << "OFX integration test not enabled";
if (ShouldSkipTest())
GTEST_SKIP() << "OFX integration test not enabled";
// CImgBilateralGuided is a multi-input plugin (Source + Guide).
// This test verifies that connecting both inputs does not trigger
// the frame-rate mismatch exception in setupClipPreferencesArgs.
VideoParams params(320, 240, core::PixelFormat::F32, 4);
TexturePtr source = CreateSolidTexture(params, 0x80);
TexturePtr guide = CreateSolidTexture(params, 0x40);
TexturePtr guide = CreateSolidTexture(params, 0x40);
ASSERT_NE(source, nullptr);
ASSERT_NE(guide, nullptr);
NodeValueRow row;
row.insert(QString::fromStdString(kOfxImageEffectSimpleSourceClipName),
NodeValue(NodeValue::kTexture, source));
row.insert(QStringLiteral("Guide"),
NodeValue(NodeValue::kTexture, guide));
bool result = RenderPlugin("net.sf.cimg.CImgBilateralGuided", params, row, true);
EXPECT_TRUE(result) << "CImgBilateralGuided plugin should produce output with both Source and Guide connected";
row.insert(QStringLiteral("Guide"), NodeValue(NodeValue::kTexture, guide));
bool result =
RenderPlugin("net.sf.cimg.CImgBilateralGuided", params, row, true);
EXPECT_TRUE(result)
<< "CImgBilateralGuided plugin should produce output with both Source and Guide connected";
}
} // namespace test