MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / HasNonBlackPixelsInRegion

Function HasNonBlackPixelsInRegion

tests/Caption.cpp:26–52  ·  view source on GitHub ↗

Function to check for non-black pixels in a given region of the frame

Source from the content-addressed store, hash-verified

24
25// Function to check for non-black pixels in a given region of the frame
26bool HasNonBlackPixelsInRegion(const std::shared_ptr<openshot::Frame>& frame, int start_row, int end_row, int start_col, int end_col) {
27 int frame_width = frame->GetWidth();
28 int frame_height = frame->GetHeight();
29
30 // Ensure the search region is within the frame bounds
31 if (start_row < 0 || end_row >= frame_height || start_col < 0 || end_col >= frame_width) {
32 throw std::out_of_range("Search region is out of frame bounds");
33 }
34
35 for (int row = start_row; row <= end_row; ++row) {
36 const unsigned char* pixels = frame->GetPixels(row);
37 if (!pixels) {
38 throw std::runtime_error("Failed to get pixels for the row");
39 }
40
41 for (int col = start_col; col <= end_col; ++col) {
42 int index = col * 4;
43 int R = pixels[index];
44 int G = pixels[index + 1];
45 int B = pixels[index + 2];
46 if (!(R == 0 && G == 0 && B == 0)) {
47 return true; // Non-black pixel found
48 }
49 }
50 }
51 return false; // No non-black pixel found
52}
53
54TEST_CASE("caption effect", "[libopenshot][caption]") {
55 // Check for QT Platform Environment variable - and ignore these tests if it's set to offscreen

Callers 1

Caption.cppFile · 0.85

Calls 3

GetWidthMethod · 0.80
GetHeightMethod · 0.80
GetPixelsMethod · 0.80

Tested by

no test coverage detected