BrightContrast not working correctly with negative contrast

followup to rB8dd95abb2ff9 (which fixed this for the Compositor node),
turns out this was also wrong for the VSE modifier and in vertex color
operator.

- also adjust min/max for VSE modifier
- also guard against division by zero

Reviewers: brecht

Maniphest Tasks: T67808

Differential Revision: https://developer.blender.org/D5398
This commit is contained in:
2019-08-01 18:17:56 +02:00
parent 31da3936b4
commit b54528fa1e
4 changed files with 12 additions and 10 deletions

View File

@@ -545,20 +545,20 @@ static void brightcontrast_apply_threaded(int width,
float brightness = data->bright / 100.0f;
float contrast = data->contrast;
float delta = contrast / 200.0f;
a = 1.0f - delta * 2.0f;
/*
* The algorithm is by Werner D. Streidt
* (http://visca.com/ffactory/archives/5-99/msg00021.html)
* Extracted of OpenCV demhist.c
*/
if (contrast > 0) {
a = 1.0f / a;
a = 1.0f - delta * 2.0f;
a = 1.0f / max_ff(a, FLT_EPSILON);
b = a * (brightness - delta);
}
else {
delta *= -1;
b = a * (brightness + delta);
a = max_ff(1.0f - delta * 2.0f, 0.0f);
b = a * brightness + delta;
}
for (y = 0; y < height; y++) {

View File

@@ -62,12 +62,13 @@ void BrightnessOperation::executePixelSampled(float output[4],
* Extracted of OpenCV demhist.c
*/
if (contrast > 0) {
a = 1.0f / (1.0f - delta * 2.0f);
a = 1.0f - delta * 2.0f;
a = 1.0f / max_ff(a, FLT_EPSILON);
b = a * (brightness - delta);
}
else {
delta *= -1;
a = 1.0f - delta * 2.0f;
a = max_ff(1.0f - delta * 2.0f, 0.0f);
b = a * brightness + delta;
}
if (this->m_use_premultiply) {

View File

@@ -372,19 +372,20 @@ static int vertex_color_brightness_contrast_exec(bContext *C, wmOperator *op)
float contrast = RNA_float_get(op->ptr, "contrast");
brightness /= 100.0f;
float delta = contrast / 200.0f;
gain = 1.0f - delta * 2.0f;
/*
* The algorithm is by Werner D. Streidt
* (http://visca.com/ffactory/archives/5-99/msg00021.html)
* Extracted of OpenCV demhist.c
*/
if (contrast > 0) {
gain = 1.0f / ((gain != 0.0f) ? gain : FLT_EPSILON);
gain = 1.0f - delta * 2.0f;
gain = 1.0f / max_ff(gain, FLT_EPSILON);
offset = gain * (brightness - delta);
}
else {
delta *= -1;
offset = gain * (brightness + delta);
gain = max_ff(1.0f - delta * 2.0f, 0.0f);
offset = gain * brightness + delta;
}
}

View File

@@ -3066,7 +3066,7 @@ static void rna_def_brightcontrast_modifier(BlenderRNA *brna)
prop = RNA_def_property(srna, "contrast", PROP_FLOAT, PROP_UNSIGNED);
RNA_def_property_float_sdna(prop, NULL, "contrast");
RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
RNA_def_property_range(prop, -100.0f, 100.0f);
RNA_def_property_ui_text(prop, "Contrast", "Adjust the difference in luminosity between pixels");
RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SequenceModifier_update");
}