Mercurial > mplayer.hg
annotate libmpcodecs/vd_raw.c @ 18619:106a0c366002
Reworked YUV2RGB fragment program setup in preparation for upcoming patches
author | reimar |
---|---|
date | Wed, 07 Jun 2006 13:24:54 +0000 |
parents | 794b55a44528 |
children | 4726edea2edd |
rev | line source |
---|---|
4969 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 | |
4 #include "config.h" | |
5 #include "mp_msg.h" | |
6 | |
7 #include "vd_internal.h" | |
8 | |
9 static vd_info_t info = { | |
10 "RAW Uncompressed Video", | |
11 "raw", | |
12 "A'rpi", | |
13 "A'rpi & Alex", | |
14 "uncompressed" | |
15 }; | |
16 | |
17 LIBVD_EXTERN(raw) | |
18 | |
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: | |
6502 | 23 if( (*((int*)arg)) == (sh->bih ? sh->bih->biCompression : sh->format) ) return CONTROL_TRUE; |
4969 | 24 return CONTROL_FALSE; |
25 } | |
26 return CONTROL_UNKNOWN; | |
27 } | |
28 | |
29 // init driver | |
30 static int init(sh_video_t *sh){ | |
31 // set format fourcc for raw RGB: | |
6502 | 32 if(sh->bih && sh->bih->biCompression==0){ // set based on bit depth |
4969 | 33 switch(sh->bih->biBitCount){ |
7773 | 34 case 1: sh->bih->biCompression=IMGFMT_BGR1; break; |
35 case 4: sh->bih->biCompression=IMGFMT_BGR4; break; | |
6229 | 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; | |
4969 | 42 default: |
43 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"RAW: depth %d not supported\n",sh->bih->biBitCount); | |
44 } | |
45 } | |
6502 | 46 return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,sh->bih ? sh->bih->biCompression : sh->format); |
4969 | 47 } |
48 | |
49 // uninit driver | |
50 static void uninit(sh_video_t *sh){ | |
51 } | |
52 | |
53 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h); | |
54 | |
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; | |
7773 | 58 int frame_size; |
59 | |
4969 | 60 if(len<=0) return NULL; // skipped frame |
7773 | 61 |
4969 | 62 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0, |
63 sh->disp_w, sh->disp_h); | |
64 if(!mpi) return NULL; | |
65 | |
66 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
67 // TODO !!! | |
68 mpi->planes[0]=data; | |
69 mpi->stride[0]=mpi->width; | |
7773 | 70 frame_size=mpi->stride[0]*mpi->h; |
10742
794b55a44528
basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents:
7782
diff
changeset
|
71 if((mpi->imgfmt == IMGFMT_NV12) || (mpi->imgfmt == IMGFMT_NV21)) |
794b55a44528
basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents:
7782
diff
changeset
|
72 { |
794b55a44528
basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents:
7782
diff
changeset
|
73 mpi->planes[1]=mpi->planes[0]+mpi->width*mpi->height; |
794b55a44528
basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents:
7782
diff
changeset
|
74 mpi->stride[1]=mpi->chroma_width; |
794b55a44528
basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents:
7782
diff
changeset
|
75 frame_size+=mpi->chroma_width*mpi->chroma_height; |
794b55a44528
basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents:
7782
diff
changeset
|
76 } else if(mpi->flags&MP_IMGFLAG_YUV) { |
794b55a44528
basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents:
7782
diff
changeset
|
77 int cb=2, cr=1; |
794b55a44528
basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents:
7782
diff
changeset
|
78 if(mpi->flags&MP_IMGFLAG_SWAPPED) { |
794b55a44528
basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents:
7782
diff
changeset
|
79 cb=1; cr=2; |
794b55a44528
basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents:
7782
diff
changeset
|
80 } |
5271
81f31373837e
adding support for 12 bit planar YUV formats (for YUV4MPEG(2))
rik
parents:
5124
diff
changeset
|
81 // Support for some common Planar YUV formats |
6480 | 82 /* YV12,I420,IYUV */ |
6667 | 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; | |
7773 | 87 frame_size+=2*mpi->chroma_width*mpi->chroma_height; |
5271
81f31373837e
adding support for 12 bit planar YUV formats (for YUV4MPEG(2))
rik
parents:
5124
diff
changeset
|
88 } |
4969 | 89 } else { |
90 mpi->planes[0]=data; | |
91 mpi->stride[0]=mpi->width*(mpi->bpp/8); | |
6229 | 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); | |
5899 | 94 if(mpi->imgfmt==IMGFMT_RGB8 || mpi->imgfmt==IMGFMT_BGR8){ |
95 // export palette: | |
7782 | 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]); | |
102 } | |
103 #endif | |
5899 | 104 } |
7773 | 105 frame_size=mpi->stride[0]*mpi->h; |
106 if(mpi->bpp<8) frame_size=frame_size*mpi->bpp/8; | |
107 } | |
108 | |
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; | |
4969 | 113 } |
114 | |
115 return mpi; | |
116 } |