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.
27 #include "cpudetect.h"
29 #include "img_format.h"
33 #include "libvo/video_out.h"
38 static struct vf_priv_s
{
42 } const vf_priv_dflt
= {
48 static void process_C(uint8_t *udst
, uint8_t *vdst
, uint8_t *usrc
, uint8_t *vsrc
, int dststride
, int srcstride
,
49 int w
, int h
, float hue
, float sat
)
52 const int s
= rint(sin(hue
) * (1<<16) * sat
);
53 const int c
= rint(cos(hue
) * (1<<16) * sat
);
58 const int u
= usrc
[i
] - 128;
59 const int v
= vsrc
[i
] - 128;
60 int new_u
= (c
*u
- s
*v
+ (1<<15) + (128<<16))>>16;
61 int new_v
= (s
*u
+ c
*v
+ (1<<15) + (128<<16))>>16;
62 if(new_u
& 768) new_u
= (-new_u
)>>31;
63 if(new_v
& 768) new_v
= (-new_v
)>>31;
74 static void (*process
)(uint8_t *udst
, uint8_t *vdst
, uint8_t *usrc
, uint8_t *vsrc
, int dststride
, int srcstride
,
75 int w
, int h
, float hue
, float sat
);
77 /* FIXME: add packed yuv version of process */
79 static int put_image(struct vf_instance
*vf
, mp_image_t
*mpi
, double pts
)
83 dmpi
=vf_get_image(vf
->next
, mpi
->imgfmt
,
87 dmpi
->planes
[0] = mpi
->planes
[0];
88 dmpi
->stride
[0] = mpi
->stride
[0];
89 dmpi
->stride
[1] = mpi
->stride
[1];
90 dmpi
->stride
[2] = mpi
->stride
[2];
92 if (!vf
->priv
->buf
[0]){
93 vf
->priv
->buf
[0] = malloc(mpi
->stride
[1]*mpi
->h
>> mpi
->chroma_y_shift
);
94 vf
->priv
->buf
[1] = malloc(mpi
->stride
[2]*mpi
->h
>> mpi
->chroma_y_shift
);
97 if (vf
->priv
->hue
== 0 && vf
->priv
->saturation
== 1){
98 dmpi
->planes
[1] = mpi
->planes
[1];
99 dmpi
->planes
[2] = mpi
->planes
[2];
101 dmpi
->planes
[1] = vf
->priv
->buf
[0];
102 dmpi
->planes
[2] = vf
->priv
->buf
[1];
103 process(dmpi
->planes
[1], dmpi
->planes
[2],
104 mpi
->planes
[1], mpi
->planes
[2],
105 dmpi
->stride
[1],mpi
->stride
[1],
106 mpi
->w
>> mpi
->chroma_x_shift
, mpi
->h
>> mpi
->chroma_y_shift
,
107 vf
->priv
->hue
, vf
->priv
->saturation
);
110 return vf_next_put_image(vf
,dmpi
, pts
);
113 static int control(struct vf_instance
*vf
, int request
, void* data
)
118 case VFCTRL_SET_EQUALIZER
:
120 if (!strcmp(eq
->item
,"hue")) {
121 vf
->priv
->hue
= eq
->value
* M_PI
/ 100;
123 } else if (!strcmp(eq
->item
,"saturation")) {
124 vf
->priv
->saturation
= (eq
->value
+ 100)/100.0;
128 case VFCTRL_GET_EQUALIZER
:
130 if (!strcmp(eq
->item
,"hue")) {
131 eq
->value
= rint(vf
->priv
->hue
*100 / M_PI
);
133 }else if (!strcmp(eq
->item
,"saturation")) {
134 eq
->value
= rint(vf
->priv
->saturation
*100 - 100);
139 return vf_next_control(vf
, request
, data
);
142 static int query_format(struct vf_instance
*vf
, unsigned int fmt
)
154 return vf_next_query_format(vf
, fmt
);
159 static void uninit(struct vf_instance
*vf
)
161 if (vf
->priv
->buf
[0]) free(vf
->priv
->buf
[0]);
162 if (vf
->priv
->buf
[1]) free(vf
->priv
->buf
[1]);
166 static int vf_open(vf_instance_t
*vf
, char *args
)
169 vf
->query_format
=query_format
;
170 vf
->put_image
=put_image
;
173 vf
->priv
->hue
*= M_PI
/ 180.0;
179 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
180 static const m_option_t vf_opts_fields
[] = {
181 {"hue", ST_OFF(hue
), CONF_TYPE_FLOAT
, M_OPT_RANGE
,-180.0 ,180.0, NULL
},
182 {"saturation", ST_OFF(saturation
), CONF_TYPE_FLOAT
, M_OPT_RANGE
,-10.0 ,10.0, NULL
},
183 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
186 static const m_struct_t vf_opts
= {
188 sizeof(struct vf_priv_s
),
193 const vf_info_t vf_info_hue
= {
196 "Michael Niedermayer",