This method is required for all derived classes of EffectBase, and returns a modified openshot::Frame object
| 46 | // This method is required for all derived classes of EffectBase, and returns a |
| 47 | // modified openshot::Frame object |
| 48 | std::shared_ptr<openshot::Frame> Bars::GetFrame(std::shared_ptr<openshot::Frame> frame, int64_t frame_number) |
| 49 | { |
| 50 | // Get the frame's image |
| 51 | std::shared_ptr<QImage> frame_image = frame->GetImage(); |
| 52 | |
| 53 | // Get bar color (and create small color image) |
| 54 | auto tempColor = std::make_shared<QImage>( |
| 55 | frame_image->width(), 1, QImage::Format_RGBA8888_Premultiplied); |
| 56 | tempColor->fill(QColor(QString::fromStdString(color.GetColorHex(frame_number)))); |
| 57 | |
| 58 | // Get current keyframe values |
| 59 | double left_value = left.GetValue(frame_number); |
| 60 | double top_value = top.GetValue(frame_number); |
| 61 | double right_value = right.GetValue(frame_number); |
| 62 | double bottom_value = bottom.GetValue(frame_number); |
| 63 | |
| 64 | // Get pixel array pointer |
| 65 | unsigned char *pixels = (unsigned char *) frame_image->bits(); |
| 66 | unsigned char *color_pixels = (unsigned char *) tempColor->bits(); |
| 67 | |
| 68 | // Get pixels sizes of all bars |
| 69 | int top_bar_height = top_value * frame_image->height(); |
| 70 | int bottom_bar_height = bottom_value * frame_image->height(); |
| 71 | int left_bar_width = left_value * frame_image->width(); |
| 72 | int right_bar_width = right_value * frame_image->width(); |
| 73 | |
| 74 | // Loop through rows |
| 75 | for (int row = 0; row < frame_image->height(); row++) { |
| 76 | |
| 77 | // Top & Bottom Bar |
| 78 | if ((top_bar_height > 0.0 && row <= top_bar_height) || (bottom_bar_height > 0.0 && row >= frame_image->height() - bottom_bar_height)) { |
| 79 | memcpy(&pixels[row * frame_image->width() * 4], color_pixels, sizeof(char) * frame_image->width() * 4); |
| 80 | } else { |
| 81 | // Left Bar |
| 82 | if (left_bar_width > 0.0) { |
| 83 | memcpy(&pixels[row * frame_image->width() * 4], color_pixels, sizeof(char) * left_bar_width * 4); |
| 84 | } |
| 85 | |
| 86 | // Right Bar |
| 87 | if (right_bar_width > 0.0) { |
| 88 | memcpy(&pixels[((row * frame_image->width()) + (frame_image->width() - right_bar_width)) * 4], color_pixels, sizeof(char) * right_bar_width * 4); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // Cleanup colors and arrays |
| 94 | tempColor.reset(); |
| 95 | |
| 96 | // return the modified frame |
| 97 | return frame; |
| 98 | } |
| 99 | |
| 100 | // Generate JSON string of this object |
| 101 | std::string Bars::Json() const { |
nothing calls this directly
no test coverage detected