You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Merge pull request #244 from OpenShot/hardware-improvements
Adding new CheckPixel method to validate certain colors
This commit is contained in:
@@ -249,6 +249,9 @@ namespace openshot
|
||||
/// Get pixel data (for only a single scan-line)
|
||||
const unsigned char* GetPixels(int row);
|
||||
|
||||
/// Check a specific pixel color value (returns True/False)
|
||||
bool CheckPixel(int row, int col, int red, int green, int blue, int alpha, int threshold);
|
||||
|
||||
/// Get height of image
|
||||
int GetHeight();
|
||||
|
||||
|
||||
@@ -934,9 +934,7 @@ std::shared_ptr<Frame> FFmpegReader::ReadStream(int64_t requested_frame) {
|
||||
// down processing considerably, but might be more stable on some systems.
|
||||
#pragma omp taskwait
|
||||
}
|
||||
} else {
|
||||
RemoveAVFrame(pFrame);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// Audio packet
|
||||
|
||||
@@ -480,6 +480,28 @@ const unsigned char* Frame::GetPixels(int row)
|
||||
return image->scanLine(row);
|
||||
}
|
||||
|
||||
// Check a specific pixel color value (returns True/False)
|
||||
bool Frame::CheckPixel(int row, int col, int red, int green, int blue, int alpha, int threshold) {
|
||||
int col_pos = col * 4; // Find column array position
|
||||
if (!image || row < 0 || row >= (height - 1) ||
|
||||
col_pos < 0 || col_pos >= (width - 1) ) {
|
||||
// invalid row / col
|
||||
return false;
|
||||
}
|
||||
// Check pixel color
|
||||
const unsigned char* pixels = GetPixels(row);
|
||||
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)) {
|
||||
// Pixel color matches successfully
|
||||
return true;
|
||||
} else {
|
||||
// Pixel color does not match
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Set Pixel Aspect Ratio
|
||||
void Frame::SetPixelRatio(int num, int den)
|
||||
{
|
||||
|
||||
@@ -38,7 +38,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
Settings *s = Settings::Instance();
|
||||
s->HARDWARE_DECODER = 2; // 1 VA-API, 2 NVDEC
|
||||
s->HW_DE_DEVICE_SET = 1;
|
||||
s->HW_DE_DEVICE_SET = 0;
|
||||
|
||||
FFmpegReader r9("/home/jonathan/Videos/sintel_trailer-720p.mp4");
|
||||
r9.Open();
|
||||
|
||||
@@ -100,6 +100,10 @@ TEST(FFmpegReader_Check_Video_File)
|
||||
CHECK_EQUAL(0, (int)pixels[pixel_index + 2]);
|
||||
CHECK_EQUAL(255, (int)pixels[pixel_index + 3]);
|
||||
|
||||
// Check pixel function
|
||||
CHECK_EQUAL(true, f->CheckPixel(10, 112, 21, 191, 0, 255, 5));
|
||||
CHECK_EQUAL(false, f->CheckPixel(10, 112, 0, 0, 0, 0, 5));
|
||||
|
||||
// Get frame 1
|
||||
f = r.GetFrame(2);
|
||||
|
||||
@@ -113,6 +117,10 @@ TEST(FFmpegReader_Check_Video_File)
|
||||
CHECK_EQUAL(188, (int)pixels[pixel_index + 2]);
|
||||
CHECK_EQUAL(255, (int)pixels[pixel_index + 3]);
|
||||
|
||||
// Check pixel function
|
||||
CHECK_EQUAL(true, f->CheckPixel(10, 112, 0, 96, 188, 255, 5));
|
||||
CHECK_EQUAL(false, f->CheckPixel(10, 112, 0, 0, 0, 0, 5));
|
||||
|
||||
// Close reader
|
||||
r.Close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user