21
21
#include " Timeline.h"
22
22
23
23
24
- TEST_CASE ( " caption effect" , " [libopenshot][caption]" )
25
- {
24
+ // Function to check for non-black pixels in a given region of the frame
25
+ bool HasNonBlackPixelsInRegion (const std::shared_ptr<openshot::Frame>& frame, int start_row, int end_row, int start_col, int end_col) {
26
+ int frame_width = frame->GetWidth ();
27
+ int frame_height = frame->GetHeight ();
28
+
29
+ // Ensure the search region is within the frame bounds
30
+ if (start_row < 0 || end_row >= frame_height || start_col < 0 || end_col >= frame_width) {
31
+ throw std::out_of_range (" Search region is out of frame bounds" );
32
+ }
33
+
34
+ for (int row = start_row; row <= end_row; ++row) {
35
+ const unsigned char * pixels = frame->GetPixels (row);
36
+ if (!pixels) {
37
+ throw std::runtime_error (" Failed to get pixels for the row" );
38
+ }
39
+
40
+ for (int col = start_col; col <= end_col; ++col) {
41
+ int index = col * 4 ;
42
+ int R = pixels[index ];
43
+ int G = pixels[index + 1 ];
44
+ int B = pixels[index + 2 ];
45
+ if (!(R == 0 && G == 0 && B == 0 )) {
46
+ return true ; // Non-black pixel found
47
+ }
48
+ }
49
+ }
50
+ return false ; // No non-black pixel found
51
+ }
52
+
53
+ TEST_CASE (" caption effect" , " [libopenshot][caption]" ) {
26
54
// Check for QT Platform Environment variable - and ignore these tests if it's set to offscreen
27
55
if (std::getenv (" QT_QPA_PLATFORM" ) != nullptr ) {
28
56
std::string qt_platform_env = std::getenv (" QT_QPA_PLATFORM" );
@@ -32,14 +60,12 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
32
60
}
33
61
}
34
62
35
- int argc;
36
- char * argv[2 ] ;
63
+ int argc = 1 ;
64
+ char * argv[1 ] = {( char *) " " } ;
37
65
QGuiApplication::setAttribute (Qt::AA_EnableHighDpiScaling);
38
66
QApplication app (argc, argv);
39
- QApplication::processEvents ();
40
67
41
- int check_row = 0 ;
42
- int check_col = 0 ;
68
+ QApplication::processEvents ();
43
69
44
70
SECTION (" default constructor" ) {
45
71
@@ -76,23 +102,12 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
76
102
// Get frame
77
103
std::shared_ptr<openshot::Frame> f = clip1.GetFrame (10 );
78
104
79
- #ifdef _WIN32
80
- // Windows pixel location
81
- check_col = 625 ;
82
- check_row = 600 ;
83
- #else
84
- // Linux/Mac pixel location
85
- check_col = 251 ;
86
- check_row = 572 ;
87
- #endif
88
-
89
105
// Verify pixel values (black background pixels)
90
- const unsigned char * pixels = f->GetPixels (1 );
91
- CHECK ((int ) pixels[0 * 4 ] == 0 );
106
+ const unsigned char * pixels = f->GetPixels (1 );
107
+ CHECK ((int )pixels[0 * 4 ] == 0 );
92
108
93
- // Verify pixel values (white text pixels)
94
- pixels = f->GetPixels (check_row);
95
- CHECK ((int ) pixels[check_col * 4 ] == 255 );
109
+ // Check for non-black pixels in the region for white text
110
+ CHECK (HasNonBlackPixelsInRegion (f, 560 , 700 , 200 , 600 ));
96
111
97
112
// Create Timeline
98
113
openshot::Timeline t (1280 , 720 , openshot::Fraction (24 , 1 ), 44100 , 2 , openshot::LAYOUT_STEREO);
@@ -101,23 +116,12 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
101
116
// Get timeline frame
102
117
f = t.GetFrame (10 );
103
118
104
- #ifdef _WIN32
105
- // Windows pixel location
106
- check_col = 625 ;
107
- check_row = 600 ;
108
- #else
109
- // Linux/Mac pixel location
110
- check_col = 251 ;
111
- check_row = 572 ;
112
- #endif
113
-
114
119
// Verify pixel values (black background pixels)
115
120
pixels = f->GetPixels (1 );
116
- CHECK ((int ) pixels[0 * 4 ] == 0 );
121
+ CHECK ((int )pixels[0 * 4 ] == 0 );
117
122
118
- // Verify pixel values (white text pixels)
119
- pixels = f->GetPixels (check_row);
120
- CHECK ((int ) pixels[check_col * 4 ] == 255 );
123
+ // Check for non-black pixels in the region for white text
124
+ CHECK (HasNonBlackPixelsInRegion (f, 560 , 700 , 200 , 600 ));
121
125
122
126
// Close objects
123
127
t.Close ();
@@ -139,24 +143,14 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
139
143
140
144
// Get frame
141
145
std::shared_ptr<openshot::Frame> f = clip1.GetFrame (10 );
142
-
143
- #ifdef _WIN32
144
- // Windows pixel location
145
- check_col = 351 ;
146
- check_row = 391 ;
147
- #else
148
- // Linux/Mac pixel location
149
- check_col = 141 ;
150
- check_row = 378 ;
151
- #endif
146
+ f->Save (" /home/jonathan/test.png" , 1.0 , " PNG" , 100 );
152
147
153
148
// Verify pixel values (black background pixels)
154
- const unsigned char * pixels = f->GetPixels (1 );
155
- CHECK ((int ) pixels[0 * 4 ] == 0 );
149
+ const unsigned char * pixels = f->GetPixels (1 );
150
+ CHECK ((int )pixels[0 * 4 ] == 0 );
156
151
157
- // Verify pixel values (white text pixels)
158
- pixels = f->GetPixels (check_row);
159
- CHECK ((int ) pixels[check_col * 4 ] == 255 );
152
+ // Check for non-black pixels in the region for white text
153
+ CHECK (HasNonBlackPixelsInRegion (f, 350 , 479 , 150 , 500 ));
160
154
161
155
// Create Timeline
162
156
openshot::Timeline t (720 , 480 , openshot::Fraction (24 , 1 ), 44100 , 2 , openshot::LAYOUT_STEREO);
@@ -165,23 +159,12 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
165
159
// Get timeline frame
166
160
f = t.GetFrame (10 );
167
161
168
- #ifdef _WIN32
169
- // Windows pixel location
170
- check_col = 351 ;
171
- check_row = 391 ;
172
- #else
173
- // Linux/Mac pixel location
174
- check_col = 141 ;
175
- check_row = 377 ;
176
- #endif
177
-
178
162
// Verify pixel values (black background pixels)
179
163
pixels = f->GetPixels (1 );
180
- CHECK ((int ) pixels[0 * 4 ] == 0 );
164
+ CHECK ((int )pixels[0 * 4 ] == 0 );
181
165
182
- // Verify pixel values (white text pixels)
183
- pixels = f->GetPixels (check_row);
184
- CHECK ((int ) pixels[check_col * 4 ] == 255 );
166
+ // Check for non-black pixels in the region for white text
167
+ CHECK (HasNonBlackPixelsInRegion (f, 200 , 479 , 200 , 600 ));
185
168
186
169
// Close objects
187
170
t.Close ();
@@ -205,23 +188,12 @@ TEST_CASE( "caption effect", "[libopenshot][caption]" )
205
188
// Get frame
206
189
std::shared_ptr<openshot::Frame> f = clip1.GetFrame (11 );
207
190
208
- #ifdef _WIN32
209
- // Windows pixel location
210
- check_col = 633 ;
211
- check_row = 580 ;
212
- #else
213
- // Linux/Mac pixel location
214
- check_col = 284 ;
215
- check_row = 569 ;
216
- #endif
217
-
218
191
// Verify pixel values (black background pixels)
219
192
const unsigned char *pixels = f->GetPixels (1 );
220
193
CHECK ((int ) pixels[0 * 4 ] == 0 );
221
194
222
- // Verify pixel values (white text pixels)
223
- pixels = f->GetPixels (check_row);
224
- CHECK ((int ) pixels[check_col * 4 ] == 255 );
195
+ // Check for non-black pixels in the region for white text
196
+ CHECK (HasNonBlackPixelsInRegion (f, 560 , 700 , 200 , 600 ));
225
197
226
198
// Close objects
227
199
clip1.Close ();
0 commit comments