11249
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <string.h>
|
|
4 #include <inttypes.h>
|
|
5 #include <math.h>
|
|
6
|
|
7 #include "../config.h"
|
|
8 #include "../mp_msg.h"
|
|
9 #include "../cpudetect.h"
|
|
10
|
|
11 #include "img_format.h"
|
|
12 #include "mp_image.h"
|
|
13 #include "vf.h"
|
|
14
|
|
15 #include "../libvo/video_out.h"
|
|
16
|
|
17 #include "m_option.h"
|
|
18 #include "m_struct.h"
|
|
19
|
|
20 static struct vf_priv_s {
|
|
21 uint8_t *buf[2];
|
|
22 float hue;
|
|
23 float saturation;
|
|
24 } vf_priv_dflt = {
|
|
25 {NULL, NULL},
|
|
26 0.0,
|
|
27 1.0,
|
|
28 };
|
|
29
|
|
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)
|
|
32 {
|
|
33 int i;
|
|
34 const int s= rint(sin(hue) * (1<<16) * sat);
|
|
35 const int c= rint(cos(hue) * (1<<16) * sat);
|
|
36
|
|
37 while (h--) {
|
|
38 for (i = 0; i<w; i++)
|
|
39 {
|
|
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;
|
|
46 udst[i]= new_u;
|
|
47 vdst[i]= new_v;
|
|
48 }
|
|
49 usrc += srcstride;
|
|
50 vsrc += srcstride;
|
|
51 udst += dststride;
|
|
52 vdst += dststride;
|
|
53 }
|
|
54 }
|
|
55
|
|
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);
|
|
58
|
|
59 /* FIXME: add packed yuv version of process */
|
|
60
|
|
61 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi)
|
|
62 {
|
|
63 mp_image_t *dmpi;
|
|
64
|
|
65 dmpi=vf_get_image(vf->next, mpi->imgfmt,
|
|
66 MP_IMGTYPE_EXPORT, 0,
|
|
67 mpi->w, mpi->h);
|
|
68
|
|
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];
|
|
73
|
|
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);
|
|
77 }
|
|
78
|
|
79 if (vf->priv->hue == 0){
|
|
80 dmpi->planes[1] = mpi->planes[1];
|
|
81 dmpi->planes[2] = mpi->planes[2];
|
|
82 }else {
|
|
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);
|
|
90 }
|
|
91
|
|
92 return vf_next_put_image(vf,dmpi);
|
|
93 }
|
|
94
|
|
95 static int control(struct vf_instance_s* vf, int request, void* data)
|
|
96 {
|
|
97 vf_equalizer_t *eq;
|
|
98
|
|
99 switch (request) {
|
|
100 case VFCTRL_SET_EQUALIZER:
|
|
101 eq = data;
|
|
102 if (!strcmp(eq->item,"hue")) {
|
|
103 vf->priv->hue = eq->value * M_PI / 100;
|
|
104 return CONTROL_TRUE;
|
|
105 } else if (!strcmp(eq->item,"saturation")) {
|
|
106 vf->priv->saturation = eq->value/100.0 + 100;
|
|
107 return CONTROL_TRUE;
|
|
108 }
|
|
109 break;
|
|
110 case VFCTRL_GET_EQUALIZER:
|
|
111 eq = data;
|
|
112 if (!strcmp(eq->item,"hue")) {
|
|
113 eq->value = rint(vf->priv->hue *100 / M_PI);
|
|
114 return CONTROL_TRUE;
|
|
115 }else if (!strcmp(eq->item,"saturation")) {
|
|
116 eq->value = rint(vf->priv->saturation*100 - 100);
|
|
117 return CONTROL_TRUE;
|
|
118 }
|
|
119 break;
|
|
120 }
|
|
121 return vf_next_control(vf, request, data);
|
|
122 }
|
|
123
|
|
124 static int query_format(struct vf_instance_s* vf, unsigned int fmt)
|
|
125 {
|
|
126 switch (fmt) {
|
|
127 case IMGFMT_YVU9:
|
|
128 case IMGFMT_IF09:
|
|
129 case IMGFMT_YV12:
|
|
130 case IMGFMT_I420:
|
|
131 case IMGFMT_IYUV:
|
|
132 case IMGFMT_CLPL:
|
|
133 case IMGFMT_NV12:
|
|
134 case IMGFMT_444P:
|
|
135 case IMGFMT_422P:
|
|
136 case IMGFMT_411P:
|
|
137 return vf_next_query_format(vf, fmt);
|
|
138 }
|
|
139 return 0;
|
|
140 }
|
|
141
|
|
142 static void uninit(struct vf_instance_s* vf)
|
|
143 {
|
|
144 if (vf->priv->buf[0]) free(vf->priv->buf[0]);
|
|
145 if (vf->priv->buf[1]) free(vf->priv->buf[1]);
|
|
146 free(vf->priv);
|
|
147 }
|
|
148
|
|
149 static int open(vf_instance_t *vf, char* args)
|
|
150 {
|
|
151 vf->control=control;
|
|
152 vf->query_format=query_format;
|
|
153 vf->put_image=put_image;
|
|
154 vf->uninit=uninit;
|
|
155
|
|
156 if(!vf->priv) {
|
|
157 vf->priv = malloc(sizeof(struct vf_priv_s));
|
|
158 memset(vf->priv, 0, sizeof(struct vf_priv_s));
|
|
159 }
|
|
160 if (args) sscanf(args, "%f:%f", &vf->priv->hue, &vf->priv->saturation);
|
|
161 vf->priv->hue *= M_PI / 180.0;
|
|
162
|
|
163 process = process_C;
|
|
164 #ifdef HAVE_MMXX
|
|
165 if(gCpuCaps.hasMMX) process = process_MMX;
|
|
166 #endif
|
|
167
|
|
168 return 1;
|
|
169 }
|
|
170
|
|
171 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
|
|
172 static m_option_t vf_opts_fields[] = {
|
|
173 {"hue", ST_OFF(hue), CONF_TYPE_FLOAT, M_OPT_RANGE,-180.0 ,180.0, NULL},
|
|
174 {"saturation", ST_OFF(saturation), CONF_TYPE_FLOAT, M_OPT_RANGE,-10.0 ,10.0, NULL},
|
|
175 { NULL, NULL, 0, 0, 0, 0, NULL }
|
|
176 };
|
|
177
|
|
178 static m_struct_t vf_opts = {
|
|
179 "hue",
|
|
180 sizeof(struct vf_priv_s),
|
|
181 &vf_priv_dflt,
|
|
182 vf_opts_fields
|
|
183 };
|
|
184
|
|
185 vf_info_t vf_info_hue = {
|
|
186 "hue changer",
|
|
187 "hue",
|
|
188 "Michael Niedermayer",
|
|
189 "",
|
|
190 open,
|
|
191 &vf_opts
|
|
192 };
|
|
193
|