diff --git a/src/effects/Hue.cpp b/src/effects/Hue.cpp index 4083d035..d8b3a2a9 100644 --- a/src/effects/Hue.cpp +++ b/src/effects/Hue.cpp @@ -66,36 +66,35 @@ std::shared_ptr Hue::GetFrame(std::shared_ptr frame, int64_t frame // Get the frame's image std::shared_ptr frame_image = frame->GetImage(); + int pixel_count = frame_image->width() * frame_image->height(); + // Get the current hue percentage shift amount, and convert to degrees double degrees = 360.0 * hue.GetValue(frame_number); float cosA = cos(degrees*3.14159265f/180); float sinA = sin(degrees*3.14159265f/180); // Calculate a rotation matrix for the RGB colorspace (based on the current hue shift keyframe value) - float matrix[3][3] = {{cosA + (1.0f - cosA) / 3.0f, 1.0f/3.0f * (1.0f - cosA) - sqrtf(1.0f/3.0f) * sinA, 1.0f/3.0f * (1.0f - cosA) + sqrtf(1.0f/3.0f) * sinA}, - {1.0f/3.0f * (1.0f - cosA) + sqrtf(1.0f/3.0f) * sinA, cosA + 1.0f/3.0f*(1.0f - cosA), 1.0f/3.0f * (1.0f - cosA) - sqrtf(1.0f/3.0f) * sinA}, - {1.0f/3.0f * (1.0f - cosA) - sqrtf(1.0f/3.0f) * sinA, 1.0f/3.0f * (1.0f - cosA) + sqrtf(1.0f/3.0f) * sinA, cosA + 1.0f/3.0f * (1.0f - cosA)}}; + float matrix[3] = { + cosA + (1.0f - cosA) / 3.0f, + 1.0f/3.0f * (1.0f - cosA) - sqrtf(1.0f/3.0f) * sinA, + 1.0f/3.0f * (1.0f - cosA) + sqrtf(1.0f/3.0f) * sinA + }; // Loop through pixels unsigned char *pixels = (unsigned char *) frame_image->bits(); - for (int pixel = 0, byte_index=0; pixel < frame_image->width() * frame_image->height(); pixel++, byte_index+=4) + + #pragma omp parallel for shared (pixels) + for (int pixel = 0; pixel < pixel_count; ++pixel) { - // Get the RGB values from the pixel - int R = pixels[byte_index]; - int G = pixels[byte_index + 1]; - int B = pixels[byte_index + 2]; - int A = pixels[byte_index + 3]; + // Get the RGB values from the pixel (ignore the alpha channel) + int R = pixels[pixel * 4]; + int G = pixels[pixel * 4 + 1]; + int B = pixels[pixel * 4 + 2]; // Multiply each color by the hue rotation matrix - float rx = constrain(R * matrix[0][0] + G * matrix[0][1] + B * matrix[0][2]); - float gx = constrain(R * matrix[1][0] + G * matrix[1][1] + B * matrix[1][2]); - float bx = constrain(R * matrix[2][0] + G * matrix[2][1] + B * matrix[2][2]); - - // Set all pixels to new value - pixels[byte_index] = rx; - pixels[byte_index + 1] = gx; - pixels[byte_index + 2] = bx; - pixels[byte_index + 3] = A; // leave the alpha value alone + pixels[pixel * 4] = constrain(R * matrix[0] + G * matrix[1] + B * matrix[2]); + pixels[pixel * 4 + 1] = constrain(R * matrix[2] + G * matrix[0] + B * matrix[1]); + pixels[pixel * 4 + 2] = constrain(R * matrix[1] + G * matrix[2] + B * matrix[0]); } // return the modified frame