@@ -29,7 +29,7 @@ const AVS_Linkage *AVS_linkage=NULL;
2929// Filters are created in order of appearance in AVS file
3030OCRFilter::OCRFilter (PClip child, const char * log_file, bool log_append, int interval, const char * time_format, bool debug, bool localized_output, bool inverted, const char * threshold, IScriptEnvironment *env):
3131 GenericVideoFilter(child),
32- fduration((unsigned int )( (double )vi.fps_denominator/vi.fps_numerator*1000)), timer(interval*1000 ), last_frame(-1 ), time_format(SEC), debug(debug), log_file(), csv_sep(), dec_sep(), neg_sign(), ssocr()
32+ fduration(((double )vi.fps_denominator/vi.fps_numerator*1000)), timer(interval*1000 ), last_frame(-1 ), time_format(SEC), debug(debug), log_file(), csv_sep(), dec_sep(), neg_sign(), ssocr()
3333{
3434 if (interval<0 )
3535 env->ThrowError (" SegmentDisplayOCR: interval can't be negative number!" );
@@ -95,13 +95,22 @@ OCRFilter::~OCRFilter()
9595 log_file.close ();
9696}
9797
98+ // Rounding algorithm from Java 7
99+ int OCRFilter::Round (double num)
100+ {
101+ if (num!=0.49999999999999994 )
102+ return (int )floor (num+0.5 );
103+ else
104+ return 0 ;
105+ }
106+
98107// GetFrame is called only when client or parent filter requests frame
99108PVideoFrame __stdcall OCRFilter::GetFrame (int n, IScriptEnvironment *env)
100109{
101110 PVideoFrame src=child->GetFrame (n, env);
102111
103112 // For the sake of optimization, following variables are computed only ones per iteration
104- unsigned int cur_mseconds=fduration*n;
113+ unsigned int cur_mseconds=Round ( fduration*n) ;
105114 bool newer=IsNewer (n);
106115 bool alarm=CheckTimer (cur_mseconds);
107116 std::string timestamp=(debug||(time_format==TMS&&alarm))?GetTimestamp (cur_mseconds):" " ;
@@ -165,7 +174,7 @@ bool OCRFilter::CheckTimer(unsigned int cur_mseconds)
165174 return true ;
166175
167176 unsigned int last_alarm=cur_mseconds-cur_mseconds%timer;
168- if (cur_mseconds>=last_alarm&&cur_mseconds<(last_alarm+fduration))
177+ if (cur_mseconds>=last_alarm&&cur_mseconds<(last_alarm+Round ( fduration) ))
169178 return true ;
170179 else
171180 return false ;
0 commit comments