1 /*****************************************************************************
2 * spu_decoder.c : spu decoder thread
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: spu_decoder.c,v 1.24 2002/05/24 12:42:14 gbazin 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_vout = NULL;
127 p_spudec->p_config = p_config;
129 p_spudec->p_fifo = p_config->p_decoder_fifo;
132 * Initialize thread and free configuration
134 p_spudec->p_fifo->b_error = InitThread( p_spudec );
137 * Main loop - it is not executed if an error occured during
140 while( (!p_spudec->p_fifo->b_die) && (!p_spudec->p_fifo->b_error) )
142 if( !SyncPacket( p_spudec ) )
144 ParsePacket( p_spudec );
151 if( p_spudec->p_fifo->b_error )
153 DecoderError( p_spudec->p_fifo );
157 boolean_t b_error = p_spudec->p_fifo->b_error;
160 EndThread( p_spudec );
171 /* following functions are local */
173 /*****************************************************************************
174 * InitThread: initialize spu decoder thread
175 *****************************************************************************
176 * This function is called from RunThread and performs the second step of the
177 * initialization. It returns 0 on success. Note that the thread's flag are not
178 * modified inside this function.
179 *****************************************************************************/
180 static int InitThread( spudec_thread_t *p_spudec )
182 /* Find an available video output */
183 vlc_mutex_lock( &p_vout_bank->lock );
185 while( p_vout_bank->i_count == 0 )
187 vlc_mutex_unlock( &p_vout_bank->lock );
189 if( p_spudec->p_fifo->b_die || p_spudec->p_fifo->b_error )
194 msleep( VOUT_OUTMEM_SLEEP );
195 vlc_mutex_lock( &p_vout_bank->lock );
198 /* Take the first video output FIXME: take the best one */
199 p_spudec->p_vout = p_vout_bank->pp_vout[ 0 ];
200 vlc_mutex_unlock( &p_vout_bank->lock );
201 InitBitstream( &p_spudec->bit_stream,
202 p_spudec->p_config->p_decoder_fifo, NULL, NULL );
204 /* Mark thread as running and return */
208 /*****************************************************************************
209 * EndThread: thread destruction
210 *****************************************************************************
211 * This function is called when the thread ends after a sucessful
213 *****************************************************************************/
214 static void EndThread( spudec_thread_t *p_spudec )
216 if( p_spudec->p_vout != NULL
217 && p_spudec->p_vout->p_subpicture != NULL )
219 subpicture_t * p_subpic;
222 for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
224 p_subpic = &p_spudec->p_vout->p_subpicture[i_subpic];
226 if( p_subpic != NULL &&
227 ( ( p_subpic->i_status == RESERVED_SUBPICTURE )
228 || ( p_subpic->i_status == READY_SUBPICTURE ) ) )
230 vout_DestroySubPicture( p_spudec->p_vout, p_subpic );
238 /*****************************************************************************
239 * SyncPacket: get in sync with the stream
240 *****************************************************************************
241 * This function makes a few sanity checks and returns 0 if it looks like we
242 * are at the beginning of a subpicture packet.
243 *****************************************************************************/
244 static int SyncPacket( spudec_thread_t *p_spudec )
246 /* Re-align the buffer on an 8-bit boundary */
247 RealignBits( &p_spudec->bit_stream );
249 /* The total SPU packet size, often bigger than a PS packet */
250 p_spudec->i_spu_size = GetBits( &p_spudec->bit_stream, 16 );
252 /* The RLE stuff size (remove 4 because we just read 32 bits) */
253 p_spudec->i_rle_size = ShowBits( &p_spudec->bit_stream, 16 ) - 4;
255 /* If the values we got are a bit strange, skip packet */
256 if( !p_spudec->i_spu_size
257 || ( p_spudec->i_rle_size >= p_spudec->i_spu_size ) )
262 RemoveBits( &p_spudec->bit_stream, 16 );
267 /*****************************************************************************
268 * ParsePacket: parse an SPU packet and send it to the video output
269 *****************************************************************************
270 * This function parses the SPU packet and, if valid, sends it to the
272 *****************************************************************************/
273 static void ParsePacket( spudec_thread_t *p_spudec )
275 subpicture_t * p_spu;
277 unsigned int i_offset;
279 intf_WarnMsg( 3, "spudec: trying to gather a 0x%.2x long subtitle",
280 p_spudec->i_spu_size );
282 /* We cannot display a subpicture with no date */
283 if( p_spudec->p_fifo->p_first->i_pts == 0 )
285 intf_WarnMsg( 3, "spudec error: subtitle without a date" );
289 /* Allocate the subpicture internal data. */
290 p_spu = vout_CreateSubPicture( p_spudec->p_vout, MEMORY_SUBPICTURE,
291 sizeof( struct subpicture_sys_s )
292 + p_spudec->i_rle_size * 4 );
293 /* Rationale for the "p_spudec->i_rle_size * 4": we are going to
294 * expand the RLE stuff so that we won't need to read nibbles later
295 * on. This will speed things up a lot. Plus, we'll only need to do
296 * this stupid interlacing stuff once. */
303 /* Fill the p_spu structure */
304 p_spu->pf_render = RenderSPU;
305 p_spu->p_sys->p_data = (u8*)p_spu->p_sys
306 + sizeof( struct subpicture_sys_s );
307 p_spu->p_sys->b_palette = 0;
309 /* Get display time now. If we do it later, we may miss the PTS. */
310 p_spu->p_sys->i_pts = p_spudec->p_fifo->p_first->i_pts;
312 /* Allocate the temporary buffer we will parse */
313 p_src = malloc( p_spudec->i_rle_size );
317 intf_ErrMsg( "spudec error: could not allocate p_src" );
318 vout_DestroySubPicture( p_spudec->p_vout, p_spu );
323 for( i_offset = 0; i_offset < p_spudec->i_rle_size;
324 i_offset += SPU_CHUNK_SIZE )
326 GetChunk( &p_spudec->bit_stream, p_src + i_offset,
327 ( i_offset + SPU_CHUNK_SIZE < p_spudec->i_rle_size ) ?
328 SPU_CHUNK_SIZE : p_spudec->i_rle_size - i_offset );
330 /* Abort subtitle parsing if we were requested to stop */
331 if( p_spudec->p_fifo->b_die )
334 vout_DestroySubPicture( p_spudec->p_vout, p_spu );
340 /* Dump the subtitle info */
341 intf_WarnHexDump( 5, p_spu->p_sys->p_data, p_spudec->i_rle_size );
344 /* Getting the control part */
345 if( ParseControlSequences( p_spudec, p_spu ) )
347 /* There was a parse error, delete the subpicture */
349 vout_DestroySubPicture( p_spudec->p_vout, p_spu );
353 /* At this point, no more GetBit() command is needed, so we have all
354 * the data we need to tell whether the subtitle is valid. Thus we
355 * try to display it and we ignore b_die. */
357 if( ParseRLE( p_spudec, p_spu, p_src ) )
359 /* There was a parse error, delete the subpicture */
361 vout_DestroySubPicture( p_spudec->p_vout, p_spu );
365 intf_WarnMsg( 3, "spudec: total size: 0x%x, RLE offsets: 0x%x 0x%x",
366 p_spudec->i_spu_size,
367 p_spu->p_sys->pi_offset[0], p_spu->p_sys->pi_offset[1] );
369 /* SPU is finished - we can ask the video output to display it */
370 vout_DisplaySubPicture( p_spudec->p_vout, p_spu );
376 /*****************************************************************************
377 * ParseControlSequences: parse all SPU control sequences
378 *****************************************************************************
379 * This is the most important part in SPU decoding. We get dates, palette
380 * information, coordinates, and so on. For more information on the
381 * subtitles format, see http://sam.zoy.org/doc/dvd/subtitles/index.html
382 *****************************************************************************/
383 static int ParseControlSequences( spudec_thread_t *p_spudec,
384 subpicture_t * p_spu )
386 /* Our current index in the SPU packet */
387 int i_index = p_spudec->i_rle_size + 4;
389 /* The next start-of-control-sequence index and the previous one */
390 int i_next_seq, i_cur_seq;
392 /* Command time and date */
398 /* XXX: temporary variables */
399 boolean_t b_force_display = 0;
401 /* Initialize the structure */
402 p_spu->i_start = p_spu->i_stop = 0;
403 p_spu->b_ephemer = 0;
407 /* Get the control sequence date */
408 i_date = GetBits( &p_spudec->bit_stream, 16 );
412 i_next_seq = GetBits( &p_spudec->bit_stream, 16 );
414 /* Skip what we just read */
419 i_command = GetBits( &p_spudec->bit_stream, 8 );
424 case SPU_CMD_FORCE_DISPLAY:
426 /* 00 (force displaying) */
427 p_spu->i_start = p_spu->p_sys->i_pts + ( i_date * 11000 );
432 /* Convert the dates in seconds to PTS values */
433 case SPU_CMD_START_DISPLAY:
435 /* 01 (start displaying) */
436 p_spu->i_start = p_spu->p_sys->i_pts + ( i_date * 11000 );
440 case SPU_CMD_STOP_DISPLAY:
442 /* 02 (stop displaying) */
443 p_spu->i_stop = p_spu->p_sys->i_pts + ( i_date * 11000 );
447 case SPU_CMD_SET_PALETTE:
449 /* 03xxxx (palette) */
450 if( p_spudec->p_config->p_demux_data &&
451 *(int*)p_spudec->p_config->p_demux_data == 0xBeeF )
455 p_spu->p_sys->b_palette = 1;
456 for( i = 0; i < 4 ; i++ )
458 i_color = ((u32*)((char*)p_spudec->p_config->
459 p_demux_data + sizeof(int)))[
460 GetBits(&p_spudec->bit_stream, 4) ];
462 p_spu->p_sys->pi_yuv[3-i][0] = (i_color>>16) & 0xff;
463 p_spu->p_sys->pi_yuv[3-i][1] = (i_color>>0) & 0xff;
464 p_spu->p_sys->pi_yuv[3-i][2] = (i_color>>8) & 0xff;
469 RemoveBits( &p_spudec->bit_stream, 16 );
475 case SPU_CMD_SET_ALPHACHANNEL:
477 /* 04xxxx (alpha channel) */
478 for( i = 0; i < 4 ; i++ )
480 p_spu->p_sys->pi_alpha[3-i]
481 = GetBits( &p_spudec->bit_stream, 4 );
487 case SPU_CMD_SET_COORDINATES:
489 /* 05xxxyyyxxxyyy (coordinates) */
490 p_spu->i_x = GetBits( &p_spudec->bit_stream, 12 );
491 p_spu->i_width = GetBits( &p_spudec->bit_stream, 12 )
494 p_spu->i_y = GetBits( &p_spudec->bit_stream, 12 );
495 p_spu->i_height = GetBits( &p_spudec->bit_stream, 12 )
502 case SPU_CMD_SET_OFFSETS:
504 /* 06xxxxyyyy (byte offsets) */
505 p_spu->p_sys->pi_offset[0] =
506 GetBits( &p_spudec->bit_stream, 16 ) - 4;
508 p_spu->p_sys->pi_offset[1] =
509 GetBits( &p_spudec->bit_stream, 16 ) - 4;
522 /* xx (unknown command) */
523 intf_ErrMsg( "spudec error: unknown command 0x%.2x",
528 /* We need to check for quit commands here */
529 if( p_spudec->p_fifo->b_die )
534 } while( i_command != SPU_CMD_END );
536 } while( i_index == i_next_seq );
538 /* Check that the next sequence index matches the current one */
539 if( i_next_seq != i_cur_seq )
541 intf_ErrMsg( "spudec error: index mismatch (0x%.4x != 0x%.4x)",
542 i_next_seq, i_cur_seq );
546 if( i_index > p_spudec->i_spu_size )
548 intf_ErrMsg( "spudec error: uh-oh, we went too far (0x%.4x > 0x%.4x)",
549 i_index, p_spudec->i_spu_size );
553 if( !p_spu->i_start )
555 intf_ErrMsg( "spudec error: no `start display' command" );
560 /* This subtitle will live for 5 seconds or until the next subtitle */
561 p_spu->i_stop = p_spu->i_start + 500 * 11000;
562 p_spu->b_ephemer = 1;
565 /* Get rid of padding bytes */
566 switch( p_spudec->i_spu_size - i_index )
568 /* Zero or one padding byte, quite usual */
570 RemoveBits( &p_spudec->bit_stream, 8 );
575 /* More than one padding byte - this is very strange, but
576 * we can deal with it */
578 intf_WarnMsg( 2, "spudec warning: %i padding bytes, we usually "
579 "get 0 or 1 of them",
580 p_spudec->i_spu_size - i_index );
582 while( i_index < p_spudec->i_spu_size )
584 RemoveBits( &p_spudec->bit_stream, 8 );
591 if( b_force_display )
593 intf_ErrMsg( "spudec: \"force display\" command" );
594 intf_ErrMsg( "spudec: send mail to <sam@zoy.org> if you "
595 "want to help debugging this" );
598 /* Successfully parsed ! */
602 /*****************************************************************************
603 * ParseRLE: parse the RLE part of the subtitle
604 *****************************************************************************
605 * This part parses the subtitle graphical data and stores it in a more
606 * convenient structure for later decoding. For more information on the
607 * subtitles format, see http://sam.zoy.org/doc/dvd/subtitles/index.html
608 *****************************************************************************/
609 static int ParseRLE( spudec_thread_t *p_spudec,
610 subpicture_t * p_spu, u8 * p_src )
614 unsigned int i_width = p_spu->i_width;
615 unsigned int i_height = p_spu->i_height;
616 unsigned int i_x, i_y;
618 u16 *p_dest = (u16 *)p_spu->p_sys->p_data;
620 /* The subtitles are interlaced, we need two offsets */
621 unsigned int i_id = 0; /* Start on the even SPU layer */
622 unsigned int pi_table[ 2 ];
623 unsigned int *pi_offset;
625 boolean_t b_empty_top = 1,
627 unsigned int i_skipped_top = 0,
628 i_skipped_bottom = 0;
630 /* Colormap statistics */
632 int stats[4]; stats[0] = stats[1] = stats[2] = stats[3] = 0;
634 pi_table[ 0 ] = p_spu->p_sys->pi_offset[ 0 ] << 1;
635 pi_table[ 1 ] = p_spu->p_sys->pi_offset[ 1 ] << 1;
637 for( i_y = 0 ; i_y < i_height ; i_y++ )
639 pi_offset = pi_table + i_id;
641 for( i_x = 0 ; i_x < i_width ; i_x += i_code >> 2 )
643 i_code = AddNibble( 0, p_src, pi_offset );
647 i_code = AddNibble( i_code, p_src, pi_offset );
651 i_code = AddNibble( i_code, p_src, pi_offset );
655 i_code = AddNibble( i_code, p_src, pi_offset );
657 if( i_code < 0x0100 )
659 /* If the 14 first bits are set to 0, then it's a
660 * new line. We emulate it. */
661 if( i_code < 0x0004 )
663 i_code |= ( i_width - i_x ) << 2;
667 /* We have a boo boo ! */
668 intf_ErrMsg( "spudec error: unknown RLE code "
677 if( ( (i_code >> 2) + i_x + i_y * i_width ) > i_height * i_width )
679 intf_ErrMsg( "spudec error: out of bounds, %i at (%i,%i) is "
681 i_code >> 2, i_x, i_y, i_width, i_height );
685 /* Try to find the border color */
686 if( p_spu->p_sys->pi_alpha[ i_code & 0x3 ] != 0x00 )
688 i_border = i_code & 0x3;
689 stats[i_border] += i_code >> 2;
692 if( (i_code >> 2) == i_width
693 && p_spu->p_sys->pi_alpha[ i_code & 0x3 ] == 0x00 )
697 /* This is a blank top line, we skip it */
702 /* We can't be sure the current lines will be skipped,
703 * so we store the code just in case. */
712 /* We got a valid code, store it */
715 /* Valid code means no blank line */
718 i_skipped_bottom = 0;
722 /* Check that we didn't go too far */
725 intf_ErrMsg( "spudec error: i_x overflowed, %i > %i",
730 /* Byte-align the stream */
731 if( *pi_offset & 0x1 )
740 /* We shouldn't get any padding bytes */
743 intf_ErrMsg( "spudec: padding bytes found in RLE sequence" );
744 intf_ErrMsg( "spudec: send mail to <sam@zoy.org> if you "
745 "want to help debugging this" );
747 /* Skip them just in case */
748 while( i_y < i_height )
750 *p_dest++ = i_width << 2;
757 intf_WarnMsg( 3, "spudec: valid subtitle, size: %ix%i, position: %i,%i",
758 p_spu->i_width, p_spu->i_height, p_spu->i_x, p_spu->i_y );
760 /* Crop if necessary */
761 if( i_skipped_top || i_skipped_bottom )
763 p_spu->i_y += i_skipped_top;
764 p_spu->i_height -= i_skipped_top + i_skipped_bottom;
766 intf_WarnMsg( 3, "spudec: cropped to: %ix%i, position: %i,%i",
767 p_spu->i_width, p_spu->i_height, p_spu->i_x, p_spu->i_y );
770 /* Handle color if no palette was found */
771 if( !p_spu->p_sys->b_palette )
773 int i, i_inner = -1, i_shade = -1;
775 /* Set the border color */
776 p_spu->p_sys->pi_yuv[i_border][0] = 0x00;
777 p_spu->p_sys->pi_yuv[i_border][1] = 0x80;
778 p_spu->p_sys->pi_yuv[i_border][2] = 0x80;
781 /* Find the inner colors */
782 for( i = 0 ; i < 4 && i_inner == -1 ; i++ )
790 for( ; i < 4 && i_shade == -1 ; i++ )
794 if( stats[i] > stats[i_inner] )
806 /* Set the inner color */
809 p_spu->p_sys->pi_yuv[i_inner][0] = 0xff;
810 p_spu->p_sys->pi_yuv[i_inner][1] = 0x80;
811 p_spu->p_sys->pi_yuv[i_inner][2] = 0x80;
814 /* Set the anti-aliasing color */
817 p_spu->p_sys->pi_yuv[i_shade][0] = 0x80;
818 p_spu->p_sys->pi_yuv[i_shade][1] = 0x80;
819 p_spu->p_sys->pi_yuv[i_shade][2] = 0x80;
822 intf_WarnMsg( 3, "spudec: using custom palette (border %i, inner %i, "
823 "shade %i)", i_border, i_inner, i_shade );
829 /*****************************************************************************
830 * RenderSPU: draw an SPU on a picture
831 *****************************************************************************
832 * This is a fast implementation of the subpicture drawing code. The data
833 * has been preprocessed once, so we don't need to parse the RLE buffer again
834 * and again. Most sanity checks are already done so that this routine can be
835 * as fast as possible.
836 *****************************************************************************/
837 static void RenderSPU( const vout_thread_t *p_vout, picture_t *p_pic,
838 const subpicture_t *p_spu )
840 /* Common variables */
844 u16 *p_source = (u16 *)p_spu->p_sys->p_data;
851 int i_xscale, i_yscale, i_width, i_height, i_ytmp, i_yreal, i_ynext;
853 switch( p_vout->output.i_chroma )
855 /* I420 target, no scaling */
860 p_dest = p_pic->Y_PIXELS + p_spu->i_x + p_spu->i_width
861 + p_pic->Y_PITCH * ( p_spu->i_y + p_spu->i_height );
863 /* Draw until we reach the bottom of the subtitle */
864 for( i_y = p_spu->i_height * p_pic->Y_PITCH ;
866 i_y -= p_pic->Y_PITCH )
868 /* Draw until we reach the end of the line */
869 for( i_x = p_spu->i_width ; i_x ; )
871 /* Get the RLE part, then draw the line */
872 i_color = *p_source & 0x3;
874 switch( p_spu->p_sys->pi_alpha[ i_color ] )
877 i_x -= *p_source++ >> 2;
881 i_len = *p_source++ >> 2;
882 memset( p_dest - i_x - i_y,
883 p_spu->p_sys->pi_yuv[i_color][0], i_len );
888 /* FIXME: we should do transparency */
889 i_len = *p_source++ >> 2;
890 memset( p_dest - i_x - i_y,
891 p_spu->p_sys->pi_yuv[i_color][0], i_len );
900 /* RV16 target, scaling */
903 /* FIXME: get this from the DVD */
904 for( i_color = 0; i_color < 4; i_color++ )
906 p_clut16[i_color] = 0x1111
907 * ( (u16)p_spu->p_sys->pi_yuv[i_color][0] >> 4 );
910 i_xscale = ( p_vout->output.i_width << 6 ) / p_vout->render.i_width;
911 i_yscale = ( p_vout->output.i_height << 6 ) / p_vout->render.i_height;
913 i_width = p_spu->i_width * i_xscale;
914 i_height = p_spu->i_height * i_yscale;
916 p_dest = p_pic->p->p_pixels + ( i_width >> 6 ) * 2
917 /* Add the picture coordinates and the SPU coordinates */
918 + ( (p_spu->i_x * i_xscale) >> 6 ) * 2
919 + ( (p_spu->i_y * i_yscale) >> 6 ) * p_vout->output.i_width * 2;
921 /* Draw until we reach the bottom of the subtitle */
922 for( i_y = 0 ; i_y < i_height ; )
927 /* Check whether we need to draw one line or more than one */
928 if( i_ytmp + 1 >= ( i_y >> 6 ) )
930 /* Just one line : we precalculate i_y >> 6 */
931 i_yreal = p_vout->output.i_width * 2 * i_ytmp;
933 /* Draw until we reach the end of the line */
934 for( i_x = i_width ; i_x ; )
936 /* Get the RLE part, then draw the line */
937 i_color = *p_source & 0x3;
939 switch( p_spu->p_sys->pi_alpha[ i_color ] )
942 i_x -= i_xscale * ( *p_source++ >> 2 );
946 i_len = i_xscale * ( *p_source++ >> 2 );
947 memset( p_dest - 2 * ( i_x >> 6 ) + i_yreal,
949 2 * ( ( i_len >> 6 ) + 1 ) );
954 /* FIXME: we should do transparency */
955 i_len = i_xscale * ( *p_source++ >> 2 );
956 memset( p_dest - 2 * ( i_x >> 6 ) + i_yreal,
958 2 * ( ( i_len >> 6 ) + 1 ) );
967 i_yreal = p_vout->output.i_width * 2 * i_ytmp;
968 i_ynext = p_vout->output.i_width * 2 * i_y >> 6;
970 /* Draw until we reach the end of the line */
971 for( i_x = i_width ; i_x ; )
973 /* Get the RLE part, then draw as many lines as needed */
974 i_color = *p_source & 0x3;
976 switch( p_spu->p_sys->pi_alpha[ i_color ] )
979 i_x -= i_xscale * ( *p_source++ >> 2 );
983 i_len = i_xscale * ( *p_source++ >> 2 );
984 for( i_ytmp = i_yreal ; i_ytmp < i_ynext ;
985 i_ytmp += p_vout->output.i_width * 2 )
987 memset( p_dest - 2 * ( i_x >> 6 ) + i_ytmp,
989 2 * ( ( i_len >> 6 ) + 1 ) );
995 /* FIXME: we should do transparency */
996 i_len = i_xscale * ( *p_source++ >> 2 );
997 for( i_ytmp = i_yreal ; i_ytmp < i_ynext ;
998 i_ytmp += p_vout->output.i_width * 2 )
1000 memset( p_dest - 2 * ( i_x >> 6 ) + i_ytmp,
1001 p_clut16[ i_color ],
1002 2 * ( ( i_len >> 6 ) + 1 ) );
1013 /* RV32 target, scaling */
1017 /* XXX: this is a COMPLETE HACK, memcpy is unable to do u32s anyway */
1018 /* FIXME: get this from the DVD */
1019 for( i_color = 0; i_color < 4; i_color++ )
1021 p_clut32[i_color] = 0x11111111
1022 * ( (u16)p_spu->p_sys->pi_yuv[i_color][0] >> 4 );
1025 i_xscale = ( p_vout->output.i_width << 6 ) / p_vout->render.i_width;
1026 i_yscale = ( p_vout->output.i_height << 6 ) / p_vout->render.i_height;
1028 i_width = p_spu->i_width * i_xscale;
1029 i_height = p_spu->i_height * i_yscale;
1031 p_dest = p_pic->p->p_pixels + ( i_width >> 6 ) * 4
1032 /* Add the picture coordinates and the SPU coordinates */
1033 + ( (p_spu->i_x * i_xscale) >> 6 ) * 4
1034 + ( (p_spu->i_y * i_yscale) >> 6 ) * p_vout->output.i_width * 4;
1036 /* Draw until we reach the bottom of the subtitle */
1037 for( i_y = 0 ; i_y < i_height ; )
1042 /* Check whether we need to draw one line or more than one */
1043 if( i_ytmp + 1 >= ( i_y >> 6 ) )
1045 /* Just one line : we precalculate i_y >> 6 */
1046 i_yreal = p_vout->output.i_width * 4 * i_ytmp;
1048 /* Draw until we reach the end of the line */
1049 for( i_x = i_width ; i_x ; )
1051 /* Get the RLE part, then draw the line */
1052 i_color = *p_source & 0x3;
1054 switch( p_spu->p_sys->pi_alpha[ i_color ] )
1057 i_x -= i_xscale * ( *p_source++ >> 2 );
1061 i_len = i_xscale * ( *p_source++ >> 2 );
1062 memset( p_dest - 4 * ( i_x >> 6 ) + i_yreal,
1063 p_clut32[ i_color ], 4 * ( ( i_len >> 6 ) + 1 ) );
1068 /* FIXME: we should do transparency */
1069 i_len = i_xscale * ( *p_source++ >> 2 );
1070 memset( p_dest - 4 * ( i_x >> 6 ) + i_yreal,
1071 p_clut32[ i_color ], 4 * ( ( i_len >> 6 ) + 1 ) );
1080 i_yreal = p_vout->output.i_width * 4 * i_ytmp;
1081 i_ynext = p_vout->output.i_width * 4 * i_y >> 6;
1083 /* Draw until we reach the end of the line */
1084 for( i_x = i_width ; i_x ; )
1086 /* Get the RLE part, then draw as many lines as needed */
1087 i_color = *p_source & 0x3;
1089 switch( p_spu->p_sys->pi_alpha[ i_color ] )
1092 i_x -= i_xscale * ( *p_source++ >> 2 );
1096 i_len = i_xscale * ( *p_source++ >> 2 );
1097 for( i_ytmp = i_yreal ; i_ytmp < i_ynext ;
1098 i_ytmp += p_vout->output.i_width * 4 )
1100 memset( p_dest - 4 * ( i_x >> 6 ) + i_ytmp,
1101 p_clut32[ i_color ],
1102 4 * ( ( i_len >> 6 ) + 1 ) );
1108 /* FIXME: we should do transparency */
1109 i_len = i_xscale * ( *p_source++ >> 2 );
1110 for( i_ytmp = i_yreal ; i_ytmp < i_ynext ;
1111 i_ytmp += p_vout->output.i_width * 4 )
1113 memset( p_dest - 4 * ( i_x >> 6 ) + i_ytmp,
1114 p_clut32[ i_color ],
1115 4 * ( ( i_len >> 6 ) + 1 ) );
1126 /* NVidia overlay, no scaling */
1129 p_dest = p_pic->p->p_pixels +
1130 (p_spu->i_x + p_spu->i_width +
1131 p_vout->output.i_width * ( p_spu->i_y + p_spu->i_height )) * 2;
1132 /* Draw until we reach the bottom of the subtitle */
1133 for( i_y = p_spu->i_height * p_vout->output.i_width;
1135 i_y -= p_vout->output.i_width )
1137 /* Draw until we reach the end of the line */
1138 for( i_x = p_spu->i_width ; i_x ; )
1140 /* Get the RLE part, then draw the line */
1141 i_color = *p_source & 0x3;
1143 switch( p_spu->p_sys->pi_alpha[ i_color ] )
1146 i_x -= *p_source++ >> 2;
1150 i_len = *p_source++ >> 2;
1151 for( i_cnt = 0; i_cnt < i_len; i_cnt++ )
1155 memset( p_dest - i_x * 2 - i_y * 2 + i_cnt * 2,
1156 p_spu->p_sys->pi_yuv[i_color][0], 1);
1158 if (!(i_cnt & 0x01))
1161 memset( p_dest - i_x * 2 - i_y * 2 + i_cnt * 2 + 1,
1163 memset( p_dest - i_x * 2 - i_y * 2 + i_cnt * 2 + 3,
1171 /* FIXME: we should do transparency */
1172 i_len = *p_source++ >> 2;
1173 for( i_cnt = 0; i_cnt < i_len; i_cnt++ )
1177 memset( p_dest - i_x * 2 - i_y * 2 + i_cnt * 2,
1178 p_spu->p_sys->pi_yuv[i_color][0], 1);
1180 if (!(i_cnt & 0x01))
1183 memset( p_dest - i_x * 2 - i_y * 2 + i_cnt * 2 + 1,
1185 memset( p_dest - i_x * 2 - i_y * 2 + i_cnt * 2 + 3,
1199 intf_ErrMsg( "vout error: unknown chroma, can't render SPU" );