Pushing the Resize patch from Default to Branch3, adding new HISTORY_MSG_ strings and correcting a small bug in the LAB/saturation limiter tool

This commit is contained in:
Hombre
2011-02-12 13:33:05 +01:00
parent bb0e24d913
commit 7b8bb9018d
28 changed files with 857 additions and 634 deletions

View File

@@ -25,12 +25,23 @@ using namespace rtengine::procparams;
Resize::Resize () : Gtk::VBox(), FoldableToolPanel(this), maxw(100000), maxh(100000) {
cropw = 0;
croph = 0;
enabled = Gtk::manage (new Gtk::CheckButton (M("GENERAL_ENABLED")));
pack_start(*enabled);
pack_start(*Gtk::manage (new Gtk::HSeparator()), Gtk::PACK_SHRINK, 2);
Gtk::Table* combos = Gtk::manage (new Gtk::Table (2, 2));
appliesTo = Gtk::manage (new Gtk::ComboBoxText ());
appliesTo->append_text (M("TP_RESIZE_CROPPEDAREA"));
appliesTo->append_text (M("TP_RESIZE_FULLIMAGE"));
appliesTo->set_active (0);
combos->attach (*Gtk::manage (new Gtk::Label (M("TP_RESIZE_APPLIESTO"))), 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 2, 2);
combos->attach (*appliesTo, 1, 2, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 2, 2);
method = Gtk::manage (new Gtk::ComboBoxText ());
method->append_text (M("TP_RESIZE_NEAREST"));
method->append_text (M("TP_RESIZE_BILINEAR"));
@@ -42,22 +53,23 @@ Resize::Resize () : Gtk::VBox(), FoldableToolPanel(this), maxw(100000), maxh(100
method->append_text (M("TP_RESIZE_LANCZOS"));
method->set_active (0);
combos->attach (*Gtk::manage (new Gtk::Label (M("TP_RESIZE_METHOD"))), 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 2, 2);
combos->attach (*method, 1, 2, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 2, 2);
combos->attach (*Gtk::manage (new Gtk::Label (M("TP_RESIZE_METHOD"))), 0, 1, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 2, 2);
combos->attach (*method, 1, 2, 1, 2, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 2, 2);
spec = Gtk::manage (new Gtk::ComboBoxText ());
spec->append_text (M("TP_RESIZE_SCALE"));
spec->append_text (M("TP_RESIZE_WIDTH"));
spec->append_text (M("TP_RESIZE_HEIGHT"));
method->set_active (0);
spec->append_text (M("TP_RESIZE_FITBOX"));
spec->set_active (0);
combos->attach (*Gtk::manage (new Gtk::Label (M("TP_RESIZE_SPECIFY"))), 0, 1, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 2, 2);
combos->attach (*spec, 1, 2, 1, 2, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 2, 2);
combos->attach (*Gtk::manage (new Gtk::Label (M("TP_RESIZE_SPECIFY"))), 0, 1, 2, 3, Gtk::SHRINK, Gtk::SHRINK, 2, 2);
combos->attach (*spec, 1, 2, 2, 3, Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK, 2, 2);
pack_start (*combos, Gtk::PACK_SHRINK, 4);
scale = new Adjuster (M("TP_RESIZE_SCALE"), 0.2, 4, 0.01, 1);
scale->setAdjusterListener (this);
scale = new Adjuster (M("TP_RESIZE_SCALE"), 0.01, 4, 0.01, 1.);
scale->setAdjusterListener (this);
pack_start (*scale, Gtk::PACK_SHRINK, 4);
@@ -91,8 +103,9 @@ Resize::Resize () : Gtk::VBox(), FoldableToolPanel(this), maxw(100000), maxh(100
wconn = w->signal_value_changed().connect ( sigc::mem_fun(*this, &Resize::entryWChanged), true);
hconn = h->signal_value_changed().connect ( sigc::mem_fun(*this, &Resize::entryHChanged), true);
aconn = appliesTo->signal_changed().connect ( sigc::mem_fun(*this, &Resize::appliesToChanged) );
method->signal_changed().connect ( sigc::mem_fun(*this, &Resize::methodChanged) );
spec->signal_changed().connect ( sigc::mem_fun(*this, &Resize::specChanged) );
sconn = spec->signal_changed().connect ( sigc::mem_fun(*this, &Resize::specChanged) );
enaConn = enabled->signal_toggled().connect ( sigc::mem_fun(*this, &Resize::enabledToggled) );
show_all();
@@ -107,14 +120,24 @@ Resize::~Resize () {
void Resize::read (const ProcParams* pp, const ParamsEdited* pedited) {
disableListener ();
aconn.block (true);
wconn.block (true);
hconn.block (true);
sconn.block (true);
scale->block(true);
scale->setValue (pp->resize.scale);
w->set_value (pp->resize.width);
h->set_value (pp->resize.height);
enabled->set_active (pp->resize.enabled);
spec->set_active (pp->resize.dataspec);
updateGUI();
appliesTo->set_active (0);
if (pp->resize.appliesTo == "Cropped area")
appliesTo->set_active (0);
else if (pp->resize.appliesTo == "Full image")
appliesTo->set_active (1);
method->set_active (2);
if (pp->resize.method == "Nearest")
@@ -141,23 +164,36 @@ void Resize::read (const ProcParams* pp, const ParamsEdited* pedited) {
wDirty = pedited->resize.width;
hDirty = pedited->resize.height;
scale->setEditedState (pedited->resize.scale ? Edited : UnEdited);
if (!pedited->resize.appliesTo)
method->set_active (2);
if (!pedited->resize.method)
method->set_active (5);
method->set_active (8);
if (!pedited->resize.dataspec)
spec->set_active (3);
spec->set_active (4);
enabled->set_inconsistent (!pedited->resize.enabled);
}
lastEnabled = pp->resize.enabled;
scale->block(false);
sconn.block (false);
wconn.block (false);
hconn.block (false);
aconn.block (false);
enableListener ();
}
void Resize::write (ProcParams* pp, ParamsEdited* pedited) {
int dataSpec = spec->get_active_row_number();
pp->resize.scale = scale->getValue();
pp->resize.appliesTo = "Cropped area";
if (appliesTo->get_active_row_number() == 0)
pp->resize.appliesTo = "Cropped area";
else if (appliesTo->get_active_row_number() == 1)
pp->resize.appliesTo = "Full image";
pp->resize.scale = scale->getValue ();
pp->resize.method = "Bicubic";
if (method->get_active_row_number() == 0)
pp->resize.method = "Nearest";
@@ -176,15 +212,17 @@ void Resize::write (ProcParams* pp, ParamsEdited* pedited) {
else if (method->get_active_row_number() == 7)
pp->resize.method = "Lanczos";
pp->resize.dataspec = spec->get_active_row_number();
pp->resize.width = round (w->get_value ());
pp->resize.height = round(h->get_value ());
pp->resize.dataspec = dataSpec;
pp->resize.width = w->get_value_as_int ();
pp->resize.height = h->get_value_as_int ();
pp->resize.enabled = enabled->get_active ();
//printf(" L:%d H:%d\n", pp->resize.width, pp->resize.height);
if (pedited) {
pedited->resize.enabled = !enabled->get_inconsistent();
pedited->resize.dataspec = spec->get_active_row_number() != 3;
pedited->resize.method = method->get_active_row_number() != 5;
pedited->resize.dataspec = dataSpec != 4;
pedited->resize.appliesTo = appliesTo->get_active_row_number() != 2;
pedited->resize.method = method->get_active_row_number() != 8;
if (pedited->resize.dataspec) {
pedited->resize.scale = scale->getEditedState ();
pedited->resize.width = wDirty;
@@ -213,14 +251,44 @@ void Resize::adjusterChanged (Adjuster* a, double newval) {
if (!batchMode) {
wconn.block (true);
hconn.block (true);
h->set_value (maxh * a->getValue ());
w->set_value (maxw * a->getValue ());
h->set_value ((croph && appliesTo->get_active_row_number()==0 ? croph : maxh) * a->getValue ());
w->set_value ((cropw && appliesTo->get_active_row_number()==0 ? cropw : maxw) * a->getValue ());
wconn.block (false);
hconn.block (false);
}
if (listener && (enabled->get_active () || batchMode))
listener->panelChanged (EvResizeScale, Glib::ustring::format (std::setw(5), std::fixed, std::setprecision(4), scale->getValue()));
listener->panelChanged (EvResizeScale, Glib::ustring::format (std::setw(5), std::fixed, std::setprecision(2), scale->getValue()));
}
int Resize::getComputedWidth() {
if (cropw && appliesTo->get_active_row_number()==0)
// we use the crop dimensions
return (int)((double)(cropw) * (h->get_value()/(double)(croph)) + 0.5);
else
// we use the image dimensions
return (int)((double)(maxw) * (h->get_value()/(double)(maxh)) + 0.5);
}
int Resize::getComputedHeight() {
if (croph && appliesTo->get_active_row_number()==0)
// we use the crop dimensions
return (int)((double)(croph) * (w->get_value()/(double)(cropw)) + 0.5);
else
// we use the image dimensions
return (int)((double)(maxh) * (w->get_value()/(double)(maxw)) + 0.5);
}
void Resize::appliesToChanged () {
//printf("\nPASSAGE EN MODE \"%s\"\n\n", appliesTo->get_active_text().c_str());
setDimensions();
if (listener && (enabled->get_active () || batchMode)) {
//printf("Appel du listener\n");
listener->panelChanged (EvResizeAppliesTo, appliesTo->get_active_text());
}
}
void Resize::methodChanged () {
@@ -229,65 +297,155 @@ void Resize::methodChanged () {
listener->panelChanged (EvResizeMethod, method->get_active_text());
}
struct setrdimparams {
Resize* resize;
int mw;
int mh;
int ow;
int oh;
};
void Resize::update (bool isCropped, int cw, int ch, int ow, int oh) {
int setrdim (void* data) {
// updating crop values now
if (isCropped) {
cropw = cw;
croph = ch;
}
else {
cropw = 0;
croph = 0;
}
gdk_threads_enter ();
setrdimparams* params = (setrdimparams*)data;
params->resize->setDimensions (params->mw, params->mh, params->ow, params->oh);
delete params;
gdk_threads_leave ();
return 0;
// updating the full image dimensions
if (ow && oh) {
maxw = ow;
maxh = oh;
}
// updating the GUI synchronously
setDimensions();
}
void Resize::sizeChanged (int mw, int mh, int ow, int oh) {
setrdimparams* params = new setrdimparams;
params->mw = mw;
params->mh = mh;
params->ow = ow;
params->oh = oh;
params->resize = this;
g_idle_add (setrdim, params);
}
void Resize::setDimensions (int mw, int mh, int ow, int oh) {
// updating max values now
maxw = ow;
maxh = oh;
// updating the GUI synchronously
setDimensions();
}
void Resize::setDimensions () {
int refw, refh;
wconn.block (true);
hconn.block (true);
scale->block(true);
w->set_range (32, 4*maxw);
h->set_range (32, 4*maxh);
if (appliesTo->get_active_row_number()==0 && cropw) {
// Applies to Cropped area
refw = cropw;
refh = croph;
}
else {
// Applies to Full image or crop is disabled
refw = maxw;
refh = maxh;
}
w->set_range (32, 4*refw);
h->set_range (32, 4*refh);
double tmpScale;
switch (spec->get_active_row_number()) {
case (0): // Scale mode
w->set_value((double)((int)( (double)(refw) * scale->getValue() + 0.5) ));
h->set_value((double)((int)( (double)(refh) * scale->getValue() + 0.5) ));
break;
case (1): // Width mode
tmpScale = w->get_value() / (double)refw;
scale->setValue (tmpScale);
h->set_value((double)((int)( (double)(refh) * tmpScale + 0.5) ));
break;
case (2): // Height mode
tmpScale = h->get_value() / (double)refh;
scale->setValue (tmpScale);
w->set_value((double)((int)( (double)(refw) * tmpScale + 0.5) ));
case (3): { // Bounding box mode
double wSliderValue = w->get_value();
double hSliderValue = h->get_value();
if ( (wSliderValue/hSliderValue) < ((double)refw/(double)refh)) {
tmpScale = wSliderValue / (double)refw;
}
else {
tmpScale = hSliderValue / (double)refh;
}
scale->setValue (tmpScale);
break;
}
default:
break;
}
scale->block(false);
wconn.block (false);
hconn.block (false);
}
void Resize::fitBoxScale() {
double tmpScale;
double neww = w->get_value ();
double newh = h->get_value ();
if (cropw && appliesTo->get_active_row_number()==0) {
// we use the crop dimensions
if (((double)(cropw) / (double)(croph)) > (neww / newh)) {
// the new scale is given by the image width
tmpScale = neww / (double)(cropw);
}
else {
// the new scale is given by the image height
tmpScale = newh / (double)(croph);
}
}
else {
// we use the image dimensions
if (((double)(maxw) / (double)(maxh)) > (neww / newh)) {
// the new scale is given by the image width
tmpScale = neww / (double)(maxw);
}
else {
// the new scale is given by the image height
tmpScale = newh / (double)(maxh);
}
}
scale->setValue (tmpScale);
}
void Resize::entryWChanged () {
wDirty = true;
if (!batchMode && listener) {
hconn.block (true);
h->set_value (w->get_value () * maxh / maxw);
hconn.block (false);
scale->setValue (w->get_value () / maxw);
// updating width
if (!batchMode) {
if (spec->get_active_row_number() == 3) {
// Fit box mode
fitBoxScale();
}
else {
// Other modes
hconn.block (true);
scale->block (true);
h->set_value ((double)(getComputedHeight()));
scale->setValue (w->get_value () / (cropw && appliesTo->get_active_row_number()==0 ? (double)cropw : (double)maxw));
scale->block (false);
hconn.block (false);
}
}
if (listener && (enabled->get_active () || batchMode))
listener->panelChanged (EvResizeWidth, Glib::ustring::format ((int)w->get_value()));
if (listener) {
if (spec->get_active_row_number() == 3)
notifyBBox();
else {
if (enabled->get_active () || batchMode)
listener->panelChanged (EvResizeWidth, Glib::ustring::format (w->get_value_as_int()));
}
}
}
void Resize::entryHChanged () {
@@ -295,39 +453,96 @@ void Resize::entryHChanged () {
hDirty = true;
if (!batchMode && listener) {
wconn.block (true);
w->set_value (h->get_value () * maxw / maxh);
wconn.block (false);
scale->setValue (h->get_value () / maxh);
if (spec->get_active_row_number() == 3) {
// Fit box mode
fitBoxScale();
}
else {
// Other modes
wconn.block (true);
scale->block (true);
w->set_value ((double)(getComputedWidth()));
scale->setValue (h->get_value () / (croph && appliesTo->get_active_row_number()==0 ? (double)croph : (double)maxh));
scale->block (false);
wconn.block (false);
}
}
if (listener && (enabled->get_active () || batchMode))
listener->panelChanged (EvResizeHeight, Glib::ustring::format ((int)h->get_value()));
if (listener) {
if (spec->get_active_row_number() == 3)
notifyBBox();
else {
if (enabled->get_active () || batchMode)
listener->panelChanged (EvResizeHeight, Glib::ustring::format (h->get_value_as_int()));
}
}
}
void Resize::specChanged () {
switch (spec->get_active_row_number()) {
case (0):
// Scale mode
scale->sliderChanged ();
break;
case (1):
// Width mode
w->set_value((double)(getComputedWidth()));
entryWChanged ();
break;
case (2):
// Height mode
h->set_value((double)(getComputedHeight()));
entryHChanged ();
break;
case (3):
// Bounding box mode
notifyBBox();
default:
break;
}
updateGUI();
}
void Resize::updateGUI () {
removeIfThere (this, scale, false);
removeIfThere (this, sizeBox, false);
if (spec->get_active_row_number() == 0) {
switch (spec->get_active_row_number()) {
case (0):
// Scale mode
pack_start (*scale, Gtk::PACK_SHRINK, 4);
scale->sliderChanged ();
}
else if (spec->get_active_row_number() == 1) {
break;
case (1):
// Width mode
pack_start (*sizeBox, Gtk::PACK_SHRINK, 4);
w->set_sensitive (true);
h->set_sensitive (false);
entryWChanged ();
}
else if (spec->get_active_row_number() == 2) {
break;
case (2):
// Height mode
pack_start (*sizeBox, Gtk::PACK_SHRINK, 4);
h->set_sensitive (true);
w->set_sensitive (false);
entryHChanged ();
h->set_sensitive (true);
break;
case (3):
// Bounding box mode
pack_start (*sizeBox, Gtk::PACK_SHRINK, 4);
w->set_sensitive (true);
h->set_sensitive (true);
default:
break;
}
}
void Resize::notifyBBox() {
if (listener && (enabled->get_active () || batchMode))
listener->panelChanged (EvResizeBoundingBox, Glib::ustring::compose("(%1x%2)",(int)w->get_value(), (int)h->get_value() ));
}
void Resize::setBatchMode (bool batchMode) {
method->append_text (M("GENERAL_UNCHANGED"));