Commit dffb93e1 authored by Sam Hocevar's avatar Sam Hocevar

  * ./plugins/spudec/spu_decoder.c: we now analyze the subtitle image
    data to find the border color and the inner colors when there was
    no way to find the palette data (network stream).
parent 39124c2d
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* spu_decoder.c : spu decoder thread * spu_decoder.c : spu decoder thread
***************************************************************************** *****************************************************************************
* Copyright (C) 2000-2001 VideoLAN * Copyright (C) 2000-2001 VideoLAN
* $Id: spu_decoder.c,v 1.12 2002/03/15 04:41:54 sam Exp $ * $Id: spu_decoder.c,v 1.13 2002/03/15 18:20:27 sam Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -279,6 +279,7 @@ static void ParsePacket( spudec_thread_t *p_spudec ) ...@@ -279,6 +279,7 @@ static void ParsePacket( spudec_thread_t *p_spudec )
p_spu->pf_render = RenderSPU; p_spu->pf_render = RenderSPU;
p_spu->p_sys->p_data = (void*)p_spu->p_sys p_spu->p_sys->p_data = (void*)p_spu->p_sys
+ sizeof( struct subpicture_sys_s ); + sizeof( struct subpicture_sys_s );
p_spu->p_sys->b_palette = 0;
/* Get display time now. If we do it later, we may miss the PTS. */ /* Get display time now. If we do it later, we may miss the PTS. */
p_spu->p_sys->i_pts = p_spudec->p_fifo->p_first->i_pts; p_spu->p_sys->i_pts = p_spudec->p_fifo->p_first->i_pts;
...@@ -425,23 +426,21 @@ static int ParseControlSequences( spudec_thread_t *p_spudec, ...@@ -425,23 +426,21 @@ static int ParseControlSequences( spudec_thread_t *p_spudec,
case SPU_CMD_SET_PALETTE: case SPU_CMD_SET_PALETTE:
/* 03xxxx (palette) */ /* 03xxxx (palette) */
if( p_spudec->p_config->p_demux_data )
{
p_spu->p_sys->b_palette = 1;
for( i = 0; i < 4 ; i++ ) for( i = 0; i < 4 ; i++ )
{ {
pi_color = (u8*)p_spudec->p_config->p_demux_data pi_color = (u8*)p_spudec->p_config->p_demux_data
+ 4 * GetBits( &p_spudec->bit_stream, 4 ); + 4 * GetBits( &p_spudec->bit_stream, 4 );
if( p_spudec->p_config->p_demux_data )
{
p_spu->p_sys->pi_yuv[3-i][0] = pi_color[2]; p_spu->p_sys->pi_yuv[3-i][0] = pi_color[2];
p_spu->p_sys->pi_yuv[3-i][1] = pi_color[0]; p_spu->p_sys->pi_yuv[3-i][1] = pi_color[0];
p_spu->p_sys->pi_yuv[3-i][2] = pi_color[1]; p_spu->p_sys->pi_yuv[3-i][2] = pi_color[1];
} }
}
else else
{ {
/* No data was available from the IFO file */ RemoveBits( &p_spudec->bit_stream, 16 );
p_spu->p_sys->pi_yuv[i][0] = 0x50 * i;
p_spu->p_sys->pi_yuv[i][1] = 0x80;
p_spu->p_sys->pi_yuv[i][2] = 0x80;
}
} }
i_index += 2; i_index += 2;
...@@ -602,6 +601,10 @@ static int ParseRLE( spudec_thread_t *p_spudec, ...@@ -602,6 +601,10 @@ static int ParseRLE( spudec_thread_t *p_spudec,
unsigned int i_skipped_top = 0, unsigned int i_skipped_top = 0,
i_skipped_bottom = 0; i_skipped_bottom = 0;
/* Colormap statistics */
int i_border = -1;
int stats[4]; stats[0] = stats[1] = stats[2] = stats[3] = 0;
pi_table[ 0 ] = p_spu->p_sys->pi_offset[ 0 ] << 1; pi_table[ 0 ] = p_spu->p_sys->pi_offset[ 0 ] << 1;
pi_table[ 1 ] = p_spu->p_sys->pi_offset[ 1 ] << 1; pi_table[ 1 ] = p_spu->p_sys->pi_offset[ 1 ] << 1;
...@@ -653,8 +656,15 @@ static int ParseRLE( spudec_thread_t *p_spudec, ...@@ -653,8 +656,15 @@ static int ParseRLE( spudec_thread_t *p_spudec,
return( 1 ); return( 1 );
} }
/* Try to find the border color */
if( p_spu->p_sys->pi_alpha[ i_code & 0x3 ] != 0x00 )
{
i_border = i_code & 0x3;
stats[i_border] += i_code >> 2;
}
if( (i_code >> 2) == i_width if( (i_code >> 2) == i_width
&& !p_spu->p_sys->pi_alpha[ i_code & 0x3 ] ) && p_spu->p_sys->pi_alpha[ i_code & 0x3 ] == 0x00 )
{ {
if( b_empty_top ) if( b_empty_top )
{ {
...@@ -731,6 +741,62 @@ static int ParseRLE( spudec_thread_t *p_spudec, ...@@ -731,6 +741,62 @@ static int ParseRLE( spudec_thread_t *p_spudec,
p_spu->i_width, p_spu->i_height, p_spu->i_x, p_spu->i_y ); p_spu->i_width, p_spu->i_height, p_spu->i_x, p_spu->i_y );
} }
/* Handle color if no palette was found */
if( !p_spu->p_sys->b_palette )
{
int i, i_inner = -1, i_shade = -1;
/* Set the border color */
p_spu->p_sys->pi_yuv[i_border][0] = 0x00;
p_spu->p_sys->pi_yuv[i_border][1] = 0x80;
p_spu->p_sys->pi_yuv[i_border][2] = 0x80;
stats[i_border] = 0;
/* Find the inner colors */
for( i = 0 ; i < 4 && i_inner == -1 ; i++ )
{
if( stats[i] )
{
i_inner = i;
}
}
for( ; i < 4 && i_shade == -1 ; i++ )
{
if( stats[i] )
{
if( stats[i] > stats[i_inner] )
{
i_shade = i_inner;
i_inner = i;
}
else
{
i_shade = i;
}
}
}
/* Set the inner color */
if( i_inner != -1 )
{
p_spu->p_sys->pi_yuv[i_inner][0] = 0xff;
p_spu->p_sys->pi_yuv[i_inner][1] = 0x80;
p_spu->p_sys->pi_yuv[i_inner][2] = 0x80;
}
/* Set the anti-aliasing color */
if( i_shade != -1 )
{
p_spu->p_sys->pi_yuv[i_shade][0] = 0x80;
p_spu->p_sys->pi_yuv[i_shade][1] = 0x80;
p_spu->p_sys->pi_yuv[i_shade][2] = 0x80;
}
intf_WarnMsg( 3, "spudec: using custom palette (border %i, inner %i, "
"shade %i)", i_border, i_inner, i_shade );
}
return( 0 ); return( 0 );
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* spu_decoder.h : sub picture unit decoder thread interface * spu_decoder.h : sub picture unit decoder thread interface
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN * Copyright (C) 1999, 2000 VideoLAN
* $Id: spu_decoder.h,v 1.2 2002/03/15 04:41:54 sam Exp $ * $Id: spu_decoder.h,v 1.3 2002/03/15 18:20:27 sam Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -29,6 +29,7 @@ typedef struct subpicture_sys_s ...@@ -29,6 +29,7 @@ typedef struct subpicture_sys_s
void *p_data; void *p_data;
/* Color information */ /* Color information */
boolean_t b_palette;
u8 pi_alpha[4]; u8 pi_alpha[4];
u8 pi_yuv[4][3]; u8 pi_yuv[4][3];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment