Mercurial > mplayer.hg
comparison libmpcodecs/native/nuppelvideo.c @ 5602:628c85c15c7b
moved to libmpcodecs/native/
author | arpi |
---|---|
date | Sat, 13 Apr 2002 18:03:02 +0000 |
parents | nuppelvideo.c@d60dcc0223ac |
children | 5bd00421d251 |
comparison
equal
deleted
inserted
replaced
5601:fd85802f755b | 5602:628c85c15c7b |
---|---|
1 /* | |
2 * NuppelVideo 0.05 file parser | |
3 * for MPlayer | |
4 * by Panagiotis Issaris <takis@lumumba.luc.ac.be> | |
5 * | |
6 * Reworked by alex | |
7 */ | |
8 | |
9 #include <stdio.h> | |
10 #include <stdlib.h> | |
11 #include <unistd.h> | |
12 | |
13 #include "config.h" | |
14 #include "mp_msg.h" | |
15 | |
16 #include "fastmemcpy.h" | |
17 | |
18 #include "libmpdemux/nuppelvideo.h" | |
19 #include "RTjpegN.h" | |
20 #include "minilzo.h" | |
21 | |
22 #define KEEP_BUFFER | |
23 | |
24 void decode_nuv( unsigned char *encoded, int encoded_size, | |
25 unsigned char *decoded, int width, int height) | |
26 { | |
27 int r; | |
28 unsigned int out_len; | |
29 struct rtframeheader *encodedh = ( struct rtframeheader* ) encoded; | |
30 static unsigned char *buffer = 0; /* for RTJpeg with LZO decompress */ | |
31 #ifdef KEEP_BUFFER | |
32 static unsigned char *previous_buffer = 0; /* to support Last-frame-copy */ | |
33 #endif | |
34 static int is_lzo_inited = 0; | |
35 | |
36 // printf("frametype: %c, comtype: %c, encoded_size: %d, width: %d, height: %d\n", | |
37 // encodedh->frametype, encodedh->comptype, encoded_size, width, height); | |
38 | |
39 switch(encodedh->frametype) | |
40 { | |
41 case 'D': /* additional data for compressors */ | |
42 { | |
43 /* tables are in encoded */ | |
44 if (encodedh->comptype == 'R') | |
45 { | |
46 RTjpeg_init_decompress ( encoded+12, width, height ); | |
47 mp_msg(MSGT_DECVIDEO, MSGL_V, "Found RTjpeg tables (size: %d, width: %d, height: %d)\n", | |
48 encoded_size-12, width, height); | |
49 } | |
50 break; | |
51 } | |
52 case 'V': | |
53 { | |
54 #ifdef KEEP_BUFFER | |
55 if (!previous_buffer) | |
56 previous_buffer = ( unsigned char * ) malloc ( width * height + ( width * height ) / 2 ); | |
57 #endif | |
58 | |
59 if (((encodedh->comptype == '2') || | |
60 (encodedh->comptype == '3')) && !is_lzo_inited) | |
61 { | |
62 /* frame using lzo, init lzo first if not inited */ | |
63 if ( lzo_init() != LZO_E_OK ) | |
64 { | |
65 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "LZO init failed\n"); | |
66 return; | |
67 } | |
68 is_lzo_inited = 1; | |
69 } | |
70 | |
71 switch(encodedh->comptype) | |
72 { | |
73 case '0': /* raw YUV420 */ | |
74 memcpy(decoded, encoded + 12, width*height*3/2); | |
75 break; | |
76 case '1': /* RTJpeg */ | |
77 RTjpeg_decompressYUV420 ( ( __s8 * ) encoded + 12, decoded ); | |
78 break; | |
79 case '2': /* RTJpeg with LZO */ | |
80 if (!buffer) | |
81 buffer = ( unsigned char * ) malloc ( width * height + ( width * height ) / 2 ); | |
82 if (!buffer) | |
83 { | |
84 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n"); | |
85 break; | |
86 } | |
87 r = lzo1x_decompress ( encoded + 12, encodedh->packetlength, buffer, &out_len, NULL ); | |
88 if ( r != LZO_E_OK ) | |
89 { | |
90 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n"); | |
91 break; | |
92 } | |
93 RTjpeg_decompressYUV420 ( ( __s8 * ) buffer, decoded ); | |
94 break; | |
95 case '3': /* raw YUV420 with LZO */ | |
96 r = lzo1x_decompress ( encoded + 12, encodedh->packetlength, decoded, &out_len, NULL ); | |
97 if ( r != LZO_E_OK ) | |
98 { | |
99 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n"); | |
100 break; | |
101 } | |
102 break; | |
103 case 'N': /* black frame */ | |
104 memset ( decoded, 0, width * height ); | |
105 memset ( decoded + width * height, 127, width * height / 2); | |
106 break; | |
107 case 'L': /* copy last frame */ | |
108 #ifdef KEEP_BUFFER | |
109 memcpy ( decoded, previous_buffer, width*height*3/2); | |
110 #endif | |
111 break; | |
112 } | |
113 | |
114 #ifdef KEEP_BUFFER | |
115 memcpy(previous_buffer, decoded, width*height*3/2); | |
116 #endif | |
117 break; | |
118 } | |
119 default: | |
120 mp_msg(MSGT_DECVIDEO, MSGL_V, "Nuppelvideo: unknwon frametype: %c\n", | |
121 encodedh->frametype); | |
122 } | |
123 } |