Mercurial > mplayer.hg
comparison libmpcodecs/vf_eq.c @ 7062:9eae15166ebb
soft video equalizer filter, currently supports brightness and
contrast adjustment for all planar yuv formats
author | rfelker |
---|---|
date | Wed, 21 Aug 2002 23:08:20 +0000 |
parents | |
children | 7685130ba4bd |
comparison
equal
deleted
inserted
replaced
7061:33624384dd7b | 7062:9eae15166ebb |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <inttypes.h> | |
5 | |
6 #include "../config.h" | |
7 #include "../mp_msg.h" | |
8 | |
9 #include "img_format.h" | |
10 #include "mp_image.h" | |
11 #include "vf.h" | |
12 | |
13 #include "../libvo/video_out.h" | |
14 #include "../libvo/fastmemcpy.h" | |
15 #include "../postproc/rgb2rgb.h" | |
16 | |
17 struct vf_priv_s { | |
18 unsigned char *buf; | |
19 int brightness; | |
20 int contrast; | |
21 }; | |
22 | |
23 static void process(unsigned char *dest, int dstride, unsigned char *src, int sstride, | |
24 int w, int h, int brightness, int contrast) | |
25 { | |
26 int i; | |
27 int pel; | |
28 int dstep = dstride-w; | |
29 int sstep = sstride-w; | |
30 | |
31 brightness = ((brightness+100)*511)/200-128; | |
32 contrast = ((contrast+100)*512)/200; | |
33 | |
34 while (h--) { | |
35 for (i = w; i; i--) | |
36 { | |
37 /* slow */ | |
38 pel = ((*src++ - 128) * contrast)/256 + brightness; | |
39 *dest++ = pel > 255 ? 255 : (pel < 0 ? 0 : pel); | |
40 } | |
41 src += sstep; | |
42 dest += dstep; | |
43 } | |
44 } | |
45 | |
46 /* FIXME: add packed yuv version of process, and optimized code! */ | |
47 | |
48 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi) | |
49 { | |
50 mp_image_t *dmpi; | |
51 | |
52 dmpi=vf_get_image(vf->next, mpi->imgfmt, | |
53 MP_IMGTYPE_EXPORT, 0, | |
54 mpi->w, mpi->h); | |
55 | |
56 dmpi->stride[0] = mpi->stride[0]; | |
57 dmpi->planes[1] = mpi->planes[1]; | |
58 dmpi->planes[2] = mpi->planes[2]; | |
59 dmpi->stride[1] = mpi->stride[1]; | |
60 dmpi->stride[2] = mpi->stride[2]; | |
61 | |
62 if (!vf->priv->buf) vf->priv->buf = malloc(mpi->stride[0]*mpi->h); | |
63 | |
64 if ((vf->priv->brightness == 0) && (vf->priv->contrast == 0)) | |
65 dmpi->planes[0] = mpi->planes[0]; | |
66 else { | |
67 dmpi->planes[0] = vf->priv->buf; | |
68 process(dmpi->planes[0], dmpi->stride[0], | |
69 mpi->planes[0], mpi->stride[0], | |
70 mpi->w, mpi->h, vf->priv->brightness, | |
71 vf->priv->contrast); | |
72 } | |
73 | |
74 vf_next_put_image(vf,dmpi); | |
75 } | |
76 | |
77 static int control(struct vf_instance_s* vf, int request, void* data) | |
78 { | |
79 vf_equalizer_t *eq; | |
80 | |
81 switch (request) { | |
82 case VFCTRL_SET_EQUALIZER: | |
83 eq = data; | |
84 if (!strcmp(eq->item,"brightness")) { | |
85 vf->priv->brightness = eq->value; | |
86 return CONTROL_TRUE; | |
87 } | |
88 else if (!strcmp(eq->item,"contrast")) { | |
89 vf->priv->contrast = eq->value; | |
90 return CONTROL_TRUE; | |
91 } | |
92 break; | |
93 case VFCTRL_GET_EQUALIZER: | |
94 eq = data; | |
95 if (!strcmp(eq->item,"brightness")) { | |
96 eq->value = vf->priv->brightness; | |
97 return CONTROL_TRUE; | |
98 } | |
99 else if (!strcmp(eq->item,"contrast")) { | |
100 eq->value = vf->priv->contrast; | |
101 return CONTROL_TRUE; | |
102 } | |
103 break; | |
104 } | |
105 return vf_next_control(vf, request, data); | |
106 } | |
107 | |
108 static int query_format(struct vf_instance_s* vf, unsigned int fmt) | |
109 { | |
110 switch (fmt) { | |
111 case IMGFMT_YVU9: | |
112 case IMGFMT_IF09: | |
113 case IMGFMT_YV12: | |
114 case IMGFMT_I420: | |
115 case IMGFMT_IYUV: | |
116 case IMGFMT_CLPL: | |
117 case IMGFMT_Y800: | |
118 case IMGFMT_Y8: | |
119 case IMGFMT_NV12: | |
120 case IMGFMT_444P: | |
121 case IMGFMT_422P: | |
122 case IMGFMT_411P: | |
123 return vf_next_query_format(vf, fmt); | |
124 } | |
125 return 0; | |
126 } | |
127 | |
128 static void uninit(struct vf_instance_s* vf) | |
129 { | |
130 if (vf->priv->buf) free(vf->priv->buf); | |
131 free(vf->priv); | |
132 } | |
133 | |
134 static int open(vf_instance_t *vf, char* args) | |
135 { | |
136 vf->control=control; | |
137 vf->query_format=query_format; | |
138 vf->put_image=put_image; | |
139 vf->uninit=uninit; | |
140 | |
141 vf->priv = malloc(sizeof(struct vf_priv_s)); | |
142 memset(vf->priv, 0, sizeof(struct vf_priv_s)); | |
143 if (args) sscanf(args, "%d:%d", &vf->priv->brightness, &vf->priv->contrast); | |
144 return 1; | |
145 } | |
146 | |
147 vf_info_t vf_info_eq = { | |
148 "soft video equalizer", | |
149 "eq", | |
150 "Richard Felker", | |
151 "", | |
152 open | |
153 }; | |
154 |