typo fixes
[mplayer/greg.git] / libmpcodecs / ve_raw.c
blob804266b8673ff8139def346dfca83f34cf33d0da
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #include "config.h"
6 #include "mp_msg.h"
7 #include "help_mp.h"
9 #include "codec-cfg.h"
10 #include "stream.h"
11 #include "demuxer.h"
12 #include "stheader.h"
14 #include "muxer.h"
16 #include "img_format.h"
17 #include "mp_image.h"
18 #include "vf.h"
21 //===========================================================================//
23 struct vf_priv_s {
24 muxer_stream_t* mux;
26 #define mux_v (vf->priv->mux)
28 static int set_format(struct vf_instance_s *vf, unsigned int fmt) {
29 mux_v->bih->biCompression = fmt;
31 mux_v->bih->biPlanes = 1;
32 if (IMGFMT_IS_RGB(fmt)) {
33 if (IMGFMT_RGB_DEPTH(fmt) < 8 && !(fmt&128))
34 mux_v->bih->biBitCount = IMGFMT_RGB_DEPTH(fmt);
35 else
36 mux_v->bih->biBitCount = (IMGFMT_RGB_DEPTH(fmt)+7)&(~7);
37 return 1;
39 if (IMGFMT_IS_BGR(fmt)) {
40 if (IMGFMT_BGR_DEPTH(fmt) < 8 && !(fmt&128))
41 mux_v->bih->biBitCount = IMGFMT_BGR_DEPTH(fmt);
42 else
43 mux_v->bih->biBitCount = (IMGFMT_BGR_DEPTH(fmt)+7)&(~7);
44 return 1;
46 switch (fmt) {
47 case IMGFMT_I420:
48 case IMGFMT_IYUV:
49 case IMGFMT_YV12:
50 case IMGFMT_411P:
51 mux_v->bih->biPlanes = 3;
52 mux_v->bih->biBitCount = 12;
53 break;
54 case IMGFMT_444P:
55 mux_v->bih->biPlanes = 3;
56 mux_v->bih->biBitCount = 24;
57 break;
58 case IMGFMT_422P:
59 mux_v->bih->biPlanes = 3;
60 mux_v->bih->biBitCount = 16;
61 break;
62 case IMGFMT_IF09:
63 mux_v->bih->biPlanes = 4;
64 case IMGFMT_YVU9:
65 mux_v->bih->biBitCount = 9;
66 break;
67 case IMGFMT_UYVY:
68 case IMGFMT_YUY2:
69 mux_v->bih->biBitCount = 16;
70 break;
71 default:
72 mp_msg(MSGT_MENCODER, MSGL_INFO, MSGTR_MPCODECS_OutputWithFourccNotSupported, fmt);
73 mux_v->bih->biCompression = 0;
74 return 0;
76 return 1;
80 static int config(struct vf_instance_s *vf,
81 int width, int height, int d_width, int d_height,
82 unsigned int flags, unsigned int outfmt)
84 int ret;
85 mux_v->bih->biWidth = width;
86 mux_v->bih->biHeight = height;
87 mux_v->aspect = (float)d_width/d_height;
88 ret = set_format(vf, outfmt);
89 if (!ret) return 0;
91 mux_v->bih->biSizeImage = mux_v->bih->biWidth*mux_v->bih->biHeight*mux_v->bih->biBitCount/8;
92 return 1;
95 static int control(struct vf_instance_s *vf, int request, void *data) {
96 return CONTROL_UNKNOWN;
99 static int query_format(struct vf_instance_s *vf, unsigned int fmt) {
100 if (IMGFMT_IS_RGB(fmt) || IMGFMT_IS_BGR(fmt))
101 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
102 switch (fmt) {
103 case IMGFMT_I420:
104 case IMGFMT_IYUV:
105 case IMGFMT_YV12:
106 case IMGFMT_411P:
107 case IMGFMT_444P:
108 case IMGFMT_422P:
109 case IMGFMT_UYVY:
110 case IMGFMT_YUY2:
111 case IMGFMT_YVU9:
112 case IMGFMT_IF09:
113 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
116 return 0;
119 static int put_image(struct vf_instance_s *vf, mp_image_t *mpi, double pts) {
120 mux_v->buffer = mpi->planes[0];
121 muxer_write_chunk(mux_v, mpi->width*mpi->height*mux_v->bih->biBitCount/8, 0x10, pts, pts);
122 return 1;
125 //===========================================================================//
127 static int vf_open(vf_instance_t *vf, char* args){
128 vf->config = config;
129 vf->default_caps = VFCAP_CONSTANT;
130 vf->control = control;
131 vf->query_format = query_format;
132 vf->put_image = put_image;
133 vf->default_caps = 0;
134 vf->priv = malloc(sizeof(struct vf_priv_s));
135 memset(vf->priv, 0, sizeof(struct vf_priv_s));
136 vf->priv->mux = (muxer_stream_t*)args;
138 mux_v->bih = calloc(1, sizeof(BITMAPINFOHEADER));
139 mux_v->bih->biSize = sizeof(BITMAPINFOHEADER);
140 mux_v->bih->biWidth = 0;
141 mux_v->bih->biHeight = 0;
143 return 1;
146 vf_info_t ve_info_raw = {
147 "raw encoder",
148 "raw",
149 "jwe21@cam.ac.uk",
150 "Based on rawrgb",
151 vf_open
154 //===========================================================================//