@@ -73,11 +73,6 @@ typedef struct dt_iop_basecurve_params_t
7373 dt_iop_rgb_norms_t preserve_colors ; /* $DEFAULT: DT_RGB_NORM_LUMINANCE $DESCRIPTION: "preserve colors" */
7474} dt_iop_basecurve_params_t ;
7575
76- static inline int _basecurve_nodes (const int nodes )
77- {
78- return CLAMP (nodes , 0 , MAXNODES );
79- }
80-
8176int legacy_params (dt_iop_module_t * self ,
8277 const void * const old_params ,
8378 const int old_version ,
@@ -1414,16 +1409,15 @@ void commit_params(dt_iop_module_t *self,
14141409 d -> preserve_colors = p -> preserve_colors ;
14151410
14161411 const int ch = 0 ;
1417- const int nodes = _basecurve_nodes (p -> basecurve_nodes [ch ]);
14181412 // take care of possible change of curve type or number of nodes (not yet implemented in UI)
1419- if (d -> basecurve_type != p -> basecurve_type [ch ] || d -> basecurve_nodes != nodes )
1413+ if (d -> basecurve_type != p -> basecurve_type [ch ] || d -> basecurve_nodes != p -> basecurve_nodes [ ch ] )
14201414 {
14211415 if (d -> curve ) // catch initial init_pipe case
14221416 dt_draw_curve_destroy (d -> curve );
14231417 d -> curve = dt_draw_curve_new (0.0 , 1.0 , p -> basecurve_type [ch ]);
1424- d -> basecurve_nodes = nodes ;
1418+ d -> basecurve_nodes = p -> basecurve_nodes [ ch ] ;
14251419 d -> basecurve_type = p -> basecurve_type [ch ];
1426- for (int k = 0 ; k < nodes ; k ++ )
1420+ for (int k = 0 ; k < p -> basecurve_nodes [ ch ] ; k ++ )
14271421 {
14281422 // printf("p->basecurve[%i][%i].x = %f;\n", ch, k, p->basecurve[ch][k].x);
14291423 // printf("p->basecurve[%i][%i].y = %f;\n", ch, k, p->basecurve[ch][k].y);
@@ -1432,13 +1426,13 @@ void commit_params(dt_iop_module_t *self,
14321426 }
14331427 else
14341428 {
1435- for (int k = 0 ; k < nodes ; k ++ )
1429+ for (int k = 0 ; k < p -> basecurve_nodes [ ch ] ; k ++ )
14361430 dt_draw_curve_set_point (d -> curve , k , p -> basecurve [ch ][k ].x , p -> basecurve [ch ][k ].y );
14371431 }
14381432 dt_draw_curve_calc_values (d -> curve , 0.0f , 1.0f , 0x10000 , NULL , d -> table );
14391433
14401434 // now the extrapolation stuff:
1441- const float xm = p -> basecurve [0 ][MAX ( 1 , nodes ) - 1 ].x ;
1435+ const float xm = p -> basecurve [0 ][p -> basecurve_nodes [ 0 ] - 1 ].x ;
14421436 const float x [4 ] = { 0.7f * xm , 0.8f * xm , 0.9f * xm , 1.0f * xm };
14431437 const float y [4 ] = { d -> table [CLAMP ((int )(x [0 ] * 0x10000ul ), 0 , 0xffff )],
14441438 d -> table [CLAMP ((int )(x [1 ] * 0x10000ul ), 0 , 0xffff )],
@@ -1566,27 +1560,27 @@ static gboolean dt_iop_basecurve_draw(GtkWidget *widget, cairo_t *crf, dt_iop_mo
15661560 dt_iop_basecurve_gui_data_t * g = self -> gui_data ;
15671561 dt_iop_basecurve_params_t * p = self -> params ;
15681562
1569- const int nodes = _basecurve_nodes ( p -> basecurve_nodes [0 ]) ;
1563+ int nodes = p -> basecurve_nodes [0 ];
15701564 dt_iop_basecurve_node_t * basecurve = p -> basecurve [0 ];
1571- if (g -> minmax_curve_type != p -> basecurve_type [0 ] || g -> minmax_curve_nodes != nodes )
1565+ if (g -> minmax_curve_type != p -> basecurve_type [0 ] || g -> minmax_curve_nodes != p -> basecurve_nodes [ 0 ] )
15721566 {
15731567 dt_draw_curve_destroy (g -> minmax_curve );
15741568 g -> minmax_curve = dt_draw_curve_new (0.0 , 1.0 , p -> basecurve_type [0 ]);
1575- g -> minmax_curve_nodes = nodes ;
1569+ g -> minmax_curve_nodes = p -> basecurve_nodes [ 0 ] ;
15761570 g -> minmax_curve_type = p -> basecurve_type [0 ];
1577- for (int k = 0 ; k < nodes ; k ++ )
1571+ for (int k = 0 ; k < p -> basecurve_nodes [ 0 ] ; k ++ )
15781572 (void )dt_draw_curve_add_point (g -> minmax_curve , p -> basecurve [0 ][k ].x , p -> basecurve [0 ][k ].y );
15791573 }
15801574 else
15811575 {
1582- for (int k = 0 ; k < nodes ; k ++ )
1576+ for (int k = 0 ; k < p -> basecurve_nodes [ 0 ] ; k ++ )
15831577 dt_draw_curve_set_point (g -> minmax_curve , k , p -> basecurve [0 ][k ].x , p -> basecurve [0 ][k ].y );
15841578 }
15851579 dt_draw_curve_t * minmax_curve = g -> minmax_curve ;
15861580 dt_draw_curve_calc_values (minmax_curve , 0.0 , 1.0 , DT_IOP_TONECURVE_RES , g -> draw_xs , g -> draw_ys );
15871581
15881582 float unbounded_coeffs [3 ];
1589- const float xm = basecurve [MAX ( 1 , nodes ) - 1 ].x ;
1583+ const float xm = basecurve [nodes - 1 ].x ;
15901584 {
15911585 const float x [4 ] = { 0.7f * xm , 0.8f * xm , 0.9f * xm , 1.0f * xm };
15921586 const float y [4 ] = { g -> draw_ys [CLAMP ((int )(x [0 ] * DT_IOP_TONECURVE_RES ), 0 , DT_IOP_TONECURVE_RES - 1 )],
@@ -1620,7 +1614,7 @@ static gboolean dt_iop_basecurve_draw(GtkWidget *widget, cairo_t *crf, dt_iop_mo
16201614 cairo_fill (cr );
16211615
16221616 cairo_translate (cr , 0 , height );
1623- if (g -> selected >= 0 && g -> selected < nodes )
1617+ if (g -> selected >= 0 )
16241618 {
16251619 char text [30 ];
16261620 // draw information about current selected node
@@ -1676,7 +1670,7 @@ static gboolean dt_iop_basecurve_draw(GtkWidget *widget, cairo_t *crf, dt_iop_mo
16761670 // draw selected cursor
16771671 cairo_set_line_width (cr , DT_PIXEL_APPLY_DPI (1. ));
16781672
1679- if (g -> selected >= 0 && g -> selected < nodes )
1673+ if (g -> selected >= 0 )
16801674 {
16811675 cairo_set_source_rgb (cr , .9 , .9 , .9 );
16821676 const float x = to_log (basecurve [g -> selected ].x , g -> loglogscale ),
@@ -1750,10 +1744,10 @@ static void dt_iop_basecurve_sanity_check(dt_iop_module_t *self, GtkWidget *widg
17501744 dt_iop_basecurve_params_t * p = self -> params ;
17511745
17521746 int ch = 0 ;
1753- const int nodes = _basecurve_nodes ( p -> basecurve_nodes [ch ]) ;
1747+ int nodes = p -> basecurve_nodes [ch ];
17541748 dt_iop_basecurve_node_t * basecurve = p -> basecurve [ch ];
17551749
1756- if (g -> selected < 0 || g -> selected >= nodes || nodes <= 2 ) return ;
1750+ if (nodes <= 2 ) return ;
17571751
17581752 const float mx = basecurve [g -> selected ].x ;
17591753
@@ -1769,7 +1763,7 @@ static void dt_iop_basecurve_sanity_check(dt_iop_module_t *self, GtkWidget *widg
17691763 basecurve [k ].y = basecurve [k + 1 ].y ;
17701764 }
17711765 g -> selected = -2 ; // avoid re-insertion of that point immediately after this
1772- p -> basecurve_nodes [ch ] = nodes - 1 ;
1766+ p -> basecurve_nodes [ch ]-- ;
17731767 }
17741768}
17751769
@@ -1788,7 +1782,7 @@ static void dt_iop_basecurve_motion_notify(GtkEventControllerMotion *controller,
17881782 dt_iop_basecurve_gui_data_t * g = self -> gui_data ;
17891783 dt_iop_basecurve_params_t * p = self -> params ;
17901784 int ch = 0 ;
1791- int nodes = _basecurve_nodes ( p -> basecurve_nodes [ch ]) ;
1785+ int nodes = p -> basecurve_nodes [ch ];
17921786 dt_iop_basecurve_node_t * basecurve = p -> basecurve [ch ];
17931787
17941788 GtkAllocation allocation ;
@@ -1804,8 +1798,6 @@ static void dt_iop_basecurve_motion_notify(GtkEventControllerMotion *controller,
18041798 const float my = 1.0f - CLAMP (g -> mouse_y , 0 , height ) / (float )height ;
18051799 const float linx = to_lin (mx , g -> loglogscale ), liny = to_lin (my , g -> loglogscale );
18061800
1807- if (g -> selected >= nodes ) g -> selected = -1 ;
1808-
18091801 if (dt_key_modifier_state () & GDK_BUTTON1_MASK )
18101802 {
18111803 // got a vertex selected:
@@ -1825,7 +1817,6 @@ static void dt_iop_basecurve_motion_notify(GtkEventControllerMotion *controller,
18251817 else if (nodes < MAXNODES && g -> selected >= -1 )
18261818 {
18271819 // no vertex was close, create a new one!
1828- p -> basecurve_nodes [ch ] = nodes ;
18291820 g -> selected = _add_node (basecurve , & p -> basecurve_nodes [ch ], linx , liny );
18301821 dt_dev_add_history_item_target (darktable .develop , self , TRUE, widget );
18311822 }
@@ -1865,7 +1856,7 @@ static void dt_iop_basecurve_button_press(GtkGestureSingle *gesture,
18651856 dt_iop_basecurve_gui_data_t * g = self -> gui_data ;
18661857
18671858 int ch = 0 ;
1868- int nodes = _basecurve_nodes ( p -> basecurve_nodes [ch ]) ;
1859+ int nodes = p -> basecurve_nodes [ch ];
18691860 dt_iop_basecurve_node_t * basecurve = p -> basecurve [ch ];
18701861
18711862 if (gtk_gesture_single_get_current_button (gesture ) == GDK_BUTTON_PRIMARY )
@@ -1911,7 +1902,6 @@ static void dt_iop_basecurve_button_press(GtkGestureSingle *gesture,
19111902 if (curve_y >= 0.0 && curve_y <= 1.0 ) // never add something outside the viewport, you couldn't change it afterwards
19121903 {
19131904 // create a new node
1914- p -> basecurve_nodes [ch ] = nodes ;
19151905 selected = _add_node (basecurve , & p -> basecurve_nodes [ch ], linx , curve_y );
19161906
19171907 // maybe set the new one as being selected
@@ -1944,13 +1934,11 @@ static void dt_iop_basecurve_button_press(GtkGestureSingle *gesture,
19441934 gtk_widget_queue_draw (GTK_WIDGET (g -> area ));
19451935 }
19461936 }
1947- else if (gtk_gesture_single_get_current_button (gesture ) == GDK_BUTTON_SECONDARY
1948- && g -> selected >= 0 && g -> selected < nodes )
1937+ else if (gtk_gesture_single_get_current_button (gesture ) == GDK_BUTTON_SECONDARY && g -> selected >= 0 )
19491938 {
19501939 // consume the event so it does not bubble to the module body's
19511940 // right-click handler (which opens the presets menu)
19521941 dt_gui_claim (gesture );
1953- p -> basecurve_nodes [ch ] = nodes ;
19541942
19551943 if (g -> selected == 0 || g -> selected == nodes - 1 )
19561944 {
@@ -1968,7 +1956,7 @@ static void dt_iop_basecurve_button_press(GtkGestureSingle *gesture,
19681956 }
19691957 basecurve [nodes - 1 ].x = basecurve [nodes - 1 ].y = 0 ;
19701958 g -> selected = -2 ; // avoid re-insertion of that point immediately after this
1971- p -> basecurve_nodes [ch ] = nodes - 1 ;
1959+ p -> basecurve_nodes [ch ]-- ;
19721960 gtk_widget_queue_draw (GTK_WIDGET (g -> area ));
19731961 dt_dev_add_history_item_target (darktable .develop , self , TRUE, widget );
19741962 }
@@ -1984,8 +1972,6 @@ static gboolean _move_point_internal(dt_iop_module_t *self,
19841972 dt_iop_basecurve_gui_data_t * g = self -> gui_data ;
19851973
19861974 const int ch = 0 ;
1987- const int nodes = _basecurve_nodes (p -> basecurve_nodes [ch ]);
1988- if (g -> selected < 0 || g -> selected >= nodes ) return FALSE;
19891975 dt_iop_basecurve_node_t * basecurve = p -> basecurve [ch ];
19901976
19911977 const float multiplier = dt_accel_get_speed_multiplier (widget , state );
0 commit comments