@@ -80,29 +80,16 @@ const float MAX_UINT8_CAST = 255.9 / 255;
80
80
#define CLAMP_UINT8 (value ) ((value > MIN_UINT8_CAST) ? ((value < MAX_UINT8_CAST) ? (int )(value * 255 ) : 255 ) : 0 )
81
81
82
82
typedef struct {
83
- public:
84
83
int changed;
85
84
double blend_time;
86
85
int dest_x, dest_y, dest_width, dest_height;
87
86
unsigned char * image;
88
87
} RenderBlendResult;
89
88
90
- double libassjs_find_next_event_start (double tm ) {
91
- if (!track || track->n_events == 0 ) return -1 ;
92
-
93
- ASS_Event *cur = track->events ;
94
- long long now = (long long )(tm * 1000 );
95
- long long closest = -1 ;
96
-
97
- for (int i = 0 ; i < track->n_events ; i++, cur++) {
98
- long long start = cur->Start ;
99
- if (start >= now && (start < closest || closest == -1 )) {
100
- closest = start;
101
- }
102
- }
103
-
104
- return closest / 1000.0 ;
105
- }
89
+ typedef struct {
90
+ double eventFinish, emptyFinish;
91
+ int is_animated;
92
+ } EventStopTimesResult;
106
93
107
94
static int _is_move_tag_animated (char *begin, char *end) {
108
95
int params[6 ];
@@ -201,63 +188,6 @@ static int _is_event_animated(ASS_Event *event) {
201
188
return 0 ;
202
189
}
203
190
204
- static void detect_animated_events () {
205
- ASS_Event *cur = track->events ;
206
- int *animated = is_animated_events;
207
- for (int i = 0 ; i < track->n_events ; i++, cur++, animated++) {
208
- *animated = _is_event_animated (cur);
209
- }
210
- }
211
-
212
- void libassjs_find_event_stop_times (double tm , double *eventFinish, double *emptyFinish, int *is_animated) {
213
- if (!track || track->n_events == 0 ) {
214
- *eventFinish = *emptyFinish = -1 ;
215
- return ;
216
- }
217
-
218
- ASS_Event *cur = track->events ;
219
- long long now = (long long )(tm * 1000 );
220
-
221
- long long minFinish = -1 , maxFinish = -1 , minStart = -1 ;
222
- int current_animated = 0 ;
223
-
224
- for (int i = 0 ; i < track->n_events ; i++, cur++) {
225
- long long start = cur->Start ;
226
- long long finish = start + cur->Duration ;
227
- if (start <= now) {
228
- if (finish > now) {
229
- if (finish < minFinish || minFinish == -1 ) {
230
- minFinish = finish;
231
- }
232
- if (finish > maxFinish) {
233
- maxFinish = finish;
234
- }
235
- if (!current_animated) current_animated = m_is_event_animated[i];
236
- }
237
- } else if (start < minStart || minStart == -1 ) {
238
- minStart = start;
239
- }
240
- }
241
- *is_animated = current_animated;
242
-
243
- if (minFinish != -1 ) {
244
- // some event is going on, so we need to re-draw either when it stops
245
- // or when some other event starts
246
- *eventFinish = ((minFinish < minStart) ? minFinish : minStart) / 1000.0 ;
247
- } else {
248
- // there's no current event, so no need to draw anything
249
- *eventFinish = -1 ;
250
- }
251
-
252
- if (minFinish == maxFinish && (minStart == -1 || minStart > maxFinish)) {
253
- // there's empty space after this event ends
254
- *emptyFinish = minStart / 1000.0 ;
255
- } else {
256
- // there's no empty space after eventFinish happens
257
- *emptyFinish = *eventFinish;
258
- }
259
- }
260
-
261
191
class SubtitleOctopus {
262
192
public:
263
193
ASS_Library* ass_library;
@@ -319,7 +249,7 @@ class SubtitleOctopus {
319
249
printf (" cannot parse animated events\n " );
320
250
exit (5 );
321
251
}
322
- detect_animated_events ();
252
+ detectAnimatedEvents ();
323
253
}
324
254
325
255
void createTrackMem (char *buf, unsigned long bufsize) {
@@ -521,7 +451,84 @@ class SubtitleOctopus {
521
451
return &m_blendResult;
522
452
}
523
453
454
+ double findNextEventStart (double tm ) {
455
+ if (!track || track->n_events == 0 ) return -1 ;
456
+
457
+ ASS_Event *cur = track->events ;
458
+ long long now = (long long )(tm * 1000 );
459
+ long long closest = -1 ;
460
+
461
+ for (int i = 0 ; i < track->n_events ; i++, cur++) {
462
+ long long start = cur->Start ;
463
+ if (start >= now && (start < closest || closest == -1 )) {
464
+ closest = start;
465
+ }
466
+ }
467
+
468
+ return closest / 1000.0 ;
469
+ }
470
+
471
+ EventStopTimesResult findEventStopTimes (double tm ) {
472
+ EventStopTimesResult result;
473
+ if (!track || track->n_events == 0 ) {
474
+ result.eventFinish = result.emptyFinish = -1 ;
475
+ return result;
476
+ }
477
+
478
+ ASS_Event *cur = track->events ;
479
+ long long now = (long long )(tm * 1000 );
480
+
481
+ long long minFinish = -1 , maxFinish = -1 , minStart = -1 ;
482
+ int current_animated = 0 ;
483
+
484
+ for (int i = 0 ; i < track->n_events ; i++, cur++) {
485
+ long long start = cur->Start ;
486
+ long long finish = start + cur->Duration ;
487
+ if (start <= now) {
488
+ if (finish > now) {
489
+ if (finish < minFinish || minFinish == -1 ) {
490
+ minFinish = finish;
491
+ }
492
+ if (finish > maxFinish) {
493
+ maxFinish = finish;
494
+ }
495
+ if (!current_animated) current_animated = m_is_event_animated[i];
496
+ }
497
+ } else if (start < minStart || minStart == -1 ) {
498
+ minStart = start;
499
+ }
500
+ }
501
+ result.is_animated = current_animated;
502
+
503
+ if (minFinish != -1 ) {
504
+ // some event is going on, so we need to re-draw either when it stops
505
+ // or when some other event starts
506
+ result.eventFinish = ((minFinish < minStart) ? minFinish : minStart) / 1000.0 ;
507
+ } else {
508
+ // there's no current event, so no need to draw anything
509
+ result.eventFinish = -1 ;
510
+ }
511
+
512
+ if (minFinish == maxFinish && (minStart == -1 || minStart > maxFinish)) {
513
+ // there's empty space after this event ends
514
+ result.emptyFinish = minStart / 1000.0 ;
515
+ } else {
516
+ // there's no empty space after eventFinish happens
517
+ result.emptyFinish = result.eventFinish ;
518
+ }
519
+
520
+ return result;
521
+ }
522
+
524
523
private:
524
+ void detectAnimatedEvents () {
525
+ ASS_Event *cur = track->events ;
526
+ int *animated = m_is_event_animated;
527
+ for (int i = 0 ; i < track->n_events ; i++, cur++, animated++) {
528
+ *animated = _is_event_animated (cur);
529
+ }
530
+ }
531
+
525
532
ReusableBuffer m_blend;
526
533
RenderBlendResult m_blendResult;
527
534
int *m_is_event_animated;
0 commit comments