float intensity;
float balance[3];
float lcoeffs[3];
+ int alternate;
int depth;
AVFrame *frame = arg;
const int width = frame->width;
const int height = frame->height;
+ const float scale = 1.f / 255.f;
const float gc = s->lcoeffs[0];
const float bc = s->lcoeffs[1];
const float rc = s->lcoeffs[2];
const float intensity = s->intensity;
+ const float alternate = s->alternate ? 1.f : -1.f;
const float gintensity = intensity * s->balance[0];
const float bintensity = intensity * s->balance[1];
const float rintensity = intensity * s->balance[2];
+ const float sgintensity = alternate * FFSIGN(gintensity);
+ const float sbintensity = alternate * FFSIGN(bintensity);
+ const float srintensity = alternate * FFSIGN(rintensity);
const int slice_start = (height * jobnr) / nb_jobs;
const int slice_end = (height * (jobnr + 1)) / nb_jobs;
const int glinesize = frame->linesize[0];
for (int y = slice_start; y < slice_end; y++) {
for (int x = 0; x < width; x++) {
- float g = gptr[x] / 255.f;
- float b = bptr[x] / 255.f;
- float r = rptr[x] / 255.f;
+ float g = gptr[x] * scale;
+ float b = bptr[x] * scale;
+ float r = rptr[x] * scale;
float max_color = FFMAX3(r, g, b);
float min_color = FFMIN3(r, g, b);
float color_saturation = max_color - min_color;
float luma = g * gc + r * rc + b * bc;
- const float cg = 1.f + gintensity * (1.f - FFSIGN(gintensity) * color_saturation);
- const float cb = 1.f + bintensity * (1.f - FFSIGN(bintensity) * color_saturation);
- const float cr = 1.f + rintensity * (1.f - FFSIGN(rintensity) * color_saturation);
+ const float cg = 1.f + gintensity * (1.f - sgintensity * color_saturation);
+ const float cb = 1.f + bintensity * (1.f - sbintensity * color_saturation);
+ const float cr = 1.f + rintensity * (1.f - srintensity * color_saturation);
g = lerpf(luma, g, cg);
b = lerpf(luma, b, cb);
AVFrame *frame = arg;
const int depth = s->depth;
const float max = (1 << depth) - 1;
+ const float scale = 1.f / max;
const float gc = s->lcoeffs[0];
const float bc = s->lcoeffs[1];
const float rc = s->lcoeffs[2];
const int width = frame->width;
const int height = frame->height;
const float intensity = s->intensity;
+ const float alternate = s->alternate ? 1.f : -1.f;
const float gintensity = intensity * s->balance[0];
const float bintensity = intensity * s->balance[1];
const float rintensity = intensity * s->balance[2];
+ const float sgintensity = alternate * FFSIGN(gintensity);
+ const float sbintensity = alternate * FFSIGN(bintensity);
+ const float srintensity = alternate * FFSIGN(rintensity);
const int slice_start = (height * jobnr) / nb_jobs;
const int slice_end = (height * (jobnr + 1)) / nb_jobs;
const int glinesize = frame->linesize[0] / 2;
for (int y = slice_start; y < slice_end; y++) {
for (int x = 0; x < width; x++) {
- float g = gptr[x] / max;
- float b = bptr[x] / max;
- float r = rptr[x] / max;
+ float g = gptr[x] * scale;
+ float b = bptr[x] * scale;
+ float r = rptr[x] * scale;
float max_color = FFMAX3(r, g, b);
float min_color = FFMIN3(r, g, b);
float color_saturation = max_color - min_color;
float luma = g * gc + r * rc + b * bc;
- const float cg = 1.f + gintensity * (1.f - FFSIGN(gintensity) * color_saturation);
- const float cb = 1.f + bintensity * (1.f - FFSIGN(bintensity) * color_saturation);
- const float cr = 1.f + rintensity * (1.f - FFSIGN(rintensity) * color_saturation);
+ const float cg = 1.f + gintensity * (1.f - sgintensity * color_saturation);
+ const float cb = 1.f + bintensity * (1.f - sbintensity * color_saturation);
+ const float cr = 1.f + rintensity * (1.f - srintensity * color_saturation);
g = lerpf(luma, g, cg);
b = lerpf(luma, b, cb);
{ "rlum", "set the red luma coefficient", OFFSET(lcoeffs[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.072186}, 0, 1, VF },
{ "glum", "set the green luma coefficient", OFFSET(lcoeffs[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.715158}, 0, 1, VF },
{ "blum", "set the blue luma coefficient", OFFSET(lcoeffs[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.212656}, 0, 1, VF },
+ { "alternate", "use alternate colors", OFFSET(alternate), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, VF },
{ NULL }
};