Making the Hue Correct Curves Wrap #117114

Merged
Omar Emara merged 31 commits from JonasDichelle/blender:hue-correct-bezier-wrap into main 2024-03-21 15:35:13 +01:00
2 changed files with 8 additions and 20 deletions
Showing only changes of commit d2bf20b47a - Show all commits

View File

@ -302,9 +302,6 @@ void BKE_curvemap_reset(CurveMap *cuma, const rctf *clipr, int preset, int slope
case CURVE_PRESET_MID8:
cuma->totpoint = 8;
break;
case CURVE_PRESET_MID9:
cuma->totpoint = 9;
break;
case CURVE_PRESET_ROUND:
cuma->totpoint = 4;
break;
@ -378,13 +375,6 @@ void BKE_curvemap_reset(CurveMap *cuma, const rctf *clipr, int preset, int slope
}
break;
}
case CURVE_PRESET_MID9: {
for (int i = 0; i < cuma->totpoint; i++) {
cuma->curve[i].x = i / (float(cuma->totpoint) - 1);
cuma->curve[i].y = 0.5;
}
break;
}
case CURVE_PRESET_ROUND:
cuma->curve[0].x = 0;
cuma->curve[0].y = 1;
@ -685,8 +675,7 @@ static void curvemap_make_table(const CurveMapping *cumap, CurveMap *cuma)
float table_range = cuma->maxtable - cuma->mintable;
/* Rely on Blender interpolation for bezier curves, support extra functionality here as well. */
JonasDichelle marked this conversation as resolved Outdated

Why allocate the extra bezier points as part of the array? Just create two stack variables for them, see below.

Why allocate the extra bezier points as part of the array? Just create two stack variables for them, see below.

I thought since we're already allocating an array of the same type to the heap we might aswell add the two new points. But you're right it's cleaner to just have them as seperate variables.

I thought since we're already allocating an array of the same type to the heap we might aswell add the two new points. But you're right it's cleaner to just have them as seperate variables.
int bezt_count = cuma->totpoint;
bezt = static_cast<BezTriple *>(MEM_callocN((bezt_count) * sizeof(BezTriple), "beztarr"));
bezt = static_cast<BezTriple *>(MEM_callocN(cuma->totpoint * sizeof(BezTriple), "beztarr"));
for (int a = 0; a < cuma->totpoint; a++) {
cuma->mintable = min_ff(cuma->mintable, cmp[a].x);
@ -751,7 +740,7 @@ static void curvemap_make_table(const CurveMapping *cumap, CurveMap *cuma)
/* first and last handle need correction, instead of pointing to center of next/prev,
* we let it point to the closest handle */
if (cuma->totpoint > 2 && not use_wrapping) {
if (cuma->totpoint > 2 && !use_wrapping) {
float hlen, nlen, vec[3];
if (bezt[0].h2 == HD_AUTO) {
@ -857,7 +846,7 @@ static void curvemap_make_table(const CurveMapping *cumap, CurveMap *cuma)
point += 2;
}
/* Check if we are on or outside the start or end point. */
if ((point == firstpoint || (point == lastpoint && cur_x >= point[0])) && not use_wrapping) {
if ((point == firstpoint || (point == lastpoint && cur_x >= point[0])) && !use_wrapping) {
if (compare_ff(cur_x, point[0], 1e-6f)) {
/* When on the point exactly, use the value directly to avoid precision
* issues with extrapolation of extreme slopes. */

View File

@ -102,12 +102,11 @@ typedef enum eCurveMappingPreset {
CURVE_PRESET_SMOOTH = 2,
CURVE_PRESET_MAX = 3,
JonasDichelle marked this conversation as resolved Outdated

Never change the values of DNA enums, if you want to add a new value, add it at the end.
That's because those values can be stored in files.

Anyway, as discussed, you can just change the MID9 to the one we want since it is only used by the hue correction curve.

Never change the values of DNA enums, if you want to add a new value, add it at the end. That's because those values can be stored in files. Anyway, as discussed, you can just change the MID9 to the one we want since it is only used by the hue correction curve.
CURVE_PRESET_MID8 = 4,
CURVE_PRESET_MID9 = 5,
CURVE_PRESET_ROUND = 6,
CURVE_PRESET_ROOT = 7,
CURVE_PRESET_GAUSS = 8,
CURVE_PRESET_BELL = 9,
CURVE_PRESET_CONSTANT_MEDIAN = 10,
CURVE_PRESET_ROUND = 5,
CURVE_PRESET_ROOT = 6,
CURVE_PRESET_GAUSS = 7,
CURVE_PRESET_BELL = 8,
CURVE_PRESET_CONSTANT_MEDIAN = 9,
} eCurveMappingPreset;
/** #CurveMapping.tone */