1 /*****************************************************************************
2 * spu_decoder.c : spu decoder thread
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: spu_decoder.c,v 1.20 2002/05/15 00:40:26 sam Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Rudolf Cornelissen <rag.cornelissen@inter.nl.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
29 #include <string.h> /* memcpy(), memset() */
31 #include <videolan/vlc.h>
34 # include <unistd.h> /* getpid() */
37 #ifdef WIN32 /* getpid() for win32 is located in process.h */
42 #include "video_output.h"
44 #include "stream_control.h"
45 #include "input_ext-dec.h"
47 #include "spu_decoder.h"
49 /*****************************************************************************
51 *****************************************************************************/
52 static int decoder_Probe ( u8
* );
53 static int decoder_Run ( decoder_config_t
* );
54 static int InitThread ( spudec_thread_t
* );
55 static void EndThread ( spudec_thread_t
* );
57 static int SyncPacket ( spudec_thread_t
* );
58 static void ParsePacket ( spudec_thread_t
* );
59 static int ParseControlSequences( spudec_thread_t
*, subpicture_t
* );
60 static int ParseRLE ( spudec_thread_t
*, subpicture_t
*, u8
* );
61 static void RenderSPU ( const vout_thread_t
*, picture_t
*,
62 const subpicture_t
* );
64 /*****************************************************************************
66 *****************************************************************************/
67 void _M( spudec_getfunctions
)( function_list_t
* p_function_list
)
69 p_function_list
->functions
.dec
.pf_probe
= decoder_Probe
;
70 p_function_list
->functions
.dec
.pf_run
= decoder_Run
;
73 /*****************************************************************************
74 * Build configuration tree.
75 *****************************************************************************/
80 SET_DESCRIPTION( _("DVD subtitles decoder module") )
81 ADD_CAPABILITY( DECODER
, 50 )
85 _M( spudec_getfunctions
)( &p_module
->p_functions
->dec
);
88 MODULE_DEACTIVATE_START
89 MODULE_DEACTIVATE_STOP
91 /*****************************************************************************
92 * decoder_Probe: probe the decoder and return score
93 *****************************************************************************
94 * Tries to launch a decoder and return score so that the interface is able
96 *****************************************************************************/
97 static int decoder_Probe( u8
*pi_type
)
99 return ( *pi_type
== DVD_SPU_ES
) ? 0 : -1;
102 /*****************************************************************************
103 * decoder_Run: this function is called just after the thread is created
104 *****************************************************************************/
105 static int decoder_Run( decoder_config_t
* p_config
)
107 spudec_thread_t
* p_spudec
;
109 intf_WarnMsg( 3, "spudec: thread launched. Initializing ..." );
111 /* Allocate the memory needed to store the thread's structure */
112 p_spudec
= (spudec_thread_t
*)malloc( sizeof(spudec_thread_t
) );
114 if ( p_spudec
== NULL
)
116 intf_ErrMsg( "spudec error: not enough memory "
117 "for spudec_CreateThread() to create the new thread" );
118 DecoderError( p_config
->p_decoder_fifo
);
123 * Initialize the thread properties
125 p_spudec
->p_config
= p_config
;
127 p_spudec
->p_fifo
= p_config
->p_decoder_fifo
;
130 * Initialize thread and free configuration
132 p_spudec
->p_fifo
->b_error
= InitThread( p_spudec
);
135 * Main loop - it is not executed if an error occured during
138 while( (!p_spudec
->p_fifo
->b_die
) && (!p_spudec
->p_fifo
->b_error
) )
140 if( !SyncPacket( p_spudec
) )
142 ParsePacket( p_spudec
);
149 if( p_spudec
->p_fifo
->b_error
)
151 DecoderError( p_spudec
->p_fifo
);
155 boolean_t b_error
= p_spudec
->p_fifo
->b_error
;
158 EndThread( p_spudec
);
169 /* following functions are local */
171 /*****************************************************************************
172 * InitThread: initialize spu decoder thread
173 *****************************************************************************
174 * This function is called from RunThread and performs the second step of the
175 * initialization. It returns 0 on success. Note that the thread's flag are not
176 * modified inside this function.
177 *****************************************************************************/
178 static int InitThread( spudec_thread_t
*p_spudec
)
180 /* Find an available video output */
181 vlc_mutex_lock( &p_vout_bank
->lock
);
183 while( p_vout_bank
->i_count
== 0 )
185 vlc_mutex_unlock( &p_vout_bank
->lock
);
187 if( p_spudec
->p_fifo
->b_die
|| p_spudec
->p_fifo
->b_error
)
192 msleep( VOUT_OUTMEM_SLEEP
);
193 vlc_mutex_lock( &p_vout_bank
->lock
);
196 /* Take the first video output FIXME: take the best one */
197 p_spudec
->p_vout
= p_vout_bank
->pp_vout
[ 0 ];
198 vlc_mutex_unlock( &p_vout_bank
->lock
);
199 InitBitstream( &p_spudec
->bit_stream
,
200 p_spudec
->p_config
->p_decoder_fifo
, NULL
, NULL
);
202 /* Mark thread as running and return */
206 /*****************************************************************************
207 * EndThread: thread destruction
208 *****************************************************************************
209 * This function is called when the thread ends after a sucessful
211 *****************************************************************************/
212 static void EndThread( spudec_thread_t
*p_spudec
)
217 /*****************************************************************************
218 * SyncPacket: get in sync with the stream
219 *****************************************************************************
220 * This function makes a few sanity checks and returns 0 if it looks like we
221 * are at the beginning of a subpicture packet.
222 *****************************************************************************/
223 static int SyncPacket( spudec_thread_t
*p_spudec
)
225 /* Re-align the buffer on an 8-bit boundary */
226 RealignBits( &p_spudec
->bit_stream
);
228 /* The total SPU packet size, often bigger than a PS packet */
229 p_spudec
->i_spu_size
= GetBits( &p_spudec
->bit_stream
, 16 );
231 /* The RLE stuff size (remove 4 because we just read 32 bits) */
232 p_spudec
->i_rle_size
= ShowBits( &p_spudec
->bit_stream
, 16 ) - 4;
234 /* If the values we got are a bit strange, skip packet */
235 if( !p_spudec
->i_spu_size
236 || ( p_spudec
->i_rle_size
>= p_spudec
->i_spu_size
) )
241 RemoveBits( &p_spudec
->bit_stream
, 16 );
246 /*****************************************************************************
247 * ParsePacket: parse an SPU packet and send it to the video output
248 *****************************************************************************
249 * This function parses the SPU packet and, if valid, sends it to the
251 *****************************************************************************/
252 static void ParsePacket( spudec_thread_t
*p_spudec
)
254 subpicture_t
* p_spu
;
256 unsigned int i_offset
;
258 intf_WarnMsg( 3, "spudec: trying to gather a 0x%.2x long subtitle",
259 p_spudec
->i_spu_size
);
261 /* We cannot display a subpicture with no date */
262 if( p_spudec
->p_fifo
->p_first
->i_pts
== 0 )
264 intf_WarnMsg( 3, "spudec error: subtitle without a date" );
268 /* Allocate the subpicture internal data. */
269 p_spu
= vout_CreateSubPicture( p_spudec
->p_vout
, MEMORY_SUBPICTURE
,
270 sizeof( struct subpicture_sys_s
)
271 + p_spudec
->i_rle_size
* 4 );
272 /* Rationale for the "p_spudec->i_rle_size * 4": we are going to
273 * expand the RLE stuff so that we won't need to read nibbles later
274 * on. This will speed things up a lot. Plus, we'll only need to do
275 * this stupid interlacing stuff once. */
282 /* Fill the p_spu structure */
283 p_spu
->pf_render
= RenderSPU
;
284 p_spu
->p_sys
->p_data
= (u8
*)p_spu
->p_sys
285 + sizeof( struct subpicture_sys_s
);
286 p_spu
->p_sys
->b_palette
= 0;
288 /* Get display time now. If we do it later, we may miss the PTS. */
289 p_spu
->p_sys
->i_pts
= p_spudec
->p_fifo
->p_first
->i_pts
;
291 /* Allocate the temporary buffer we will parse */
292 p_src
= malloc( p_spudec
->i_rle_size
);
296 intf_ErrMsg( "spudec error: could not allocate p_src" );
297 vout_DestroySubPicture( p_spudec
->p_vout
, p_spu
);
303 i_offset
+ SPU_CHUNK_SIZE
< p_spudec
->i_rle_size
;
304 i_offset
+= SPU_CHUNK_SIZE
)
306 GetChunk( &p_spudec
->bit_stream
, p_src
+ i_offset
, SPU_CHUNK_SIZE
);
308 /* Abort subtitle parsing if we were requested to stop */
309 if( p_spudec
->p_fifo
->b_die
)
312 vout_DestroySubPicture( p_spudec
->p_vout
, p_spu
);
317 GetChunk( &p_spudec
->bit_stream
, p_src
+ i_offset
,
318 p_spudec
->i_rle_size
- i_offset
);
321 /* Dump the subtitle info */
322 intf_WarnHexDump( 5, p_spu
->p_sys
->p_data
, p_spudec
->i_rle_size
);
325 /* Getting the control part */
326 if( ParseControlSequences( p_spudec
, p_spu
) )
328 /* There was a parse error, delete the subpicture */
330 vout_DestroySubPicture( p_spudec
->p_vout
, p_spu
);
334 /* At this point, no more GetBit() command is needed, so we have all
335 * the data we need to tell whether the subtitle is valid. Thus we
336 * try to display it and we ignore b_die. */
338 if( ParseRLE( p_spudec
, p_spu
, p_src
) )
340 /* There was a parse error, delete the subpicture */
342 vout_DestroySubPicture( p_spudec
->p_vout
, p_spu
);
346 intf_WarnMsg( 3, "spudec: total size: 0x%x, RLE offsets: 0x%x 0x%x",
347 p_spudec
->i_spu_size
,
348 p_spu
->p_sys
->pi_offset
[0], p_spu
->p_sys
->pi_offset
[1] );
350 /* SPU is finished - we can ask the video output to display it */
351 vout_DisplaySubPicture( p_spudec
->p_vout
, p_spu
);
357 /*****************************************************************************
358 * ParseControlSequences: parse all SPU control sequences
359 *****************************************************************************
360 * This is the most important part in SPU decoding. We get dates, palette
361 * information, coordinates, and so on. For more information on the
362 * subtitles format, see http://sam.zoy.org/doc/dvd/subtitles/index.html
363 *****************************************************************************/
364 static int ParseControlSequences( spudec_thread_t
*p_spudec
,
365 subpicture_t
* p_spu
)
367 /* Our current index in the SPU packet */
368 int i_index
= p_spudec
->i_rle_size
+ 4;
370 /* The next start-of-control-sequence index and the previous one */
371 int i_next_seq
, i_cur_seq
;
373 /* Command time and date */
379 /* XXX: temporary variables */
380 boolean_t b_force_display
= 0;
382 /* Initialize the structure */
383 p_spu
->i_start
= p_spu
->i_stop
= 0;
384 p_spu
->b_ephemer
= 0;
388 /* Get the control sequence date */
389 i_date
= GetBits( &p_spudec
->bit_stream
, 16 );
393 i_next_seq
= GetBits( &p_spudec
->bit_stream
, 16 );
395 /* Skip what we just read */
400 i_command
= GetBits( &p_spudec
->bit_stream
, 8 );
405 case SPU_CMD_FORCE_DISPLAY
:
407 /* 00 (force displaying) */
408 p_spu
->i_start
= p_spu
->p_sys
->i_pts
+ ( i_date
* 11000 );
413 /* Convert the dates in seconds to PTS values */
414 case SPU_CMD_START_DISPLAY
:
416 /* 01 (start displaying) */
417 p_spu
->i_start
= p_spu
->p_sys
->i_pts
+ ( i_date
* 11000 );
421 case SPU_CMD_STOP_DISPLAY
:
423 /* 02 (stop displaying) */
424 p_spu
->i_stop
= p_spu
->p_sys
->i_pts
+ ( i_date
* 11000 );
428 case SPU_CMD_SET_PALETTE
:
430 /* 03xxxx (palette) */
431 if( p_spudec
->p_config
->p_demux_data
&&
432 *(int*)p_spudec
->p_config
->p_demux_data
== 0xBeeF )
436 p_spu
->p_sys
->b_palette
= 1;
437 for( i
= 0; i
< 4 ; i
++ )
439 i_color
= ((u32
*)((void*)p_spudec
->p_config
->
440 p_demux_data
+ sizeof(int)))[
441 GetBits(&p_spudec
->bit_stream
, 4) ];
443 p_spu
->p_sys
->pi_yuv
[3-i
][0] = (i_color
>>16) & 0xff;
444 p_spu
->p_sys
->pi_yuv
[3-i
][1] = (i_color
>>0) & 0xff;
445 p_spu
->p_sys
->pi_yuv
[3-i
][2] = (i_color
>>8) & 0xff;
450 RemoveBits( &p_spudec
->bit_stream
, 16 );
456 case SPU_CMD_SET_ALPHACHANNEL
:
458 /* 04xxxx (alpha channel) */
459 for( i
= 0; i
< 4 ; i
++ )
461 p_spu
->p_sys
->pi_alpha
[3-i
]
462 = GetBits( &p_spudec
->bit_stream
, 4 );
468 case SPU_CMD_SET_COORDINATES
:
470 /* 05xxxyyyxxxyyy (coordinates) */
471 p_spu
->i_x
= GetBits( &p_spudec
->bit_stream
, 12 );
472 p_spu
->i_width
= GetBits( &p_spudec
->bit_stream
, 12 )
475 p_spu
->i_y
= GetBits( &p_spudec
->bit_stream
, 12 );
476 p_spu
->i_height
= GetBits( &p_spudec
->bit_stream
, 12 )
483 case SPU_CMD_SET_OFFSETS
:
485 /* 06xxxxyyyy (byte offsets) */
486 p_spu
->p_sys
->pi_offset
[0] =
487 GetBits( &p_spudec
->bit_stream
, 16 ) - 4;
489 p_spu
->p_sys
->pi_offset
[1] =
490 GetBits( &p_spudec
->bit_stream
, 16 ) - 4;
503 /* xx (unknown command) */
504 intf_ErrMsg( "spudec error: unknown command 0x%.2x",
509 /* We need to check for quit commands here */
510 if( p_spudec
->p_fifo
->b_die
)
515 } while( i_command
!= SPU_CMD_END
);
517 } while( i_index
== i_next_seq
);
519 /* Check that the next sequence index matches the current one */
520 if( i_next_seq
!= i_cur_seq
)
522 intf_ErrMsg( "spudec error: index mismatch (0x%.4x != 0x%.4x)",
523 i_next_seq
, i_cur_seq
);
527 if( i_index
> p_spudec
->i_spu_size
)
529 intf_ErrMsg( "spudec error: uh-oh, we went too far (0x%.4x > 0x%.4x)",
530 i_index
, p_spudec
->i_spu_size
);
534 if( !p_spu
->i_start
)
536 intf_ErrMsg( "spudec error: no `start display' command" );
541 /* This subtitle will live for 5 seconds or until the next subtitle */
542 p_spu
->i_stop
= p_spu
->i_start
+ 500 * 11000;
543 p_spu
->b_ephemer
= 1;
546 /* Get rid of padding bytes */
547 switch( p_spudec
->i_spu_size
- i_index
)
549 /* Zero or one padding byte, quite usual */
551 RemoveBits( &p_spudec
->bit_stream
, 8 );
556 /* More than one padding byte - this is very strange, but
557 * we can deal with it */
559 intf_WarnMsg( 2, "spudec warning: %i padding bytes, we usually "
560 "get 0 or 1 of them",
561 p_spudec
->i_spu_size
- i_index
);
563 while( i_index
< p_spudec
->i_spu_size
)
565 RemoveBits( &p_spudec
->bit_stream
, 8 );
572 if( b_force_display
)
574 intf_ErrMsg( "spudec: \"force display\" command" );
575 intf_ErrMsg( "spudec: send mail to <sam@zoy.org> if you "
576 "want to help debugging this" );
579 /* Successfully parsed ! */
583 /*****************************************************************************
584 * ParseRLE: parse the RLE part of the subtitle
585 *****************************************************************************
586 * This part parses the subtitle graphical data and stores it in a more
587 * convenient structure for later decoding. For more information on the
588 * subtitles format, see http://sam.zoy.org/doc/dvd/subtitles/index.html
589 *****************************************************************************/
590 static int ParseRLE( spudec_thread_t
*p_spudec
,
591 subpicture_t
* p_spu
, u8
* p_src
)
595 unsigned int i_width
= p_spu
->i_width
;
596 unsigned int i_height
= p_spu
->i_height
;
597 unsigned int i_x
, i_y
;
599 u16
*p_dest
= (u16
*)p_spu
->p_sys
->p_data
;
601 /* The subtitles are interlaced, we need two offsets */
602 unsigned int i_id
= 0; /* Start on the even SPU layer */
603 unsigned int pi_table
[ 2 ];
604 unsigned int *pi_offset
;
606 boolean_t b_empty_top
= 1,
608 unsigned int i_skipped_top
= 0,
609 i_skipped_bottom
= 0;
611 /* Colormap statistics */
613 int stats
[4]; stats
[0] = stats
[1] = stats
[2] = stats
[3] = 0;
615 pi_table
[ 0 ] = p_spu
->p_sys
->pi_offset
[ 0 ] << 1;
616 pi_table
[ 1 ] = p_spu
->p_sys
->pi_offset
[ 1 ] << 1;
618 for( i_y
= 0 ; i_y
< i_height
; i_y
++ )
620 pi_offset
= pi_table
+ i_id
;
622 for( i_x
= 0 ; i_x
< i_width
; i_x
+= i_code
>> 2 )
624 i_code
= AddNibble( 0, p_src
, pi_offset
);
628 i_code
= AddNibble( i_code
, p_src
, pi_offset
);
632 i_code
= AddNibble( i_code
, p_src
, pi_offset
);
636 i_code
= AddNibble( i_code
, p_src
, pi_offset
);
638 if( i_code
< 0x0100 )
640 /* If the 14 first bits are set to 0, then it's a
641 * new line. We emulate it. */
642 if( i_code
< 0x0004 )
644 i_code
|= ( i_width
- i_x
) << 2;
648 /* We have a boo boo ! */
649 intf_ErrMsg( "spudec error: unknown RLE code "
658 if( ( (i_code
>> 2) + i_x
+ i_y
* i_width
) > i_height
* i_width
)
660 intf_ErrMsg( "spudec error: out of bounds, %i at (%i,%i) is "
662 i_code
>> 2, i_x
, i_y
, i_width
, i_height
);
666 /* Try to find the border color */
667 if( p_spu
->p_sys
->pi_alpha
[ i_code
& 0x3 ] != 0x00 )
669 i_border
= i_code
& 0x3;
670 stats
[i_border
] += i_code
>> 2;
673 if( (i_code
>> 2) == i_width
674 && p_spu
->p_sys
->pi_alpha
[ i_code
& 0x3 ] == 0x00 )
678 /* This is a blank top line, we skip it */
683 /* We can't be sure the current lines will be skipped,
684 * so we store the code just in case. */
693 /* We got a valid code, store it */
696 /* Valid code means no blank line */
699 i_skipped_bottom
= 0;
703 /* Check that we didn't go too far */
706 intf_ErrMsg( "spudec error: i_x overflowed, %i > %i",
711 /* Byte-align the stream */
712 if( *pi_offset
& 0x1 )
721 /* We shouldn't get any padding bytes */
724 intf_ErrMsg( "spudec: padding bytes found in RLE sequence" );
725 intf_ErrMsg( "spudec: send mail to <sam@zoy.org> if you "
726 "want to help debugging this" );
728 /* Skip them just in case */
729 while( i_y
< i_height
)
731 *p_dest
++ = i_width
<< 2;
738 intf_WarnMsg( 3, "spudec: valid subtitle, size: %ix%i, position: %i,%i",
739 p_spu
->i_width
, p_spu
->i_height
, p_spu
->i_x
, p_spu
->i_y
);
741 /* Crop if necessary */
742 if( i_skipped_top
|| i_skipped_bottom
)
744 p_spu
->i_y
+= i_skipped_top
;
745 p_spu
->i_height
-= i_skipped_top
+ i_skipped_bottom
;
747 intf_WarnMsg( 3, "spudec: cropped to: %ix%i, position: %i,%i",
748 p_spu
->i_width
, p_spu
->i_height
, p_spu
->i_x
, p_spu
->i_y
);
751 /* Handle color if no palette was found */
752 if( !p_spu
->p_sys
->b_palette
)
754 int i
, i_inner
= -1, i_shade
= -1;
756 /* Set the border color */
757 p_spu
->p_sys
->pi_yuv
[i_border
][0] = 0x00;
758 p_spu
->p_sys
->pi_yuv
[i_border
][1] = 0x80;
759 p_spu
->p_sys
->pi_yuv
[i_border
][2] = 0x80;
762 /* Find the inner colors */
763 for( i
= 0 ; i
< 4 && i_inner
== -1 ; i
++ )
771 for( ; i
< 4 && i_shade
== -1 ; i
++ )
775 if( stats
[i
] > stats
[i_inner
] )
787 /* Set the inner color */
790 p_spu
->p_sys
->pi_yuv
[i_inner
][0] = 0xff;
791 p_spu
->p_sys
->pi_yuv
[i_inner
][1] = 0x80;
792 p_spu
->p_sys
->pi_yuv
[i_inner
][2] = 0x80;
795 /* Set the anti-aliasing color */
798 p_spu
->p_sys
->pi_yuv
[i_shade
][0] = 0x80;
799 p_spu
->p_sys
->pi_yuv
[i_shade
][1] = 0x80;
800 p_spu
->p_sys
->pi_yuv
[i_shade
][2] = 0x80;
803 intf_WarnMsg( 3, "spudec: using custom palette (border %i, inner %i, "
804 "shade %i)", i_border
, i_inner
, i_shade
);
810 /*****************************************************************************
811 * RenderSPU: draw an SPU on a picture
812 *****************************************************************************
813 * This is a fast implementation of the subpicture drawing code. The data
814 * has been preprocessed once, so we don't need to parse the RLE buffer again
815 * and again. Most sanity checks are already done so that this routine can be
816 * as fast as possible.
817 *****************************************************************************/
818 static void RenderSPU( const vout_thread_t
*p_vout
, picture_t
*p_pic
,
819 const subpicture_t
*p_spu
)
821 /* Common variables */
825 u16
*p_source
= (u16
*)p_spu
->p_sys
->p_data
;
832 int i_xscale
, i_yscale
, i_width
, i_height
, i_ytmp
, i_yreal
, i_ynext
;
834 switch( p_vout
->output
.i_chroma
)
836 /* I420 target, no scaling */
841 p_dest
= p_pic
->Y_PIXELS
+ p_spu
->i_x
+ p_spu
->i_width
842 + p_pic
->Y_PITCH
* ( p_spu
->i_y
+ p_spu
->i_height
);
844 /* Draw until we reach the bottom of the subtitle */
845 for( i_y
= p_spu
->i_height
* p_pic
->Y_PITCH
;
847 i_y
-= p_pic
->Y_PITCH
)
849 /* Draw until we reach the end of the line */
850 for( i_x
= p_spu
->i_width
; i_x
; )
852 /* Get the RLE part, then draw the line */
853 i_color
= *p_source
& 0x3;
855 switch( p_spu
->p_sys
->pi_alpha
[ i_color
] )
858 i_x
-= *p_source
++ >> 2;
862 i_len
= *p_source
++ >> 2;
863 memset( p_dest
- i_x
- i_y
,
864 p_spu
->p_sys
->pi_yuv
[i_color
][0], i_len
);
869 /* FIXME: we should do transparency */
870 i_len
= *p_source
++ >> 2;
871 memset( p_dest
- i_x
- i_y
,
872 p_spu
->p_sys
->pi_yuv
[i_color
][0], i_len
);
881 /* RV16 target, scaling */
884 /* FIXME: get this from the DVD */
885 for( i_color
= 0; i_color
< 4; i_color
++ )
887 p_clut16
[i_color
] = 0x1111
888 * ( (u16
)p_spu
->p_sys
->pi_yuv
[i_color
][0] >> 4 );
891 i_xscale
= ( p_vout
->output
.i_width
<< 6 ) / p_vout
->render
.i_width
;
892 i_yscale
= ( p_vout
->output
.i_height
<< 6 ) / p_vout
->render
.i_height
;
894 i_width
= p_spu
->i_width
* i_xscale
;
895 i_height
= p_spu
->i_height
* i_yscale
;
897 p_dest
= p_pic
->p
->p_pixels
+ ( i_width
>> 6 ) * 2
898 /* Add the picture coordinates and the SPU coordinates */
899 + ( (p_spu
->i_x
* i_xscale
) >> 6 ) * 2
900 + ( (p_spu
->i_y
* i_yscale
) >> 6 ) * p_vout
->output
.i_width
* 2;
902 /* Draw until we reach the bottom of the subtitle */
903 for( i_y
= 0 ; i_y
< i_height
; )
908 /* Check whether we need to draw one line or more than one */
909 if( i_ytmp
+ 1 >= ( i_y
>> 6 ) )
911 /* Just one line : we precalculate i_y >> 6 */
912 i_yreal
= p_vout
->output
.i_width
* 2 * i_ytmp
;
914 /* Draw until we reach the end of the line */
915 for( i_x
= i_width
; i_x
; )
917 /* Get the RLE part, then draw the line */
918 i_color
= *p_source
& 0x3;
920 switch( p_spu
->p_sys
->pi_alpha
[ i_color
] )
923 i_x
-= i_xscale
* ( *p_source
++ >> 2 );
927 i_len
= i_xscale
* ( *p_source
++ >> 2 );
928 memset( p_dest
- 2 * ( i_x
>> 6 ) + i_yreal
,
930 2 * ( ( i_len
>> 6 ) + 1 ) );
935 /* FIXME: we should do transparency */
936 i_len
= i_xscale
* ( *p_source
++ >> 2 );
937 memset( p_dest
- 2 * ( i_x
>> 6 ) + i_yreal
,
939 2 * ( ( i_len
>> 6 ) + 1 ) );
948 i_yreal
= p_vout
->output
.i_width
* 2 * i_ytmp
;
949 i_ynext
= p_vout
->output
.i_width
* 2 * i_y
>> 6;
951 /* Draw until we reach the end of the line */
952 for( i_x
= i_width
; i_x
; )
954 /* Get the RLE part, then draw as many lines as needed */
955 i_color
= *p_source
& 0x3;
957 switch( p_spu
->p_sys
->pi_alpha
[ i_color
] )
960 i_x
-= i_xscale
* ( *p_source
++ >> 2 );
964 i_len
= i_xscale
* ( *p_source
++ >> 2 );
965 for( i_ytmp
= i_yreal
; i_ytmp
< i_ynext
;
966 i_ytmp
+= p_vout
->output
.i_width
* 2 )
968 memset( p_dest
- 2 * ( i_x
>> 6 ) + i_ytmp
,
970 2 * ( ( i_len
>> 6 ) + 1 ) );
976 /* FIXME: we should do transparency */
977 i_len
= i_xscale
* ( *p_source
++ >> 2 );
978 for( i_ytmp
= i_yreal
; i_ytmp
< i_ynext
;
979 i_ytmp
+= p_vout
->output
.i_width
* 2 )
981 memset( p_dest
- 2 * ( i_x
>> 6 ) + i_ytmp
,
983 2 * ( ( i_len
>> 6 ) + 1 ) );
994 /* RV32 target, scaling */
998 /* XXX: this is a COMPLETE HACK, memcpy is unable to do u32s anyway */
999 /* FIXME: get this from the DVD */
1000 for( i_color
= 0; i_color
< 4; i_color
++ )
1002 p_clut32
[i_color
] = 0x11111111
1003 * ( (u16
)p_spu
->p_sys
->pi_yuv
[i_color
][0] >> 4 );
1006 i_xscale
= ( p_vout
->output
.i_width
<< 6 ) / p_vout
->render
.i_width
;
1007 i_yscale
= ( p_vout
->output
.i_height
<< 6 ) / p_vout
->render
.i_height
;
1009 i_width
= p_spu
->i_width
* i_xscale
;
1010 i_height
= p_spu
->i_height
* i_yscale
;
1012 p_dest
= p_pic
->p
->p_pixels
+ ( i_width
>> 6 ) * 4
1013 /* Add the picture coordinates and the SPU coordinates */
1014 + ( (p_spu
->i_x
* i_xscale
) >> 6 ) * 4
1015 + ( (p_spu
->i_y
* i_yscale
) >> 6 ) * p_vout
->output
.i_width
* 4;
1017 /* Draw until we reach the bottom of the subtitle */
1018 for( i_y
= 0 ; i_y
< i_height
; )
1023 /* Check whether we need to draw one line or more than one */
1024 if( i_ytmp
+ 1 >= ( i_y
>> 6 ) )
1026 /* Just one line : we precalculate i_y >> 6 */
1027 i_yreal
= p_vout
->output
.i_width
* 4 * i_ytmp
;
1029 /* Draw until we reach the end of the line */
1030 for( i_x
= i_width
; i_x
; )
1032 /* Get the RLE part, then draw the line */
1033 i_color
= *p_source
& 0x3;
1035 switch( p_spu
->p_sys
->pi_alpha
[ i_color
] )
1038 i_x
-= i_xscale
* ( *p_source
++ >> 2 );
1042 i_len
= i_xscale
* ( *p_source
++ >> 2 );
1043 memset( p_dest
- 4 * ( i_x
>> 6 ) + i_yreal
,
1044 p_clut32
[ i_color
], 4 * ( ( i_len
>> 6 ) + 1 ) );
1049 /* FIXME: we should do transparency */
1050 i_len
= i_xscale
* ( *p_source
++ >> 2 );
1051 memset( p_dest
- 4 * ( i_x
>> 6 ) + i_yreal
,
1052 p_clut32
[ i_color
], 4 * ( ( i_len
>> 6 ) + 1 ) );
1061 i_yreal
= p_vout
->output
.i_width
* 4 * i_ytmp
;
1062 i_ynext
= p_vout
->output
.i_width
* 4 * i_y
>> 6;
1064 /* Draw until we reach the end of the line */
1065 for( i_x
= i_width
; i_x
; )
1067 /* Get the RLE part, then draw as many lines as needed */
1068 i_color
= *p_source
& 0x3;
1070 switch( p_spu
->p_sys
->pi_alpha
[ i_color
] )
1073 i_x
-= i_xscale
* ( *p_source
++ >> 2 );
1077 i_len
= i_xscale
* ( *p_source
++ >> 2 );
1078 for( i_ytmp
= i_yreal
; i_ytmp
< i_ynext
;
1079 i_ytmp
+= p_vout
->output
.i_width
* 4 )
1081 memset( p_dest
- 4 * ( i_x
>> 6 ) + i_ytmp
,
1082 p_clut32
[ i_color
],
1083 4 * ( ( i_len
>> 6 ) + 1 ) );
1089 /* FIXME: we should do transparency */
1090 i_len
= i_xscale
* ( *p_source
++ >> 2 );
1091 for( i_ytmp
= i_yreal
; i_ytmp
< i_ynext
;
1092 i_ytmp
+= p_vout
->output
.i_width
* 4 )
1094 memset( p_dest
- 4 * ( i_x
>> 6 ) + i_ytmp
,
1095 p_clut32
[ i_color
],
1096 4 * ( ( i_len
>> 6 ) + 1 ) );
1107 /* NVidia overlay, no scaling */
1110 p_dest
= p_pic
->p
->p_pixels
+
1111 (p_spu
->i_x
+ p_spu
->i_width
+
1112 p_vout
->output
.i_width
* ( p_spu
->i_y
+ p_spu
->i_height
)) * 2;
1113 /* Draw until we reach the bottom of the subtitle */
1114 for( i_y
= p_spu
->i_height
* p_vout
->output
.i_width
;
1116 i_y
-= p_vout
->output
.i_width
)
1118 /* Draw until we reach the end of the line */
1119 for( i_x
= p_spu
->i_width
; i_x
; )
1121 /* Get the RLE part, then draw the line */
1122 i_color
= *p_source
& 0x3;
1124 switch( p_spu
->p_sys
->pi_alpha
[ i_color
] )
1127 i_x
-= *p_source
++ >> 2;
1131 i_len
= *p_source
++ >> 2;
1132 for( i_cnt
= 0; i_cnt
< i_len
; i_cnt
++ )
1136 memset( p_dest
- i_x
* 2 - i_y
* 2 + i_cnt
* 2,
1137 p_spu
->p_sys
->pi_yuv
[i_color
][0], 1);
1139 if (!(i_cnt
& 0x01))
1142 memset( p_dest
- i_x
* 2 - i_y
* 2 + i_cnt
* 2 + 1,
1144 memset( p_dest
- i_x
* 2 - i_y
* 2 + i_cnt
* 2 + 3,
1152 /* FIXME: we should do transparency */
1153 i_len
= *p_source
++ >> 2;
1154 for( i_cnt
= 0; i_cnt
< i_len
; i_cnt
++ )
1158 memset( p_dest
- i_x
* 2 - i_y
* 2 + i_cnt
* 2,
1159 p_spu
->p_sys
->pi_yuv
[i_color
][0], 1);
1161 if (!(i_cnt
& 0x01))
1164 memset( p_dest
- i_x
* 2 - i_y
* 2 + i_cnt
* 2 + 1,
1166 memset( p_dest
- i_x
* 2 - i_y
* 2 + i_cnt
* 2 + 3,
1180 intf_ErrMsg( "vout error: unknown chroma, can't render SPU" );