| 480 | } |
| 481 | |
| 482 | void EffectBase::BlendWithMask(std::shared_ptr<QImage> original_image, std::shared_ptr<QImage> effected_image, |
| 483 | std::shared_ptr<QImage> mask_image) const { |
| 484 | if (!original_image || !effected_image || !mask_image) |
| 485 | return; |
| 486 | if (original_image->size() != effected_image->size() || effected_image->size() != mask_image->size()) |
| 487 | return; |
| 488 | |
| 489 | unsigned char* original_pixels = reinterpret_cast<unsigned char*>(original_image->bits()); |
| 490 | unsigned char* effected_pixels = reinterpret_cast<unsigned char*>(effected_image->bits()); |
| 491 | unsigned char* mask_pixels = reinterpret_cast<unsigned char*>(mask_image->bits()); |
| 492 | const int pixel_count = effected_image->width() * effected_image->height(); |
| 493 | |
| 494 | #pragma omp parallel for schedule(static) |
| 495 | for (int i = 0; i < pixel_count; ++i) { |
| 496 | const int idx = i * 4; |
| 497 | int gray = qGray(mask_pixels[idx], mask_pixels[idx + 1], mask_pixels[idx + 2]); |
| 498 | if (mask_invert) |
| 499 | gray = 255 - gray; |
| 500 | const float factor = static_cast<float>(gray) / 255.0f; |
| 501 | const float inverse = 1.0f - factor; |
| 502 | |
| 503 | effected_pixels[idx] = static_cast<unsigned char>( |
| 504 | (original_pixels[idx] * inverse) + (effected_pixels[idx] * factor)); |
| 505 | effected_pixels[idx + 1] = static_cast<unsigned char>( |
| 506 | (original_pixels[idx + 1] * inverse) + (effected_pixels[idx + 1] * factor)); |
| 507 | effected_pixels[idx + 2] = static_cast<unsigned char>( |
| 508 | (original_pixels[idx + 2] * inverse) + (effected_pixels[idx + 2] * factor)); |
| 509 | effected_pixels[idx + 3] = static_cast<unsigned char>( |
| 510 | (original_pixels[idx + 3] * inverse) + (effected_pixels[idx + 3] * factor)); |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | std::shared_ptr<openshot::Frame> EffectBase::ProcessFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number) { |
| 515 | // Audio-only effects skip common mask handling. |
nothing calls this directly
no outgoing calls
no test coverage detected