diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-05-11 02:12:46 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-05-11 13:12:21 +0200 |
| commit | 08c59d5232072f604e15216bd1abc29e7b7576be (patch) | |
| tree | 7b81ab2b399dc9c5de656767a3c4cd8c5816a43e | |
| parent | 2910224db701d1e5328ffa9685de953135ab3d6f (diff) | |
Use wxNumberFormatter instead of locale_convert.
| -rw-r--r-- | src/wx/colour_conversion_editor.cc | 103 | ||||
| -rw-r--r-- | src/wx/content_advanced_dialog.cc | 8 | ||||
| -rw-r--r-- | src/wx/dcp_panel.cc | 7 | ||||
| -rw-r--r-- | src/wx/image_sequence_dialog.cc | 15 | ||||
| -rw-r--r-- | src/wx/playhead_to_frame_dialog.cc | 12 | ||||
| -rw-r--r-- | src/wx/timer_display.cc | 12 | ||||
| -rw-r--r-- | src/wx/video_waveform_plot.cc | 5 |
7 files changed, 76 insertions, 86 deletions
diff --git a/src/wx/colour_conversion_editor.cc b/src/wx/colour_conversion_editor.cc index d869b51d2..0c667b51f 100644 --- a/src/wx/colour_conversion_editor.cc +++ b/src/wx/colour_conversion_editor.cc @@ -26,7 +26,6 @@ #include "lib/colour_conversion.h" #include <dcp/gamma_transfer_function.h> #include <dcp/identity_transfer_function.h> -#include <dcp/locale_convert.h> #include <dcp/modified_gamma_transfer_function.h> #include <dcp/s_gamut3_transfer_function.h> #include <dcp/warnings.h> @@ -41,7 +40,6 @@ using std::dynamic_pointer_cast; using std::make_shared; using std::string; using boost::bind; -using dcp::locale_convert; int const ColourConversionEditor::INPUT_GAMMA = 0; @@ -281,32 +279,21 @@ ColourConversionEditor::set (ColourConversion conversion) _ignore_chromaticity_changed = true; - char buffer[256]; - snprintf (buffer, sizeof (buffer), "%.6f", conversion.red().x); - _red_x->SetValue (std_to_wx (buffer)); - snprintf (buffer, sizeof (buffer), "%.6f", conversion.red().y); - _red_y->SetValue (std_to_wx (buffer)); - snprintf (buffer, sizeof (buffer), "%.6f", conversion.green().x); - _green_x->SetValue (std_to_wx (buffer)); - snprintf (buffer, sizeof (buffer), "%.6f", conversion.green().y); - _green_y->SetValue (std_to_wx (buffer)); - snprintf (buffer, sizeof (buffer), "%.6f", conversion.blue().x); - _blue_x->SetValue (std_to_wx (buffer)); - snprintf (buffer, sizeof (buffer), "%.6f", conversion.blue().y); - _blue_y->SetValue (std_to_wx (buffer)); - snprintf (buffer, sizeof (buffer), "%.6f", conversion.white().x); - _white_x->SetValue (std_to_wx (buffer)); - snprintf (buffer, sizeof (buffer), "%.6f", conversion.white().y); - _white_y->SetValue (std_to_wx (buffer)); + _red_x->SetValue(wxNumberFormatter::ToString(conversion.red().x, 6)); + _red_y->SetValue(wxNumberFormatter::ToString(conversion.red().y, 6)); + _green_x->SetValue(wxNumberFormatter::ToString(conversion.green().y, 6)); + _green_y->SetValue(wxNumberFormatter::ToString(conversion.green().y, 6)); + _blue_x->SetValue(wxNumberFormatter::ToString(conversion.blue().x, 6)); + _blue_y->SetValue(wxNumberFormatter::ToString(conversion.blue().y, 6)); + _white_x->SetValue(wxNumberFormatter::ToString(conversion.white().x, 6)); + _white_y->SetValue(wxNumberFormatter::ToString(conversion.white().y, 6)); _ignore_chromaticity_changed = false; if (conversion.adjusted_white ()) { _adjust_white->SetValue (true); - snprintf (buffer, sizeof (buffer), "%.6f", conversion.adjusted_white().get().x); - _adjusted_white_x->SetValue (std_to_wx (buffer)); - snprintf (buffer, sizeof (buffer), "%.6f", conversion.adjusted_white().get().y); - _adjusted_white_y->SetValue (std_to_wx (buffer)); + _adjusted_white_x->SetValue(wxNumberFormatter::ToString(conversion.adjusted_white().get().x, 6)); + _adjusted_white_y->SetValue(wxNumberFormatter::ToString(conversion.adjusted_white().get().x, 6)); } else { _adjust_white->SetValue (false); } @@ -331,16 +318,24 @@ ColourConversionEditor::get () const ); break; case INPUT_GAMMA_LINEARISED: + { /* Linearised gamma */ + double threshold = 0; + double input_A = 0; + double input_B = 0; + wxNumberFormatter::FromString(_input_threshold->GetValue(), &threshold); + wxNumberFormatter::FromString(_input_A->GetValue(), &input_A); + wxNumberFormatter::FromString(_input_B->GetValue(), &input_B); conversion.set_in ( make_shared<dcp::ModifiedGammaTransferFunction>( _input_power->GetValue (), - locale_convert<double>(wx_to_std(_input_threshold->GetValue())), - locale_convert<double>(wx_to_std(_input_A->GetValue())), - locale_convert<double>(wx_to_std(_input_B->GetValue())) + threshold, + input_A, + input_B ) ); break; + } case INPUT_SGAMUT3: /* SGamut3 */ conversion.set_in (make_shared<dcp::SGamut3TransferFunction>()); @@ -349,26 +344,30 @@ ColourConversionEditor::get () const conversion.set_yuv_to_rgb (static_cast<dcp::YUVToRGB>(_yuv_to_rgb->GetSelection())); - conversion.set_red ( - dcp::Chromaticity(locale_convert<double>(wx_to_std(_red_x->GetValue())), locale_convert<double>(wx_to_std(_red_y->GetValue()))) - ); - conversion.set_green ( - dcp::Chromaticity(locale_convert<double>(wx_to_std(_green_x->GetValue())), locale_convert<double>(wx_to_std(_green_y->GetValue()))) - ); - conversion.set_blue ( - dcp::Chromaticity(locale_convert<double>(wx_to_std(_blue_x->GetValue())), locale_convert<double>(wx_to_std(_blue_y->GetValue()))) - ); - conversion.set_white ( - dcp::Chromaticity(locale_convert<double>(wx_to_std(_white_x->GetValue())), locale_convert<double>(wx_to_std(_white_y->GetValue()))) - ); + double red_x = 0; + double red_y = 0; + double green_x = 0; + double green_y = 0; + double blue_x = 0; + double blue_y = 0; + + wxNumberFormatter::FromString(_red_x->GetValue(), &red_x); + wxNumberFormatter::FromString(_red_y->GetValue(), &red_y); + wxNumberFormatter::FromString(_green_x->GetValue(), &green_x); + wxNumberFormatter::FromString(_green_y->GetValue(), &green_y); + wxNumberFormatter::FromString(_blue_x->GetValue(), &blue_x); + wxNumberFormatter::FromString(_blue_y->GetValue(), &blue_y); + + conversion.set_red(dcp::Chromaticity(red_x, red_y)); + conversion.set_green(dcp::Chromaticity(green_x, green_y)); + conversion.set_blue(dcp::Chromaticity(blue_x, blue_y)); if (_adjust_white->GetValue()) { - conversion.set_adjusted_white( - dcp::Chromaticity( - locale_convert<double>(wx_to_std(_adjusted_white_x->GetValue())), - locale_convert<double>(wx_to_std(_adjusted_white_y->GetValue())) - ) - ); + double white_x = 0; + double white_y = 0; + wxNumberFormatter::FromString(_adjusted_white_x->GetValue(), &white_x); + wxNumberFormatter::FromString(_adjusted_white_y->GetValue(), &white_y); + conversion.set_adjusted_white(dcp::Chromaticity(white_x, white_y)); } else { conversion.unset_adjusted_white (); } @@ -423,12 +422,10 @@ ColourConversionEditor::update_bradford () _adjusted_white_x->Enable (_adjust_white->GetValue ()); _adjusted_white_y->Enable (_adjust_white->GetValue ()); - auto m = get().bradford(); + auto const m = get().bradford(); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { - char buffer[256]; - snprintf (buffer, sizeof (buffer), "%.7f", m (i, j)); - _bradford[i][j]->SetLabel (std_to_wx (buffer)); + _bradford[i][j]->SetLabel(wxNumberFormatter::ToString(m(i, j), 7)); } } } @@ -437,12 +434,10 @@ ColourConversionEditor::update_bradford () void ColourConversionEditor::update_rgb_to_xyz () { - auto m = get().rgb_to_xyz(); + auto const m = get().rgb_to_xyz(); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { - char buffer[256]; - snprintf (buffer, sizeof (buffer), "%.7f", m (i, j)); - _rgb_to_xyz[i][j]->SetLabel (std_to_wx (buffer)); + _rgb_to_xyz[i][j]->SetLabel(wxNumberFormatter::ToString(m(i, j), 7)); } } } @@ -474,7 +469,5 @@ ColourConversionEditor::set_spin_ctrl (wxSpinCtrlDouble* control, double value) void ColourConversionEditor::set_text_ctrl (wxTextCtrl* control, double value) { - char buffer[256]; - snprintf (buffer, sizeof (buffer), "%.7f", value); - control->SetValue (std_to_wx (buffer)); + control->SetValue(wxNumberFormatter::ToString(value, 7)); } diff --git a/src/wx/content_advanced_dialog.cc b/src/wx/content_advanced_dialog.cc index cc888aeb1..daa35d251 100644 --- a/src/wx/content_advanced_dialog.cc +++ b/src/wx/content_advanced_dialog.cc @@ -37,6 +37,7 @@ LIBDCP_DISABLE_WARNINGS #include <wx/gbsizer.h> #include <wx/propgrid/property.h> #include <wx/propgrid/props.h> +#include <wx/numformatter.h> #include <wx/wx.h> LIBDCP_ENABLE_WARNINGS #include <boost/bind/bind.hpp> @@ -51,7 +52,6 @@ using boost::optional; #if BOOST_VERSION >= 106100 using namespace boost::placeholders; #endif -using dcp::locale_convert; @@ -127,7 +127,7 @@ ContentAdvancedDialog::ContentAdvancedDialog (wxWindow* parent, shared_ptr<Conte auto vfr = _content->video_frame_rate (); if (vfr) { - _video_frame_rate->SetValue (std_to_wx(locale_convert<string>(*vfr))); + _video_frame_rate->SetValue(wxNumberFormatter::ToString(*vfr, 3)); } _burnt_subtitle->SetValue (_content->video && static_cast<bool>(_content->video->burnt_subtitle_language())); @@ -199,7 +199,9 @@ ContentAdvancedDialog::video_frame_rate() const return {}; } - return locale_convert<double>(wx_to_std(_video_frame_rate->GetValue())); + double v = 0; + wxNumberFormatter::FromString(_video_frame_rate->GetValue(), &v); + return v; } diff --git a/src/wx/dcp_panel.cc b/src/wx/dcp_panel.cc index 2341bf043..398137b1e 100644 --- a/src/wx/dcp_panel.cc +++ b/src/wx/dcp_panel.cc @@ -45,11 +45,11 @@ #include "lib/text_content.h" #include "lib/util.h" #include "lib/video_content.h" -#include <dcp/locale_convert.h> #include <dcp/warnings.h> LIBDCP_DISABLE_WARNINGS #include <wx/gbsizer.h> #include <wx/notebook.h> +#include <wx/numformatter.h> #include <wx/spinctrl.h> #include <wx/wx.h> LIBDCP_ENABLE_WARNINGS @@ -68,7 +68,6 @@ using boost::lexical_cast; #if BOOST_VERSION >= 106100 using namespace boost::placeholders; #endif -using dcp::locale_convert; DCPPanel::DCPPanel(wxNotebook* n, shared_ptr<Film> film, FilmViewer& viewer) @@ -321,7 +320,7 @@ DCPPanel::audio_channels_changed() return; } - _film->set_audio_channels(locale_convert<int>(string_client_data(_audio_channels->GetClientObject(*_audio_channels->get())))); + _film->set_audio_channels(wxNumberFormatter::FromString(string_client_data(_audio_channels->GetClientObject(*_audio_channels->get())))); } @@ -437,7 +436,7 @@ DCPPanel::film_changed(FilmProperty p) if (_film->audio_channels() < minimum_allowed_audio_channels()) { _film->set_audio_channels(minimum_allowed_audio_channels()); } else { - checked_set(_audio_channels, locale_convert<string>(max(minimum_allowed_audio_channels(), _film->audio_channels()))); + checked_set(_audio_channels, wxNumberFormatter::ToString(static_cast<long>(max(minimum_allowed_audio_channels(), _film->audio_channels())))); setup_dcp_name(); } break; diff --git a/src/wx/image_sequence_dialog.cc b/src/wx/image_sequence_dialog.cc index 6d1d00c49..a5ec959de 100644 --- a/src/wx/image_sequence_dialog.cc +++ b/src/wx/image_sequence_dialog.cc @@ -21,10 +21,7 @@ #include "image_sequence_dialog.h" #include "wx_util.h" -#include <dcp/locale_convert.h> - - -using dcp::locale_convert; +#include <wx/numformatter.h> ImageSequenceDialog::ImageSequenceDialog (wxWindow* parent) @@ -38,11 +35,7 @@ ImageSequenceDialog::ImageSequenceDialog (wxWindow* parent) double ImageSequenceDialog::frame_rate () const { - try { - return locale_convert<double> (wx_to_std (_frame_rate->GetValue ())); - } catch (...) { - - } - - return 0; + double r = 0; + wxNumberFormatter::FromString(_frame_rate->GetValue(), &r); + return r; } diff --git a/src/wx/playhead_to_frame_dialog.cc b/src/wx/playhead_to_frame_dialog.cc index e307fa6b1..002cb789a 100644 --- a/src/wx/playhead_to_frame_dialog.cc +++ b/src/wx/playhead_to_frame_dialog.cc @@ -18,13 +18,15 @@ */ + #include "playhead_to_frame_dialog.h" -#include <dcp/locale_convert.h> +#include <wx/numformatter.h> + using std::string; -using dcp::locale_convert; using namespace dcpomatic; + PlayheadToFrameDialog::PlayheadToFrameDialog (wxWindow* parent, DCPTime time, int fps) : TableDialog (parent, _("Go to frame"), 2, 1, true) , _fps (fps) @@ -32,7 +34,7 @@ PlayheadToFrameDialog::PlayheadToFrameDialog (wxWindow* parent, DCPTime time, in add (_("Go to"), true); _frame = add(new wxTextCtrl(this, wxID_ANY, {})); _frame->SetFocus (); - _frame->SetValue (std_to_wx(locale_convert<string>(time.frames_round(fps) + 1))); + _frame->SetValue(wxNumberFormatter::ToString(static_cast<long>(time.frames_round(fps) + 1))); _frame->SetSelection (-1, -1); layout (); @@ -41,5 +43,7 @@ PlayheadToFrameDialog::PlayheadToFrameDialog (wxWindow* parent, DCPTime time, in DCPTime PlayheadToFrameDialog::get () const { - return DCPTime::from_frames (locale_convert<Frame> (wx_to_std (_frame->GetValue ())) - 1, _fps); + long long frame = 1; + wxNumberFormatter::FromString(_frame->GetValue(), &frame); + return DCPTime::from_frames(frame - 1, _fps); } diff --git a/src/wx/timer_display.cc b/src/wx/timer_display.cc index 4dd9adf42..451b134ab 100644 --- a/src/wx/timer_display.cc +++ b/src/wx/timer_display.cc @@ -22,7 +22,7 @@ #include "timer_display.h" #include "wx_util.h" #include "lib/timer.h" -#include <dcp/locale_convert.h> +#include <wx/numformatter.h> #include <list> @@ -47,15 +47,15 @@ TimerDisplay::TimerDisplay (wxWindow* parent, StateTimer const & timer, int gets }); add(char_to_wx("get() calls"), true); - add (std_to_wx(dcp::locale_convert<string>(gets)), false); + add(wxNumberFormatter::ToString(static_cast<long>(gets)), false); add_spacer (); add_spacer (); for (auto const& i: sorted) { - add (std_to_wx(i.first), true); - add (std_to_wx(dcp::locale_convert<string>(i.second.total_time)), false); - add (std_to_wx(dcp::locale_convert<string>(i.second.number)), false); - add (std_to_wx(dcp::locale_convert<string>(i.second.total_time / i.second.number)), false); + add(std_to_wx(i.first), true); + add(wxNumberFormatter::ToString(i.second.total_time, 1), false); + add(wxNumberFormatter::ToString(static_cast<long>(i.second.number)), false); + add(wxNumberFormatter::ToString(i.second.total_time / i.second.number, 1), false); } layout (); diff --git a/src/wx/video_waveform_plot.cc b/src/wx/video_waveform_plot.cc index 2827689a7..f5c1c80c1 100644 --- a/src/wx/video_waveform_plot.cc +++ b/src/wx/video_waveform_plot.cc @@ -26,11 +26,11 @@ #include "lib/film.h" #include "lib/image.h" #include "lib/player_video.h" -#include <dcp/locale_convert.h> #include <dcp/openjpeg_image.h> #include <dcp/warnings.h> LIBDCP_DISABLE_WARNINGS #include <wx/graphics.h> +#include <wx/numformatter.h> #include <wx/rawbmp.h> LIBDCP_ENABLE_WARNINGS #include <boost/bind/bind.hpp> @@ -45,7 +45,6 @@ using std::weak_ptr; #if BOOST_VERSION >= 106100 using namespace boost::placeholders; #endif -using dcp::locale_convert; int const VideoWaveformPlot::_vertical_margin = 8; @@ -132,7 +131,7 @@ VideoWaveformPlot::paint () } else if (n < 1000) { x += extra[2]; } - gc->DrawText (std_to_wx(locale_convert<string>(n)), x, y - (label_height / 2)); + gc->DrawText(wxNumberFormatter::ToString(static_cast<long>(n)), x, y - (label_height / 2)); } wxImage waveform (_waveform->size().width, height, _waveform->data()[0], true); |
