Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/paint_vertex_color_ops.c
| Show First 20 Lines • Show All 366 Lines • ▼ Show 20 Lines | static int vertex_color_brightness_contrast_exec(bContext *C, wmOperator *op) | ||||
| Object *obact = CTX_data_active_object(C); | Object *obact = CTX_data_active_object(C); | ||||
| float gain, offset; | float gain, offset; | ||||
| { | { | ||||
| float brightness = RNA_float_get(op->ptr, "brightness"); | float brightness = RNA_float_get(op->ptr, "brightness"); | ||||
| float contrast = RNA_float_get(op->ptr, "contrast"); | float contrast = RNA_float_get(op->ptr, "contrast"); | ||||
| brightness /= 100.0f; | brightness /= 100.0f; | ||||
| float delta = contrast / 200.0f; | float delta = contrast / 200.0f; | ||||
| gain = 1.0f - delta * 2.0f; | |||||
| /* | /* | ||||
| * The algorithm is by Werner D. Streidt | * The algorithm is by Werner D. Streidt | ||||
| * (http://visca.com/ffactory/archives/5-99/msg00021.html) | * (http://visca.com/ffactory/archives/5-99/msg00021.html) | ||||
| * Extracted of OpenCV demhist.c | * Extracted of OpenCV demhist.c | ||||
| */ | */ | ||||
| if (contrast > 0) { | 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); | offset = gain * (brightness - delta); | ||||
| } | } | ||||
| else { | else { | ||||
| delta *= -1; | delta *= -1; | ||||
| offset = gain * (brightness + delta); | gain = max_ff(1.0f - delta * 2.0f, 0.0f); | ||||
| offset = gain * brightness + delta; | |||||
| } | } | ||||
| } | } | ||||
| const struct VPaintTx_BrightContrastData user_data = { | const struct VPaintTx_BrightContrastData user_data = { | ||||
| .gain = gain, | .gain = gain, | ||||
| .offset = offset, | .offset = offset, | ||||
| }; | }; | ||||
| ▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines | |||||