diff --git a/rtengine/curves.cc b/rtengine/curves.cc index 942ecdbbf..4f97c1b60 100644 --- a/rtengine/curves.cc +++ b/rtengine/curves.cc @@ -51,7 +51,8 @@ Curve::Curve (const std::vector& p, int poly_pn) : x(NULL), y(NULL), ypp if (kind==Spline) spline_cubic_set (); else if (kind==NURBS && N > 2) - NURBS_set (); + NURBS_set (); + else kind=Linear; } else if (kind==Parametric) { if (p.size()!=8 && p.size()!=9) @@ -110,7 +111,7 @@ void Curve::NURBS_set () { std::vector sc_x(nbSubCurvesPoints); // X sub-curve points ( XP0,XP1,XP2, XP2,XP3,XP4, ...) std::vector sc_y(nbSubCurvesPoints); // Y sub-curve points ( YP0,YP1,YP2, YP2,YP3,YP4, ...) - std::vector sc_length(N-2); // Length of the subcurves + std::vector sc_length(N+2); // Length of the subcurves double total_length=0.; // Create the list of Bezier sub-curves @@ -159,24 +160,24 @@ void Curve::NURBS_set () { total_length += length; } - unsigned int total_points = 0; - for (unsigned int i=0; i < sc_x.size(); i+=3) { - total_points += (int)(((double)ppn+N-2) * sc_length[i/3] / total_length) + (i==0 ? 1 : 0) - 1; - } - poly_x.resize(total_points); - poly_y.resize(total_points); - + poly_x.clear(); + poly_y.clear(); + unsigned int sc_xsize=j-1; j = 0; // create the polyline with the number of points adapted to the X range of the sub-curve - for (unsigned int i=0; i < sc_x.size(); i+=3) { + for (unsigned int i=0; i < sc_xsize /*sc_x.size()*/; i+=3) { // TODO: Speeding-up the interface by caching the polyline, instead of rebuilding it at each action on sliders !!! - int nbr_points = (int)(((double)ppn+N-2) * sc_length[i/3] / total_length); - + int nbr_points = (int)(((double)(ppn+N-2) * sc_length[i/3] )/ total_length); + if (nbr_points<0){ + for(int it=0;it < sc_x.size(); it+=3) printf("sc_length[%d/3]=%f \n",it,sc_length[it/3]); + printf("NURBS: error detected!\n i=%d nbr_points=%d ppn=%d N=%d sc_length[i/3]=%f total_length=%f",i,nbr_points,ppn,N,sc_length[i/3],total_length); + exit(0); + } // increment along the curve, not along the X axis double increment = 1.0 / (double)(nbr_points-1); if (!i) { - poly_x[j ] = sc_x[i]; - poly_y[j++] = sc_y[i]; + poly_x.push_back( sc_x[i]); + poly_y.push_back(sc_y[i]); } for (k=1; k<(nbr_points-1); k++) { double t = k*increment; @@ -186,12 +187,12 @@ void Curve::NURBS_set () { double tr2t = tr*2*t; // adding a point to the polyline - poly_x[j ] = tr2*sc_x[i] + tr2t*sc_x[i+1] + t2*sc_x[i+2]; - poly_y[j++] = tr2*sc_y[i] + tr2t*sc_y[i+1] + t2*sc_y[i+2]; + poly_x.push_back( tr2*sc_x[i] + tr2t*sc_x[i+1] + t2*sc_x[i+2]); + poly_y.push_back( tr2*sc_y[i] + tr2t*sc_y[i+1] + t2*sc_y[i+2]); } // adding the last point of the sub-curve - poly_x[j ] = sc_x[i+2]; - poly_y[j++] = sc_y[i+2]; + poly_x.push_back( sc_x[i+2]); + poly_y.push_back(sc_y[i+2]); } } diff --git a/rtengine/curves.h b/rtengine/curves.h index e566383f6..e0bb94e2a 100644 --- a/rtengine/curves.h +++ b/rtengine/curves.h @@ -162,6 +162,6 @@ class Curve { double getVal (double x); void getVal (const std::vector& t, std::vector& res); }; -}; +} #endif diff --git a/rtgui/curveeditor.cc b/rtgui/curveeditor.cc index 395e965b3..8c5ec6d89 100644 --- a/rtgui/curveeditor.cc +++ b/rtgui/curveeditor.cc @@ -412,8 +412,12 @@ void CurveEditor::typeSelectionChanged () { void CurveEditor::curveChanged () { - if (cl) - cl->curveChanged (); + if (cl) { + if (cl->isMulti()) + cl->curveChanged (this); + else + cl->curveChanged (); + } } void CurveEditor::curveResetPressed () { diff --git a/rtgui/curvelistener.h b/rtgui/curvelistener.h index e07fed2d5..72980c5d2 100644 --- a/rtgui/curvelistener.h +++ b/rtgui/curvelistener.h @@ -19,10 +19,18 @@ #ifndef _CURVELISTENER_ #define _CURVELISTENER_ +class CurveEditor; + class CurveListener { + private: + bool multi; public: virtual void curveChanged () {} + virtual void curveChanged (CurveEditor* ce) {} + void setMulti(bool value) { multi = value; } + bool isMulti() { return multi; } + CurveListener() : multi(false) {} }; #endif diff --git a/rtgui/labcurve.cc b/rtgui/labcurve.cc index 842796794..66e6426d1 100644 --- a/rtgui/labcurve.cc +++ b/rtgui/labcurve.cc @@ -43,47 +43,50 @@ LCurve::LCurve () : ToolPanel(), brAdd(false), contrAdd(false) { //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - Gtk::HBox* abox = Gtk::manage (new Gtk::HBox ()); - abox->set_border_width (2); + Gtk::HBox* abox = Gtk::manage (new Gtk::HBox ()); + abox->set_border_width (2); - // brightness = Gtk::manage (new Adjuster (M("TP_LUMACURVE_BRIGHTNESS"), -100, 100, 0.01, 0)); - //contrast = Gtk::manage (new Adjuster (M("TP_LUMACURVE_CONTRAST"), -100, 100, 1, 0)); + // brightness = Gtk::manage (new Adjuster (M("TP_LUMACURVE_BRIGHTNESS"), -100, 100, 0.01, 0)); + //contrast = Gtk::manage (new Adjuster (M("TP_LUMACURVE_CONTRAST"), -100, 100, 1, 0)); brightness = Gtk::manage (new Adjuster (M("TP_LABCURVE_BRIGHTNESS"), -100, 100, 0.01, 0)); contrast = Gtk::manage (new Adjuster (M("TP_LABCURVE_CONTRAST"), -100, 100, 1, 0)); saturation = Gtk::manage (new Adjuster (M("TP_LABCURVE_SATURATION"), -100, 100, 1, 0)); - pack_start (*brightness); - brightness->show (); + pack_start (*brightness); + brightness->show (); - pack_start (*contrast); - contrast->show (); + pack_start (*contrast); + contrast->show (); pack_start (*saturation); saturation->show (); - Gtk::HSeparator *hsep3 = Gtk::manage (new Gtk::HSeparator()); - hsep3->show (); - pack_start (*hsep3); + Gtk::HSeparator *hsep3 = Gtk::manage (new Gtk::HSeparator()); + hsep3->show (); + pack_start (*hsep3); - lshape = Gtk::manage (new CurveEditor ()); - lshape->show (); - lshape->setCurveListener (this); + lshape = Gtk::manage (new CurveEditor ()); + lshape->show (); + lshape->setCurveListener (this); + CurveListener::setMulti(true); ashape = Gtk::manage (new CurveEditor ()); ashape->show (); ashape->setCurveListener (this); + CurveListener::setMulti(true); bshape = Gtk::manage (new CurveEditor ()); bshape->show (); bshape->setCurveListener (this); + CurveListener::setMulti(true); - pack_start (*lshape, Gtk::PACK_SHRINK, 4); + pack_start (*lshape, Gtk::PACK_SHRINK, 4); pack_start (*ashape, Gtk::PACK_SHRINK, 4); pack_start (*bshape, Gtk::PACK_SHRINK, 4); - brightness->setAdjusterListener (this); - contrast->setAdjusterListener (this); + brightness->setAdjusterListener (this); + contrast->setAdjusterListener (this); saturation->setAdjusterListener (this); //channel->signal_changed().connect( sigc::mem_fun(*this, &LCurve::channel) ); @@ -158,12 +161,15 @@ void LCurve::setDefaults (const ProcParams* defParams, const ParamsEdited* pedit } } -void LCurve::curveChanged () { +void LCurve::curveChanged (CurveEditor* ce) { if (listener) { - listener->panelChanged (EvLLCurve, M("HISTORY_CUSTOMCURVE")); - listener->panelChanged (EvLaCurve, M("HISTORY_CUSTOMCURVE")); - listener->panelChanged (EvLbCurve, M("HISTORY_CUSTOMCURVE")); + if (ce == lshape) + listener->panelChanged (EvLLCurve, M("HISTORY_CUSTOMCURVE")); + if (ce == ashape) + listener->panelChanged (EvLaCurve, M("HISTORY_CUSTOMCURVE")); + if (ce == bshape) + listener->panelChanged (EvLbCurve, M("HISTORY_CUSTOMCURVE")); } } diff --git a/rtgui/labcurve.h b/rtgui/labcurve.h index 687e36674..14dc531f2 100644 --- a/rtgui/labcurve.h +++ b/rtgui/labcurve.h @@ -49,7 +49,7 @@ class LCurve : public Gtk::VBox, public AdjusterListener, public ToolPanel, publ void setBatchMode (bool batchMode); void setAdjusterBehavior (bool bradd, bool contradd, bool satadd); - void curveChanged (); + void curveChanged (CurveEditor* ce); void adjusterChanged (Adjuster* a, double newval); void updateCurveBackgroundHistogram (unsigned* hist); }; diff --git a/rtgui/mycurve.cc b/rtgui/mycurve.cc index ff079b1d4..4430fabba 100644 --- a/rtgui/mycurve.cc +++ b/rtgui/mycurve.cc @@ -621,7 +621,7 @@ void MyCurve::setType (CurveType t) { void MyCurve::notifyListener () { if (listener) - listener->curveChanged (); + listener->curveChanged (); } void MyCurve::setActiveParam (int ac) {