11 #include "img_format.h"
15 #include "libvo/video_out.h"
20 static struct vf_priv_s
{
24 } const vf_priv_dflt
= {
30 static void process_C(uint8_t *udst
, uint8_t *vdst
, uint8_t *usrc
, uint8_t *vsrc
, int dststride
, int srcstride
,
31 int w
, int h
, float hue
, float sat
)
34 const int s
= rint(sin(hue
) * (1<<16) * sat
);
35 const int c
= rint(cos(hue
) * (1<<16) * sat
);
40 const int u
= usrc
[i
] - 128;
41 const int v
= vsrc
[i
] - 128;
42 int new_u
= (c
*u
- s
*v
+ (1<<15) + (128<<16))>>16;
43 int new_v
= (s
*u
+ c
*v
+ (1<<15) + (128<<16))>>16;
44 if(new_u
& 768) new_u
= (-new_u
)>>31;
45 if(new_v
& 768) new_v
= (-new_v
)>>31;
56 static void (*process
)(uint8_t *udst
, uint8_t *vdst
, uint8_t *usrc
, uint8_t *vsrc
, int dststride
, int srcstride
,
57 int w
, int h
, float hue
, float sat
);
59 /* FIXME: add packed yuv version of process */
61 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
)
65 dmpi
=vf_get_image(vf
->next
, mpi
->imgfmt
,
69 dmpi
->planes
[0] = mpi
->planes
[0];
70 dmpi
->stride
[0] = mpi
->stride
[0];
71 dmpi
->stride
[1] = mpi
->stride
[1];
72 dmpi
->stride
[2] = mpi
->stride
[2];
74 if (!vf
->priv
->buf
[0]){
75 vf
->priv
->buf
[0] = malloc(mpi
->stride
[1]*mpi
->h
>> mpi
->chroma_y_shift
);
76 vf
->priv
->buf
[1] = malloc(mpi
->stride
[2]*mpi
->h
>> mpi
->chroma_y_shift
);
79 if (vf
->priv
->hue
== 0 && vf
->priv
->saturation
== 1){
80 dmpi
->planes
[1] = mpi
->planes
[1];
81 dmpi
->planes
[2] = mpi
->planes
[2];
83 dmpi
->planes
[1] = vf
->priv
->buf
[0];
84 dmpi
->planes
[2] = vf
->priv
->buf
[1];
85 process(dmpi
->planes
[1], dmpi
->planes
[2],
86 mpi
->planes
[1], mpi
->planes
[2],
87 dmpi
->stride
[1],mpi
->stride
[1],
88 mpi
->w
>> mpi
->chroma_x_shift
, mpi
->h
>> mpi
->chroma_y_shift
,
89 vf
->priv
->hue
, vf
->priv
->saturation
);
92 return vf_next_put_image(vf
,dmpi
, pts
);
95 static int control(struct vf_instance_s
* vf
, int request
, void* data
)
100 case VFCTRL_SET_EQUALIZER
:
102 if (!strcmp(eq
->item
,"hue")) {
103 vf
->priv
->hue
= eq
->value
* M_PI
/ 100;
105 } else if (!strcmp(eq
->item
,"saturation")) {
106 vf
->priv
->saturation
= (eq
->value
+ 100)/100.0;
110 case VFCTRL_GET_EQUALIZER
:
112 if (!strcmp(eq
->item
,"hue")) {
113 eq
->value
= rint(vf
->priv
->hue
*100 / M_PI
);
115 }else if (!strcmp(eq
->item
,"saturation")) {
116 eq
->value
= rint(vf
->priv
->saturation
*100 - 100);
121 return vf_next_control(vf
, request
, data
);
124 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
)
136 return vf_next_query_format(vf
, fmt
);
141 static void uninit(struct vf_instance_s
* vf
)
143 if (vf
->priv
->buf
[0]) free(vf
->priv
->buf
[0]);
144 if (vf
->priv
->buf
[1]) free(vf
->priv
->buf
[1]);
148 static int open(vf_instance_t
*vf
, char* args
)
151 vf
->query_format
=query_format
;
152 vf
->put_image
=put_image
;
156 vf
->priv
= malloc(sizeof(struct vf_priv_s
));
157 memset(vf
->priv
, 0, sizeof(struct vf_priv_s
));
159 if (args
) sscanf(args
, "%f:%f", &vf
->priv
->hue
, &vf
->priv
->saturation
);
160 vf
->priv
->hue
*= M_PI
/ 180.0;
166 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
167 static m_option_t vf_opts_fields
[] = {
168 {"hue", ST_OFF(hue
), CONF_TYPE_FLOAT
, M_OPT_RANGE
,-180.0 ,180.0, NULL
},
169 {"saturation", ST_OFF(saturation
), CONF_TYPE_FLOAT
, M_OPT_RANGE
,-10.0 ,10.0, NULL
},
170 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
173 static m_struct_t vf_opts
= {
175 sizeof(struct vf_priv_s
),
180 const vf_info_t vf_info_hue
= {
183 "Michael Niedermayer",