This method is required for all derived classes of EffectBase, and returns a modified openshot::Frame object
| 47 | // This method is required for all derived classes of EffectBase, and returns a |
| 48 | // modified openshot::Frame object |
| 49 | std::shared_ptr<openshot::Frame> Deinterlace::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number) |
| 50 | { |
| 51 | // Get original size of frame's image |
| 52 | int original_width = frame->GetImage()->width(); |
| 53 | int original_height = frame->GetImage()->height(); |
| 54 | |
| 55 | // Access the current QImage and its raw pixel data |
| 56 | auto image = frame->GetImage(); |
| 57 | const unsigned char* pixels = image->bits(); |
| 58 | int line_bytes = image->bytesPerLine(); |
| 59 | |
| 60 | // Decide whether to copy even lines (start = 0) or odd lines (start = 1) |
| 61 | int start = isOdd ? 1 : 0; |
| 62 | |
| 63 | // Compute how many rows we will end up copying |
| 64 | // If start = 0, rows_to_copy = ceil(original_height / 2.0) |
| 65 | // If start = 1, rows_to_copy = floor(original_height / 2.0) |
| 66 | int rows_to_copy = (original_height - start + 1) / 2; |
| 67 | |
| 68 | // Create a new image with exactly 'rows_to_copy' scanlines |
| 69 | QImage deinterlaced_image( |
| 70 | original_width, |
| 71 | rows_to_copy, |
| 72 | QImage::Format_RGBA8888_Premultiplied |
| 73 | ); |
| 74 | unsigned char* deinterlaced_pixels = deinterlaced_image.bits(); |
| 75 | |
| 76 | // Copy every other row from the source into the new image |
| 77 | // Parallelize over 'i' so each thread writes to a distinct slice of memory |
| 78 | #pragma omp parallel for |
| 79 | for (int i = 0; i < rows_to_copy; i++) { |
| 80 | int row = start + 2 * i; |
| 81 | const unsigned char* src = pixels + (row * line_bytes); |
| 82 | unsigned char* dst = deinterlaced_pixels + (i * line_bytes); |
| 83 | memcpy(dst, src, line_bytes); |
| 84 | } |
| 85 | |
| 86 | // Resize deinterlaced image back to original size, and update frame's image |
| 87 | image = std::make_shared<QImage>(deinterlaced_image.scaled( |
| 88 | original_width, original_height, |
| 89 | Qt::IgnoreAspectRatio, Qt::FastTransformation)); |
| 90 | |
| 91 | // Update image on frame |
| 92 | frame->AddImage(image); |
| 93 | |
| 94 | // return the modified frame |
| 95 | return frame; |
| 96 | } |
| 97 | |
| 98 | // Generate JSON string of this object |
| 99 | std::string Deinterlace::Json() const { |