[vlc-commits] oldmovie: factorize the code to randomize end triggers

Steve Lhomme git at videolan.org
Tue Sep 18 16:42:41 CEST 2018


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Jun 14 09:12:45 2018 +0200| [dc902f4edc03a264ab9f287f3b61e9fd641681dd] | committer: Steve Lhomme

oldmovie: factorize the code to randomize end triggers

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=dc902f4edc03a264ab9f287f3b61e9fd641681dd
---

 modules/video_filter/oldmovie.c | 49 ++++++++++++++---------------------------
 1 file changed, 16 insertions(+), 33 deletions(-)

diff --git a/modules/video_filter/oldmovie.c b/modules/video_filter/oldmovie.c
index eb418b869e..0dc2e6773b 100644
--- a/modules/video_filter/oldmovie.c
+++ b/modules/video_filter/oldmovie.c
@@ -390,6 +390,11 @@ static void oldmovie_shutter_effect( filter_t *p_filter, picture_t *p_pic_out )
             DARKEN_PIXEL( i_x, i_y, SHUTTER_INTENSITY, &p_pic_out->p[Y_PLANE] );
 }
 
+static vlc_tick_t RandomEnd(filter_sys_t *p_sys, vlc_tick_t modulo)
+{
+    return p_sys->i_cur_time + (uint64_t)vlc_mrand48() % modulo + modulo / 2;
+}
+
 /**
  * sliding & offset effect
  */
@@ -407,9 +412,7 @@ static int oldmovie_sliding_offset_effect( filter_t *p_filter, picture_t *p_pic_
     if ( p_sys->i_offset_trigger == 0
          || p_sys->i_sliding_speed != 0 ) { /* do not mix sliding and offset */
         /* random trigger for offset effect */
-        p_sys->i_offset_trigger = p_sys->i_cur_time
-                                + ( (uint64_t) vlc_mrand48() ) % OFFSET_AVERAGE_PERIOD
-                                + OFFSET_AVERAGE_PERIOD / 2;
+        p_sys->i_offset_trigger = RandomEnd(p_sys, OFFSET_AVERAGE_PERIOD);
         p_sys->i_offset_ofs = 0;
     } else if ( p_sys->i_offset_trigger <= p_sys->i_cur_time ) {
         /* trigger for offset effect */
@@ -432,9 +435,7 @@ static int oldmovie_sliding_offset_effect( filter_t *p_filter, picture_t *p_pic_
          && ( p_sys->i_sliding_trigger    == 0 )
          && ( p_sys->i_sliding_speed      == 0 ) ) {
         /* random trigger which enable sliding effect */
-        p_sys->i_sliding_trigger = p_sys->i_cur_time
-                                 + ( (uint64_t) vlc_mrand48() ) % SLIDING_AVERAGE_PERIOD
-                                 + SLIDING_AVERAGE_PERIOD / 2;
+        p_sys->i_sliding_trigger = RandomEnd(p_sys, SLIDING_AVERAGE_PERIOD);
     }
     /* start trigger just occurs */
     else if (    ( p_sys->i_sliding_stop_trig  == 0 )
@@ -442,9 +443,7 @@ static int oldmovie_sliding_offset_effect( filter_t *p_filter, picture_t *p_pic_
               && ( p_sys->i_sliding_speed      == 0 ) ) {
         /* init sliding parameters */
         p_sys->i_sliding_trigger   = 0;
-        p_sys->i_sliding_stop_trig = p_sys->i_cur_time
-                                   + ((uint64_t) vlc_mrand48() ) % SLIDING_AVERAGE_DURATION
-                                   + SLIDING_AVERAGE_DURATION / 2;
+        p_sys->i_sliding_stop_trig = RandomEnd(p_sys, SLIDING_AVERAGE_DURATION);
         p_sys->i_sliding_ofs = 0;
         /* note: sliding speed unit = image per 100 s */
         p_sys->i_sliding_speed = MOD(((int32_t) vlc_mrand48() ), 201) - 100;
@@ -594,15 +593,11 @@ static int oldmovie_film_scratch_effect( filter_t *p_filter, picture_t *p_pic_ou
                                                 % __MAX( p_sys->i_width[Y_PLANE] / 500, 1 ) )
                                                 + 1;
                 p_sys->p_scratch[i_s]->i_intensity = (unsigned) vlc_mrand48() % 50 + 10;
-                p_sys->p_scratch[i_s]->i_stop_trigger = p_sys->i_cur_time
-                                                      + (uint64_t) vlc_mrand48() % SCRATCH_DURATION
-                                                      + SCRATCH_DURATION / 2;
+                p_sys->p_scratch[i_s]->i_stop_trigger = RandomEnd(p_sys, SCRATCH_DURATION);
 
                 break;
             }
-        p_sys->i_scratch_trigger = p_sys->i_cur_time
-                                 + ( (uint64_t)vlc_mrand48() ) % SCRATCH_GENERATOR_PERIOD
-                                 + SCRATCH_GENERATOR_PERIOD / 2;
+        p_sys->i_scratch_trigger = RandomEnd(p_sys, SCRATCH_GENERATOR_PERIOD);
     }
 
     /* manage and apply current scratch */
@@ -661,9 +656,7 @@ static void oldmovie_film_blotch_effect( filter_t *p_filter, picture_t *p_pic_ou
                                                i_intensity, &p_pic_out->p[Y_PLANE] );
         }
 
-        p_sys->i_blotch_trigger = p_sys->i_cur_time
-                                + (uint64_t)vlc_mrand48() % BLOTCH_GENERATOR_PERIOD
-                                + BLOTCH_GENERATOR_PERIOD / 2;
+        p_sys->i_blotch_trigger = RandomEnd(p_sys, BLOTCH_GENERATOR_PERIOD);
     }
 }
 
@@ -708,9 +701,7 @@ static void oldmovie_define_hair_location( filter_t *p_filter, hair_t* ps_hair )
     ps_hair->i_y = (unsigned)vlc_mrand48() % p_sys->i_height[Y_PLANE];
     ps_hair->i_rotation = (unsigned)vlc_mrand48() % 200;
 
-    ps_hair->i_stop_trigger = p_sys->i_cur_time
-                            + (uint64_t)vlc_mrand48() % HAIR_DURATION
-                            + HAIR_DURATION / 2;
+    ps_hair->i_stop_trigger = RandomEnd(p_sys, HAIR_DURATION);
 }
 
 /**
@@ -741,9 +732,7 @@ static int oldmovie_lens_hair_effect( filter_t *p_filter, picture_t *p_pic_out )
 
                 break;
             }
-        p_sys->i_hair_trigger = p_sys->i_cur_time
-                              + (uint64_t)vlc_mrand48() % HAIR_GENERATOR_PERIOD
-                              + HAIR_GENERATOR_PERIOD / 2;
+        p_sys->i_hair_trigger = RandomEnd(p_sys, HAIR_GENERATOR_PERIOD);
     }
 
     /* manage and apply current hair */
@@ -797,17 +786,13 @@ static void oldmovie_define_dust_location( filter_t *p_filter, dust_t* ps_dust )
     ps_dust->i_x = (unsigned)vlc_mrand48() % p_sys->i_width[Y_PLANE];
     ps_dust->i_y = (unsigned)vlc_mrand48() % p_sys->i_height[Y_PLANE];
 
-    ps_dust->i_stop_trigger = p_sys->i_cur_time
-                            + (uint64_t)vlc_mrand48() % HAIR_DURATION
-                            + HAIR_DURATION / 2;
+    ps_dust->i_stop_trigger = RandomEnd(p_sys, HAIR_DURATION);
 
 
     ps_dust->i_x = MOD( (int32_t)vlc_mrand48(), p_sys->i_width[Y_PLANE]  );
     ps_dust->i_y = MOD( (int32_t)vlc_mrand48(), p_sys->i_height[Y_PLANE] );
 
-    ps_dust->i_stop_trigger = p_sys->i_cur_time
-                            + (uint64_t)vlc_mrand48() % DUST_DURATION
-                            + DUST_DURATION / 2;
+    ps_dust->i_stop_trigger = RandomEnd(p_sys, DUST_DURATION);
 }
 
 /**
@@ -833,9 +818,7 @@ static int oldmovie_lens_dust_effect( filter_t *p_filter, picture_t *p_pic_out )
 
                 break;
             }
-        p_sys->i_dust_trigger = p_sys->i_cur_time
-                              + (uint64_t)vlc_mrand48() % DUST_GENERATOR_PERIOD
-                              + DUST_GENERATOR_PERIOD / 2;
+        p_sys->i_dust_trigger = RandomEnd(p_sys, DUST_GENERATOR_PERIOD);
     }
 
     /* manage and apply current dust */



More information about the vlc-commits mailing list