From 1d68fe1e3ad1a9aa85fa7fc6071a0b8c64973953 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 25 Aug 2015 22:17:23 +0100 Subject: [PATCH] Purge rint() and use llrint and friends. --- src/lib/audio_content.cc | 2 +- src/lib/dcp_content.cc | 2 +- src/lib/dcpomatic_time.cc | 4 ++-- src/lib/dcpomatic_time.h | 4 ++-- src/lib/ffmpeg_content.cc | 2 +- src/lib/ffmpeg_decoder.cc | 2 +- src/lib/image.cc | 8 ++++---- src/lib/image_content.cc | 2 +- src/lib/job.cc | 2 +- src/lib/player.cc | 4 ++-- src/lib/util.cc | 4 ++-- src/lib/video_content_scale.cc | 4 ++-- src/lib/writer.cc | 2 +- src/wx/film_viewer.cc | 6 +++--- src/wx/subtitle_panel.cc | 4 ++-- src/wx/timeline_time_axis_view.cc | 8 ++++---- src/wx/wx_util.cc | 2 +- test/audio_decoder_test.cc | 2 +- test/frame_rate_test.cc | 2 +- 19 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/lib/audio_content.cc b/src/lib/audio_content.cc index 4d821ad60..5e14fb232 100644 --- a/src/lib/audio_content.cc +++ b/src/lib/audio_content.cc @@ -206,7 +206,7 @@ AudioContent::resampled_audio_frame_rate () const t /= frc.speed_up; } - return rint (t); + return lrint (t); } string diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc index b1c9e3815..57c103e03 100644 --- a/src/lib/dcp_content.cc +++ b/src/lib/dcp_content.cc @@ -146,7 +146,7 @@ DCPContent::full_length () const shared_ptr film = _film.lock (); DCPOMATIC_ASSERT (film); FrameRateChange const frc (video_frame_rate (), film->video_frame_rate ()); - return DCPTime::from_frames (rint (video_length () * frc.factor ()), film->video_frame_rate ()); + return DCPTime::from_frames (llrint (video_length () * frc.factor ()), film->video_frame_rate ()); } string diff --git a/src/lib/dcpomatic_time.cc b/src/lib/dcpomatic_time.cc index 3d4ed1139..6f8f5efa2 100644 --- a/src/lib/dcpomatic_time.cc +++ b/src/lib/dcpomatic_time.cc @@ -23,14 +23,14 @@ using std::ostream; template <> Time::Time (DCPTime d, FrameRateChange f) - : _t (rint (d.get() * f.speed_up)) + : _t (llrint (d.get() * f.speed_up)) { } template <> Time::Time (ContentTime d, FrameRateChange f) - : _t (rint (d.get() / f.speed_up)) + : _t (llrint (d.get() / f.speed_up)) { } diff --git a/src/lib/dcpomatic_time.h b/src/lib/dcpomatic_time.h index c1d27407a..ba3c8fcad 100644 --- a/src/lib/dcpomatic_time.h +++ b/src/lib/dcpomatic_time.h @@ -118,7 +118,7 @@ public: * @param r Sampling rate. */ Time round_up (float r) { - Type const n = rint (HZ / r); + Type const n = llrintf (HZ / r); Type const a = _t + n - 1; return Time (a - (a % n)); } @@ -180,7 +180,7 @@ public: static Time from_seconds (double s) { - return Time (rint (s * HZ)); + return Time (llrint (s * HZ)); } template diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 071f98612..4e49e1254 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -281,7 +281,7 @@ FFmpegContent::full_length () const shared_ptr film = _film.lock (); DCPOMATIC_ASSERT (film); FrameRateChange const frc (video_frame_rate (), film->video_frame_rate ()); - return DCPTime::from_frames (rint (video_length_after_3d_combine() * frc.factor()), film->video_frame_rate()); + return DCPTime::from_frames (llrint (video_length_after_3d_combine() * frc.factor()), film->video_frame_rate()); } void diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index a17419dc7..eab85c04e 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -418,7 +418,7 @@ FFmpegDecoder::decode_video_packet () double const pts = i->second * av_q2d (_format_context->streams[_video_stream]->time_base) + _pts_offset.seconds (); video ( shared_ptr (new RawImageProxy (image)), - rint (pts * _ffmpeg_content->video_frame_rate ()) + llrint (pts * _ffmpeg_content->video_frame_rate ()) ); } else { LOG_WARNING_NC ("Dropping frame without PTS"); diff --git a/src/lib/image.cc b/src/lib/image.cc index 0c7a0ef0d..fcdcca95a 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -76,8 +76,8 @@ Image::sample_size (int n) const } return dcp::Size ( - rint (ceil (static_cast(size().width) / horizontal_factor)), - rint (ceil (static_cast(size().height) / line_factor (n))) + lrint (ceil (static_cast(size().width) / horizontal_factor)), + lrint (ceil (static_cast(size().height) / line_factor (n))) ); } @@ -166,7 +166,7 @@ Image::crop_scale_window ( round down so that we don't crop a subsampled pixel until we've cropped all of its Y-channel pixels. */ - int const x = int (rint (bytes_per_pixel(c) * crop.left)) & ~ ((int) desc->log2_chroma_w); + int const x = lrintf (bytes_per_pixel(c) * crop.left) & ~ ((int) desc->log2_chroma_w); scale_in_data[c] = data()[c] + x + stride()[c] * (crop.top / line_factor(c)); } @@ -175,7 +175,7 @@ Image::crop_scale_window ( uint8_t* scale_out_data[out->planes()]; for (int c = 0; c < out->planes(); ++c) { - scale_out_data[c] = out->data()[c] + int (rint (out->bytes_per_pixel(c) * corner.x)) + out->stride()[c] * corner.y; + scale_out_data[c] = out->data()[c] + lrintf (out->bytes_per_pixel(c) * corner.x) + out->stride()[c] * corner.y; } sws_scale ( diff --git a/src/lib/image_content.cc b/src/lib/image_content.cc index 920d7ae54..87aa1d66d 100644 --- a/src/lib/image_content.cc +++ b/src/lib/image_content.cc @@ -142,7 +142,7 @@ ImageContent::full_length () const shared_ptr film = _film.lock (); DCPOMATIC_ASSERT (film); FrameRateChange const frc (video_frame_rate(), film->video_frame_rate()); - return DCPTime::from_frames (rint (video_length_after_3d_combine() * frc.factor ()), film->video_frame_rate ()); + return DCPTime::from_frames (llrint (video_length_after_3d_combine() * frc.factor ()), film->video_frame_rate ()); } string diff --git a/src/lib/job.cc b/src/lib/job.cc index 25a533654..d9715aa18 100644 --- a/src/lib/job.cc +++ b/src/lib/job.cc @@ -332,7 +332,7 @@ Job::status () const SafeStringStream s; if (!finished () && p) { - int pc = rint (p.get() * 100); + int pc = lrintf (p.get() * 100); if (pc == 100) { /* 100% makes it sound like we've finished when we haven't */ pc = 99; diff --git a/src/lib/player.cc b/src/lib/player.cc index c51f80067..a40c65cd5 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -293,8 +293,8 @@ Player::transform_image_subtitles (list subs) const true ), Position ( - rint (_video_container_size.width * i->rectangle.x), - rint (_video_container_size.height * i->rectangle.y) + lrint (_video_container_size.width * i->rectangle.x), + lrint (_video_container_size.height * i->rectangle.y) ) ) ); diff --git a/src/lib/util.cc b/src/lib/util.cc index 76e76328d..bccc368da 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -539,10 +539,10 @@ dcp::Size fit_ratio_within (float ratio, dcp::Size full_frame) { if (ratio < full_frame.ratio ()) { - return dcp::Size (rint (full_frame.height * ratio), full_frame.height); + return dcp::Size (lrintf (full_frame.height * ratio), full_frame.height); } - return dcp::Size (full_frame.width, rint (full_frame.width / ratio)); + return dcp::Size (full_frame.width, lrintf (full_frame.width / ratio)); } void * diff --git a/src/lib/video_content_scale.cc b/src/lib/video_content_scale.cc index c8c295361..aae135311 100644 --- a/src/lib/video_content_scale.cc +++ b/src/lib/video_content_scale.cc @@ -155,8 +155,8 @@ VideoContentScale::size (shared_ptr c, dcp::Size display_con float (display_container.height) / film_container.height ); - size.width = rint (size.width * scale); - size.height = rint (size.height * scale); + size.width = lrintf (size.width * scale); + size.height = lrintf (size.height * scale); } return size; diff --git a/src/lib/writer.cc b/src/lib/writer.cc index 053c18451..b7c85c2ae 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -770,7 +770,7 @@ operator== (QueueItem const & a, QueueItem const & b) void Writer::set_encoder_threads (int threads) { - _maximum_frames_in_memory = rint (threads * 1.1); + _maximum_frames_in_memory = lrint (threads * 1.1); } long diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index 9b648a8b9..b43db0d7b 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -316,11 +316,11 @@ FilmViewer::calculate_sizes () if (panel_ratio < film_ratio) { /* panel is less widscreen than the film; clamp width */ _out_size.width = _panel_size.width; - _out_size.height = rint (_out_size.width / film_ratio); + _out_size.height = lrintf (_out_size.width / film_ratio); } else { /* panel is more widescreen than the film; clamp height */ _out_size.height = _panel_size.height; - _out_size.width = rint (_out_size.height * film_ratio); + _out_size.width = lrintf (_out_size.height * film_ratio); } /* Catch silly values */ @@ -379,7 +379,7 @@ FilmViewer::update_position_label () double const fps = _film->video_frame_rate (); /* Count frame number from 1 ... not sure if this is the best idea */ - _frame_number->SetLabel (wxString::Format (wxT("%d"), int (rint (_position.seconds() * fps)) + 1)); + _frame_number->SetLabel (wxString::Format (wxT("%d"), lrint (_position.seconds() * fps) + 1)); _timecode->SetLabel (time_to_timecode (_position, fps)); } diff --git a/src/wx/subtitle_panel.cc b/src/wx/subtitle_panel.cc index 3d6e5c8c3..d99b54558 100644 --- a/src/wx/subtitle_panel.cc +++ b/src/wx/subtitle_panel.cc @@ -173,9 +173,9 @@ SubtitlePanel::film_content_changed (int property) } else if (property == SubtitleContentProperty::SUBTITLE_Y_OFFSET) { checked_set (_y_offset, scs ? (scs->subtitle_y_offset() * 100) : 0); } else if (property == SubtitleContentProperty::SUBTITLE_X_SCALE) { - checked_set (_x_scale, scs ? int (rint (scs->subtitle_x_scale() * 100)) : 100); + checked_set (_x_scale, scs ? lrint (scs->subtitle_x_scale() * 100) : 100); } else if (property == SubtitleContentProperty::SUBTITLE_Y_SCALE) { - checked_set (_y_scale, scs ? int (rint (scs->subtitle_y_scale() * 100)) : 100); + checked_set (_y_scale, scs ? lrint (scs->subtitle_y_scale() * 100) : 100); } else if (property == SubtitleContentProperty::SUBTITLE_LANGUAGE) { checked_set (_language, scs ? scs->subtitle_language() : ""); } diff --git a/src/wx/timeline_time_axis_view.cc b/src/wx/timeline_time_axis_view.cc index 7882c1231..2667d9834 100644 --- a/src/wx/timeline_time_axis_view.cc +++ b/src/wx/timeline_time_axis_view.cc @@ -55,16 +55,16 @@ TimelineTimeAxisView::do_paint (wxGraphicsContext* gc) double mark_interval = rint (128 / pps); if (mark_interval > 5) { - mark_interval -= int (rint (mark_interval)) % 5; + mark_interval -= lrint (mark_interval) % 5; } if (mark_interval > 10) { - mark_interval -= int (rint (mark_interval)) % 10; + mark_interval -= lrint (mark_interval) % 10; } if (mark_interval > 60) { - mark_interval -= int (rint (mark_interval)) % 60; + mark_interval -= lrint (mark_interval) % 60; } if (mark_interval > 3600) { - mark_interval -= int (rint (mark_interval)) % 3600; + mark_interval -= lrint (mark_interval) % 3600; } if (mark_interval < 1) { diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc index 5acc2d6cd..3d37c373b 100644 --- a/src/wx/wx_util.cc +++ b/src/wx/wx_util.cc @@ -341,6 +341,6 @@ time_to_timecode (DCPTime t, double fps) w -= m * 60; int const s = floor (w); w -= s; - int const f = rint (w * fps); + int const f = lrint (w * fps); return wxString::Format (wxT("%02d:%02d:%02d.%02d"), h, m, s, f); } diff --git a/test/audio_decoder_test.cc b/test/audio_decoder_test.cc index 8af5dfb11..00d555d86 100644 --- a/test/audio_decoder_test.cc +++ b/test/audio_decoder_test.cc @@ -51,7 +51,7 @@ public: } Frame audio_length () const { - return rint (61.2942 * audio_stream()->frame_rate ()); + return llrint (61.2942 * audio_stream()->frame_rate ()); } }; diff --git a/test/frame_rate_test.cc b/test/frame_rate_test.cc index b9fd51391..a318ada11 100644 --- a/test/frame_rate_test.cc +++ b/test/frame_rate_test.cc @@ -301,5 +301,5 @@ BOOST_AUTO_TEST_CASE (audio_sampling_rate_test) /* The FrameRateChange within resampled_audio_frame_rate should choose to double-up the 14.99 fps video to 30 and then run it slow at 25. */ - BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), rint (48000 * 2 * 14.99 / 25)); + BOOST_CHECK_EQUAL (content->resampled_audio_frame_rate(), lrint (48000 * 2 * 14.99 / 25)); } -- 2.30.2