File: AnalogTape.cpp

package info (click to toggle)
libopenshot 0.5.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,228 kB
  • sloc: cpp: 32,692; python: 92; sh: 77; makefile: 21; ruby: 5
file content (90 lines) | stat: -rw-r--r-- 2,487 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
 * @file
 * @brief Unit tests for AnalogTape effect
 * @author Jonathan Thomas <jonathan@openshot.org>
 *
 * @ref License
 */

// Copyright (c) 2008-2025 OpenShot Studios, LLC
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include <QColor>
#include <QImage>
#include <memory>

#include "Frame.h"
#include "effects/AnalogTape.h"
#include "openshot_catch.h"

using namespace openshot;

// Fixed helper ensures Frame invariants are respected (size/format/flags)
static std::shared_ptr<Frame> makeGrayFrame(int w = 64, int h = 64) {
	auto f = std::make_shared<Frame>(1, w, h, "#000000", 0, 2);

	// Use premultiplied format to match Frame::AddImage expectations
	auto img = std::make_shared<QImage>(w, h, QImage::Format_RGBA8888_Premultiplied);
	img->fill(QColor(100, 100, 100, 255));

	// Route through AddImage so width/height/has_image_data are set correctly
	f->AddImage(img);
	return f;
}

TEST_CASE("AnalogTape modifies frame", "[effect][analogtape]") {
	AnalogTape eff;
	eff.Id("analogtape-test-seed");
	eff.seed_offset = 1234;
	auto frame = makeGrayFrame();
	QColor before = frame->GetImage()->pixelColor(2, 2);
	auto out = eff.GetFrame(frame, 1);
	QColor after = out->GetImage()->pixelColor(2, 2);
	CHECK(after != before);
}

TEST_CASE("AnalogTape deterministic per id", "[effect][analogtape]") {
	AnalogTape e1;
	e1.Id("same");
	AnalogTape e2;
	e2.Id("same");
	auto f1 = makeGrayFrame();
	auto f2 = makeGrayFrame();
	auto o1 = e1.GetFrame(f1, 1);
	auto o2 = e2.GetFrame(f2, 1);
	QColor c1 = o1->GetImage()->pixelColor(1, 1);
	QColor c2 = o2->GetImage()->pixelColor(1, 1);
	CHECK(c1 == c2);
}

TEST_CASE("AnalogTape seed offset alters output", "[effect][analogtape]") {
	AnalogTape e1;
	e1.Id("seed");
	e1.seed_offset = 0;
	AnalogTape e2;
	e2.Id("seed");
	e2.seed_offset = 5;
	auto f1 = makeGrayFrame();
	auto f2 = makeGrayFrame();
	auto o1 = e1.GetFrame(f1, 1);
	auto o2 = e2.GetFrame(f2, 1);
	QColor c1 = o1->GetImage()->pixelColor(1, 1);
	QColor c2 = o2->GetImage()->pixelColor(1, 1);
	CHECK(c1 != c2);
}

TEST_CASE("AnalogTape stripe lifts bottom", "[effect][analogtape]") {
	AnalogTape e;
	e.tracking = Keyframe(0.0);
	e.bleed = Keyframe(0.0);
	e.softness = Keyframe(0.0);
	e.noise = Keyframe(0.0);
	e.stripe = Keyframe(1.0);
	e.staticBands = Keyframe(0.0);
	auto frame = makeGrayFrame(20, 20);
	auto out = e.GetFrame(frame, 1);
	QColor top = out->GetImage()->pixelColor(10, 0);
	QColor bottom = out->GetImage()->pixelColor(10, 19);
	CHECK(bottom.red() > top.red());
}