typo fixes
[mplayer/greg.git] / libmpcodecs / vd_raw.c
blob407bcec7e638af00e87b633a436c7dcc21ee630d
1 #include <stdio.h>
2 #include <stdlib.h>
4 #include "config.h"
5 #include "mp_msg.h"
7 #include "vd_internal.h"
9 static vd_info_t info = {
10 "RAW Uncompressed Video",
11 "raw",
12 "A'rpi",
13 "A'rpi & Alex",
14 "uncompressed"
17 LIBVD_EXTERN(raw)
19 // to set/get/query special features/parameters
20 static int control(sh_video_t *sh,int cmd,void* arg,...){
21 switch(cmd){
22 case VDCTRL_QUERY_FORMAT:
23 if( (*((int*)arg)) == (sh->bih ? sh->bih->biCompression : sh->format) ) return CONTROL_TRUE;
24 return CONTROL_FALSE;
26 return CONTROL_UNKNOWN;
29 // init driver
30 static int init(sh_video_t *sh){
31 // set format fourcc for raw RGB:
32 if(sh->bih && sh->bih->biCompression==0){ // set based on bit depth
33 switch(sh->bih->biBitCount){
34 case 1: sh->bih->biCompression=IMGFMT_BGR1; break;
35 case 4: sh->bih->biCompression=IMGFMT_BGR4; break;
36 case 8: sh->bih->biCompression=IMGFMT_BGR8; break;
37 case 15: sh->bih->biCompression=IMGFMT_BGR15; break;
38 // workaround bitcount==16 => bgr15 case for avi files:
39 case 16: sh->bih->biCompression=(sh->format)?IMGFMT_BGR16:IMGFMT_BGR15; break;
40 case 24: sh->bih->biCompression=IMGFMT_BGR24; break;
41 case 32: sh->bih->biCompression=IMGFMT_BGR32; break;
42 default:
43 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"RAW: depth %d not supported\n",sh->bih->biBitCount);
46 return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,sh->bih ? sh->bih->biCompression : sh->format);
49 // uninit driver
50 static void uninit(sh_video_t *sh){
53 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
55 // decode a frame
56 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
57 mp_image_t* mpi;
58 int frame_size;
60 if(len<=0) return NULL; // skipped frame
62 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0,
63 sh->disp_w, sh->disp_h);
64 if(!mpi) return NULL;
66 if(mpi->flags&MP_IMGFLAG_PLANAR){
67 // TODO !!!
68 mpi->planes[0]=data;
69 mpi->stride[0]=mpi->width;
70 frame_size=mpi->stride[0]*mpi->h;
71 if((mpi->imgfmt == IMGFMT_NV12) || (mpi->imgfmt == IMGFMT_NV21))
73 mpi->planes[1]=mpi->planes[0]+mpi->width*mpi->height;
74 mpi->stride[1]=mpi->chroma_width;
75 frame_size+=mpi->chroma_width*mpi->chroma_height;
76 } else if(mpi->flags&MP_IMGFLAG_YUV) {
77 int cb=2, cr=1;
78 if(mpi->flags&MP_IMGFLAG_SWAPPED) {
79 cb=1; cr=2;
81 // Support for some common Planar YUV formats
82 /* YV12,I420,IYUV */
83 mpi->planes[cb]=mpi->planes[0]+mpi->width*mpi->height;
84 mpi->stride[cb]=mpi->chroma_width;
85 mpi->planes[cr]=mpi->planes[cb]+mpi->chroma_width*mpi->chroma_height;
86 mpi->stride[cr]=mpi->chroma_width;
87 frame_size+=2*mpi->chroma_width*mpi->chroma_height;
89 } else {
90 mpi->planes[0]=data;
91 mpi->stride[0]=mpi->width*(mpi->bpp/8);
92 // .AVI files has uncompressed lines 4-byte aligned:
93 if(sh->format==0 || sh->format==3) mpi->stride[0]=(mpi->stride[0]+3)&(~3);
94 if(mpi->imgfmt==IMGFMT_RGB8 || mpi->imgfmt==IMGFMT_BGR8){
95 // export palette:
96 mpi->planes[1]=sh->bih ? (unsigned char*)(sh->bih+1) : NULL;
97 #if 0
98 printf("Exporting palette: %p !!\n",mpi->planes[1]);
99 { unsigned char* p=mpi->planes[1];
100 int i;
101 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]);
103 #endif
105 frame_size=mpi->stride[0]*mpi->h;
106 if(mpi->bpp<8) frame_size=frame_size*mpi->bpp/8;
109 if(len<frame_size){
110 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Frame too small! (%d<%d) Wrong format?\n",
111 len,frame_size);
112 return NULL;
115 return mpi;