| 97 | } |
| 98 | |
| 99 | void Pixelate::ApplyCustomMaskBlend(std::shared_ptr<QImage> original_image, std::shared_ptr<QImage> effected_image, |
| 100 | std::shared_ptr<QImage> mask_image, int64_t frame_number) const { |
| 101 | (void) frame_number; |
| 102 | if (!original_image || !effected_image || !mask_image) |
| 103 | return; |
| 104 | if (original_image->size() != effected_image->size() || effected_image->size() != mask_image->size()) |
| 105 | return; |
| 106 | |
| 107 | unsigned char* original_pixels = reinterpret_cast<unsigned char*>(original_image->bits()); |
| 108 | unsigned char* effected_pixels = reinterpret_cast<unsigned char*>(effected_image->bits()); |
| 109 | unsigned char* mask_pixels = reinterpret_cast<unsigned char*>(mask_image->bits()); |
| 110 | const int pixel_count = effected_image->width() * effected_image->height(); |
| 111 | |
| 112 | #pragma omp parallel for schedule(static) |
| 113 | for (int i = 0; i < pixel_count; ++i) { |
| 114 | const int idx = i * 4; |
| 115 | float factor = static_cast<float>(qGray(mask_pixels[idx], mask_pixels[idx + 1], mask_pixels[idx + 2])) / 255.0f; |
| 116 | if (mask_invert) |
| 117 | factor = 1.0f - factor; |
| 118 | factor = factor * factor; |
| 119 | const float inverse = 1.0f - factor; |
| 120 | |
| 121 | effected_pixels[idx] = static_cast<unsigned char>( |
| 122 | (original_pixels[idx] * inverse) + (effected_pixels[idx] * factor)); |
| 123 | effected_pixels[idx + 1] = static_cast<unsigned char>( |
| 124 | (original_pixels[idx + 1] * inverse) + (effected_pixels[idx + 1] * factor)); |
| 125 | effected_pixels[idx + 2] = static_cast<unsigned char>( |
| 126 | (original_pixels[idx + 2] * inverse) + (effected_pixels[idx + 2] * factor)); |
| 127 | effected_pixels[idx + 3] = original_pixels[idx + 3]; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | // Generate JSON string of this object |
| 132 | std::string Pixelate::Json() const { |
nothing calls this directly
no outgoing calls
no test coverage detected