annotate libmpcodecs/vd_raw.c @ 35643:f8eb470c25ea

Add doxygen comments.
author ib
date Sat, 12 Jan 2013 00:04:24 +0000
parents 0f14ab03ec98
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30421
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
1 /*
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
2 * This file is part of MPlayer.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
3 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
5 * it under the terms of the GNU General Public License as published by
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
7 * (at your option) any later version.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
8 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
12 * GNU General Public License for more details.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
13 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
14 * You should have received a copy of the GNU General Public License along
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
17 */
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
18
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
19 #include <stdio.h>
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
20 #include <stdlib.h>
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
21
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
22 #include "config.h"
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
23 #include "mp_msg.h"
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
24
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
25 #include "vd_internal.h"
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
26
30504
cc27da5d7286 Mark all ad_info_t/vd_info_t structure declarations as const.
diego
parents: 30421
diff changeset
27 static const vd_info_t info = {
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
28 "RAW Uncompressed Video",
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
29 "raw",
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
30 "A'rpi",
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
31 "A'rpi & Alex",
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
32 "uncompressed"
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
33 };
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
34
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
35 LIBVD_EXTERN(raw)
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
36
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
37 // to set/get/query special features/parameters
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
38 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
39 int format = sh->bih ? sh->bih->biCompression : sh->format;
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
40 switch(cmd){
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
41 case VDCTRL_QUERY_FORMAT:
23298
4726edea2edd Make vd_raw VDCTRL_QUERY_FORMAT simpler to understand
reimar
parents: 10742
diff changeset
42 if (*(int *)arg == format) return CONTROL_TRUE;
25182
b90f13d1f7eb Add support for Apple's yuv2 raw format
reimar
parents: 23298
diff changeset
43 if (*(int *)arg == IMGFMT_YUY2 && format == MKTAG('y', 'u', 'v', '2')) return CONTROL_TRUE;
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
44 return CONTROL_FALSE;
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
45 }
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
46 return CONTROL_UNKNOWN;
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
47 }
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
48
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
49 // init driver
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
50 static int init(sh_video_t *sh){
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
51 // set format fourcc for raw RGB:
6502
01ada897cc89 don't require sh->bih (should fix v4l)
arpi
parents: 6480
diff changeset
52 if(sh->bih && sh->bih->biCompression==0){ // set based on bit depth
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
53 switch(sh->bih->biBitCount){
7773
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
54 case 1: sh->bih->biCompression=IMGFMT_BGR1; break;
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
55 case 4: sh->bih->biCompression=IMGFMT_BGR4; break;
6229
b03cdd8adb32 - modify bih->biCompression instead of sh->format
arpi
parents: 5966
diff changeset
56 case 8: sh->bih->biCompression=IMGFMT_BGR8; break;
b03cdd8adb32 - modify bih->biCompression instead of sh->format
arpi
parents: 5966
diff changeset
57 case 15: sh->bih->biCompression=IMGFMT_BGR15; break;
b03cdd8adb32 - modify bih->biCompression instead of sh->format
arpi
parents: 5966
diff changeset
58 // workaround bitcount==16 => bgr15 case for avi files:
b03cdd8adb32 - modify bih->biCompression instead of sh->format
arpi
parents: 5966
diff changeset
59 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
60 case 24: sh->bih->biCompression=IMGFMT_BGR24; break;
b03cdd8adb32 - modify bih->biCompression instead of sh->format
arpi
parents: 5966
diff changeset
61 case 32: sh->bih->biCompression=IMGFMT_BGR32; break;
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
62 default:
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
63 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"RAW: depth %d not supported\n",sh->bih->biBitCount);
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
64 }
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
65 }
6502
01ada897cc89 don't require sh->bih (should fix v4l)
arpi
parents: 6480
diff changeset
66 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
67 }
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
68
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
69 // uninit driver
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
70 static void uninit(sh_video_t *sh){
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
71 }
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
72
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
73 //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
74
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
75 // decode a frame
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
76 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
77 mp_image_t* mpi;
7773
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
78 int frame_size;
25182
b90f13d1f7eb Add support for Apple's yuv2 raw format
reimar
parents: 23298
diff changeset
79 int format = sh->bih ? sh->bih->biCompression : sh->format;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25182
diff changeset
80
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
81 if(len<=0) return NULL; // skipped frame
7773
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
82
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25182
diff changeset
83 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0,
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
84 sh->disp_w, sh->disp_h);
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
85 if(!mpi) return NULL;
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
86
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
87 if(mpi->flags&MP_IMGFLAG_PLANAR){
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
88 // TODO !!!
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
89 mpi->planes[0]=data;
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
90 mpi->stride[0]=mpi->width;
7773
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
91 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
92 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
93 {
794b55a44528 basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents: 7782
diff changeset
94 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
95 mpi->stride[1]=mpi->chroma_width;
794b55a44528 basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents: 7782
diff changeset
96 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
97 } 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
98 int cb=2, cr=1;
794b55a44528 basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents: 7782
diff changeset
99 if(mpi->flags&MP_IMGFLAG_SWAPPED) {
794b55a44528 basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents: 7782
diff changeset
100 cb=1; cr=2;
794b55a44528 basic nv12 and nv21 support by Angelo Cano <angelo_cano@fastmail.fm>
alex
parents: 7782
diff changeset
101 }
5271
81f31373837e adding support for 12 bit planar YUV formats (for YUV4MPEG(2))
rik
parents: 5124
diff changeset
102 // Support for some common Planar YUV formats
6480
0dcaa477d200 yvu9 support
alex
parents: 6229
diff changeset
103 /* YV12,I420,IYUV */
6667
15efad628385 yuv handling simplified (using new mpi fields)
alex
parents: 6502
diff changeset
104 mpi->planes[cb]=mpi->planes[0]+mpi->width*mpi->height;
15efad628385 yuv handling simplified (using new mpi fields)
alex
parents: 6502
diff changeset
105 mpi->stride[cb]=mpi->chroma_width;
15efad628385 yuv handling simplified (using new mpi fields)
alex
parents: 6502
diff changeset
106 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
107 mpi->stride[cr]=mpi->chroma_width;
7773
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
108 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
109 }
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
110 } else {
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
111 mpi->planes[0]=data;
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
112 mpi->stride[0]=mpi->width*(mpi->bpp/8);
6229
b03cdd8adb32 - modify bih->biCompression instead of sh->format
arpi
parents: 5966
diff changeset
113 // .AVI files has uncompressed lines 4-byte aligned:
b03cdd8adb32 - modify bih->biCompression instead of sh->format
arpi
parents: 5966
diff changeset
114 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
115 if(mpi->imgfmt==IMGFMT_RGB8 || mpi->imgfmt==IMGFMT_BGR8){
a79f46ea2a6a 8bpp raw avi support
arpi
parents: 5271
diff changeset
116 // export palette:
7782
4f6bbaf09dbc fixing palette export
arpi
parents: 7773
diff changeset
117 mpi->planes[1]=sh->bih ? (unsigned char*)(sh->bih+1) : NULL;
4f6bbaf09dbc fixing palette export
arpi
parents: 7773
diff changeset
118 #if 0
4f6bbaf09dbc fixing palette export
arpi
parents: 7773
diff changeset
119 printf("Exporting palette: %p !!\n",mpi->planes[1]);
4f6bbaf09dbc fixing palette export
arpi
parents: 7773
diff changeset
120 { unsigned char* p=mpi->planes[1];
4f6bbaf09dbc fixing palette export
arpi
parents: 7773
diff changeset
121 int i;
4f6bbaf09dbc fixing palette export
arpi
parents: 7773
diff changeset
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]);
4f6bbaf09dbc fixing palette export
arpi
parents: 7773
diff changeset
123 }
4f6bbaf09dbc fixing palette export
arpi
parents: 7773
diff changeset
124 #endif
5899
a79f46ea2a6a 8bpp raw avi support
arpi
parents: 5271
diff changeset
125 }
7773
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
126 frame_size=mpi->stride[0]*mpi->h;
30930
0f14ab03ec98 Fix crash with incomplete yuv2 frames.
reimar
parents: 30504
diff changeset
127 if (len >= frame_size && format == MKTAG('y', 'u', 'v', '2')) {
25182
b90f13d1f7eb Add support for Apple's yuv2 raw format
reimar
parents: 23298
diff changeset
128 int i;
b90f13d1f7eb Add support for Apple's yuv2 raw format
reimar
parents: 23298
diff changeset
129 for (i = 1; i < frame_size; i += 2)
b90f13d1f7eb Add support for Apple's yuv2 raw format
reimar
parents: 23298
diff changeset
130 mpi->planes[0][i] ^= 128;
b90f13d1f7eb Add support for Apple's yuv2 raw format
reimar
parents: 23298
diff changeset
131 }
7773
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
132 if(mpi->bpp<8) frame_size=frame_size*mpi->bpp/8;
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
133 }
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
134
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
135 if(len<frame_size){
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
136 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Frame too small! (%d<%d) Wrong format?\n",
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
137 len,frame_size);
e7dd97c4c840 rgb1/rgb4 support
arpi
parents: 7180
diff changeset
138 return NULL;
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
139 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25182
diff changeset
140
4969
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
141 return mpi;
db86fcf25ede xanim, raw, rle added
arpi
parents:
diff changeset
142 }