We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 2be5e5e + 722d672 commit 30e546fCopy full SHA for 30e546f
include/Frame.h
@@ -250,7 +250,7 @@ namespace openshot
250
const unsigned char* GetPixels(int row);
251
252
/// Check a specific pixel color value (returns True/False)
253
- bool CheckPixel(int row, int col, int red, int green, int blue, int alpha);
+ bool CheckPixel(int row, int col, int red, int green, int blue, int alpha, int threshold);
254
255
/// Get height of image
256
int GetHeight();
src/Frame.cpp
@@ -481,7 +481,7 @@ const unsigned char* Frame::GetPixels(int row)
481
}
482
483
// Check a specific pixel color value (returns True/False)
484
-bool Frame::CheckPixel(int row, int col, int red, int green, int blue, int alpha) {
+bool Frame::CheckPixel(int row, int col, int red, int green, int blue, int alpha, int threshold) {
485
int col_pos = col * 4; // Find column array position
486
if (!image || row < 0 || row >= (height - 1) ||
487
col_pos < 0 || col_pos >= (width - 1) ) {
@@ -490,10 +490,10 @@ bool Frame::CheckPixel(int row, int col, int red, int green, int blue, int alpha
490
491
// Check pixel color
492
const unsigned char* pixels = GetPixels(row);
493
- if (pixels[col_pos + 0] == red &&
494
- pixels[col_pos + 1] == green &&
495
- pixels[col_pos + 2] == blue &&
496
- pixels[col_pos + 3] == alpha) {
+ if (pixels[col_pos + 0] >= (red - threshold) && pixels[col_pos + 0] <= (red + threshold) &&
+ pixels[col_pos + 1] >= (green - threshold) && pixels[col_pos + 1] <= (green + threshold) &&
+ pixels[col_pos + 2] >= (blue - threshold) && pixels[col_pos + 2] <= (blue + threshold) &&
+ pixels[col_pos + 3] >= (alpha - threshold) && pixels[col_pos + 3] <= (alpha + threshold)) {
497
// Pixel color matches successfully
498
return true;
499
} else {
tests/FFmpegReader_Tests.cpp
@@ -101,8 +101,8 @@ TEST(FFmpegReader_Check_Video_File)
101
CHECK_EQUAL(255, (int)pixels[pixel_index + 3]);
102
103
// Check pixel function
104
- CHECK_EQUAL(true, f->CheckPixel(10, 112, 21, 191, 0, 255));
105
- CHECK_EQUAL(false, f->CheckPixel(10, 112, 0, 0, 0, 0));
+ CHECK_EQUAL(true, f->CheckPixel(10, 112, 21, 191, 0, 255, 5));
+ CHECK_EQUAL(false, f->CheckPixel(10, 112, 0, 0, 0, 0, 5));
106
107
// Get frame 1
108
f = r.GetFrame(2);
@@ -118,8 +118,8 @@ TEST(FFmpegReader_Check_Video_File)
118
119
120
121
- CHECK_EQUAL(true, f->CheckPixel(10, 112, 0, 96, 188, 255));
122
+ CHECK_EQUAL(true, f->CheckPixel(10, 112, 0, 96, 188, 255, 5));
123
124
// Close reader
125
r.Close();
0 commit comments