From 58724e7a50f4a2d9adfd32b6dcffe1c4c863277f Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 27 Dec 2001 21:32:17 +0000 Subject: NuppelVideo decoder added, based on Panagiotis Issaris' patch git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@3805 b3059339-0415-0410-9bf9-f77b7e298cf2 --- nuppelvideo.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 nuppelvideo.c (limited to 'nuppelvideo.c') diff --git a/nuppelvideo.c b/nuppelvideo.c new file mode 100644 index 0000000000..4e33d1c77f --- /dev/null +++ b/nuppelvideo.c @@ -0,0 +1,125 @@ +/* + * NuppelVideo 0.05 file parser + * for MPlayer + * by Panagiotis Issaris + * + * Reworked by alex + */ + +#include +#include +#include + +#include "config.h" +#include "mp_msg.h" + +#include "libmpdemux/nuppelvideo.h" +#include "RTjpegN.h" +#include "minilzo.h" + +#define KEEP_BUFFER + +void decode_nuv( unsigned char *encoded, int encoded_size, + unsigned char *decoded, int width, int height) +{ + int r; + unsigned int out_len; + struct rtframeheader *encodedh = ( struct rtframeheader* ) encoded; + static unsigned char *buffer = 0; + static unsigned char *previous_buffer = 0; + static is_lzo_inited = 0; + +// printf("NUV packet: frametype: %c comptype: %c\n", +// encodedh->frametype, encodedh->comptype); + + switch(encodedh->frametype) + { + case 'D': /* additional data for compressors */ + { + /* tables are in encoded */ + if (encodedh->comptype == 'R') + { + RTjpeg_init_decompress ( encoded, width, height ); + printf("Found RTjpeg tables\n"); + } + break; + } + case 'V': + { + /* do the buffer stuffs */ + if ( buffer == NULL ) + { + buffer = ( unsigned char * ) malloc ( width * height + ( width * height ) / 2 ); +#if 0 + printf ( "Allocated for %dx%d image %d bytes\n", width, height, + width * height + ( width * height ) / 2 ); +#endif + } + +#ifdef KEEP_BUFFER + if ( previous_buffer == NULL ) + { + previous_buffer = ( unsigned char * ) malloc ( width * height + ( width * height ) / 2 ); +#if 0 + printf ( "Allocated for %dx%d image %d bytes\n", width, height, + width * height + ( width * height ) / 2 ); +#endif + } +#endif + + if (((encodedh->comptype == '2') || + (encodedh->comptype == '3')) && !is_lzo_inited) + { + /* frame using lzo, init lzo first if not inited */ + if ( lzo_init() != LZO_E_OK ) + { + fprintf ( stderr, "%s\n", "lzo_init() failed !!!" ); + return NULL; + } + is_lzo_inited = 1; + } + + switch(encodedh->comptype) + { + case '0': /* raw YUV420 */ + memcpy(decoded, encoded + 12, width*height*3/2); + break; + case '1': /* RTJpeg */ + RTjpeg_decompressYUV420 ( ( __s8 * ) encoded + 12, decoded ); + break; + case '2': /* RTJpeg with LZO */ + r = lzo1x_decompress ( encoded + 12, encodedh->packetlength, buffer, &out_len, NULL ); + if ( r != LZO_E_OK ) + { + printf ( "Error decompressing\n" ); + } + RTjpeg_decompressYUV420 ( ( __s8 * ) buffer, decoded ); + break; + case '3': /* raw YUV420 with LZO */ + r = lzo1x_decompress ( encoded + 12, encodedh->packetlength, buffer, &out_len, NULL ); + if ( r != LZO_E_OK ) + { + printf ( "Error decompressing\n" ); + } + memcpy(decoded, buffer, width*height*3/2); + break; + case 'N': /* black frame */ + memset ( decoded, 0, width * height ); + memset ( decoded + width * height, 127, width * height / 2); + break; + case 'L': /* copy last frame */ +#ifdef KEEP_BUFFER + memcpy ( decoded, previous_buffer, width*height*3/2); +#endif + break; + } + +#ifdef KEEP_BUFFER + memcpy(previous_buffer, decoded, width*height*3/2); +#endif + break; + } + default: + printf("Unknown chunk: %c\n", encodedh->frametype); + } +} -- cgit v1.2.3