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"
41 static void process_C(uint8_t *udst, uint8_t *vdst, uint8_t *usrc, uint8_t *vsrc, int dststride, int srcstride,
42 int w, int h, float hue, float sat)
45 const int s= rint(sin(hue) * (1<<16) * sat);
46 const int c= rint(cos(hue) * (1<<16) * sat);
51 const int u= usrc[i] - 128;
52 const int v= vsrc[i] - 128;
53 int new_u= (c*u - s*v + (1<<15) + (128<<16))>>16;
54 int new_v= (s*u + c*v + (1<<15) + (128<<16))>>16;
55 if(new_u & 768) new_u= (-new_u)>>31;
56 if(new_v & 768) new_v= (-new_v)>>31;
67 static void (*process)(uint8_t *udst, uint8_t *vdst, uint8_t *usrc, uint8_t *vsrc, int dststride, int srcstride,
68 int w, int h, float hue, float sat);
70 /* FIXME: add packed yuv version of process */
72 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
76 dmpi=vf_get_image(vf->next, mpi->imgfmt,
80 dmpi->planes[0] = mpi->planes[0];
81 dmpi->stride[0] = mpi->stride[0];
82 dmpi->stride[1] = mpi->stride[1];
83 dmpi->stride[2] = mpi->stride[2];
85 if (!vf->priv->buf[0]){
86 vf->priv->buf[0] = malloc(mpi->stride[1]*mpi->h >> mpi->chroma_y_shift);
87 vf->priv->buf[1] = malloc(mpi->stride[2]*mpi->h >> mpi->chroma_y_shift);
90 if (vf->priv->hue == 0 && vf->priv->saturation == 1){
91 dmpi->planes[1] = mpi->planes[1];
92 dmpi->planes[2] = mpi->planes[2];
94 dmpi->planes[1] = vf->priv->buf[0];
95 dmpi->planes[2] = vf->priv->buf[1];
96 process(dmpi->planes[1], dmpi->planes[2],
97 mpi->planes[1], mpi->planes[2],
98 dmpi->stride[1],mpi->stride[1],
99 mpi->w>> mpi->chroma_x_shift, mpi->h>> mpi->chroma_y_shift,
100 vf->priv->hue, vf->priv->saturation);
103 return vf_next_put_image(vf,dmpi, pts);
106 static int control(struct vf_instance *vf, int request, void* data)
111 case VFCTRL_SET_EQUALIZER:
113 if (!strcmp(eq->item,"hue")) {
114 vf->priv->hue = eq->value * M_PI / 100;
116 } else if (!strcmp(eq->item,"saturation")) {
117 vf->priv->saturation = (eq->value + 100)/100.0;
121 case VFCTRL_GET_EQUALIZER:
123 if (!strcmp(eq->item,"hue")) {
124 eq->value = rint(vf->priv->hue *100 / M_PI);
126 }else if (!strcmp(eq->item,"saturation")) {
127 eq->value = rint(vf->priv->saturation*100 - 100);
132 return vf_next_control(vf, request, data);
135 static int query_format(struct vf_instance *vf, unsigned int fmt)
147 return vf_next_query_format(vf, fmt);
152 static void uninit(struct vf_instance *vf)
154 free(vf->priv->buf[0]);
155 free(vf->priv->buf[1]);
159 static int vf_open(vf_instance_t *vf, char *args)
162 vf->query_format=query_format;
163 vf->put_image=put_image;
166 vf->priv = malloc(sizeof(struct vf_priv_s));
167 memset(vf->priv, 0, sizeof(struct vf_priv_s));
168 sscanf(args, "%f:%f", &vf->priv->hue, &vf->priv->saturation);
169 vf->priv->hue *= M_PI / 180.0;
175 const vf_info_t vf_info_hue = {
178 "Michael Niedermayer",