@@ -199,19 +199,23 @@ class SubtitleOctopus {
199199
200200 int status;
201201
202- SubtitleOctopus () {
203- status = 0 ;
204- ass_library = NULL ;
205- ass_renderer = NULL ;
206- track = NULL ;
207- canvas_w = 0 ;
208- canvas_h = 0 ;
202+ SubtitleOctopus (): status(0 ), ass_library(NULL ), ass_renderer(NULL ), track(NULL ), canvas_w(0 ), canvas_h(0 ), m_is_event_animated(NULL ), m_drop_animations(false ) {
209203 }
210204
211205 void setLogLevel (int level) {
212206 log_level = level;
213207 }
214208
209+ void setDropAnimations (bool value) {
210+ bool rescan = m_drop_animations != value && track != NULL ;
211+ m_drop_animations = value;
212+ if (rescan) rescanAllAnimations ();
213+ }
214+
215+ bool getDropAnimations () const {
216+ return m_drop_animations;
217+ }
218+
215219 void initLibrary (int frame_w, int frame_h) {
216220 ass_library = ass_library_init ();
217221 if (!ass_library) {
@@ -242,14 +246,7 @@ class SubtitleOctopus {
242246 printf (" Failed to start a track\n " );
243247 exit (4 );
244248 }
245-
246- free (m_is_event_animated);
247- m_is_event_animated = (int *)malloc (sizeof (int ) * track->n_events );
248- if (m_is_event_animated == NULL ) {
249- printf (" cannot parse animated events\n " );
250- exit (5 );
251- }
252- detectAnimatedEvents ();
249+ rescanAllAnimations ();
253250 }
254251
255252 void createTrackMem (char *buf, unsigned long bufsize) {
@@ -259,6 +256,7 @@ class SubtitleOctopus {
259256 printf (" Failed to start a track\n " );
260257 exit (4 );
261258 }
259+ rescanAllAnimations ();
262260 }
263261
264262 void removeTrack () {
@@ -277,6 +275,7 @@ class SubtitleOctopus {
277275 canvas_h = frame_h;
278276 canvas_w = frame_w;
279277 }
278+
280279 ASS_Image* renderImage (double time, int * changed) {
281280 ASS_Image *img = ass_render_frame (ass_renderer, track, (int ) (time * 1000 ), changed);
282281 return img;
@@ -291,6 +290,7 @@ class SubtitleOctopus {
291290 free (m_is_event_animated);
292291 m_is_event_animated = NULL ;
293292 }
293+
294294 void reloadLibrary () {
295295 quitLibrary ();
296296
@@ -305,23 +305,27 @@ class SubtitleOctopus {
305305 ass_set_margins (ass_renderer, top, bottom, left, right);
306306 }
307307
308- int getEventCount () {
308+ int getEventCount () const {
309309 return track->n_events ;
310310 }
311311
312312 int allocEvent () {
313+ free (m_is_event_animated);
314+ m_is_event_animated = NULL ;
313315 return ass_alloc_event (track);
314316 }
315317
316318 void removeEvent (int eid) {
319+ free (m_is_event_animated);
320+ m_is_event_animated = NULL ;
317321 ass_free_event (track, eid);
318322 }
319323
320- int getStyleCount () {
324+ int getStyleCount () const {
321325 return track->n_styles ;
322326 }
323327
324- int getStyleByName (const char * name) {
328+ int getStyleByName (const char * name) const {
325329 for (int n = 0 ; n < track->n_styles ; n++) {
326330 if (track->styles [n].Name && strcmp (track->styles [n].Name , name) == 0 )
327331 return n;
@@ -338,6 +342,8 @@ class SubtitleOctopus {
338342 }
339343
340344 void removeAllEvents () {
345+ free (m_is_event_animated);
346+ m_is_event_animated = NULL ;
341347 ass_flush_events (track);
342348 }
343349
@@ -452,7 +458,7 @@ class SubtitleOctopus {
452458 return &m_blendResult;
453459 }
454460
455- double findNextEventStart (double tm) {
461+ double findNextEventStart (double tm) const {
456462 if (!track || track->n_events == 0 ) return -1 ;
457463
458464 ASS_Event *cur = track->events ;
@@ -469,7 +475,7 @@ class SubtitleOctopus {
469475 return closest / 1000.0 ;
470476 }
471477
472- EventStopTimesResult* findEventStopTimes (double tm) {
478+ EventStopTimesResult* findEventStopTimes (double tm) const {
473479 static EventStopTimesResult result;
474480 if (!track || track->n_events == 0 ) {
475481 result.eventFinish = result.emptyFinish = -1 ;
@@ -493,7 +499,7 @@ class SubtitleOctopus {
493499 if (finish > maxFinish) {
494500 maxFinish = finish;
495501 }
496- if (!current_animated) current_animated = m_is_event_animated[i];
502+ if (!current_animated && m_is_event_animated ) current_animated = m_is_event_animated[i];
497503 }
498504 } else if (start < minStart || minStart == -1 ) {
499505 minStart = start;
@@ -521,18 +527,26 @@ class SubtitleOctopus {
521527 return &result;
522528 }
523529
524- private:
525- void detectAnimatedEvents () {
530+ void rescanAllAnimations () {
531+ free (m_is_event_animated);
532+ m_is_event_animated = (int *)malloc (sizeof (int ) * track->n_events );
533+ if (m_is_event_animated == NULL ) {
534+ printf (" cannot parse animated events\n " );
535+ exit (5 );
536+ }
537+
526538 ASS_Event *cur = track->events ;
527539 int *animated = m_is_event_animated;
528540 for (int i = 0 ; i < track->n_events ; i++, cur++, animated++) {
529541 *animated = _is_event_animated (cur);
530542 }
531543 }
532544
545+ private:
533546 ReusableBuffer m_blend;
534547 RenderBlendResult m_blendResult;
535548 int *m_is_event_animated;
549+ bool m_drop_animations;
536550};
537551
538552int main (int argc, char *argv[]) { return 0 ; }
0 commit comments