vo_xv: Fix context Shminfo table size
[mplayer.git] / libmpcodecs / vd_raw.c
blob7eeda88c002c991f3ec531cc86d4e7eab738677f
1 #include <stdio.h>
2 #include <stdlib.h>
4 #include "config.h"
5 #include "mp_msg.h"
7 #include "vd_internal.h"
9 static const 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 int format = sh->bih ? sh->bih->biCompression : sh->format;
22 switch(cmd){
23 case VDCTRL_QUERY_FORMAT:
24 if (*(int *)arg == format) return CONTROL_TRUE;
25 if (*(int *)arg == IMGFMT_YUY2 && format == MKTAG('y', 'u', 'v', '2')) return CONTROL_TRUE;
26 return CONTROL_FALSE;
28 return CONTROL_UNKNOWN;
31 // init driver
32 static int init(sh_video_t *sh){
33 // set format fourcc for raw RGB:
34 if(sh->bih && sh->bih->biCompression==0){ // set based on bit depth
35 switch(sh->bih->biBitCount){
36 case 1: sh->bih->biCompression=IMGFMT_BGR1; break;
37 case 4: sh->bih->biCompression=IMGFMT_BGR4; break;
38 case 8: sh->bih->biCompression=IMGFMT_BGR8; break;
39 case 15: sh->bih->biCompression=IMGFMT_BGR15; break;
40 // workaround bitcount==16 => bgr15 case for avi files:
41 case 16: sh->bih->biCompression=(sh->format)?IMGFMT_BGR16:IMGFMT_BGR15; break;
42 case 24: sh->bih->biCompression=IMGFMT_BGR24; break;
43 case 32: sh->bih->biCompression=IMGFMT_BGR32; break;
44 default:
45 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"RAW: depth %d not supported\n",sh->bih->biBitCount);
48 return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,sh->bih ? sh->bih->biCompression : sh->format);
51 // uninit driver
52 static void uninit(sh_video_t *sh){
55 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
57 // decode a frame
58 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
59 mp_image_t* mpi;
60 int frame_size;
61 int format = sh->bih ? sh->bih->biCompression : sh->format;
63 if(len<=0) return NULL; // skipped frame
65 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0,
66 sh->disp_w, sh->disp_h);
67 if(!mpi) return NULL;
69 if(mpi->flags&MP_IMGFLAG_PLANAR){
70 // TODO !!!
71 mpi->planes[0]=data;
72 mpi->stride[0]=mpi->width;
73 frame_size=mpi->stride[0]*mpi->h;
74 if((mpi->imgfmt == IMGFMT_NV12) || (mpi->imgfmt == IMGFMT_NV21))
76 mpi->planes[1]=mpi->planes[0]+mpi->width*mpi->height;
77 mpi->stride[1]=mpi->chroma_width;
78 frame_size+=mpi->chroma_width*mpi->chroma_height;
79 } else if(mpi->flags&MP_IMGFLAG_YUV) {
80 int cb=2, cr=1;
81 if(mpi->flags&MP_IMGFLAG_SWAPPED) {
82 cb=1; cr=2;
84 // Support for some common Planar YUV formats
85 /* YV12,I420,IYUV */
86 mpi->planes[cb]=mpi->planes[0]+mpi->width*mpi->height;
87 mpi->stride[cb]=mpi->chroma_width;
88 mpi->planes[cr]=mpi->planes[cb]+mpi->chroma_width*mpi->chroma_height;
89 mpi->stride[cr]=mpi->chroma_width;
90 frame_size+=2*mpi->chroma_width*mpi->chroma_height;
92 } else {
93 mpi->planes[0]=data;
94 mpi->stride[0]=mpi->width*(mpi->bpp/8);
95 // .AVI files has uncompressed lines 4-byte aligned:
96 if(sh->format==0 || sh->format==3) mpi->stride[0]=(mpi->stride[0]+3)&(~3);
97 if(mpi->imgfmt==IMGFMT_RGB8 || mpi->imgfmt==IMGFMT_BGR8){
98 // export palette:
99 mpi->planes[1]=sh->bih ? (unsigned char*)(sh->bih+1) : NULL;
100 #if 0
101 printf("Exporting palette: %p !!\n",mpi->planes[1]);
102 { unsigned char* p=mpi->planes[1];
103 int i;
104 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]);
106 #endif
108 frame_size=mpi->stride[0]*mpi->h;
109 if (format == MKTAG('y', 'u', 'v', '2')) {
110 int i;
111 for (i = 1; i < frame_size; i += 2)
112 mpi->planes[0][i] ^= 128;
114 if(mpi->bpp<8) frame_size=frame_size*mpi->bpp/8;
117 if(len<frame_size){
118 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Frame too small! (%d<%d) Wrong format?\n",
119 len,frame_size);
120 return NULL;
123 return mpi;