vo_gl: Some small whitespace and {} cosmetics
[mplayer/glamo.git] / libmpcodecs / ve_raw.c
blobf2b8e9528cc80d04c8f2b4d94dbf19e87f20ffa1
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>
21 #include <string.h>
23 #include "config.h"
24 #include "mp_msg.h"
26 #include "codec-cfg.h"
27 #include "stream/stream.h"
28 #include "libmpdemux/demuxer.h"
29 #include "libmpdemux/stheader.h"
31 #include "stream/stream.h"
32 #include "libmpdemux/muxer.h"
34 #include "img_format.h"
35 #include "mp_image.h"
36 #include "vf.h"
39 //===========================================================================//
41 struct vf_priv_s {
42 muxer_stream_t* mux;
44 #define mux_v (vf->priv->mux)
46 static int set_format(struct vf_instance *vf, unsigned int fmt) {
47 if (!force_fourcc)
48 mux_v->bih->biCompression = fmt;
50 mux_v->bih->biPlanes = 1;
51 if (IMGFMT_IS_RGB(fmt)) {
52 if (IMGFMT_RGB_DEPTH(fmt) < 8 && !(fmt&128))
53 mux_v->bih->biBitCount = IMGFMT_RGB_DEPTH(fmt);
54 else
55 mux_v->bih->biBitCount = (IMGFMT_RGB_DEPTH(fmt)+7)&(~7);
56 return 1;
58 if (IMGFMT_IS_BGR(fmt)) {
59 if (IMGFMT_BGR_DEPTH(fmt) < 8 && !(fmt&128))
60 mux_v->bih->biBitCount = IMGFMT_BGR_DEPTH(fmt);
61 else
62 mux_v->bih->biBitCount = (IMGFMT_BGR_DEPTH(fmt)+7)&(~7);
63 return 1;
65 switch (fmt) {
66 case IMGFMT_I420:
67 case IMGFMT_IYUV:
68 case IMGFMT_YV12:
69 case IMGFMT_411P:
70 mux_v->bih->biPlanes = 3;
71 mux_v->bih->biBitCount = 12;
72 break;
73 case IMGFMT_444P:
74 mux_v->bih->biPlanes = 3;
75 mux_v->bih->biBitCount = 24;
76 break;
77 case IMGFMT_422P:
78 mux_v->bih->biPlanes = 3;
79 mux_v->bih->biBitCount = 16;
80 break;
81 case IMGFMT_IF09:
82 mux_v->bih->biPlanes = 4;
83 case IMGFMT_YVU9:
84 mux_v->bih->biBitCount = 9;
85 break;
86 case IMGFMT_UYVY:
87 case IMGFMT_YUY2:
88 mux_v->bih->biBitCount = 16;
89 break;
90 case IMGFMT_Y8:
91 mux_v->bih->biBitCount = 8;
92 break;
93 default:
94 mp_tmsg(MSGT_MENCODER, MSGL_INFO, "[VE_RAW] Raw output with FourCC [%x] not supported!\n", fmt);
95 mux_v->bih->biCompression = 0;
96 return 0;
98 return 1;
102 static int config(struct vf_instance *vf,
103 int width, int height, int d_width, int d_height,
104 unsigned int flags, unsigned int outfmt)
106 int ret;
107 mux_v->bih->biWidth = width;
108 mux_v->bih->biHeight = height;
109 mux_v->aspect = (float)d_width/d_height;
110 ret = set_format(vf, outfmt);
111 if (!ret) return 0;
113 mux_v->bih->biSizeImage = mux_v->bih->biWidth*mux_v->bih->biHeight*mux_v->bih->biBitCount/8;
114 return 1;
117 static int control(struct vf_instance *vf, int request, void *data) {
118 return CONTROL_UNKNOWN;
121 static int query_format(struct vf_instance *vf, unsigned int fmt) {
122 if (IMGFMT_IS_RGB(fmt) || IMGFMT_IS_BGR(fmt))
123 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
124 switch (fmt) {
125 case IMGFMT_I420:
126 case IMGFMT_IYUV:
127 case IMGFMT_YV12:
128 case IMGFMT_411P:
129 case IMGFMT_444P:
130 case IMGFMT_422P:
131 case IMGFMT_UYVY:
132 case IMGFMT_YUY2:
133 case IMGFMT_YVU9:
134 case IMGFMT_IF09:
135 case IMGFMT_Y8:
136 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
139 return 0;
142 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) {
143 mux_v->buffer = mpi->planes[0];
144 muxer_write_chunk(mux_v, mpi->width*mpi->height*mux_v->bih->biBitCount/8, 0x10, pts, pts);
145 return 1;
148 //===========================================================================//
150 static int vf_open(vf_instance_t *vf, char* args){
151 vf->config = config;
152 vf->default_caps = VFCAP_CONSTANT;
153 vf->control = control;
154 vf->query_format = query_format;
155 vf->put_image = put_image;
156 vf->default_caps = 0;
157 vf->priv = malloc(sizeof(struct vf_priv_s));
158 memset(vf->priv, 0, sizeof(struct vf_priv_s));
159 vf->priv->mux = (muxer_stream_t*)args;
161 mux_v->bih = calloc(1, sizeof(BITMAPINFOHEADER));
162 mux_v->bih->biSize = sizeof(BITMAPINFOHEADER);
163 mux_v->bih->biWidth = 0;
164 mux_v->bih->biHeight = 0;
166 return 1;
169 vf_info_t ve_info_raw = {
170 "raw encoder",
171 "raw",
172 "jwe21@cam.ac.uk",
173 "Based on rawrgb",
174 vf_open
177 //===========================================================================//