Skip to content

Commit 0d4ea7f

Browse files
authored
Merge pull request #244 from OpenShot/hardware-improvements
Adding new CheckPixel method to validate certain colors
2 parents 85d6ac6 + 30e546f commit 0d4ea7f

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

include/Frame.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ namespace openshot
249249
/// Get pixel data (for only a single scan-line)
250250
const unsigned char* GetPixels(int row);
251251

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, int threshold);
254+
252255
/// Get height of image
253256
int GetHeight();
254257

src/FFmpegReader.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -934,9 +934,7 @@ std::shared_ptr<Frame> FFmpegReader::ReadStream(int64_t requested_frame) {
934934
// down processing considerably, but might be more stable on some systems.
935935
#pragma omp taskwait
936936
}
937-
} else {
938-
RemoveAVFrame(pFrame);
939-
}
937+
}
940938

941939
}
942940
// Audio packet

src/Frame.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,28 @@ const unsigned char* Frame::GetPixels(int row)
480480
return image->scanLine(row);
481481
}
482482

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, 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) ) {
488+
// invalid row / col
489+
return false;
490+
}
491+
// Check pixel color
492+
const unsigned char* pixels = GetPixels(row);
493+
if (pixels[col_pos + 0] >= (red - threshold) && pixels[col_pos + 0] <= (red + threshold) &&
494+
pixels[col_pos + 1] >= (green - threshold) && pixels[col_pos + 1] <= (green + threshold) &&
495+
pixels[col_pos + 2] >= (blue - threshold) && pixels[col_pos + 2] <= (blue + threshold) &&
496+
pixels[col_pos + 3] >= (alpha - threshold) && pixels[col_pos + 3] <= (alpha + threshold)) {
497+
// Pixel color matches successfully
498+
return true;
499+
} else {
500+
// Pixel color does not match
501+
return false;
502+
}
503+
}
504+
483505
// Set Pixel Aspect Ratio
484506
void Frame::SetPixelRatio(int num, int den)
485507
{

src/examples/Example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ int main(int argc, char* argv[]) {
3838

3939
Settings *s = Settings::Instance();
4040
s->HARDWARE_DECODER = 2; // 1 VA-API, 2 NVDEC
41-
s->HW_DE_DEVICE_SET = 1;
41+
s->HW_DE_DEVICE_SET = 0;
4242

4343
FFmpegReader r9("/home/jonathan/Videos/sintel_trailer-720p.mp4");
4444
r9.Open();

tests/FFmpegReader_Tests.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ TEST(FFmpegReader_Check_Video_File)
100100
CHECK_EQUAL(0, (int)pixels[pixel_index + 2]);
101101
CHECK_EQUAL(255, (int)pixels[pixel_index + 3]);
102102

103+
// Check pixel function
104+
CHECK_EQUAL(true, f->CheckPixel(10, 112, 21, 191, 0, 255, 5));
105+
CHECK_EQUAL(false, f->CheckPixel(10, 112, 0, 0, 0, 0, 5));
106+
103107
// Get frame 1
104108
f = r.GetFrame(2);
105109

@@ -113,6 +117,10 @@ TEST(FFmpegReader_Check_Video_File)
113117
CHECK_EQUAL(188, (int)pixels[pixel_index + 2]);
114118
CHECK_EQUAL(255, (int)pixels[pixel_index + 3]);
115119

120+
// Check pixel function
121+
CHECK_EQUAL(true, f->CheckPixel(10, 112, 0, 96, 188, 255, 5));
122+
CHECK_EQUAL(false, f->CheckPixel(10, 112, 0, 0, 0, 0, 5));
123+
116124
// Close reader
117125
r.Close();
118126
}

0 commit comments

Comments
 (0)