@@ -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
@@ -451,7 +457,7 @@ class SubtitleOctopus {
451457 return &m_blendResult;
452458 }
453459
454- double findNextEventStart (double tm) {
460+ double findNextEventStart (double tm) const {
455461 if (!track || track->n_events == 0 ) return -1 ;
456462
457463 ASS_Event *cur = track->events ;
@@ -468,7 +474,7 @@ class SubtitleOctopus {
468474 return closest / 1000.0 ;
469475 }
470476
471- EventStopTimesResult* findEventStopTimes (double tm) {
477+ EventStopTimesResult* findEventStopTimes (double tm) const {
472478 static EventStopTimesResult result;
473479 if (!track || track->n_events == 0 ) {
474480 result.eventFinish = result.emptyFinish = -1 ;
@@ -492,7 +498,7 @@ class SubtitleOctopus {
492498 if (finish > maxFinish) {
493499 maxFinish = finish;
494500 }
495- if (!current_animated) current_animated = m_is_event_animated[i];
501+ if (!current_animated && m_is_event_animated ) current_animated = m_is_event_animated[i];
496502 }
497503 } else if (start < minStart || minStart == -1 ) {
498504 minStart = start;
@@ -520,18 +526,26 @@ class SubtitleOctopus {
520526 return &result;
521527 }
522528
523- private:
524- void detectAnimatedEvents () {
529+ void rescanAllAnimations () {
530+ free (m_is_event_animated);
531+ m_is_event_animated = (int *)malloc (sizeof (int ) * track->n_events );
532+ if (m_is_event_animated == NULL ) {
533+ printf (" cannot parse animated events\n " );
534+ exit (5 );
535+ }
536+
525537 ASS_Event *cur = track->events ;
526538 int *animated = m_is_event_animated;
527539 for (int i = 0 ; i < track->n_events ; i++, cur++, animated++) {
528540 *animated = _is_event_animated (cur);
529541 }
530542 }
531543
544+ private:
532545 ReusableBuffer m_blend;
533546 RenderBlendResult m_blendResult;
534547 int *m_is_event_animated;
548+ bool m_drop_animations;
535549};
536550
537551int main (int argc, char *argv[]) { return 0 ; }
0 commit comments