annotate libmpcodecs/vf_hue.c @ 21644:f0923677efc3

Trnaslated section "CODEC SPECIFIC ENCODING OPTIONS (MENCODER ONLY)" Now man page translaton is complete. However, translation contains many FIXME issues and needs additional checks.
author voroshil
date Sun, 17 Dec 2006 20:25:06 +0000
parents 20aca9baf5d8
children 0b262e00bc99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11249
michael
parents:
diff changeset
1 #include <stdio.h>
michael
parents:
diff changeset
2 #include <stdlib.h>
michael
parents:
diff changeset
3 #include <string.h>
michael
parents:
diff changeset
4 #include <inttypes.h>
michael
parents:
diff changeset
5 #include <math.h>
michael
parents:
diff changeset
6
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16305
diff changeset
7 #include "config.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16305
diff changeset
8 #include "mp_msg.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16305
diff changeset
9 #include "cpudetect.h"
11249
michael
parents:
diff changeset
10
michael
parents:
diff changeset
11 #include "img_format.h"
michael
parents:
diff changeset
12 #include "mp_image.h"
michael
parents:
diff changeset
13 #include "vf.h"
michael
parents:
diff changeset
14
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16305
diff changeset
15 #include "libvo/video_out.h"
11249
michael
parents:
diff changeset
16
michael
parents:
diff changeset
17 #include "m_option.h"
michael
parents:
diff changeset
18 #include "m_struct.h"
michael
parents:
diff changeset
19
michael
parents:
diff changeset
20 static struct vf_priv_s {
michael
parents:
diff changeset
21 uint8_t *buf[2];
michael
parents:
diff changeset
22 float hue;
michael
parents:
diff changeset
23 float saturation;
michael
parents:
diff changeset
24 } vf_priv_dflt = {
michael
parents:
diff changeset
25 {NULL, NULL},
michael
parents:
diff changeset
26 0.0,
michael
parents:
diff changeset
27 1.0,
michael
parents:
diff changeset
28 };
michael
parents:
diff changeset
29
michael
parents:
diff changeset
30 static void process_C(uint8_t *udst, uint8_t *vdst, uint8_t *usrc, uint8_t *vsrc, int dststride, int srcstride,
michael
parents:
diff changeset
31 int w, int h, float hue, float sat)
michael
parents:
diff changeset
32 {
michael
parents:
diff changeset
33 int i;
michael
parents:
diff changeset
34 const int s= rint(sin(hue) * (1<<16) * sat);
michael
parents:
diff changeset
35 const int c= rint(cos(hue) * (1<<16) * sat);
michael
parents:
diff changeset
36
michael
parents:
diff changeset
37 while (h--) {
michael
parents:
diff changeset
38 for (i = 0; i<w; i++)
michael
parents:
diff changeset
39 {
michael
parents:
diff changeset
40 const int u= usrc[i] - 128;
michael
parents:
diff changeset
41 const int v= vsrc[i] - 128;
michael
parents:
diff changeset
42 int new_u= (c*u - s*v + (1<<15) + (128<<16))>>16;
michael
parents:
diff changeset
43 int new_v= (s*u + c*v + (1<<15) + (128<<16))>>16;
michael
parents:
diff changeset
44 if(new_u & 768) new_u= (-new_u)>>31;
michael
parents:
diff changeset
45 if(new_v & 768) new_v= (-new_v)>>31;
michael
parents:
diff changeset
46 udst[i]= new_u;
michael
parents:
diff changeset
47 vdst[i]= new_v;
michael
parents:
diff changeset
48 }
michael
parents:
diff changeset
49 usrc += srcstride;
michael
parents:
diff changeset
50 vsrc += srcstride;
michael
parents:
diff changeset
51 udst += dststride;
michael
parents:
diff changeset
52 vdst += dststride;
michael
parents:
diff changeset
53 }
michael
parents:
diff changeset
54 }
michael
parents:
diff changeset
55
michael
parents:
diff changeset
56 static void (*process)(uint8_t *udst, uint8_t *vdst, uint8_t *usrc, uint8_t *vsrc, int dststride, int srcstride,
michael
parents:
diff changeset
57 int w, int h, float hue, float sat);
michael
parents:
diff changeset
58
michael
parents:
diff changeset
59 /* FIXME: add packed yuv version of process */
michael
parents:
diff changeset
60
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17012
diff changeset
61 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts)
11249
michael
parents:
diff changeset
62 {
michael
parents:
diff changeset
63 mp_image_t *dmpi;
michael
parents:
diff changeset
64
michael
parents:
diff changeset
65 dmpi=vf_get_image(vf->next, mpi->imgfmt,
michael
parents:
diff changeset
66 MP_IMGTYPE_EXPORT, 0,
michael
parents:
diff changeset
67 mpi->w, mpi->h);
michael
parents:
diff changeset
68
michael
parents:
diff changeset
69 dmpi->planes[0] = mpi->planes[0];
michael
parents:
diff changeset
70 dmpi->stride[0] = mpi->stride[0];
michael
parents:
diff changeset
71 dmpi->stride[1] = mpi->stride[1];
michael
parents:
diff changeset
72 dmpi->stride[2] = mpi->stride[2];
michael
parents:
diff changeset
73
michael
parents:
diff changeset
74 if (!vf->priv->buf[0]){
michael
parents:
diff changeset
75 vf->priv->buf[0] = malloc(mpi->stride[1]*mpi->h >> mpi->chroma_y_shift);
michael
parents:
diff changeset
76 vf->priv->buf[1] = malloc(mpi->stride[2]*mpi->h >> mpi->chroma_y_shift);
michael
parents:
diff changeset
77 }
michael
parents:
diff changeset
78
13232
4b7b0cb1d6f3 hue filter bugfix by ("James Crowson" <jbcrowso at ncsu dot edu>)
michael
parents: 11306
diff changeset
79 if (vf->priv->hue == 0 && vf->priv->saturation == 1){
11249
michael
parents:
diff changeset
80 dmpi->planes[1] = mpi->planes[1];
michael
parents:
diff changeset
81 dmpi->planes[2] = mpi->planes[2];
michael
parents:
diff changeset
82 }else {
michael
parents:
diff changeset
83 dmpi->planes[1] = vf->priv->buf[0];
michael
parents:
diff changeset
84 dmpi->planes[2] = vf->priv->buf[1];
michael
parents:
diff changeset
85 process(dmpi->planes[1], dmpi->planes[2],
michael
parents:
diff changeset
86 mpi->planes[1], mpi->planes[2],
michael
parents:
diff changeset
87 dmpi->stride[1],mpi->stride[1],
michael
parents:
diff changeset
88 mpi->w>> mpi->chroma_x_shift, mpi->h>> mpi->chroma_y_shift,
michael
parents:
diff changeset
89 vf->priv->hue, vf->priv->saturation);
michael
parents:
diff changeset
90 }
michael
parents:
diff changeset
91
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17012
diff changeset
92 return vf_next_put_image(vf,dmpi, pts);
11249
michael
parents:
diff changeset
93 }
michael
parents:
diff changeset
94
michael
parents:
diff changeset
95 static int control(struct vf_instance_s* vf, int request, void* data)
michael
parents:
diff changeset
96 {
michael
parents:
diff changeset
97 vf_equalizer_t *eq;
michael
parents:
diff changeset
98
michael
parents:
diff changeset
99 switch (request) {
michael
parents:
diff changeset
100 case VFCTRL_SET_EQUALIZER:
michael
parents:
diff changeset
101 eq = data;
michael
parents:
diff changeset
102 if (!strcmp(eq->item,"hue")) {
michael
parents:
diff changeset
103 vf->priv->hue = eq->value * M_PI / 100;
michael
parents:
diff changeset
104 return CONTROL_TRUE;
michael
parents:
diff changeset
105 } else if (!strcmp(eq->item,"saturation")) {
16305
514353affc6e Wrong scale conversion from VFCTRL_SET_EQUALIZER, priv->saturation should
reimar
parents: 14715
diff changeset
106 vf->priv->saturation = (eq->value + 100)/100.0;
11249
michael
parents:
diff changeset
107 return CONTROL_TRUE;
michael
parents:
diff changeset
108 }
michael
parents:
diff changeset
109 break;
michael
parents:
diff changeset
110 case VFCTRL_GET_EQUALIZER:
michael
parents:
diff changeset
111 eq = data;
michael
parents:
diff changeset
112 if (!strcmp(eq->item,"hue")) {
michael
parents:
diff changeset
113 eq->value = rint(vf->priv->hue *100 / M_PI);
michael
parents:
diff changeset
114 return CONTROL_TRUE;
michael
parents:
diff changeset
115 }else if (!strcmp(eq->item,"saturation")) {
michael
parents:
diff changeset
116 eq->value = rint(vf->priv->saturation*100 - 100);
michael
parents:
diff changeset
117 return CONTROL_TRUE;
michael
parents:
diff changeset
118 }
michael
parents:
diff changeset
119 break;
michael
parents:
diff changeset
120 }
michael
parents:
diff changeset
121 return vf_next_control(vf, request, data);
michael
parents:
diff changeset
122 }
michael
parents:
diff changeset
123
michael
parents:
diff changeset
124 static int query_format(struct vf_instance_s* vf, unsigned int fmt)
michael
parents:
diff changeset
125 {
michael
parents:
diff changeset
126 switch (fmt) {
michael
parents:
diff changeset
127 case IMGFMT_YVU9:
michael
parents:
diff changeset
128 case IMGFMT_IF09:
michael
parents:
diff changeset
129 case IMGFMT_YV12:
michael
parents:
diff changeset
130 case IMGFMT_I420:
michael
parents:
diff changeset
131 case IMGFMT_IYUV:
michael
parents:
diff changeset
132 case IMGFMT_CLPL:
michael
parents:
diff changeset
133 case IMGFMT_444P:
michael
parents:
diff changeset
134 case IMGFMT_422P:
michael
parents:
diff changeset
135 case IMGFMT_411P:
michael
parents:
diff changeset
136 return vf_next_query_format(vf, fmt);
michael
parents:
diff changeset
137 }
michael
parents:
diff changeset
138 return 0;
michael
parents:
diff changeset
139 }
michael
parents:
diff changeset
140
michael
parents:
diff changeset
141 static void uninit(struct vf_instance_s* vf)
michael
parents:
diff changeset
142 {
michael
parents:
diff changeset
143 if (vf->priv->buf[0]) free(vf->priv->buf[0]);
michael
parents:
diff changeset
144 if (vf->priv->buf[1]) free(vf->priv->buf[1]);
michael
parents:
diff changeset
145 free(vf->priv);
michael
parents:
diff changeset
146 }
michael
parents:
diff changeset
147
michael
parents:
diff changeset
148 static int open(vf_instance_t *vf, char* args)
michael
parents:
diff changeset
149 {
michael
parents:
diff changeset
150 vf->control=control;
michael
parents:
diff changeset
151 vf->query_format=query_format;
michael
parents:
diff changeset
152 vf->put_image=put_image;
michael
parents:
diff changeset
153 vf->uninit=uninit;
michael
parents:
diff changeset
154
michael
parents:
diff changeset
155 if(!vf->priv) {
michael
parents:
diff changeset
156 vf->priv = malloc(sizeof(struct vf_priv_s));
michael
parents:
diff changeset
157 memset(vf->priv, 0, sizeof(struct vf_priv_s));
michael
parents:
diff changeset
158 }
michael
parents:
diff changeset
159 if (args) sscanf(args, "%f:%f", &vf->priv->hue, &vf->priv->saturation);
michael
parents:
diff changeset
160 vf->priv->hue *= M_PI / 180.0;
michael
parents:
diff changeset
161
michael
parents:
diff changeset
162 process = process_C;
michael
parents:
diff changeset
163 #ifdef HAVE_MMXX
michael
parents:
diff changeset
164 if(gCpuCaps.hasMMX) process = process_MMX;
michael
parents:
diff changeset
165 #endif
michael
parents:
diff changeset
166
michael
parents:
diff changeset
167 return 1;
michael
parents:
diff changeset
168 }
michael
parents:
diff changeset
169
michael
parents:
diff changeset
170 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
michael
parents:
diff changeset
171 static m_option_t vf_opts_fields[] = {
michael
parents:
diff changeset
172 {"hue", ST_OFF(hue), CONF_TYPE_FLOAT, M_OPT_RANGE,-180.0 ,180.0, NULL},
michael
parents:
diff changeset
173 {"saturation", ST_OFF(saturation), CONF_TYPE_FLOAT, M_OPT_RANGE,-10.0 ,10.0, NULL},
michael
parents:
diff changeset
174 { NULL, NULL, 0, 0, 0, 0, NULL }
michael
parents:
diff changeset
175 };
michael
parents:
diff changeset
176
michael
parents:
diff changeset
177 static m_struct_t vf_opts = {
michael
parents:
diff changeset
178 "hue",
michael
parents:
diff changeset
179 sizeof(struct vf_priv_s),
michael
parents:
diff changeset
180 &vf_priv_dflt,
michael
parents:
diff changeset
181 vf_opts_fields
michael
parents:
diff changeset
182 };
michael
parents:
diff changeset
183
michael
parents:
diff changeset
184 vf_info_t vf_info_hue = {
michael
parents:
diff changeset
185 "hue changer",
michael
parents:
diff changeset
186 "hue",
michael
parents:
diff changeset
187 "Michael Niedermayer",
michael
parents:
diff changeset
188 "",
michael
parents:
diff changeset
189 open,
michael
parents:
diff changeset
190 &vf_opts
michael
parents:
diff changeset
191 };
michael
parents:
diff changeset
192