partial sync with obsolete section removal
[mplayer/glamo.git] / libmpcodecs / native / nuppelvideo.c
blob8128f85c47ca3b5408ab94983eccdd1260395b37
1 /*
2 * NuppelVideo 0.05 file parser
3 * for MPlayer
4 * by Panagiotis Issaris <takis@lumumba.luc.ac.be>
6 * Reworked by alex
7 */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <string.h>
14 #include "config.h"
15 #include "mp_msg.h"
16 #include "mpbswap.h"
18 #include "libvo/fastmemcpy.h"
20 #include "libmpdemux/nuppelvideo.h"
21 #include "rtjpegn.h"
22 #include "libavutil/lzo.h"
24 #define KEEP_BUFFER
26 void decode_nuv( unsigned char *encoded, int encoded_size,
27 unsigned char *decoded, int width, int height)
29 int r;
30 unsigned int out_len = width * height + ( width * height ) / 2;
31 struct rtframeheader *encodedh = ( struct rtframeheader* ) encoded;
32 static unsigned char *buffer = 0; /* for RTJpeg with LZO decompress */
33 #ifdef KEEP_BUFFER
34 static unsigned char *previous_buffer = 0; /* to support Last-frame-copy */
35 #endif
37 // printf("frametype: %c, comtype: %c, encoded_size: %d, width: %d, height: %d\n",
38 // encodedh->frametype, encodedh->comptype, encoded_size, width, height);
40 le2me_rtframeheader(encodedh);
41 switch(encodedh->frametype)
43 case 'D': /* additional data for compressors */
45 /* tables are in encoded */
46 if (encodedh->comptype == 'R')
48 RTjpeg_init_decompress ( (unsigned long *)(encoded+12), width, height );
49 mp_msg(MSGT_DECVIDEO, MSGL_V, "Found RTjpeg tables (size: %d, width: %d, height: %d)\n",
50 encoded_size-12, width, height);
52 break;
54 case 'V':
56 int in_len = encodedh->packetlength;
57 #ifdef KEEP_BUFFER
58 if (!previous_buffer)
59 previous_buffer = ( unsigned char * ) malloc ( out_len + AV_LZO_OUTPUT_PADDING );
60 #endif
62 switch(encodedh->comptype)
64 case '0': /* raw YUV420 */
65 fast_memcpy(decoded, encoded + 12, out_len);
66 break;
67 case '1': /* RTJpeg */
68 RTjpeg_decompressYUV420 ( ( __s8 * ) encoded + 12, decoded );
69 break;
70 case '2': /* RTJpeg with LZO */
71 if (!buffer)
72 buffer = ( unsigned char * ) malloc ( out_len + AV_LZO_OUTPUT_PADDING );
73 if (!buffer)
75 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n");
76 break;
78 r = av_lzo1x_decode ( buffer, &out_len, encoded + 12, &in_len );
79 if ( r )
81 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n");
82 break;
84 RTjpeg_decompressYUV420 ( ( __s8 * ) buffer, decoded );
85 break;
86 case '3': /* raw YUV420 with LZO */
87 r = av_lzo1x_decode ( decoded, &out_len, encoded + 12, &in_len );
88 if ( r )
90 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n");
91 break;
93 break;
94 case 'N': /* black frame */
95 memset ( decoded, 0, width * height );
96 memset ( decoded + width * height, 127, width * height / 2);
97 break;
98 case 'L': /* copy last frame */
99 #ifdef KEEP_BUFFER
100 fast_memcpy ( decoded, previous_buffer, width*height*3/2);
101 #endif
102 break;
105 #ifdef KEEP_BUFFER
106 fast_memcpy(previous_buffer, decoded, width*height*3/2);
107 #endif
108 break;
110 default:
111 mp_msg(MSGT_DECVIDEO, MSGL_V, "Nuppelvideo: unknwon frametype: %c\n",
112 encodedh->frametype);