diff options
author | titer <[email protected]> | 2006-02-22 19:32:43 +0000 |
---|---|---|
committer | titer <[email protected]> | 2006-02-22 19:32:43 +0000 |
commit | 59fdec6de410480ca0b9eb7bb9b7e37a6ddc1384 (patch) | |
tree | 1c8a9cff6be5a3ac200dc671c3ab029c69299341 | |
parent | f2d6457b5e4951bf5cc8d4d005e5ef82b5e6eda9 (diff) |
Fix for missing subtitles
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@28 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | libhb/decsub.c | 9 | ||||
-rw-r--r-- | libhb/fifo.c | 16 | ||||
-rw-r--r-- | libhb/internal.h | 1 | ||||
-rw-r--r-- | libhb/render.c | 54 | ||||
-rw-r--r-- | libhb/sync.c | 15 |
5 files changed, 71 insertions, 24 deletions
diff --git a/libhb/decsub.c b/libhb/decsub.c index 72f742bd9..de844a1c1 100644 --- a/libhb/decsub.c +++ b/libhb/decsub.c @@ -222,6 +222,9 @@ static void ParseControls( hb_work_object_t * w ) int command; int date, next; + w->pts_start = 0; + w->pts_stop = 0; + for( i = w->size_rle; ; ) { date = ( w->buf[i] << 8 ) | w->buf[i+1]; i += 2; @@ -300,6 +303,12 @@ static void ParseControls( hb_work_object_t * w ) } i = next; } + + if( !w->pts_stop ) + { + /* Show it for 3 seconds */ + w->pts_stop = w->pts_start + 3 * 90000; + } } /*********************************************************************** diff --git a/libhb/fifo.c b/libhb/fifo.c index 81ca2a184..acdb21188 100644 --- a/libhb/fifo.c +++ b/libhb/fifo.c @@ -136,6 +136,22 @@ hb_buffer_t * hb_fifo_see( hb_fifo_t * f ) return b; } +hb_buffer_t * hb_fifo_see2( hb_fifo_t * f ) +{ + hb_buffer_t * b; + + hb_lock( f->lock ); + if( f->size < 2 ) + { + hb_unlock( f->lock ); + return NULL; + } + b = f->first->next; + hb_unlock( f->lock ); + + return b; +} + void hb_fifo_push( hb_fifo_t * f, hb_buffer_t * b ) { if( !b ) diff --git a/libhb/internal.h b/libhb/internal.h index 02fb61578..c93d48245 100644 --- a/libhb/internal.h +++ b/libhb/internal.h @@ -61,6 +61,7 @@ int hb_fifo_size( hb_fifo_t * ); int hb_fifo_is_full( hb_fifo_t * ); hb_buffer_t * hb_fifo_get( hb_fifo_t * ); hb_buffer_t * hb_fifo_see( hb_fifo_t * ); +hb_buffer_t * hb_fifo_see2( hb_fifo_t * ); void hb_fifo_push( hb_fifo_t *, hb_buffer_t * ); void hb_fifo_close( hb_fifo_t ** ); diff --git a/libhb/render.c b/libhb/render.c index 914fa3995..cdada7f18 100644 --- a/libhb/render.c +++ b/libhb/render.c @@ -34,24 +34,29 @@ static void ApplySub( hb_job_t * job, hb_buffer_t * buf, return; } - if( sub->width > title->width - job->crop[0] - job->crop[1] - 40 || - sub->height > title->height - job->crop[2] - job->crop[3] - 40 ) - { - /* The subtitle won't fit */ - hb_buffer_close( _sub ); - return; - } - - /* If necessary, move the subtitle so it is 20 pixels far from each - border of the cropped picture */ - offset_top = sub->y; - offset_top = MAX( offset_top, job->crop[0] + 20 ); - offset_top = MIN( offset_top, - title->height - job->crop[1] - 20 - sub->height ); - offset_left = sub->x; - offset_left = MAX( offset_left, job->crop[2] + 20 ); - offset_left = MIN( offset_left, - title->width - job->crop[3] - 20 - sub->width ); + /* If necessary, move the subtitle so it is not in a cropped zone. + When it won't fit, we center it so we loose as much on both ends. + Otherwise we try to leave a 20px margin around it. */ + + if( sub->height > title->height - job->crop[0] - job->crop[1] - 40 ) + offset_top = job->crop[0] + ( title->height - job->crop[0] - + job->crop[1] - sub->height ) / 2; + else if( sub->y < job->crop[0] + 20 ) + offset_top = job->crop[0] + 20; + else if( sub->y > title->height - job->crop[1] - 20 - sub->height ) + offset_top = title->height - job->crop[1] - 20 - sub->height; + else + offset_top = sub->y; + + if( sub->width > title->width - job->crop[2] - job->crop[3] - 40 ) + offset_left = job->crop[2] + ( title->width - job->crop[2] - + job->crop[3] - sub->width ) / 2; + else if( sub->x < job->crop[2] + 20 ) + offset_left = job->crop[2] + 20; + else if( sub->x > title->width - job->crop[3] - 20 - sub->width ) + offset_left = title->width - job->crop[3] - 20 - sub->width; + else + offset_left = sub->x; lum = sub->data; alpha = lum + sub->width * sub->height; @@ -59,11 +64,18 @@ static void ApplySub( hb_job_t * job, hb_buffer_t * buf, for( i = 0; i < sub->height; i++ ) { - for( j = 0; j < sub->width; j++ ) + if( offset_top + i >= 0 && offset_top + i < title->height ) { - out[j] = ( (uint16_t) out[j] * ( 16 - (uint16_t) alpha[j] ) + - (uint16_t) lum[j] * (uint16_t) alpha[j] ) >> 4; + for( j = 0; j < sub->width; j++ ) + { + if( offset_left + j >= 0 && offset_left + j < title->width ) + { + out[j] = ( (uint16_t) out[j] * ( 16 - (uint16_t) alpha[j] ) + + (uint16_t) lum[j] * (uint16_t) alpha[j] ) >> 4; + } + } } + lum += sub->width; alpha += sub->width; out += title->width; diff --git a/libhb/sync.c b/libhb/sync.c index e0530a03a..866f872b5 100644 --- a/libhb/sync.c +++ b/libhb/sync.c @@ -307,10 +307,19 @@ static int SyncVideo( hb_work_object_t * w ) /* Look for a subtitle for this frame */ if( w->subtitle ) { - /* Trash subtitles older than this picture */ - while( ( sub = hb_fifo_see( w->subtitle->fifo_raw ) ) && - sub->stop < cur->start ) + hb_buffer_t * sub2; + while( ( sub = hb_fifo_see( w->subtitle->fifo_raw ) ) ) { + /* If two subtitles overlap, make the first one stop + when the second one starts */ + sub2 = hb_fifo_see2( w->subtitle->fifo_raw ); + if( sub2 && sub->stop > sub2->start ) + sub->stop = sub2->start; + + if( sub->stop > cur->start ) + break; + + /* The subtitle is older than this picture, trash it */ sub = hb_fifo_get( w->subtitle->fifo_raw ); hb_buffer_close( &sub ); } |