@@ -29,7 +29,7 @@ const AVS_Linkage *AVS_linkage=NULL;
29
29
// Filters are created in order of appearance in AVS file
30
30
OCRFilter::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):
31
31
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()
33
33
{
34
34
if (interval<0 )
35
35
env->ThrowError (" SegmentDisplayOCR: interval can't be negative number!" );
@@ -95,13 +95,22 @@ OCRFilter::~OCRFilter()
95
95
log_file.close ();
96
96
}
97
97
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
+
98
107
// GetFrame is called only when client or parent filter requests frame
99
108
PVideoFrame __stdcall OCRFilter::GetFrame (int n, IScriptEnvironment *env)
100
109
{
101
110
PVideoFrame src=child->GetFrame (n, env);
102
111
103
112
// 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) ;
105
114
bool newer=IsNewer (n);
106
115
bool alarm =CheckTimer (cur_mseconds);
107
116
std::string timestamp=(debug||(time_format==TMS&&alarm ))?GetTimestamp (cur_mseconds):" " ;
@@ -165,7 +174,7 @@ bool OCRFilter::CheckTimer(unsigned int cur_mseconds)
165
174
return true ;
166
175
167
176
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) ))
169
178
return true ;
170
179
else
171
180
return false ;
0 commit comments