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> ColorShift::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 | unsigned char *pixels = (unsigned char *) frame_image->bits(); |
| 53 | |
| 54 | // Get image size |
| 55 | int frame_image_width = frame_image->width(); |
| 56 | int frame_image_height = frame_image->height(); |
| 57 | |
| 58 | // Get the current shift amount, and clamp to range (-1 to 1 range) |
| 59 | // Red Keyframes |
| 60 | float red_x_shift = red_x.GetValue(frame_number); |
| 61 | int red_x_shift_limit = round(frame_image_width * fmod(fabs(red_x_shift), 1.0)); |
| 62 | float red_y_shift = red_y.GetValue(frame_number); |
| 63 | int red_y_shift_limit = round(frame_image_height * fmod(fabs(red_y_shift), 1.0)); |
| 64 | // Green Keyframes |
| 65 | float green_x_shift = green_x.GetValue(frame_number); |
| 66 | int green_x_shift_limit = round(frame_image_width * fmod(fabs(green_x_shift), 1.0)); |
| 67 | float green_y_shift = green_y.GetValue(frame_number); |
| 68 | int green_y_shift_limit = round(frame_image_height * fmod(fabs(green_y_shift), 1.0)); |
| 69 | // Blue Keyframes |
| 70 | float blue_x_shift = blue_x.GetValue(frame_number); |
| 71 | int blue_x_shift_limit = round(frame_image_width * fmod(fabs(blue_x_shift), 1.0)); |
| 72 | float blue_y_shift = blue_y.GetValue(frame_number); |
| 73 | int blue_y_shift_limit = round(frame_image_height * fmod(fabs(blue_y_shift), 1.0)); |
| 74 | // Alpha Keyframes |
| 75 | float alpha_x_shift = alpha_x.GetValue(frame_number); |
| 76 | int alpha_x_shift_limit = round(frame_image_width * fmod(fabs(alpha_x_shift), 1.0)); |
| 77 | float alpha_y_shift = alpha_y.GetValue(frame_number); |
| 78 | int alpha_y_shift_limit = round(frame_image_height * fmod(fabs(alpha_y_shift), 1.0)); |
| 79 | |
| 80 | // Make temp copy of pixels |
| 81 | unsigned char *temp_image = new unsigned char[frame_image_width * frame_image_height * 4](); |
| 82 | memcpy(temp_image, pixels, sizeof(char) * frame_image_width * frame_image_height * 4); |
| 83 | |
| 84 | // Init position of current row and pixel |
| 85 | int starting_row_index = 0; |
| 86 | int byte_index = 0; |
| 87 | |
| 88 | // Init RGBA values |
| 89 | unsigned char R = 0; |
| 90 | unsigned char G = 0; |
| 91 | unsigned char B = 0; |
| 92 | unsigned char A = 0; |
| 93 | |
| 94 | int red_starting_row_index = 0; |
| 95 | int green_starting_row_index = 0; |
| 96 | int blue_starting_row_index = 0; |
| 97 | int alpha_starting_row_index = 0; |
| 98 | |
| 99 | int red_pixel_offset = 0; |
| 100 | int green_pixel_offset = 0; |
| 101 | int blue_pixel_offset = 0; |
| 102 | int alpha_pixel_offset = 0; |
| 103 | |
| 104 | // Loop through rows of pixels |
| 105 | for (int row = 0; row < frame_image_height; row++) { |