2 * Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of MPlayer.
6 * MPlayer is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * MPlayer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include "cpudetect.h"
32 #include "img_format.h"
36 #include "libavcodec/avcodec.h"
37 #include "libavutil/eval.h"
45 static int config(struct vf_instance
*vf
,
46 int width
, int height
, int d_width
, int d_height
,
47 unsigned int flags
, unsigned int outfmt
){
48 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,outfmt
);
51 static inline double getpix(struct vf_instance
*vf
, double x
, double y
, int plane
){
53 mp_image_t
*mpi
= vf
->priv
->mpi
;
54 int stride
= mpi
->stride
[plane
];
55 uint8_t *src
= mpi
->planes
[plane
];
56 xi
=x
= FFMIN(FFMAX(x
, 0), (mpi
->w
>> (plane
? mpi
->chroma_x_shift
: 0))-1);
57 yi
=y
= FFMIN(FFMAX(y
, 0), (mpi
->h
>> (plane
? mpi
->chroma_y_shift
: 0))-1);
63 (1-y
)*((1-x
)*src
[xi
+ yi
* stride
] + x
*src
[xi
+ 1 + yi
* stride
])
64 + y
*((1-x
)*src
[xi
+ (yi
+1) * stride
] + x
*src
[xi
+ 1 + (yi
+1) * stride
]);
67 //FIXME cubic interpolate
68 //FIXME keep the last few frames
69 static double lum(void *vf
, double x
, double y
){
70 return getpix(vf
, x
, y
, 0);
73 static double cb(void *vf
, double x
, double y
){
74 return getpix(vf
, x
, y
, 1);
77 static double cr(void *vf
, double x
, double y
){
78 return getpix(vf
, x
, y
, 2);
81 static int put_image(struct vf_instance
*vf
, mp_image_t
*mpi
, double pts
){
85 if(!(mpi
->flags
&MP_IMGFLAG_DIRECT
)){
86 // no DR, so get a new image! hope we'll get DR buffer:
87 vf
->dmpi
=vf_get_image(vf
->next
,mpi
->imgfmt
, MP_IMGTYPE_TEMP
,
88 MP_IMGFLAG_ACCEPT_STRIDE
|MP_IMGFLAG_PREFER_ALIGNED_STRIDE
,
95 vf_clone_mpi_attributes(dmpi
, mpi
);
97 for(plane
=0; plane
<3; plane
++){
98 int w
= mpi
->w
>> (plane
? mpi
->chroma_x_shift
: 0);
99 int h
= mpi
->h
>> (plane
? mpi
->chroma_y_shift
: 0);
100 uint8_t *dst
= dmpi
->planes
[plane
];
101 int dst_stride
= dmpi
->stride
[plane
];
102 double const_values
[]={
114 if (!vf
->priv
->e
[plane
]) continue;
119 dst
[x
+ y
* dst_stride
] = av_eval_expr(vf
->priv
->e
[plane
],
125 vf
->priv
->framenum
++;
127 return vf_next_put_image(vf
,dmpi
, pts
);
130 static void uninit(struct vf_instance
*vf
){
131 if(!vf
->priv
) return;
137 //===========================================================================//
138 static int vf_open(vf_instance_t
*vf
, char *args
){
139 char eq
[3][2000] = { { 0 }, { 0 }, { 0 } };
143 vf
->put_image
=put_image
;
144 // vf->get_image=get_image;
146 vf
->priv
=av_malloc(sizeof(struct vf_priv_s
));
147 memset(vf
->priv
, 0, sizeof(struct vf_priv_s
));
149 if (args
) sscanf(args
, "%1999[^:]:%1999[^:]:%1999[^:]", eq
[0], eq
[1], eq
[2]);
151 if (!eq
[1][0]) strncpy(eq
[1], eq
[0], sizeof(eq
[0])-1);
152 if (!eq
[2][0]) strncpy(eq
[2], eq
[1], sizeof(eq
[0])-1);
154 for(plane
=0; plane
<3; plane
++){
155 const char * const const_names
[]={
167 const char * const func2_names
[]={
174 double (*func2
[])(void *, double, double)={
178 plane
==0 ? lum
: (plane
==1 ? cb
: cr
),
181 res
= av_parse_expr(&vf
->priv
->e
[plane
], eq
[plane
], const_names
, NULL
, NULL
, func2_names
, func2
, 0, NULL
);
184 mp_msg(MSGT_VFILTER
, MSGL_ERR
, "geq: error loading equation `%s'\n", eq
[plane
]);
192 const vf_info_t vf_info_geq
= {
193 "generic equation filter",
195 "Michael Niedermayer",