2
* NuppelVideo 0.05 file parser
4
* by Panagiotis Issaris <takis@lumumba.luc.ac.be>
18
#include "../libvo/fastmemcpy.h"
20
#include "libmpdemux/nuppelvideo.h"
26
void decode_nuv( unsigned char *encoded, int encoded_size,
27
unsigned char *decoded, int width, int height)
31
struct rtframeheader *encodedh = ( struct rtframeheader* ) encoded;
32
static unsigned char *buffer = 0; /* for RTJpeg with LZO decompress */
34
static unsigned char *previous_buffer = 0; /* to support Last-frame-copy */
36
static int is_lzo_inited = 0;
38
// printf("frametype: %c, comtype: %c, encoded_size: %d, width: %d, height: %d\n",
39
// encodedh->frametype, encodedh->comptype, encoded_size, width, height);
41
le2me_rtframeheader(encodedh);
42
switch(encodedh->frametype)
44
case 'D': /* additional data for compressors */
46
/* tables are in encoded */
47
if (encodedh->comptype == 'R')
49
RTjpeg_init_decompress ( (unsigned long *)(encoded+12), width, height );
50
mp_msg(MSGT_DECVIDEO, MSGL_V, "Found RTjpeg tables (size: %d, width: %d, height: %d)\n",
51
encoded_size-12, width, height);
59
previous_buffer = ( unsigned char * ) malloc ( width * height + ( width * height ) / 2 );
62
if (((encodedh->comptype == '2') ||
63
(encodedh->comptype == '3')) && !is_lzo_inited)
65
/* frame using lzo, init lzo first if not inited */
66
if ( lzo_init() != LZO_E_OK )
68
mp_msg(MSGT_DECVIDEO, MSGL_ERR, "LZO init failed\n");
74
switch(encodedh->comptype)
76
case '0': /* raw YUV420 */
77
memcpy(decoded, encoded + 12, width*height*3/2);
79
case '1': /* RTJpeg */
80
RTjpeg_decompressYUV420 ( ( __s8 * ) encoded + 12, decoded );
82
case '2': /* RTJpeg with LZO */
84
buffer = ( unsigned char * ) malloc ( width * height + ( width * height ) / 2 );
87
mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n");
90
r = lzo1x_decompress ( encoded + 12, encodedh->packetlength, buffer, &out_len, NULL );
93
mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n");
96
RTjpeg_decompressYUV420 ( ( __s8 * ) buffer, decoded );
98
case '3': /* raw YUV420 with LZO */
99
r = lzo1x_decompress ( encoded + 12, encodedh->packetlength, decoded, &out_len, NULL );
102
mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n");
106
case 'N': /* black frame */
107
memset ( decoded, 0, width * height );
108
memset ( decoded + width * height, 127, width * height / 2);
110
case 'L': /* copy last frame */
112
memcpy ( decoded, previous_buffer, width*height*3/2);
118
memcpy(previous_buffer, decoded, width*height*3/2);
123
mp_msg(MSGT_DECVIDEO, MSGL_V, "Nuppelvideo: unknwon frametype: %c\n",
124
encodedh->frametype);