Merge pull request #244 from OpenShot/hardware-improvements

Adding new CheckPixel method to validate certain colors
This commit is contained in:
Jonathan Thomas
2019-06-08 23:13:49 -05:00
committed by GitHub
5 changed files with 35 additions and 4 deletions

View File

@@ -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();

View File

@@ -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

View File

@@ -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)
{

View File

@@ -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();

View File

@@ -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();
}