Static pthread support
[mplayer/kovensky.git] / libmpcodecs / ve_raw.c
blob5e438f727d294adc8b5c33af54f35b43afce8884
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/stream.h"
11 #include "libmpdemux/demuxer.h"
12 #include "libmpdemux/stheader.h"
14 #include "stream/stream.h"
15 #include "libmpdemux/muxer.h"
17 #include "img_format.h"
18 #include "mp_image.h"
19 #include "vf.h"
22 //===========================================================================//
24 struct vf_priv_s {
25 muxer_stream_t* mux;
27 #define mux_v (vf->priv->mux)
29 static int set_format(struct vf_instance *vf, unsigned int fmt) {
30 if (!force_fourcc)
31 mux_v->bih->biCompression = fmt;
33 mux_v->bih->biPlanes = 1;
34 if (IMGFMT_IS_RGB(fmt)) {
35 if (IMGFMT_RGB_DEPTH(fmt) < 8 && !(fmt&128))
36 mux_v->bih->biBitCount = IMGFMT_RGB_DEPTH(fmt);
37 else
38 mux_v->bih->biBitCount = (IMGFMT_RGB_DEPTH(fmt)+7)&(~7);
39 return 1;
41 if (IMGFMT_IS_BGR(fmt)) {
42 if (IMGFMT_BGR_DEPTH(fmt) < 8 && !(fmt&128))
43 mux_v->bih->biBitCount = IMGFMT_BGR_DEPTH(fmt);
44 else
45 mux_v->bih->biBitCount = (IMGFMT_BGR_DEPTH(fmt)+7)&(~7);
46 return 1;
48 switch (fmt) {
49 case IMGFMT_I420:
50 case IMGFMT_IYUV:
51 case IMGFMT_YV12:
52 case IMGFMT_411P:
53 mux_v->bih->biPlanes = 3;
54 mux_v->bih->biBitCount = 12;
55 break;
56 case IMGFMT_444P:
57 mux_v->bih->biPlanes = 3;
58 mux_v->bih->biBitCount = 24;
59 break;
60 case IMGFMT_422P:
61 mux_v->bih->biPlanes = 3;
62 mux_v->bih->biBitCount = 16;
63 break;
64 case IMGFMT_IF09:
65 mux_v->bih->biPlanes = 4;
66 case IMGFMT_YVU9:
67 mux_v->bih->biBitCount = 9;
68 break;
69 case IMGFMT_UYVY:
70 case IMGFMT_YUY2:
71 mux_v->bih->biBitCount = 16;
72 break;
73 case IMGFMT_Y8:
74 mux_v->bih->biBitCount = 8;
75 break;
76 default:
77 mp_tmsg(MSGT_MENCODER, MSGL_INFO, "[VE_RAW] Raw output with FourCC [%x] not supported!\n", fmt);
78 mux_v->bih->biCompression = 0;
79 return 0;
81 return 1;
85 static int config(struct vf_instance *vf,
86 int width, int height, int d_width, int d_height,
87 unsigned int flags, unsigned int outfmt)
89 int ret;
90 mux_v->bih->biWidth = width;
91 mux_v->bih->biHeight = height;
92 mux_v->aspect = (float)d_width/d_height;
93 ret = set_format(vf, outfmt);
94 if (!ret) return 0;
96 mux_v->bih->biSizeImage = mux_v->bih->biWidth*mux_v->bih->biHeight*mux_v->bih->biBitCount/8;
97 return 1;
100 static int control(struct vf_instance *vf, int request, void *data) {
101 return CONTROL_UNKNOWN;
104 static int query_format(struct vf_instance *vf, unsigned int fmt) {
105 if (IMGFMT_IS_RGB(fmt) || IMGFMT_IS_BGR(fmt))
106 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
107 switch (fmt) {
108 case IMGFMT_I420:
109 case IMGFMT_IYUV:
110 case IMGFMT_YV12:
111 case IMGFMT_411P:
112 case IMGFMT_444P:
113 case IMGFMT_422P:
114 case IMGFMT_UYVY:
115 case IMGFMT_YUY2:
116 case IMGFMT_YVU9:
117 case IMGFMT_IF09:
118 case IMGFMT_Y8:
119 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
122 return 0;
125 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) {
126 mux_v->buffer = mpi->planes[0];
127 muxer_write_chunk(mux_v, mpi->width*mpi->height*mux_v->bih->biBitCount/8, 0x10, pts, pts);
128 return 1;
131 //===========================================================================//
133 static int vf_open(vf_instance_t *vf, char* args){
134 vf->config = config;
135 vf->default_caps = VFCAP_CONSTANT;
136 vf->control = control;
137 vf->query_format = query_format;
138 vf->put_image = put_image;
139 vf->default_caps = 0;
140 vf->priv = malloc(sizeof(struct vf_priv_s));
141 memset(vf->priv, 0, sizeof(struct vf_priv_s));
142 vf->priv->mux = (muxer_stream_t*)args;
144 mux_v->bih = calloc(1, sizeof(BITMAPINFOHEADER));
145 mux_v->bih->biSize = sizeof(BITMAPINFOHEADER);
146 mux_v->bih->biWidth = 0;
147 mux_v->bih->biHeight = 0;
149 return 1;
152 vf_info_t ve_info_raw = {
153 "raw encoder",
154 "raw",
155 "jwe21@cam.ac.uk",
156 "Based on rawrgb",
157 vf_open
160 //===========================================================================//