Mercurial > mplayer.hg
annotate libmpcodecs/vf_eq2.c @ 10493:40df234f2d30
translation by Juan Martin <nauj27@teleline.es> and Andoni Zubimendi
author | diego |
---|---|
date | Mon, 28 Jul 2003 02:24:05 +0000 |
parents | e9a2af584986 |
children | 8af26336d9f7 |
rev | line source |
---|---|
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
1 /* |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
2 * vf_eq2.c |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
3 * |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
4 * Software equalizer (brightness, contrast, gamma, saturation) |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
5 * |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
6 * Hampa Hug <hampa@hampa.ch> (original LUT gamma/contrast/brightness filter) |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
7 * Daniel Moreno <comac@comac.darktech.org> (saturation, R/G/B gamma support) |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
8 * Richard Felker (original MMX contrast/brightness code (vf_eq.c)) |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
9 */ |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
10 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
11 #include <stdio.h> |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
12 #include <stdlib.h> |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
13 #include <string.h> |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
14 #include <math.h> |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
15 |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
16 #include "config.h" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
17 #include "mp_msg.h" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
18 #include "cpudetect.h" |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
19 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
20 #include "img_format.h" |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
21 #include "mp_image.h" |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
22 #include "vf.h" |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
23 |
8087 | 24 #ifdef USE_SETLOCALE |
25 #include <locale.h> | |
26 #endif | |
27 | |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
28 |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
29 /* Per channel parameters */ |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
30 typedef struct eq2_param_t { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
31 unsigned char lut[256]; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
32 int lut_clean; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
33 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
34 void (*adjust) (struct eq2_param_t *par, unsigned char *dst, unsigned char *src, |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
35 unsigned w, unsigned h, unsigned dstride, unsigned sstride); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
36 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
37 double c; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
38 double b; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
39 double g; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
40 } eq2_param_t; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
41 |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
42 typedef struct vf_priv_s { |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
43 eq2_param_t param[3]; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
44 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
45 double contrast; |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
46 double brightness; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
47 double saturation; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
48 |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
49 double gamma; |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
50 double rgamma; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
51 double ggamma; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
52 double bgamma; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
53 |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
54 unsigned buf_w[3]; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
55 unsigned buf_h[3]; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
56 unsigned char *buf[3]; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
57 } vf_eq2_t; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
58 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
59 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
60 static |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
61 void create_lut (eq2_param_t *par) |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
62 { |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
63 unsigned i; |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
64 double g, v; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
65 |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
66 g = par->g; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
67 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
68 if ((g < 0.001) || (g > 1000.0)) { |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
69 g = 1.0; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
70 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
71 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
72 g = 1.0 / g; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
73 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
74 for (i = 0; i < 256; i++) { |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
75 v = (double) i / 255.0; |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
76 v = par->c * (v - 0.5) + 0.5 + par->b; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
77 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
78 if (v <= 0.0) { |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
79 par->lut[i] = 0; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
80 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
81 else { |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
82 v = pow (v, g); |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
83 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
84 if (v >= 1.0) { |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
85 par->lut[i] = 255; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
86 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
87 else { |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
88 par->lut[i] = (unsigned char) (256.0 * v); |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
89 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
90 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
91 } |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
92 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
93 par->lut_clean = 1; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
94 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
95 |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
96 #ifdef HAVE_MMX |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
97 static |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
98 void affine_1d_MMX (eq2_param_t *par, unsigned char *dst, unsigned char *src, |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
99 unsigned w, unsigned h, unsigned dstride, unsigned sstride) |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
100 { |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
101 unsigned i; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
102 int contrast, brightness; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
103 unsigned dstep, sstep; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
104 int pel; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
105 short brvec[4]; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
106 short contvec[4]; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
107 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
108 // printf("\nmmx: src=%p dst=%p w=%d h=%d ds=%d ss=%d\n",src,dst,w,h,dstride,sstride); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
109 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
110 contrast = (int) (par->c * 256 * 16); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
111 brightness = ((int) (100.0 * par->b + 100.0) * 511) / 200 - 128 - contrast / 32; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
112 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
113 brvec[0] = brvec[1] = brvec[2] = brvec[3] = brightness; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
114 contvec[0] = contvec[1] = contvec[2] = contvec[3] = contrast; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
115 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
116 sstep = sstride - w; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
117 dstep = dstride - w; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
118 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
119 while (h-- > 0) { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
120 asm volatile ( |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
121 "movq (%5), %%mm3 \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
122 "movq (%6), %%mm4 \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
123 "pxor %%mm0, %%mm0 \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
124 "movl %4, %%eax\n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
125 ".balign 16 \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
126 "1: \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
127 "movq (%0), %%mm1 \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
128 "movq (%0), %%mm2 \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
129 "punpcklbw %%mm0, %%mm1 \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
130 "punpckhbw %%mm0, %%mm2 \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
131 "psllw $4, %%mm1 \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
132 "psllw $4, %%mm2 \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
133 "pmulhw %%mm4, %%mm1 \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
134 "pmulhw %%mm4, %%mm2 \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
135 "paddw %%mm3, %%mm1 \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
136 "paddw %%mm3, %%mm2 \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
137 "packuswb %%mm2, %%mm1 \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
138 "addl $8, %0 \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
139 "movq %%mm1, (%1) \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
140 "addl $8, %1 \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
141 "decl %%eax \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
142 "jnz 1b \n\t" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
143 : "=r" (src), "=r" (dst) |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
144 : "0" (src), "1" (dst), "r" (w >> 3), "r" (brvec), "r" (contvec) |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
145 : "%eax" |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
146 ); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
147 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
148 for (i = w & 7; i > 0; i--) { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
149 pel = ((*src++ * contrast) >> 12) + brightness; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
150 if (pel & 768) { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
151 pel = (-pel) >> 31; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
152 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
153 *dst++ = pel; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
154 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
155 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
156 src += sstep; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
157 dst += dstep; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
158 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
159 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
160 asm volatile ( "emms \n\t" ::: "memory" ); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
161 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
162 #endif |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
163 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
164 static |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
165 void apply_lut (eq2_param_t *par, unsigned char *dst, unsigned char *src, |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
166 unsigned w, unsigned h, unsigned dstride, unsigned sstride) |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
167 { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
168 unsigned i, j; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
169 unsigned char *lut; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
170 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
171 if (!par->lut_clean) { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
172 create_lut (par); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
173 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
174 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
175 lut = par->lut; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
176 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
177 for (j = 0; j < h; j++) { |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
178 for (i = 0; i < w; i++) { |
8349
916d5392dcc9
- It fixes a small bug where a byte value is divided by 255.0 to convert
arpi
parents:
8087
diff
changeset
|
179 dst[i] = lut[src[i]]; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
180 } |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
181 |
8349
916d5392dcc9
- It fixes a small bug where a byte value is divided by 255.0 to convert
arpi
parents:
8087
diff
changeset
|
182 src += sstride; |
916d5392dcc9
- It fixes a small bug where a byte value is divided by 255.0 to convert
arpi
parents:
8087
diff
changeset
|
183 dst += dstride; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
184 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
185 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
186 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
187 static |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
188 int put_image (vf_instance_t *vf, mp_image_t *src) |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
189 { |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
190 unsigned i; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
191 vf_eq2_t *eq2; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
192 mp_image_t *dst; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
193 unsigned long img_n,img_c; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
194 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
195 eq2 = vf->priv; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
196 |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
197 if ((eq2->buf_w[0] != src->w) || (eq2->buf_h[0] != src->h)) { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
198 eq2->buf_w[0] = src->w; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
199 eq2->buf_h[0] = src->h; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
200 eq2->buf_w[1] = eq2->buf_w[2] = src->w >> src->chroma_x_shift; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
201 eq2->buf_h[1] = eq2->buf_h[2] = src->h >> src->chroma_y_shift; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
202 img_n = eq2->buf_w[0]*eq2->buf_h[0]; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
203 if(src->num_planes>1){ |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
204 img_c = eq2->buf_w[1]*eq2->buf_h[1]; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
205 eq2->buf[0] = (unsigned char *) realloc (eq2->buf[0], img_n + 2*img_c); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
206 eq2->buf[1] = eq2->buf[0] + img_n; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
207 eq2->buf[2] = eq2->buf[1] + img_c; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
208 } else |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
209 eq2->buf[0] = (unsigned char *) realloc (eq2->buf[0], img_n); |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
210 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
211 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
212 dst = vf_get_image (vf->next, src->imgfmt, MP_IMGTYPE_EXPORT, 0, src->w, src->h); |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
213 |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
214 for (i = 0; i < ((src->num_planes>1)?3:1); i++) { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
215 if (eq2->param[i].adjust != NULL) { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
216 dst->planes[i] = eq2->buf[i]; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
217 dst->stride[i] = eq2->buf_w[i]; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
218 |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
219 eq2->param[i].adjust (&eq2->param[i], dst->planes[i], src->planes[i], |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
220 eq2->buf_w[i], eq2->buf_h[i], dst->stride[i], src->stride[i]); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
221 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
222 else { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
223 dst->planes[i] = src->planes[i]; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
224 dst->stride[i] = src->stride[i]; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
225 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
226 } |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
227 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
228 return vf_next_put_image (vf, dst); |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
229 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
230 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
231 static |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
232 void check_values (eq2_param_t *par) |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
233 { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
234 /* yuck! floating point comparisons... */ |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
235 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
236 if ((par->c == 1.0) && (par->b == 0.0) && (par->g == 1.0)) { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
237 par->adjust = NULL; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
238 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
239 #ifdef HAVE_MMX |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
240 else if (par->g == 1.0 && gCpuCaps.hasMMX) { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
241 par->adjust = &affine_1d_MMX; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
242 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
243 #endif |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
244 else { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
245 par->adjust = &apply_lut; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
246 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
247 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
248 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
249 static |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
250 void print_values (vf_eq2_t *eq2) |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
251 { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
252 mp_msg (MSGT_VFILTER, MSGL_V, "vf_eq2: c=%.2f b=%.2f g=%.4f s=%.2f \n", |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
253 eq2->contrast, eq2->brightness, eq2->gamma, eq2->saturation |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
254 ); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
255 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
256 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
257 static |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
258 void set_contrast (vf_eq2_t *eq2, double c) |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
259 { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
260 eq2->contrast = c; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
261 eq2->param[0].c = c; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
262 eq2->param[0].lut_clean = 0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
263 check_values (&eq2->param[0]); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
264 print_values (eq2); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
265 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
266 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
267 static |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
268 void set_brightness (vf_eq2_t *eq2, double b) |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
269 { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
270 eq2->brightness = b; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
271 eq2->param[0].b = b; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
272 eq2->param[0].lut_clean = 0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
273 check_values (&eq2->param[0]); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
274 print_values (eq2); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
275 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
276 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
277 static |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
278 void set_gamma (vf_eq2_t *eq2, double g) |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
279 { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
280 eq2->gamma = g; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
281 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
282 eq2->param[0].g = eq2->gamma * eq2->ggamma; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
283 eq2->param[1].g = sqrt (eq2->bgamma / eq2->ggamma); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
284 eq2->param[2].g = sqrt (eq2->rgamma / eq2->ggamma); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
285 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
286 eq2->param[0].lut_clean = 0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
287 eq2->param[1].lut_clean = 0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
288 eq2->param[2].lut_clean = 0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
289 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
290 check_values (&eq2->param[0]); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
291 check_values (&eq2->param[1]); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
292 check_values (&eq2->param[2]); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
293 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
294 print_values (eq2); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
295 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
296 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
297 static |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
298 void set_saturation (vf_eq2_t *eq2, double s) |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
299 { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
300 eq2->saturation = s; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
301 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
302 eq2->param[1].c = s; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
303 eq2->param[2].c = s; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
304 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
305 eq2->param[1].lut_clean = 0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
306 eq2->param[2].lut_clean = 0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
307 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
308 check_values (&eq2->param[1]); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
309 check_values (&eq2->param[2]); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
310 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
311 print_values (eq2); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
312 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
313 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
314 static |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
315 int control (vf_instance_t *vf, int request, void *data) |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
316 { |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
317 vf_equalizer_t *eq; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
318 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
319 switch (request) { |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
320 case VFCTRL_SET_EQUALIZER: |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
321 eq = (vf_equalizer_t *) data; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
322 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
323 if (strcmp (eq->item, "gamma") == 0) { |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
324 set_gamma (vf->priv, exp (log (8.0) * eq->value / 100.0)); |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
325 return CONTROL_TRUE; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
326 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
327 else if (strcmp (eq->item, "contrast") == 0) { |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
328 set_contrast (vf->priv, (1.0 / 100.0) * (eq->value + 100)); |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
329 return CONTROL_TRUE; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
330 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
331 else if (strcmp (eq->item, "brightness") == 0) { |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
332 set_brightness (vf->priv, (1.0 / 100.0) * eq->value); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
333 return CONTROL_TRUE; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
334 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
335 else if (strcmp (eq->item, "saturation") == 0) { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
336 set_saturation (vf->priv, (double) (eq->value + 100) / 100.0); |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
337 return CONTROL_TRUE; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
338 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
339 break; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
340 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
341 case VFCTRL_GET_EQUALIZER: |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
342 eq = (vf_equalizer_t *) data; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
343 if (strcmp (eq->item, "gamma") == 0) { |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
344 eq->value = (int) (100.0 * log (vf->priv->gamma) / log (8.0)); |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
345 return CONTROL_TRUE; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
346 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
347 else if (strcmp (eq->item, "contrast") == 0) { |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
348 eq->value = (int) (100.0 * vf->priv->contrast) - 100; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
349 return CONTROL_TRUE; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
350 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
351 else if (strcmp (eq->item, "brightness") == 0) { |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
352 eq->value = (int) (100.0 * vf->priv->brightness); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
353 return CONTROL_TRUE; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
354 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
355 else if (strcmp (eq->item, "saturation") == 0) { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
356 eq->value = (int) (100.0 * vf->priv->saturation) - 100; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
357 return CONTROL_TRUE; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
358 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
359 break; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
360 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
361 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
362 return vf_next_control (vf, request, data); |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
363 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
364 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
365 static |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
366 int query_format (vf_instance_t *vf, unsigned fmt) |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
367 { |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
368 switch (fmt) { |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
369 case IMGFMT_YVU9: |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
370 case IMGFMT_IF09: |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
371 case IMGFMT_YV12: |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
372 case IMGFMT_I420: |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
373 case IMGFMT_IYUV: |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
374 case IMGFMT_Y800: |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
375 case IMGFMT_Y8: |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
376 case IMGFMT_444P: |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
377 case IMGFMT_422P: |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
378 case IMGFMT_411P: |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
379 return vf_next_query_format (vf, fmt); |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
380 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
381 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
382 return 0; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
383 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
384 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
385 static |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
386 void uninit (vf_instance_t *vf) |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
387 { |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
388 if (vf->priv != NULL) { |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
389 free (vf->priv->buf[0]); |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
390 free (vf->priv); |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
391 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
392 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
393 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
394 static |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
395 int open (vf_instance_t *vf, char *args) |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
396 { |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
397 unsigned i; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
398 vf_eq2_t *eq2; |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
399 double par[7]; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
400 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
401 vf->control = control; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
402 vf->query_format = query_format; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
403 vf->put_image = put_image; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
404 vf->uninit = uninit; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
405 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
406 vf->priv = (vf_eq2_t *) malloc (sizeof (vf_eq2_t)); |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
407 eq2 = vf->priv; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
408 |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
409 for (i = 0; i < 3; i++) { |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
410 eq2->buf[i] = NULL; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
411 eq2->buf_w[i] = 0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
412 eq2->buf_h[i] = 0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
413 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
414 eq2->param[i].adjust = NULL; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
415 eq2->param[i].c = 1.0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
416 eq2->param[i].b = 0.0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
417 eq2->param[i].g = 1.0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
418 eq2->param[i].lut_clean = 0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
419 } |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
420 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
421 eq2->contrast = 1.0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
422 eq2->brightness = 0.0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
423 eq2->saturation = 1.0; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
424 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
425 eq2->gamma = 1.0; |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
426 eq2->rgamma = 1.0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
427 eq2->ggamma = 1.0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
428 eq2->bgamma = 1.0; |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
429 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
430 if (args != NULL) { |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
431 par[0] = 1.0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
432 par[1] = 1.0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
433 par[2] = 0.0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
434 par[3] = 1.0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
435 par[4] = 1.0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
436 par[5] = 1.0; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
437 par[6] = 1.0; |
8087 | 438 #ifdef USE_SETLOCALE |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
439 setlocale (LC_NUMERIC, "C"); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
440 #endif |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
441 sscanf (args, "%lf:%lf:%lf:%lf:%lf:%lf:%lf", |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
442 par, par + 1, par + 2, par + 3, par + 4, par + 5, par + 6 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
443 ); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
444 #ifdef USE_SETLOCALE |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
445 setlocale (LC_NUMERIC, ""); |
8087 | 446 #endif |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
447 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
448 eq2->rgamma = par[4]; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
449 eq2->ggamma = par[5]; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
450 eq2->bgamma = par[6]; |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
451 |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
452 set_gamma (eq2, par[0]); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
453 set_contrast (eq2, par[1]); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
454 set_brightness (eq2, par[2]); |
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
455 set_saturation (eq2, par[3]); |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
456 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
457 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
458 return 1; |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
459 } |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
460 |
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
461 vf_info_t vf_info_eq2 = { |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
462 "Software equalizer", |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
463 "eq2", |
9213
601ed700e1cc
Based on the discussion in the other thread I made a new
arpi
parents:
8349
diff
changeset
|
464 "Hampa Hug, Daniel Moreno, Richard Felker", |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
465 "", |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9213
diff
changeset
|
466 &open, |
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9213
diff
changeset
|
467 NULL |
7517
9d433771b6d0
-vf eq2, LUT-based brightness/contrast/gamma correction (Y-only)
arpi
parents:
diff
changeset
|
468 }; |