cocoa_common: add HiDPI/retina support
[mplayer.git] / libmpcodecs / vd_raw.c
blob4b18ab301e8cdba8ffaed006a995f491571a0a8b
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdio.h>
20 #include <stdlib.h>
22 #include "config.h"
23 #include "mp_msg.h"
25 #include "vd_internal.h"
27 static const vd_info_t info = {
28 "RAW Uncompressed Video",
29 "raw",
30 "A'rpi",
31 "A'rpi & Alex",
32 "uncompressed"
35 LIBVD_EXTERN(raw)
37 // to set/get/query special features/parameters
38 static int control(sh_video_t *sh,int cmd,void* arg,...){
39 int format = sh->bih ? sh->bih->biCompression : sh->format;
40 switch(cmd){
41 case VDCTRL_QUERY_FORMAT:
42 if (*(int *)arg == format) return CONTROL_TRUE;
43 if (*(int *)arg == IMGFMT_YUY2 && format == MKTAG('y', 'u', 'v', '2')) return CONTROL_TRUE;
44 return CONTROL_FALSE;
46 return CONTROL_UNKNOWN;
49 // init driver
50 static int init(sh_video_t *sh){
51 // set format fourcc for raw RGB:
52 if(sh->bih && sh->bih->biCompression==0){ // set based on bit depth
53 switch(sh->bih->biBitCount){
54 case 1: sh->bih->biCompression=IMGFMT_BGR1; break;
55 case 4: sh->bih->biCompression=IMGFMT_BGR4; break;
56 case 8: sh->bih->biCompression=IMGFMT_BGR8; break;
57 case 15: sh->bih->biCompression=IMGFMT_BGR15; break;
58 // workaround bitcount==16 => bgr15 case for avi files:
59 case 16: sh->bih->biCompression=(sh->format)?IMGFMT_BGR16:IMGFMT_BGR15; break;
60 case 24: sh->bih->biCompression=IMGFMT_BGR24; break;
61 case 32: sh->bih->biCompression=IMGFMT_BGR32; break;
62 default:
63 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"RAW: depth %d not supported\n",sh->bih->biBitCount);
66 return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,sh->bih ? sh->bih->biCompression : sh->format);
69 // uninit driver
70 static void uninit(sh_video_t *sh){
73 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
75 // decode a frame
76 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
77 mp_image_t* mpi;
78 int frame_size;
79 int format = sh->bih ? sh->bih->biCompression : sh->format;
81 if(len<=0) return NULL; // skipped frame
83 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0,
84 sh->disp_w, sh->disp_h);
85 if(!mpi) return NULL;
87 if(mpi->flags&MP_IMGFLAG_PLANAR){
88 // TODO !!!
89 mpi->planes[0]=data;
90 mpi->stride[0]=mpi->width;
91 frame_size=mpi->stride[0]*mpi->h;
92 if((mpi->imgfmt == IMGFMT_NV12) || (mpi->imgfmt == IMGFMT_NV21))
94 mpi->planes[1]=mpi->planes[0]+mpi->width*mpi->height;
95 mpi->stride[1]=mpi->chroma_width;
96 frame_size+=mpi->chroma_width*mpi->chroma_height;
97 } else if(mpi->flags&MP_IMGFLAG_YUV) {
98 int cb=2, cr=1;
99 if(mpi->flags&MP_IMGFLAG_SWAPPED) {
100 cb=1; cr=2;
102 // Support for some common Planar YUV formats
103 /* YV12,I420,IYUV */
104 mpi->planes[cb]=mpi->planes[0]+mpi->width*mpi->height;
105 mpi->stride[cb]=mpi->chroma_width;
106 mpi->planes[cr]=mpi->planes[cb]+mpi->chroma_width*mpi->chroma_height;
107 mpi->stride[cr]=mpi->chroma_width;
108 frame_size+=2*mpi->chroma_width*mpi->chroma_height;
110 } else {
111 mpi->planes[0]=data;
112 mpi->stride[0]=mpi->width*(mpi->bpp/8);
113 // .AVI files has uncompressed lines 4-byte aligned:
114 if(sh->format==0 || sh->format==3) mpi->stride[0]=(mpi->stride[0]+3)&(~3);
115 if(mpi->imgfmt==IMGFMT_RGB8 || mpi->imgfmt==IMGFMT_BGR8){
116 // export palette:
117 mpi->planes[1]=sh->bih ? (unsigned char*)(sh->bih+1) : NULL;
118 #if 0
119 printf("Exporting palette: %p !!\n",mpi->planes[1]);
120 { unsigned char* p=mpi->planes[1];
121 int i;
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]);
124 #endif
126 frame_size=mpi->stride[0]*mpi->h;
127 if (len >= frame_size && format == MKTAG('y', 'u', 'v', '2')) {
128 int i;
129 for (i = 1; i < frame_size; i += 2)
130 mpi->planes[0][i] ^= 128;
132 if(mpi->bpp<8) frame_size=frame_size*mpi->bpp/8;
135 if(len<frame_size){
136 mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Frame too small! (%d<%d) Wrong format?\n",
137 len,frame_size);
138 return NULL;
141 return mpi;