~ubuntu-dev/mplayer/ubuntu-feisty

« back to all changes in this revision

Viewing changes to libmpcodecs/native/nuppelvideo.c

  • Committer: Reinhard Tartler
  • Date: 2006-07-08 08:45:33 UTC
  • Revision ID: siretart@tauware.de-20060708084533-dbc155bde7122e78
imported mplayer_0.99+1.0pre7try2+cvs20060117

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#include <string.h>
 
13
 
 
14
#include "config.h"
 
15
#include "mp_msg.h"
 
16
#include "bswap.h"
 
17
 
 
18
#include "../libvo/fastmemcpy.h"
 
19
 
 
20
#include "libmpdemux/nuppelvideo.h" 
 
21
#include "RTjpegN.h"
 
22
#include "minilzo.h"
 
23
 
 
24
#define KEEP_BUFFER
 
25
 
 
26
void decode_nuv( unsigned char *encoded, int encoded_size,
 
27
                unsigned char *decoded, int width, int height)
 
28
{
 
29
        int r;
 
30
        unsigned int out_len;
 
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
 
36
        static int is_lzo_inited = 0;
 
37
 
 
38
//      printf("frametype: %c, comtype: %c, encoded_size: %d, width: %d, height: %d\n",
 
39
//          encodedh->frametype, encodedh->comptype, encoded_size, width, height);
 
40
 
 
41
        le2me_rtframeheader(encodedh);
 
42
        switch(encodedh->frametype)
 
43
        {
 
44
            case 'D':   /* additional data for compressors */
 
45
            {
 
46
                /* tables are in encoded */
 
47
                if (encodedh->comptype == 'R')
 
48
                {
 
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);
 
52
                }
 
53
                break;
 
54
            }
 
55
            case 'V':
 
56
            {
 
57
#ifdef KEEP_BUFFER              
 
58
                if (!previous_buffer) 
 
59
                        previous_buffer = ( unsigned char * ) malloc ( width * height + ( width * height ) / 2 );
 
60
#endif
 
61
 
 
62
                if (((encodedh->comptype == '2') ||
 
63
                    (encodedh->comptype == '3')) && !is_lzo_inited)
 
64
                {
 
65
                    /* frame using lzo, init lzo first if not inited */
 
66
                    if ( lzo_init() != LZO_E_OK ) 
 
67
                    {
 
68
                        mp_msg(MSGT_DECVIDEO, MSGL_ERR, "LZO init failed\n");
 
69
                        return;
 
70
                    }
 
71
                    is_lzo_inited = 1;
 
72
                }
 
73
 
 
74
                switch(encodedh->comptype)
 
75
                {
 
76
                    case '0': /* raw YUV420 */
 
77
                        memcpy(decoded, encoded + 12, width*height*3/2);
 
78
                        break;
 
79
                    case '1': /* RTJpeg */
 
80
                        RTjpeg_decompressYUV420 ( ( __s8 * ) encoded + 12, decoded );
 
81
                        break;
 
82
                    case '2': /* RTJpeg with LZO */
 
83
                        if (!buffer) 
 
84
                            buffer = ( unsigned char * ) malloc ( width * height + ( width * height ) / 2 );
 
85
                        if (!buffer)
 
86
                        {
 
87
                            mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n");
 
88
                            break;
 
89
                        }
 
90
                        r = lzo1x_decompress ( encoded + 12, encodedh->packetlength, buffer, &out_len, NULL );
 
91
                        if ( r != LZO_E_OK ) 
 
92
                        {
 
93
                            mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n");
 
94
                            break;
 
95
                        }
 
96
                        RTjpeg_decompressYUV420 ( ( __s8 * ) buffer, decoded );
 
97
                        break;
 
98
                    case '3': /* raw YUV420 with LZO */
 
99
                        r = lzo1x_decompress ( encoded + 12, encodedh->packetlength, decoded, &out_len, NULL );
 
100
                        if ( r != LZO_E_OK ) 
 
101
                        {
 
102
                            mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n");
 
103
                            break;
 
104
                        }
 
105
                        break;
 
106
                    case 'N': /* black frame */
 
107
                        memset ( decoded, 0,  width * height );
 
108
                        memset ( decoded + width * height, 127, width * height / 2);
 
109
                        break;
 
110
                    case 'L': /* copy last frame */
 
111
#ifdef KEEP_BUFFER
 
112
                        memcpy ( decoded, previous_buffer, width*height*3/2);
 
113
#endif
 
114
                        break;
 
115
                }
 
116
 
 
117
#ifdef KEEP_BUFFER
 
118
                memcpy(previous_buffer, decoded, width*height*3/2);
 
119
#endif
 
120
                break;
 
121
            }
 
122
            default:
 
123
                mp_msg(MSGT_DECVIDEO, MSGL_V, "Nuppelvideo: unknwon frametype: %c\n",
 
124
                    encodedh->frametype);
 
125
        }
 
126
}