stream: http: Allow setting custom http header
[mplayer/greg.git] / libmpcodecs / vf_tile.c
blobad3d662875183a954a01a807d0cd8eb61f2a4c37
1 /*
2 * filter to tile a serie of image in a single, bigger, image
4 * The parameters are:
6 * xtile: number of tile on the x axis (5)
7 * ytile: number of tile on the y axis (5)
8 * xytile: when write the image, it can be different then xtile * ytile
9 * (for example you can write 8 * 7 tile, writing the file every
10 * 50 frame, to have one image every 2 seconds @ 25 fps ).
11 * start: pixel at the start (x/y), default 2
12 * delta: pixel between 2 tile, (x/y), default 4
14 * For example a valid command line is:
15 * ... -vf tile=10:5:-1:4:8 ...
16 * that make images of 10 * 5 tiles, with 4 pixel at the beginning and
17 * 8 pixel between tiles.
19 * The default command is:
20 * ... -vf tile=5:5:25:2:4
22 * If you omit a parameter or put a value less then 0, the default is used.
23 * ... -vf tile=10:5::-1:10
25 * You can also stop when you're ok
26 * ... -vf tile=10:5
27 * (and this is probably the option you will use more often ...)
29 * Probably is good to put the scale filter before the tile :-)
31 * copyright (c) 2003 Daniele Forghieri ( guru@digitalfantasy.it )
33 * This file is part of MPlayer.
35 * MPlayer is free software; you can redistribute it and/or modify
36 * it under the terms of the GNU General Public License as published by
37 * the Free Software Foundation; either version 2 of the License, or
38 * (at your option) any later version.
40 * MPlayer is distributed in the hope that it will be useful,
41 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 * GNU General Public License for more details.
45 * You should have received a copy of the GNU General Public License along
46 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
47 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
50 // strtoi memcpy_pic
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <string.h>
56 #include "config.h"
57 #include "mp_msg.h"
58 #include "cpudetect.h"
60 #include "img_format.h"
61 #include "mp_image.h"
62 #include "vf.h"
64 #include "libvo/fastmemcpy.h"
66 /* private data */
67 struct vf_priv_s {
68 /* configuration data */
69 /* Number on hor/ver tiles */
70 int xtile;
71 int ytile;
72 /* When write the whole frame (default = xtile * ytile) */
73 int xytile;
74 /* pixel at start / end (default = 4) */
75 int start;
76 /* pixel between image (default = 2) */
77 int delta;
78 // /* Background color, in destination format */
79 // int bkgSet;
81 /* Work data */
82 int frame_cur;
86 static int config(struct vf_instance *vf,
87 int width, int height, int d_width, int d_height,
88 unsigned int flags, unsigned int outfmt){
90 struct vf_priv_s *priv;
91 int xw;
92 int yh;
94 /* Calculate new destination size */
95 priv = vf->priv;
96 xw = priv->start * 2 +
97 priv->xtile * width +
98 (priv->xtile - 1) * priv->delta;
99 yh = priv->start * 2 +
100 priv->ytile * height +
101 (priv->ytile - 1) * priv->delta;
103 mp_msg(MSGT_VFILTER,MSGL_V,"vf_tile:config size set to %d * %d\n", xw, yh);
105 return vf_next_config(vf, xw, yh, xw, yh, flags, outfmt);
108 /* Filter handler */
109 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
111 mp_image_t *dmpi;
112 struct vf_priv_s *priv;
113 int t;
114 int xw;
115 int yh;
116 int xi;
117 int yi;
118 int by;
119 int dw;
121 /* Calculate new size */
122 priv = vf->priv;
123 xw = priv->start * 2 +
124 priv->xtile * mpi->w +
125 (priv->xtile - 1) * priv->delta;
126 yh = priv->start * 2 +
127 priv->ytile * mpi->h+
128 (priv->ytile - 1) * priv->delta;
130 /* Get the big image! */
131 dmpi=vf_get_image(vf->next, mpi->imgfmt,
132 MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE,
133 xw, yh);
135 /* bytes x pixel & bytes x line */
136 if (mpi->flags & MP_IMGFLAG_PLANAR) {
137 by = 1;
138 dw = mpi->w;
140 else {
141 by = (mpi->bpp + 7) / 8;
142 dw = mpi->w * by;
144 /* Index position */
145 t = priv->frame_cur % priv->xytile;
146 // if ((t == 0) && (bkg != 0)) {
147 // /* First frame, delete the background */
149 // }
151 /* Position of image */
152 xi = priv->start + (mpi->w + priv->delta) * (t % priv->xtile);
153 yi = priv->start + (mpi->h + priv->delta) * (t / priv->xtile);
155 /* Copy first (or only) plane */
156 memcpy_pic( dmpi->planes[0] + xi * by + yi * dmpi->stride[0],
157 mpi->planes[0],
159 mpi->h,
160 dmpi->stride[0],
161 mpi->stride[0]);
163 if (mpi->flags & MP_IMGFLAG_PLANAR) {
164 /* Copy the other 2 planes */
165 memcpy_pic( dmpi->planes[1] + (xi >> mpi->chroma_x_shift) + (yi >> mpi->chroma_y_shift) * dmpi->stride[1],
166 mpi->planes[1],
167 mpi->chroma_width,
168 mpi->chroma_height,
169 dmpi->stride[1],
170 mpi->stride[1]);
171 memcpy_pic( dmpi->planes[2] + (xi >> mpi->chroma_x_shift) + (yi >> mpi->chroma_y_shift) * dmpi->stride[2],
172 mpi->planes[2],
173 mpi->chroma_width,
174 mpi->chroma_height,
175 dmpi->stride[2],
176 mpi->stride[2]);
179 /* Increment current frame */
180 ++priv->frame_cur;
182 if (t == priv->xytile - 1) {
183 /* Display the composition */
184 dmpi->width = xw;
185 dmpi->height = yh;
186 return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
188 else {
189 /* Skip the frame */
190 return 0;
194 static void uninit(struct vf_instance *vf)
196 /* free local data */
197 free(vf->priv);
200 /* rgb/bgr 12->32 supported & some Yxxx */
201 static int query_format(struct vf_instance *vf, unsigned int fmt)
203 switch (fmt) {
204 /* rgb 12...32 bit */
205 case IMGFMT_RGB12:
206 case IMGFMT_RGB15:
207 case IMGFMT_RGB16:
208 case IMGFMT_RGB24:
209 case IMGFMT_RGB32:
210 /* bgr 12...32 bit */
211 case IMGFMT_BGR12:
212 case IMGFMT_BGR15:
213 case IMGFMT_BGR16:
214 case IMGFMT_BGR24:
215 case IMGFMT_BGR32:
216 /* Various Yxxx Formats */
217 case IMGFMT_444P:
218 case IMGFMT_422P:
219 case IMGFMT_411P:
220 case IMGFMT_YUY2:
221 case IMGFMT_YV12:
222 case IMGFMT_I420:
223 case IMGFMT_YVU9:
224 case IMGFMT_IF09:
225 case IMGFMT_IYUV:
226 return vf_next_query_format(vf, fmt);
228 return 0;
231 /* Get an integer from the string pointed by s, adjusting s.
232 * If the value is less then 0 def_val is used.
233 * Return 0 for ok
235 * Look below ( in vf_open(...) ) for a use ...
237 static int parse_int(char **s, int *rt, int def_val)
240 int t = 0;
242 if (**s) {
243 /* Get value (dec, hex or octal) */
244 t = strtol( *s, s, 0 );
246 /* Use default */
247 if (t < 0) {
248 t = def_val;
251 if (**s == ':') {
252 /* Point to next character (problably a digit) */
253 ++(*s);
255 else if (**s != '\0') {
256 /* Error, we got some wrong char */
257 return 1;
260 else {
261 t = def_val;
264 *rt = t;
265 return 0;
269 /* Main entry funct for the filter */
270 static int vf_open(vf_instance_t *vf, char *args)
272 struct vf_priv_s *p;
273 int er;
275 vf->put_image = put_image;
276 vf->query_format = query_format;
277 vf->config = config;
278 vf->uninit = uninit;
279 vf->default_reqs = VFCAP_ACCEPT_STRIDE;
280 /* Private data */
281 vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
282 if (p == NULL) {
283 return 0;
286 if (args == NULL) {
287 /* Use the default */
288 args = "";
290 /* Parse all the arguments */
291 er = parse_int( &args, &p->xtile, 5 );
292 er |= parse_int( &args, &p->ytile, 5 );
293 er |= parse_int( &args, &p->xytile, 0 );
294 er |= parse_int( &args, &p->start, 2 );
295 er |= parse_int( &args, &p->delta, 4 );
296 // er |= parse_int( &args, &p->bkgSet, 0 );
298 if (er) {
299 mp_tmsg(MSGT_VFILTER, MSGL_ERR, "[VF_FRAMESTEP] Error parsing argument.\n");
300 return 0;
302 /* Load some default */
303 if ((p->xytile <= 0) || (p->xytile > p->xtile * p->ytile)) {
304 p->xytile = p->xtile * p->ytile;
307 /* Say what happen: use mp_msg(...)? */
308 if ( mp_msg_test(MSGT_VFILTER,MSGL_V) ) {
309 printf("vf_tile: tiling %d * %d, output every %d frames\n",
310 p->xtile,
311 p->ytile,
312 p->xytile);
313 printf("vf_tile: start pixel %d, delta pixel %d\n",
314 p->start,
315 p->delta);
316 // printf("vf_tile: background 0x%x\n",
317 // p->bkgSet);
319 return 1;
322 const vf_info_t vf_info_tile = {
323 "Make a single image tiling x/y images",
324 "tile",
325 "Daniele Forghieri",
327 vf_open,
328 NULL