28 #include "../../include/effects/ColorShift.h"
33 ColorShift::ColorShift() : red_x(-0.05), red_y(0.0), green_x(0.05), green_y(0.0), blue_x(0.0), blue_y(0.0), alpha_x(0.0), alpha_y(0.0) {
35 init_effect_details();
40 red_x(red_x), red_y(red_y), green_x(green_x), green_y(green_y), blue_x(blue_x), blue_y(blue_y), alpha_x(alpha_x), alpha_y(alpha_y)
43 init_effect_details();
47 void ColorShift::init_effect_details()
55 info.
description =
"Shift the colors of an image up, down, left, and right (with infinite wrapping).";
65 std::shared_ptr<QImage> frame_image = frame->GetImage();
66 unsigned char *pixels = (
unsigned char *) frame_image->bits();
69 int frame_image_width = frame_image->width();
70 int frame_image_height = frame_image->height();
75 int red_x_shift_limit = round(frame_image_width * fmod(abs(red_x_shift), 1.0));
77 int red_y_shift_limit = round(frame_image_height * fmod(abs(red_y_shift), 1.0));
80 int green_x_shift_limit = round(frame_image_width * fmod(abs(green_x_shift), 1.0));
82 int green_y_shift_limit = round(frame_image_height * fmod(abs(green_y_shift), 1.0));
85 int blue_x_shift_limit = round(frame_image_width * fmod(abs(blue_x_shift), 1.0));
87 int blue_y_shift_limit = round(frame_image_height * fmod(abs(blue_y_shift), 1.0));
90 int alpha_x_shift_limit = round(frame_image_width * fmod(abs(alpha_x_shift), 1.0));
92 int alpha_y_shift_limit = round(frame_image_height * fmod(abs(alpha_y_shift), 1.0));
96 unsigned char *temp_image =
new unsigned char[frame_image_width * frame_image_height * 4]();
97 memcpy(temp_image, pixels,
sizeof(
char) * frame_image_width * frame_image_height * 4);
100 int starting_row_index = 0;
109 int red_starting_row_index = 0;
110 int green_starting_row_index = 0;
111 int blue_starting_row_index = 0;
112 int alpha_starting_row_index = 0;
114 int red_pixel_offset = 0;
115 int green_pixel_offset = 0;
116 int blue_pixel_offset = 0;
117 int alpha_pixel_offset = 0;
120 for (
int row = 0; row < frame_image_height; row++) {
121 for (
int col = 0; col < frame_image_width; col++) {
123 starting_row_index = row * frame_image_width * 4;
124 byte_index = starting_row_index + (col * 4);
125 red_starting_row_index = starting_row_index;
126 green_starting_row_index = starting_row_index;
127 blue_starting_row_index = starting_row_index;
128 alpha_starting_row_index = starting_row_index;
131 red_pixel_offset = 0;
132 green_pixel_offset = 0;
133 blue_pixel_offset = 0;
134 alpha_pixel_offset = 0;
137 R = temp_image[byte_index];
138 G = temp_image[byte_index + 1];
139 B = temp_image[byte_index + 2];
140 A = temp_image[byte_index + 3];
143 if (red_x_shift > 0.0)
144 red_pixel_offset = (col + red_x_shift_limit) % frame_image_width;
145 if (red_x_shift < 0.0)
146 red_pixel_offset = (frame_image_width + col - red_x_shift_limit) % frame_image_width;
147 if (green_x_shift > 0.0)
148 green_pixel_offset = (col + green_x_shift_limit) % frame_image_width;
149 if (green_x_shift < 0.0)
150 green_pixel_offset = (frame_image_width + col - green_x_shift_limit) % frame_image_width;
151 if (blue_x_shift > 0.0)
152 blue_pixel_offset = (col + blue_x_shift_limit) % frame_image_width;
153 if (blue_x_shift < 0.0)
154 blue_pixel_offset = (frame_image_width + col - blue_x_shift_limit) % frame_image_width;
155 if (alpha_x_shift > 0.0)
156 alpha_pixel_offset = (col + alpha_x_shift_limit) % frame_image_width;
157 if (alpha_x_shift < 0.0)
158 alpha_pixel_offset = (frame_image_width + col - alpha_x_shift_limit) % frame_image_width;
161 if (red_y_shift > 0.0)
162 red_starting_row_index = ((row + red_y_shift_limit) % frame_image_height) * frame_image_width * 4;
163 if (red_y_shift < 0.0)
164 red_starting_row_index = ((frame_image_height + row - red_y_shift_limit) % frame_image_height) * frame_image_width * 4;
165 if (green_y_shift > 0.0)
166 green_starting_row_index = ((row + green_y_shift_limit) % frame_image_height) * frame_image_width * 4;
167 if (green_y_shift < 0.0)
168 green_starting_row_index = ((frame_image_height + row - green_y_shift_limit) % frame_image_height) * frame_image_width * 4;
169 if (blue_y_shift > 0.0)
170 blue_starting_row_index = ((row + blue_y_shift_limit) % frame_image_height) * frame_image_width * 4;
171 if (blue_y_shift < 0.0)
172 blue_starting_row_index = ((frame_image_height + row - blue_y_shift_limit) % frame_image_height) * frame_image_width * 4;
173 if (alpha_y_shift > 0.0)
174 alpha_starting_row_index = ((row + alpha_y_shift_limit) % frame_image_height) * frame_image_width * 4;
175 if (alpha_y_shift < 0.0)
176 alpha_starting_row_index = ((frame_image_height + row - alpha_y_shift_limit) % frame_image_height) * frame_image_width * 4;
179 pixels[red_starting_row_index + 0 + (red_pixel_offset * 4)] = R;
180 pixels[green_starting_row_index + 1 + (green_pixel_offset * 4)] = G;
181 pixels[blue_starting_row_index + 2 + (blue_pixel_offset * 4)] = B;
182 pixels[alpha_starting_row_index + 3 + (alpha_pixel_offset * 4)] = A;
225 bool success = reader.parse( value, root );
228 throw InvalidJSON(
"JSON could not be parsed (or is invalid)",
"");
238 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)",
"");
249 if (!root[
"red_x"].isNull())
251 if (!root[
"red_y"].isNull())
253 if (!root[
"green_x"].isNull())
255 if (!root[
"green_y"].isNull())
257 if (!root[
"blue_x"].isNull())
259 if (!root[
"blue_y"].isNull())
261 if (!root[
"alpha_x"].isNull())
263 if (!root[
"alpha_y"].isNull())
272 root[
"id"] =
add_property_json(
"ID", 0.0,
"string",
Id(), NULL, -1, -1,
true, requested_frame);
273 root[
"position"] =
add_property_json(
"Position", Position(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
274 root[
"layer"] =
add_property_json(
"Track", Layer(),
"int",
"", NULL, 0, 20,
false, requested_frame);
275 root[
"start"] =
add_property_json(
"Start", Start(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
276 root[
"end"] =
add_property_json(
"End", End(),
"float",
"", NULL, 0, 1000 * 60 * 30,
false, requested_frame);
277 root[
"duration"] =
add_property_json(
"Duration", Duration(),
"float",
"", NULL, 0, 1000 * 60 * 30,
true, requested_frame);
290 return root.toStyledString();