annotate libmpcodecs/vd_raw.c @ 25924:257833210f96

sync w/r25955
author gpoirier
date Tue, 05 Feb 2008 12:28:41 +0000
parents b90f13d1f7eb
children 0f1b5b68af32
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
1 #include <stdio.h>
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
2 #include <stdlib.h>
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
3
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
4 #include "config.h"
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
5 #include "mp_msg.h"
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
6
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
7 #include "vd_internal.h"
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
8
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
9 static vd_info_t info = {
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
10 "RAW Uncompressed Video",
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
11 "raw",
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
12 "A'rpi",
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
13 "A'rpi & Alex",
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
14 "uncompressed"
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
15 };
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
16
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
17 LIBVD_EXTERN(raw)
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
18
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
19 // to set/get/query special features/parameters
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
20 static int control(sh_video_t *sh,int cmd,void* arg,...){
23298
4726edea2edd Make vd_raw VDCTRL_QUERY_FORMAT simpler to understand
reimar
parents: 10742
diff changeset
21 int format = sh->bih ? sh->bih->biCompression : sh->format;
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
22 switch(cmd){
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
23 case VDCTRL_QUERY_FORMAT:
23298
4726edea2edd Make vd_raw VDCTRL_QUERY_FORMAT simpler to understand
reimar
parents: 10742
diff changeset
24 if (*(int *)arg == format) return CONTROL_TRUE;
25182
b90f13d1f7eb Add support for Apple's yuv2 raw format
reimar
parents: 23298
diff changeset
25 if (*(int *)arg == IMGFMT_YUY2 && format == MKTAG('y', 'u', 'v', '2')) return CONTROL_TRUE;
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
26 return CONTROL_FALSE;
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
27 }
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
28 return CONTROL_UNKNOWN;
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
29 }
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
30
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
31 // init driver
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
32 static int init(sh_video_t *sh){
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
33 // set format fourcc for raw RGB:
6502
01ada897cc89 don't require sh->bih (should fix v4l)
arpi
parents: 6480
diff changeset
34 if(sh->bih && sh->bih->biCompression==0){ // set based on bit depth
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
35 switch(sh->bih->biBitCount){
7773
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
36 case 1: sh->bih->biCompression=IMGFMT_BGR1; break;
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
37 case 4: sh->bih->biCompression=IMGFMT_BGR4; break;
6229
b03cdd8adb32 - modify bih->biCompression instead of sh->format
arpi
parents: 5966
diff changeset
38 case 8: sh->bih->biCompression=IMGFMT_BGR8; break;
b03cdd8adb32 - modify bih->biCompression instead of sh->format
arpi
parents: 5966
diff changeset
39 case 15: sh->bih->biCompression=IMGFMT_BGR15; break;
b03cdd8adb32 - modify bih->biCompression instead of sh->format
arpi
parents: 5966
diff changeset
40 // workaround bitcount==16 => bgr15 case for avi files:
b03cdd8adb32 - modify bih->biCompression instead of sh->format
arpi
parents: 5966
diff changeset
41 case 16: sh->bih->biCompression=(sh->format)?IMGFMT_BGR16:IMGFMT_BGR15; break;
b03cdd8adb32 - modify bih->biCompression instead of sh->format
arpi
parents: 5966
diff changeset
42 case 24: sh->bih->biCompression=IMGFMT_BGR24; break;
b03cdd8adb32 - modify bih->biCompression instead of sh->format
arpi
parents: 5966
diff changeset
43 case 32: sh->bih->biCompression=IMGFMT_BGR32; break;
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
44 default:
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
45 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"RAW: depth %d not supported\n",sh->bih->biBitCount);
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
46 }
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
47 }
6502
01ada897cc89 don't require sh->bih (should fix v4l)
arpi
parents: 6480
diff changeset
48 return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,sh->bih ? sh->bih->biCompression : sh->format);
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
49 }
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
50
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
51 // uninit driver
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
52 static void uninit(sh_video_t *sh){
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
53 }
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
54
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
55 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
56
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
57 // decode a frame
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
58 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
59 mp_image_t* mpi;
7773
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
60 int frame_size;
25182
b90f13d1f7eb Add support for Apple's yuv2 raw format
reimar
parents: 23298
diff changeset
61 int format = sh->bih ? sh->bih->biCompression : sh->format;
7773
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
62
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
63 if(len<=0) return NULL; // skipped frame
7773
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
64
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
65 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0,
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
66 sh->disp_w, sh->disp_h);
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
67 if(!mpi) return NULL;
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
68
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
69 if(mpi->flags&MP_IMGFLAG_PLANAR){
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
70 // TODO !!!
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
71 mpi->planes[0]=data;
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
72 mpi->stride[0]=mpi->width;
7773
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
73 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
74 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
75 {
794b55a44528 basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents: 7782
diff changeset
76 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
77 mpi->stride[1]=mpi->chroma_width;
794b55a44528 basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents: 7782
diff changeset
78 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
79 } 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
80 int cb=2, cr=1;
794b55a44528 basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents: 7782
diff changeset
81 if(mpi->flags&MP_IMGFLAG_SWAPPED) {
794b55a44528 basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents: 7782
diff changeset
82 cb=1; cr=2;
794b55a44528 basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents: 7782
diff changeset
83 }
5271
81f31373837e adding support for 12 bit planar YUV formats (for YUV4MPEG(2))
rik
parents: 5124
diff changeset
84 // Support for some common Planar YUV formats
6480
0dcaa477d200 yvu9 support
alex
parents: 6229
diff changeset
85 /* YV12,I420,IYUV */
6667
15efad628385 yuv handling simplified (using new mpi fields)
alex
parents: 6502
diff changeset
86 mpi->planes[cb]=mpi->planes[0]+mpi->width*mpi->height;
15efad628385 yuv handling simplified (using new mpi fields)
alex
parents: 6502
diff changeset
87 mpi->stride[cb]=mpi->chroma_width;
15efad628385 yuv handling simplified (using new mpi fields)
alex
parents: 6502
diff changeset
88 mpi->planes[cr]=mpi->planes[cb]+mpi->chroma_width*mpi->chroma_height;
15efad628385 yuv handling simplified (using new mpi fields)
alex
parents: 6502
diff changeset
89 mpi->stride[cr]=mpi->chroma_width;
7773
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
90 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
91 }
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
92 } else {
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
93 mpi->planes[0]=data;
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
94 mpi->stride[0]=mpi->width*(mpi->bpp/8);
6229
b03cdd8adb32 - modify bih->biCompression instead of sh->format
arpi
parents: 5966
diff changeset
95 // .AVI files has uncompressed lines 4-byte aligned:
b03cdd8adb32 - modify bih->biCompression instead of sh->format
arpi
parents: 5966
diff changeset
96 if(sh->format==0 || sh->format==3) mpi->stride[0]=(mpi->stride[0]+3)&(~3);
5899
a79f46ea2a6a 8bpp raw avi support
arpi
parents: 5271
diff changeset
97 if(mpi->imgfmt==IMGFMT_RGB8 || mpi->imgfmt==IMGFMT_BGR8){
a79f46ea2a6a 8bpp raw avi support
arpi
parents: 5271
diff changeset
98 // export palette:
7782
4f6bbaf09dbc fixing palette export
arpi
parents: 7773
diff changeset
99 mpi->planes[1]=sh->bih ? (unsigned char*)(sh->bih+1) : NULL;
4f6bbaf09dbc fixing palette export
arpi
parents: 7773
diff changeset
100 #if 0
4f6bbaf09dbc fixing palette export
arpi
parents: 7773
diff changeset
101 printf("Exporting palette: %p !!\n",mpi->planes[1]);
4f6bbaf09dbc fixing palette export
arpi
parents: 7773
diff changeset
102 { unsigned char* p=mpi->planes[1];
4f6bbaf09dbc fixing palette export
arpi
parents: 7773
diff changeset
103 int i;
4f6bbaf09dbc fixing palette export
arpi
parents: 7773
diff changeset
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]);
4f6bbaf09dbc fixing palette export
arpi
parents: 7773
diff changeset
105 }
4f6bbaf09dbc fixing palette export
arpi
parents: 7773
diff changeset
106 #endif
5899
a79f46ea2a6a 8bpp raw avi support
arpi
parents: 5271
diff changeset
107 }
7773
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
108 frame_size=mpi->stride[0]*mpi->h;
25182
b90f13d1f7eb Add support for Apple's yuv2 raw format
reimar
parents: 23298
diff changeset
109 if (format == MKTAG('y', 'u', 'v', '2')) {
b90f13d1f7eb Add support for Apple's yuv2 raw format
reimar
parents: 23298
diff changeset
110 int i;
b90f13d1f7eb Add support for Apple's yuv2 raw format
reimar
parents: 23298
diff changeset
111 for (i = 1; i < frame_size; i += 2)
b90f13d1f7eb Add support for Apple's yuv2 raw format
reimar
parents: 23298
diff changeset
112 mpi->planes[0][i] ^= 128;
b90f13d1f7eb Add support for Apple's yuv2 raw format
reimar
parents: 23298
diff changeset
113 }
7773
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
114 if(mpi->bpp<8) frame_size=frame_size*mpi->bpp/8;
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
115 }
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
116
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
117 if(len<frame_size){
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
118 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Frame too small! (%d<%d) Wrong format?\n",
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
119 len,frame_size);
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
120 return NULL;
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
121 }
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
122
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
123 return mpi;
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
124 }