~ubuntu-branches/ubuntu/oneiric/mplayer2/oneiric-proposed

« back to all changes in this revision

Viewing changes to mplayer/libmpcodecs/vd_raw.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2011-03-20 22:48:03 UTC
  • Revision ID: james.westby@ubuntu.com-20110320224803-kc2nlrxz6pcphmf1
Tags: upstream-2.0~rc2
ImportĀ upstreamĀ versionĀ 2.0~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of MPlayer.
 
3
 *
 
4
 * MPlayer is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * MPlayer is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License along
 
15
 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
 
16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
17
 */
 
18
 
 
19
#include <stdio.h>
 
20
#include <stdlib.h>
 
21
 
 
22
#include "config.h"
 
23
#include "mp_msg.h"
 
24
 
 
25
#include "vd_internal.h"
 
26
 
 
27
static const vd_info_t info = {
 
28
        "RAW Uncompressed Video",
 
29
        "raw",
 
30
        "A'rpi",
 
31
        "A'rpi & Alex",
 
32
        "uncompressed"
 
33
};
 
34
 
 
35
LIBVD_EXTERN(raw)
 
36
 
 
37
// to set/get/query special features/parameters
 
38
static int control(sh_video_t *sh,int cmd,void* arg,...){
 
39
    int format = sh->bih ? sh->bih->biCompression : sh->format;
 
40
    switch(cmd){
 
41
    case VDCTRL_QUERY_FORMAT:
 
42
        if (*(int *)arg == format) return CONTROL_TRUE;
 
43
        if (*(int *)arg == IMGFMT_YUY2 && format == MKTAG('y', 'u', 'v', '2')) return CONTROL_TRUE;
 
44
        return CONTROL_FALSE;
 
45
    }
 
46
    return CONTROL_UNKNOWN;
 
47
}
 
48
 
 
49
// init driver
 
50
static int init(sh_video_t *sh){
 
51
    // set format fourcc for raw RGB:
 
52
    if(sh->bih && sh->bih->biCompression==0){   // set based on bit depth
 
53
        switch(sh->bih->biBitCount){
 
54
        case 1:  sh->bih->biCompression=IMGFMT_BGR1; break;
 
55
        case 4:  sh->bih->biCompression=IMGFMT_BGR4; break;
 
56
        case 8:  sh->bih->biCompression=IMGFMT_BGR8; break;
 
57
        case 15: sh->bih->biCompression=IMGFMT_BGR15; break;
 
58
        // workaround bitcount==16 => bgr15 case for avi files:
 
59
        case 16: sh->bih->biCompression=(sh->format)?IMGFMT_BGR16:IMGFMT_BGR15; break;
 
60
        case 24: sh->bih->biCompression=IMGFMT_BGR24; break;
 
61
        case 32: sh->bih->biCompression=IMGFMT_BGR32; break;
 
62
        default:
 
63
            mp_msg(MSGT_DECVIDEO,MSGL_WARN,"RAW: depth %d not supported\n",sh->bih->biBitCount);
 
64
        }
 
65
    }
 
66
    return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,sh->bih ? sh->bih->biCompression : sh->format);
 
67
}
 
68
 
 
69
// uninit driver
 
70
static void uninit(sh_video_t *sh){
 
71
}
 
72
 
 
73
//mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
 
74
 
 
75
// decode a frame
 
76
static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
 
77
    mp_image_t* mpi;
 
78
    int frame_size;
 
79
    int format = sh->bih ? sh->bih->biCompression : sh->format;
 
80
 
 
81
    if(len<=0) return NULL; // skipped frame
 
82
 
 
83
    mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0,
 
84
        sh->disp_w, sh->disp_h);
 
85
    if(!mpi) return NULL;
 
86
 
 
87
    if(mpi->flags&MP_IMGFLAG_PLANAR){
 
88
        // TODO !!!
 
89
        mpi->planes[0]=data;
 
90
        mpi->stride[0]=mpi->width;
 
91
        frame_size=mpi->stride[0]*mpi->h;
 
92
        if((mpi->imgfmt == IMGFMT_NV12) || (mpi->imgfmt == IMGFMT_NV21))
 
93
        {
 
94
            mpi->planes[1]=mpi->planes[0]+mpi->width*mpi->height;
 
95
            mpi->stride[1]=mpi->chroma_width;
 
96
            frame_size+=mpi->chroma_width*mpi->chroma_height;
 
97
        } else if(mpi->flags&MP_IMGFLAG_YUV) {
 
98
            int cb=2, cr=1;
 
99
            if(mpi->flags&MP_IMGFLAG_SWAPPED) {
 
100
                cb=1; cr=2;
 
101
            }
 
102
            // Support for some common Planar YUV formats
 
103
            /* YV12,I420,IYUV */
 
104
            mpi->planes[cb]=mpi->planes[0]+mpi->width*mpi->height;
 
105
            mpi->stride[cb]=mpi->chroma_width;
 
106
            mpi->planes[cr]=mpi->planes[cb]+mpi->chroma_width*mpi->chroma_height;
 
107
            mpi->stride[cr]=mpi->chroma_width;
 
108
            frame_size+=2*mpi->chroma_width*mpi->chroma_height;
 
109
        }
 
110
    } else {
 
111
        mpi->planes[0]=data;
 
112
        mpi->stride[0]=mpi->width*(mpi->bpp/8);
 
113
        // .AVI files has uncompressed lines 4-byte aligned:
 
114
        if(sh->format==0 || sh->format==3) mpi->stride[0]=(mpi->stride[0]+3)&(~3);
 
115
        if(mpi->imgfmt==IMGFMT_RGB8 || mpi->imgfmt==IMGFMT_BGR8){
 
116
            // export palette:
 
117
            mpi->planes[1]=sh->bih ? (unsigned char*)(sh->bih+1) : NULL;
 
118
#if 0
 
119
            printf("Exporting palette: %p !!\n",mpi->planes[1]);
 
120
            {   unsigned char* p=mpi->planes[1];
 
121
                int i;
 
122
                for(i=0;i<64;i++) printf("%3d: %02X %02X %02X (%02X)\n",i,p[4*i],p[4*i+1],p[4*i+2],p[4*i+3]);
 
123
            }
 
124
#endif
 
125
        }
 
126
        frame_size=mpi->stride[0]*mpi->h;
 
127
        if (len >= frame_size && format == MKTAG('y', 'u', 'v', '2')) {
 
128
          int i;
 
129
          for (i = 1; i < frame_size; i += 2)
 
130
            mpi->planes[0][i] ^= 128;
 
131
        }
 
132
        if(mpi->bpp<8) frame_size=frame_size*mpi->bpp/8;
 
133
    }
 
134
 
 
135
    if(len<frame_size){
 
136
        mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Frame too small! (%d<%d) Wrong format?\n",
 
137
            len,frame_size);
 
138
        return NULL;
 
139
    }
 
140
 
 
141
    return mpi;
 
142
}