Fix a waterfall palette designer import bug.

Yet another rework of waterfall palette interpolation to try and avoid
invalid colour values.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3999 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville 2014-04-08 16:59:09 +00:00
parent cc4a7624e5
commit a611d86676
1 changed files with 27 additions and 12 deletions

View File

@ -135,15 +135,21 @@ namespace
auto export_button = ui_.button_box->addButton ("&Export...", QDialogButtonBox::ActionRole); auto export_button = ui_.button_box->addButton ("&Export...", QDialogButtonBox::ActionRole);
connect (export_button, &QPushButton::clicked, this, &Designer::export_palette); connect (export_button, &QPushButton::clicked, this, &Designer::export_palette);
// hookup the context menu handler
connect (ui_.colour_table_widget, &QWidget::customContextMenuRequested, this, &Designer::context_menu);
load_table ();
}
void load_table ()
{
// load the table items // load the table items
ui_.colour_table_widget->clear ();
ui_.colour_table_widget->setRowCount (colours_.size ()); ui_.colour_table_widget->setRowCount (colours_.size ());
for (int i {0}; i < colours_.size (); ++i) for (int i {0}; i < colours_.size (); ++i)
{ {
insert_item (i); insert_item (i);
} }
// hookup the context menu handler
connect (ui_.colour_table_widget, &QWidget::customContextMenuRequested, this, &Designer::context_menu);
} }
Colours colours () const Colours colours () const
@ -224,6 +230,7 @@ namespace
if (!file_name.isEmpty ()) if (!file_name.isEmpty ())
{ {
colours_ = load_palette (file_name); colours_ = load_palette (file_name);
load_table ();
} }
} }
@ -279,24 +286,32 @@ QVector<QColor> WFPalette::interpolate () const
QVector<QColor> result; QVector<QColor> result;
result.reserve (points); result.reserve (points);
// do a linear gradient between each supplied colour point // do a linear-ish gradient between each supplied colour point
int interval = points / (colours.size () - 1); auto interval = qreal (points) / (colours.size () - 1);
for (int i {0}; i < points; ++i) for (int i {0}; i < points; ++i)
{ {
int prior {i / interval}; int prior = i / interval;
int next {prior + 1}; if (prior >= (colours.size () - 1))
{
--prior;
}
auto next = prior + 1;
if (next >= colours.size ()) if (next >= colours.size ())
{ {
--next; --next;
--prior;
} }
auto increment = i - interval * prior; // qDebug () << "WFPalette::interpolate: prior:" << prior << "total:" << colours.size ();
qreal r {std::max (0., colours[prior].redF () + (increment * (colours[next].redF () - colours[prior].redF ()))/interval)};
qreal g {std::max (0., colours[prior].greenF () + (increment * (colours[next].greenF () - colours[prior].greenF ()))/interval)}; auto increment = i - qreal (interval) * prior;
qreal b {std::max (0., colours[prior].blueF () + (increment * (colours[next].blueF () - colours[prior].blueF ()))/interval)}; qreal r {colours[prior].redF () + (increment * (colours[next].redF () - colours[prior].redF ()))/interval};
qreal g {colours[prior].greenF () + (increment * (colours[next].greenF () - colours[prior].greenF ()))/interval};
qreal b {colours[prior].blueF () + (increment * (colours[next].blueF () - colours[prior].blueF ()))/interval};
result.append (QColor::fromRgbF (r, g, b)); result.append (QColor::fromRgbF (r, g, b));
// qDebug () << "Palette colour[" << (result.size () - 1) << "] =" << result[result.size () - 1] << "from: r:" << r << "g:" << g << "b:" << b;
} }
return result; return result;