1 /*****************************************************************************
2 * spu_decoder.c : spu decoder thread
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: spu_decoder.c,v 1.18 2002/05/01 19:18:09 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 EndThread( p_spudec
);
157 if( p_spudec
->p_fifo
->b_error
)
166 /* following functions are local */
168 /*****************************************************************************
169 * InitThread: initialize spu decoder thread
170 *****************************************************************************
171 * This function is called from RunThread and performs the second step of the
172 * initialization. It returns 0 on success. Note that the thread's flag are not
173 * modified inside this function.
174 *****************************************************************************/
175 static int InitThread( spudec_thread_t
*p_spudec
)
177 /* Find an available video output */
178 vlc_mutex_lock( &p_vout_bank
->lock
);
180 while( p_vout_bank
->i_count
== 0 )
182 vlc_mutex_unlock( &p_vout_bank
->lock
);
184 if( p_spudec
->p_fifo
->b_die
|| p_spudec
->p_fifo
->b_error
)
189 msleep( VOUT_OUTMEM_SLEEP
);
190 vlc_mutex_lock( &p_vout_bank
->lock
);
193 /* Take the first video output FIXME: take the best one */
194 p_spudec
->p_vout
= p_vout_bank
->pp_vout
[ 0 ];
195 vlc_mutex_unlock( &p_vout_bank
->lock
);
196 InitBitstream( &p_spudec
->bit_stream
,
197 p_spudec
->p_config
->p_decoder_fifo
, NULL
, NULL
);
199 /* Mark thread as running and return */
203 /*****************************************************************************
204 * EndThread: thread destruction
205 *****************************************************************************
206 * This function is called when the thread ends after a sucessful
208 *****************************************************************************/
209 static void EndThread( spudec_thread_t
*p_spudec
)
214 /*****************************************************************************
215 * SyncPacket: get in sync with the stream
216 *****************************************************************************
217 * This function makes a few sanity checks and returns 0 if it looks like we
218 * are at the beginning of a subpicture packet.
219 *****************************************************************************/
220 static int SyncPacket( spudec_thread_t
*p_spudec
)
222 /* Re-align the buffer on an 8-bit boundary */
223 RealignBits( &p_spudec
->bit_stream
);
225 /* The total SPU packet size, often bigger than a PS packet */
226 p_spudec
->i_spu_size
= GetBits( &p_spudec
->bit_stream
, 16 );
228 /* The RLE stuff size (remove 4 because we just read 32 bits) */
229 p_spudec
->i_rle_size
= ShowBits( &p_spudec
->bit_stream
, 16 ) - 4;
231 /* If the values we got are a bit strange, skip packet */
232 if( !p_spudec
->i_spu_size
233 || ( p_spudec
->i_rle_size
>= p_spudec
->i_spu_size
) )
238 RemoveBits( &p_spudec
->bit_stream
, 16 );
243 /*****************************************************************************
244 * ParsePacket: parse an SPU packet and send it to the video output
245 *****************************************************************************
246 * This function parses the SPU packet and, if valid, sends it to the
248 *****************************************************************************/
249 static void ParsePacket( spudec_thread_t
*p_spudec
)
251 subpicture_t
* p_spu
;
253 unsigned int i_offset
;
255 intf_WarnMsg( 3, "spudec: trying to gather a 0x%.2x long subtitle",
256 p_spudec
->i_spu_size
);
258 /* We cannot display a subpicture with no date */
259 if( p_spudec
->p_fifo
->p_first
->i_pts
== 0 )
261 intf_WarnMsg( 3, "spudec error: subtitle without a date" );
265 /* Allocate the subpicture internal data. */
266 p_spu
= vout_CreateSubPicture( p_spudec
->p_vout
, MEMORY_SUBPICTURE
,
267 sizeof( struct subpicture_sys_s
)
268 + p_spudec
->i_rle_size
* 4 );
269 /* Rationale for the "p_spudec->i_rle_size * 4": we are going to
270 * expand the RLE stuff so that we won't need to read nibbles later
271 * on. This will speed things up a lot. Plus, we'll only need to do
272 * this stupid interlacing stuff once. */
279 /* Fill the p_spu structure */
280 p_spu
->pf_render
= RenderSPU
;
281 p_spu
->p_sys
->p_data
= (u8
*)p_spu
->p_sys
282 + sizeof( struct subpicture_sys_s
);
283 p_spu
->p_sys
->b_palette
= 0;
285 /* Get display time now. If we do it later, we may miss the PTS. */
286 p_spu
->p_sys
->i_pts
= p_spudec
->p_fifo
->p_first
->i_pts
;
288 /* Allocate the temporary buffer we will parse */
289 p_src
= malloc( p_spudec
->i_rle_size
);
293 intf_ErrMsg( "spudec error: could not allocate p_src" );
294 vout_DestroySubPicture( p_spudec
->p_vout
, p_spu
);
300 i_offset
+ SPU_CHUNK_SIZE
< p_spudec
->i_rle_size
;
301 i_offset
+= SPU_CHUNK_SIZE
)
303 GetChunk( &p_spudec
->bit_stream
, p_src
+ i_offset
, SPU_CHUNK_SIZE
);
305 /* Abort subtitle parsing if we were requested to stop */
306 if( p_spudec
->p_fifo
->b_die
)
309 vout_DestroySubPicture( p_spudec
->p_vout
, p_spu
);
314 GetChunk( &p_spudec
->bit_stream
, p_src
+ i_offset
,
315 p_spudec
->i_rle_size
- i_offset
);
318 /* Dump the subtitle info */
319 intf_WarnHexDump( 5, p_spu
->p_sys
->p_data
, p_spudec
->i_rle_size
);
322 /* Getting the control part */
323 if( ParseControlSequences( p_spudec
, p_spu
) )
325 /* There was a parse error, delete the subpicture */
327 vout_DestroySubPicture( p_spudec
->p_vout
, p_spu
);
331 /* At this point, no more GetBit() command is needed, so we have all
332 * the data we need to tell whether the subtitle is valid. Thus we
333 * try to display it and we ignore b_die. */
335 if( ParseRLE( p_spudec
, p_spu
, p_src
) )
337 /* There was a parse error, delete the subpicture */
339 vout_DestroySubPicture( p_spudec
->p_vout
, p_spu
);
343 intf_WarnMsg( 3, "spudec: total size: 0x%x, RLE offsets: 0x%x 0x%x",
344 p_spudec
->i_spu_size
,
345 p_spu
->p_sys
->pi_offset
[0], p_spu
->p_sys
->pi_offset
[1] );
347 /* SPU is finished - we can ask the video output to display it */
348 vout_DisplaySubPicture( p_spudec
->p_vout
, p_spu
);
354 /*****************************************************************************
355 * ParseControlSequences: parse all SPU control sequences
356 *****************************************************************************
357 * This is the most important part in SPU decoding. We get dates, palette
358 * information, coordinates, and so on. For more information on the
359 * subtitles format, see http://sam.zoy.org/doc/dvd/subtitles/index.html
360 *****************************************************************************/
361 static int ParseControlSequences( spudec_thread_t
*p_spudec
,
362 subpicture_t
* p_spu
)
364 /* Our current index in the SPU packet */
365 int i_index
= p_spudec
->i_rle_size
+ 4;
367 /* The next start-of-control-sequence index and the previous one */
368 int i_next_seq
, i_cur_seq
;
370 /* Command time and date */
378 /* XXX: temporary variables */
379 boolean_t b_force_display
= 0;
381 /* Initialize the structure */
382 p_spu
->i_start
= p_spu
->i_stop
= 0;
383 p_spu
->b_ephemer
= 0;
387 /* Get the control sequence date */
388 i_date
= GetBits( &p_spudec
->bit_stream
, 16 );
392 i_next_seq
= GetBits( &p_spudec
->bit_stream
, 16 );
394 /* Skip what we just read */
399 i_command
= GetBits( &p_spudec
->bit_stream
, 8 );
404 case SPU_CMD_FORCE_DISPLAY
:
406 /* 00 (force displaying) */
407 p_spu
->i_start
= p_spu
->p_sys
->i_pts
+ ( i_date
* 11000 );
412 /* Convert the dates in seconds to PTS values */
413 case SPU_CMD_START_DISPLAY
:
415 /* 01 (start displaying) */
416 p_spu
->i_start
= p_spu
->p_sys
->i_pts
+ ( i_date
* 11000 );
420 case SPU_CMD_STOP_DISPLAY
:
422 /* 02 (stop displaying) */
423 p_spu
->i_stop
= p_spu
->p_sys
->i_pts
+ ( i_date
* 11000 );
427 case SPU_CMD_SET_PALETTE
:
429 /* 03xxxx (palette) */
430 if( p_spudec
->p_config
->p_demux_data
&&
431 *(int*)p_spudec
->p_config
->p_demux_data
== 0xBeeF )
433 p_spu
->p_sys
->b_palette
= 1;
434 for( i
= 0; i
< 4 ; i
++ )
436 pi_color
= (void*)p_spudec
->p_config
->p_demux_data
437 + sizeof(int) + 4 * sizeof(u8
) *
438 GetBits( &p_spudec
->bit_stream
, 4 );
439 p_spu
->p_sys
->pi_yuv
[3-i
][0] = pi_color
[2];
440 p_spu
->p_sys
->pi_yuv
[3-i
][1] = pi_color
[0];
441 p_spu
->p_sys
->pi_yuv
[3-i
][2] = pi_color
[1];
446 RemoveBits( &p_spudec
->bit_stream
, 16 );
452 case SPU_CMD_SET_ALPHACHANNEL
:
454 /* 04xxxx (alpha channel) */
455 for( i
= 0; i
< 4 ; i
++ )
457 p_spu
->p_sys
->pi_alpha
[3-i
]
458 = GetBits( &p_spudec
->bit_stream
, 4 );
464 case SPU_CMD_SET_COORDINATES
:
466 /* 05xxxyyyxxxyyy (coordinates) */
467 p_spu
->i_x
= GetBits( &p_spudec
->bit_stream
, 12 );
468 p_spu
->i_width
= GetBits( &p_spudec
->bit_stream
, 12 )
471 p_spu
->i_y
= GetBits( &p_spudec
->bit_stream
, 12 );
472 p_spu
->i_height
= GetBits( &p_spudec
->bit_stream
, 12 )
479 case SPU_CMD_SET_OFFSETS
:
481 /* 06xxxxyyyy (byte offsets) */
482 p_spu
->p_sys
->pi_offset
[0] =
483 GetBits( &p_spudec
->bit_stream
, 16 ) - 4;
485 p_spu
->p_sys
->pi_offset
[1] =
486 GetBits( &p_spudec
->bit_stream
, 16 ) - 4;
499 /* xx (unknown command) */
500 intf_ErrMsg( "spudec error: unknown command 0x%.2x",
505 /* We need to check for quit commands here */
506 if( p_spudec
->p_fifo
->b_die
)
511 } while( i_command
!= SPU_CMD_END
);
513 } while( i_index
== i_next_seq
);
515 /* Check that the next sequence index matches the current one */
516 if( i_next_seq
!= i_cur_seq
)
518 intf_ErrMsg( "spudec error: index mismatch (0x%.4x != 0x%.4x)",
519 i_next_seq
, i_cur_seq
);
523 if( i_index
> p_spudec
->i_spu_size
)
525 intf_ErrMsg( "spudec error: uh-oh, we went too far (0x%.4x > 0x%.4x)",
526 i_index
, p_spudec
->i_spu_size
);
530 if( !p_spu
->i_start
)
532 intf_ErrMsg( "spudec error: no `start display' command" );
537 /* This subtitle will live for 5 seconds or until the next subtitle */
538 p_spu
->i_stop
= p_spu
->i_start
+ 500 * 11000;
539 p_spu
->b_ephemer
= 1;
542 /* Get rid of padding bytes */
543 switch( p_spudec
->i_spu_size
- i_index
)
545 /* Zero or one padding byte, quite usual */
547 RemoveBits( &p_spudec
->bit_stream
, 8 );
552 /* More than one padding byte - this is very strange, but
553 * we can deal with it */
555 intf_WarnMsg( 2, "spudec warning: %i padding bytes, we usually "
556 "get 0 or 1 of them",
557 p_spudec
->i_spu_size
- i_index
);
559 while( i_index
< p_spudec
->i_spu_size
)
561 RemoveBits( &p_spudec
->bit_stream
, 8 );
568 if( b_force_display
)
570 intf_ErrMsg( "spudec: \"force display\" command" );
571 intf_ErrMsg( "spudec: send mail to <sam@zoy.org> if you "
572 "want to help debugging this" );
575 /* Successfully parsed ! */
579 /*****************************************************************************
580 * ParseRLE: parse the RLE part of the subtitle
581 *****************************************************************************
582 * This part parses the subtitle graphical data and stores it in a more
583 * convenient structure for later decoding. For more information on the
584 * subtitles format, see http://sam.zoy.org/doc/dvd/subtitles/index.html
585 *****************************************************************************/
586 static int ParseRLE( spudec_thread_t
*p_spudec
,
587 subpicture_t
* p_spu
, u8
* p_src
)
591 unsigned int i_width
= p_spu
->i_width
;
592 unsigned int i_height
= p_spu
->i_height
;
593 unsigned int i_x
, i_y
;
595 u16
*p_dest
= (u16
*)p_spu
->p_sys
->p_data
;
597 /* The subtitles are interlaced, we need two offsets */
598 unsigned int i_id
= 0; /* Start on the even SPU layer */
599 unsigned int pi_table
[ 2 ];
600 unsigned int *pi_offset
;
602 boolean_t b_empty_top
= 1,
604 unsigned int i_skipped_top
= 0,
605 i_skipped_bottom
= 0;
607 /* Colormap statistics */
609 int stats
[4]; stats
[0] = stats
[1] = stats
[2] = stats
[3] = 0;
611 pi_table
[ 0 ] = p_spu
->p_sys
->pi_offset
[ 0 ] << 1;
612 pi_table
[ 1 ] = p_spu
->p_sys
->pi_offset
[ 1 ] << 1;
614 for( i_y
= 0 ; i_y
< i_height
; i_y
++ )
616 pi_offset
= pi_table
+ i_id
;
618 for( i_x
= 0 ; i_x
< i_width
; i_x
+= i_code
>> 2 )
620 i_code
= AddNibble( 0, p_src
, pi_offset
);
624 i_code
= AddNibble( i_code
, p_src
, pi_offset
);
628 i_code
= AddNibble( i_code
, p_src
, pi_offset
);
632 i_code
= AddNibble( i_code
, p_src
, pi_offset
);
634 if( i_code
< 0x0100 )
636 /* If the 14 first bits are set to 0, then it's a
637 * new line. We emulate it. */
638 if( i_code
< 0x0004 )
640 i_code
|= ( i_width
- i_x
) << 2;
644 /* We have a boo boo ! */
645 intf_ErrMsg( "spudec error: unknown RLE code "
654 if( ( (i_code
>> 2) + i_x
+ i_y
* i_width
) > i_height
* i_width
)
656 intf_ErrMsg( "spudec error: out of bounds, %i at (%i,%i) is "
658 i_code
>> 2, i_x
, i_y
, i_width
, i_height
);
662 /* Try to find the border color */
663 if( p_spu
->p_sys
->pi_alpha
[ i_code
& 0x3 ] != 0x00 )
665 i_border
= i_code
& 0x3;
666 stats
[i_border
] += i_code
>> 2;
669 if( (i_code
>> 2) == i_width
670 && p_spu
->p_sys
->pi_alpha
[ i_code
& 0x3 ] == 0x00 )
674 /* This is a blank top line, we skip it */
679 /* We can't be sure the current lines will be skipped,
680 * so we store the code just in case. */
689 /* We got a valid code, store it */
692 /* Valid code means no blank line */
695 i_skipped_bottom
= 0;
699 /* Check that we didn't go too far */
702 intf_ErrMsg( "spudec error: i_x overflowed, %i > %i",
707 /* Byte-align the stream */
708 if( *pi_offset
& 0x1 )
717 /* We shouldn't get any padding bytes */
720 intf_ErrMsg( "spudec: padding bytes found in RLE sequence" );
721 intf_ErrMsg( "spudec: send mail to <sam@zoy.org> if you "
722 "want to help debugging this" );
724 /* Skip them just in case */
725 while( i_y
< i_height
)
727 *p_dest
++ = i_width
<< 2;
734 intf_WarnMsg( 3, "spudec: valid subtitle, size: %ix%i, position: %i,%i",
735 p_spu
->i_width
, p_spu
->i_height
, p_spu
->i_x
, p_spu
->i_y
);
737 /* Crop if necessary */
738 if( i_skipped_top
|| i_skipped_bottom
)
740 p_spu
->i_y
+= i_skipped_top
;
741 p_spu
->i_height
-= i_skipped_top
+ i_skipped_bottom
;
743 intf_WarnMsg( 3, "spudec: cropped to: %ix%i, position: %i,%i",
744 p_spu
->i_width
, p_spu
->i_height
, p_spu
->i_x
, p_spu
->i_y
);
747 /* Handle color if no palette was found */
748 if( !p_spu
->p_sys
->b_palette
)
750 int i
, i_inner
= -1, i_shade
= -1;
752 /* Set the border color */
753 p_spu
->p_sys
->pi_yuv
[i_border
][0] = 0x00;
754 p_spu
->p_sys
->pi_yuv
[i_border
][1] = 0x80;
755 p_spu
->p_sys
->pi_yuv
[i_border
][2] = 0x80;
758 /* Find the inner colors */
759 for( i
= 0 ; i
< 4 && i_inner
== -1 ; i
++ )
767 for( ; i
< 4 && i_shade
== -1 ; i
++ )
771 if( stats
[i
] > stats
[i_inner
] )
783 /* Set the inner color */
786 p_spu
->p_sys
->pi_yuv
[i_inner
][0] = 0xff;
787 p_spu
->p_sys
->pi_yuv
[i_inner
][1] = 0x80;
788 p_spu
->p_sys
->pi_yuv
[i_inner
][2] = 0x80;
791 /* Set the anti-aliasing color */
794 p_spu
->p_sys
->pi_yuv
[i_shade
][0] = 0x80;
795 p_spu
->p_sys
->pi_yuv
[i_shade
][1] = 0x80;
796 p_spu
->p_sys
->pi_yuv
[i_shade
][2] = 0x80;
799 intf_WarnMsg( 3, "spudec: using custom palette (border %i, inner %i, "
800 "shade %i)", i_border
, i_inner
, i_shade
);
806 /*****************************************************************************
807 * RenderSPU: draw an SPU on a picture
808 *****************************************************************************
809 * This is a fast implementation of the subpicture drawing code. The data
810 * has been preprocessed once, so we don't need to parse the RLE buffer again
811 * and again. Most sanity checks are already done so that this routine can be
812 * as fast as possible.
813 *****************************************************************************/
814 static void RenderSPU( const vout_thread_t
*p_vout
, picture_t
*p_pic
,
815 const subpicture_t
*p_spu
)
817 /* Common variables */
821 u16
*p_source
= (u16
*)p_spu
->p_sys
->p_data
;
828 int i_xscale
, i_yscale
, i_width
, i_height
, i_ytmp
, i_yreal
, i_ynext
;
830 switch( p_vout
->output
.i_chroma
)
832 /* I420 target, no scaling */
837 p_dest
= p_pic
->Y_PIXELS
+ p_spu
->i_x
+ p_spu
->i_width
838 + p_pic
->Y_PITCH
* ( p_spu
->i_y
+ p_spu
->i_height
);
840 /* Draw until we reach the bottom of the subtitle */
841 for( i_y
= p_spu
->i_height
* p_pic
->Y_PITCH
;
843 i_y
-= p_pic
->Y_PITCH
)
845 /* Draw until we reach the end of the line */
846 for( i_x
= p_spu
->i_width
; i_x
; )
848 /* Get the RLE part, then draw the line */
849 i_color
= *p_source
& 0x3;
851 switch( p_spu
->p_sys
->pi_alpha
[ i_color
] )
854 i_x
-= *p_source
++ >> 2;
858 i_len
= *p_source
++ >> 2;
859 memset( p_dest
- i_x
- i_y
,
860 p_spu
->p_sys
->pi_yuv
[i_color
][0], i_len
);
865 /* FIXME: we should do transparency */
866 i_len
= *p_source
++ >> 2;
867 memset( p_dest
- i_x
- i_y
,
868 p_spu
->p_sys
->pi_yuv
[i_color
][0], i_len
);
877 /* RV16 target, scaling */
880 /* FIXME: get this from the DVD */
881 for( i_color
= 0; i_color
< 4; i_color
++ )
883 p_clut16
[i_color
] = 0x1111
884 * ( (u16
)p_spu
->p_sys
->pi_yuv
[i_color
][0] >> 4 );
887 i_xscale
= ( p_vout
->output
.i_width
<< 6 ) / p_vout
->render
.i_width
;
888 i_yscale
= ( p_vout
->output
.i_height
<< 6 ) / p_vout
->render
.i_height
;
890 i_width
= p_spu
->i_width
* i_xscale
;
891 i_height
= p_spu
->i_height
* i_yscale
;
893 p_dest
= p_pic
->p
->p_pixels
+ ( i_width
>> 6 ) * 2
894 /* Add the picture coordinates and the SPU coordinates */
895 + ( (p_spu
->i_x
* i_xscale
) >> 6 ) * 2
896 + ( (p_spu
->i_y
* i_yscale
) >> 6 ) * p_vout
->output
.i_width
* 2;
898 /* Draw until we reach the bottom of the subtitle */
899 for( i_y
= 0 ; i_y
< i_height
; )
904 /* Check whether we need to draw one line or more than one */
905 if( i_ytmp
+ 1 >= ( i_y
>> 6 ) )
907 /* Just one line : we precalculate i_y >> 6 */
908 i_yreal
= p_vout
->output
.i_width
* 2 * i_ytmp
;
910 /* Draw until we reach the end of the line */
911 for( i_x
= i_width
; i_x
; )
913 /* Get the RLE part, then draw the line */
914 i_color
= *p_source
& 0x3;
916 switch( p_spu
->p_sys
->pi_alpha
[ i_color
] )
919 i_x
-= i_xscale
* ( *p_source
++ >> 2 );
923 i_len
= i_xscale
* ( *p_source
++ >> 2 );
924 memset( p_dest
- 2 * ( i_x
>> 6 ) + i_yreal
,
926 2 * ( ( i_len
>> 6 ) + 1 ) );
931 /* FIXME: we should do transparency */
932 i_len
= i_xscale
* ( *p_source
++ >> 2 );
933 memset( p_dest
- 2 * ( i_x
>> 6 ) + i_yreal
,
935 2 * ( ( i_len
>> 6 ) + 1 ) );
944 i_yreal
= p_vout
->output
.i_width
* 2 * i_ytmp
;
945 i_ynext
= p_vout
->output
.i_width
* 2 * i_y
>> 6;
947 /* Draw until we reach the end of the line */
948 for( i_x
= i_width
; i_x
; )
950 /* Get the RLE part, then draw as many lines as needed */
951 i_color
= *p_source
& 0x3;
953 switch( p_spu
->p_sys
->pi_alpha
[ i_color
] )
956 i_x
-= i_xscale
* ( *p_source
++ >> 2 );
960 i_len
= i_xscale
* ( *p_source
++ >> 2 );
961 for( i_ytmp
= i_yreal
; i_ytmp
< i_ynext
;
962 i_ytmp
+= p_vout
->output
.i_width
* 2 )
964 memset( p_dest
- 2 * ( i_x
>> 6 ) + i_ytmp
,
966 2 * ( ( i_len
>> 6 ) + 1 ) );
972 /* FIXME: we should do transparency */
973 i_len
= i_xscale
* ( *p_source
++ >> 2 );
974 for( i_ytmp
= i_yreal
; i_ytmp
< i_ynext
;
975 i_ytmp
+= p_vout
->output
.i_width
* 2 )
977 memset( p_dest
- 2 * ( i_x
>> 6 ) + i_ytmp
,
979 2 * ( ( i_len
>> 6 ) + 1 ) );
990 /* RV32 target, scaling */
994 /* XXX: this is a COMPLETE HACK, memcpy is unable to do u32s anyway */
995 /* FIXME: get this from the DVD */
996 for( i_color
= 0; i_color
< 4; i_color
++ )
998 p_clut32
[i_color
] = 0x11111111
999 * ( (u16
)p_spu
->p_sys
->pi_yuv
[i_color
][0] >> 4 );
1002 i_xscale
= ( p_vout
->output
.i_width
<< 6 ) / p_vout
->render
.i_width
;
1003 i_yscale
= ( p_vout
->output
.i_height
<< 6 ) / p_vout
->render
.i_height
;
1005 i_width
= p_spu
->i_width
* i_xscale
;
1006 i_height
= p_spu
->i_height
* i_yscale
;
1008 p_dest
= p_pic
->p
->p_pixels
+ ( i_width
>> 6 ) * 4
1009 /* Add the picture coordinates and the SPU coordinates */
1010 + ( (p_spu
->i_x
* i_xscale
) >> 6 ) * 4
1011 + ( (p_spu
->i_y
* i_yscale
) >> 6 ) * p_vout
->output
.i_width
* 4;
1013 /* Draw until we reach the bottom of the subtitle */
1014 for( i_y
= 0 ; i_y
< i_height
; )
1019 /* Check whether we need to draw one line or more than one */
1020 if( i_ytmp
+ 1 >= ( i_y
>> 6 ) )
1022 /* Just one line : we precalculate i_y >> 6 */
1023 i_yreal
= p_vout
->output
.i_width
* 4 * i_ytmp
;
1025 /* Draw until we reach the end of the line */
1026 for( i_x
= i_width
; i_x
; )
1028 /* Get the RLE part, then draw the line */
1029 i_color
= *p_source
& 0x3;
1031 switch( p_spu
->p_sys
->pi_alpha
[ i_color
] )
1034 i_x
-= i_xscale
* ( *p_source
++ >> 2 );
1038 i_len
= i_xscale
* ( *p_source
++ >> 2 );
1039 memset( p_dest
- 4 * ( i_x
>> 6 ) + i_yreal
,
1040 p_clut32
[ i_color
], 4 * ( ( i_len
>> 6 ) + 1 ) );
1045 /* FIXME: we should do transparency */
1046 i_len
= i_xscale
* ( *p_source
++ >> 2 );
1047 memset( p_dest
- 4 * ( i_x
>> 6 ) + i_yreal
,
1048 p_clut32
[ i_color
], 4 * ( ( i_len
>> 6 ) + 1 ) );
1057 i_yreal
= p_vout
->output
.i_width
* 4 * i_ytmp
;
1058 i_ynext
= p_vout
->output
.i_width
* 4 * i_y
>> 6;
1060 /* Draw until we reach the end of the line */
1061 for( i_x
= i_width
; i_x
; )
1063 /* Get the RLE part, then draw as many lines as needed */
1064 i_color
= *p_source
& 0x3;
1066 switch( p_spu
->p_sys
->pi_alpha
[ i_color
] )
1069 i_x
-= i_xscale
* ( *p_source
++ >> 2 );
1073 i_len
= i_xscale
* ( *p_source
++ >> 2 );
1074 for( i_ytmp
= i_yreal
; i_ytmp
< i_ynext
;
1075 i_ytmp
+= p_vout
->output
.i_width
* 4 )
1077 memset( p_dest
- 4 * ( i_x
>> 6 ) + i_ytmp
,
1078 p_clut32
[ i_color
],
1079 4 * ( ( i_len
>> 6 ) + 1 ) );
1085 /* FIXME: we should do transparency */
1086 i_len
= i_xscale
* ( *p_source
++ >> 2 );
1087 for( i_ytmp
= i_yreal
; i_ytmp
< i_ynext
;
1088 i_ytmp
+= p_vout
->output
.i_width
* 4 )
1090 memset( p_dest
- 4 * ( i_x
>> 6 ) + i_ytmp
,
1091 p_clut32
[ i_color
],
1092 4 * ( ( i_len
>> 6 ) + 1 ) );
1103 /* NVidia overlay, no scaling */
1106 p_dest
= p_pic
->p
->p_pixels
+
1107 (p_spu
->i_x
+ p_spu
->i_width
+
1108 p_vout
->output
.i_width
* ( p_spu
->i_y
+ p_spu
->i_height
)) * 2;
1109 /* Draw until we reach the bottom of the subtitle */
1110 for( i_y
= p_spu
->i_height
* p_vout
->output
.i_width
;
1112 i_y
-= p_vout
->output
.i_width
)
1114 /* Draw until we reach the end of the line */
1115 for( i_x
= p_spu
->i_width
; i_x
; )
1117 /* Get the RLE part, then draw the line */
1118 i_color
= *p_source
& 0x3;
1120 switch( p_spu
->p_sys
->pi_alpha
[ i_color
] )
1123 i_x
-= *p_source
++ >> 2;
1127 i_len
= *p_source
++ >> 2;
1128 for( i_cnt
= 0; i_cnt
< i_len
; i_cnt
++ )
1132 memset( p_dest
- i_x
* 2 - i_y
* 2 + i_cnt
* 2,
1133 p_spu
->p_sys
->pi_yuv
[i_color
][0], 1);
1135 if (!(i_cnt
& 0x01))
1138 memset( p_dest
- i_x
* 2 - i_y
* 2 + i_cnt
* 2 + 1,
1140 memset( p_dest
- i_x
* 2 - i_y
* 2 + i_cnt
* 2 + 3,
1148 /* FIXME: we should do transparency */
1149 i_len
= *p_source
++ >> 2;
1150 for( i_cnt
= 0; i_cnt
< i_len
; i_cnt
++ )
1154 memset( p_dest
- i_x
* 2 - i_y
* 2 + i_cnt
* 2,
1155 p_spu
->p_sys
->pi_yuv
[i_color
][0], 1);
1157 if (!(i_cnt
& 0x01))
1160 memset( p_dest
- i_x
* 2 - i_y
* 2 + i_cnt
* 2 + 1,
1162 memset( p_dest
- i_x
* 2 - i_y
* 2 + i_cnt
* 2 + 3,
1176 intf_ErrMsg( "vout error: unknown chroma, can't render SPU" );